droidchef / android-lockpattern

Automatically exported from code.google.com/p/android-lockpattern
Apache License 2.0
0 stars 0 forks source link

start from preference screen #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

How could I start it from a preference screen?

Thanks

Original issue reported on code.google.com by rojas....@gmail.com on 10 May 2013 at 5:43

GoogleCodeExporter commented 9 years ago
Hi @rojas...,

For example here is an XML file for a PreferenceActivity (pre Honeycomb), we 
name it `res/xml/your_preferences.xml`:

    <?xml version="1.0" encoding="utf-8"?>
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="Settings" >

        <Preference
            android:key="pkey_lock_pattern_change_pattern"
            android:title="Change pattern" />
    </PreferenceScreen>

In your PreferenceActivity, you load it with:

    import android.preference.Preference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.your_preferences);

        findPreference("pkey_lock_pattern_change_pattern")
                .setOnPreferenceClickListener(
                        new Preference.OnPreferenceClickListener() {

                            @Override
                            public boolean onPreferenceClick(
                                    Preference preference) {
                                // Start LockPatternActivity here...
                                return true;
                            }// onPreferenceClick()
                        });
    }// onCreate()

I hardcoded some strings, you might want to put them into 
`res/values/strings.xml`. With Honeycomb+, you do the same in your 
`PreferenceFragment`'s.

Hope this helps  :-)

Have a nice day,
Hai

Original comment by haibison...@gmail.com on 10 May 2013 at 5:58

GoogleCodeExporter commented 9 years ago

Original comment by haibison...@gmail.com on 10 May 2013 at 3:29

GoogleCodeExporter commented 9 years ago
Thanks, that was easy!

Excellent library by the way!

Original comment by rojas....@gmail.com on 11 May 2013 at 4:10

GoogleCodeExporter commented 9 years ago
I've added some changes to the 
[https://code.google.com/p/android-lockpattern/source/browse/demo demo project] 
which make use of `PreferenceActivity` and `PreferenceFragment`'s. Though it's 
a little complicated  :-D

You might want to download the demo APK in 
[https://code.google.com/p/android-lockpattern/downloads/list Downloads] 
section or on 
[https://play.google.com/store/apps/details?id=group.pals.android.lib.ui.lockpat
tern.demo Google Play]  :-)

Original comment by haibison...@gmail.com on 21 May 2013 at 1:48

GoogleCodeExporter commented 9 years ago
Thanks, I'll check it out. Nice job!

Original comment by rojas....@gmail.com on 22 May 2013 at 2:12