Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19ea2e0d authored by Freeman Ng's avatar Freeman Ng
Browse files

Give all PreferenceActivity subclasses ability to be launched in wizard mode with Back/Next buttons

Change-Id: Ifc8c22c70e808629a9a889406f17a962615e2574
parent d784cc4a
Loading
Loading
Loading
Loading
+95 −29
Original line number Diff line number Diff line
@@ -23,7 +23,10 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * Shows a hierarchy of {@link Preference} objects as
@@ -78,6 +81,19 @@ public abstract class PreferenceActivity extends ListActivity implements

    private static final String PREFERENCES_TAG = "android:preferences";

    // extras that allow any preference activity to be launched as part of a wizard

    // show Back and Next buttons? takes boolean parameter
    // Back will then return RESULT_CANCELED and Next RESULT_OK
    private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar";

    // specify custom text for the Back or Next buttons, or cause a button to not appear
    // at all by setting it to null
    private static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text";
    private static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text";

    private Button mNextButton;

    private PreferenceManager mPreferenceManager;

    private Bundle mSavedInstanceState;
@@ -106,6 +122,48 @@ public abstract class PreferenceActivity extends ListActivity implements

        setContentView(com.android.internal.R.layout.preference_list_content);

        // see if we should show Back/Next buttons
        Intent intent = getIntent();
        if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {

            findViewById(com.android.internal.R.id.button_bar).setVisibility(View.VISIBLE);

            Button backButton = (Button)findViewById(com.android.internal.R.id.back_button);
            backButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setResult(RESULT_CANCELED);
                    finish();
                }
            });
            mNextButton = (Button)findViewById(com.android.internal.R.id.next_button);
            mNextButton.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    setResult(RESULT_OK);
                    finish();
                }
            });

            // set our various button parameters
            if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    mNextButton.setVisibility(View.GONE);
                }
                else {
                    mNextButton.setText(buttonText);
                }
            }
            if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    backButton.setVisibility(View.GONE);
                }
                else {
                    backButton.setText(buttonText);
                }
            }
        }

        mPreferenceManager = onCreatePreferenceManager();
        getListView().setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    }
@@ -120,7 +178,6 @@ public abstract class PreferenceActivity extends ListActivity implements
    @Override
    protected void onDestroy() {
        super.onDestroy();
        
        mPreferenceManager.dispatchActivityDestroy();
    }

@@ -293,4 +350,13 @@ public abstract class PreferenceActivity extends ListActivity implements
        }
    }

    // give subclasses access to the Next button
    /** @hide */
    protected boolean hasNextButton() {
        return mNextButton != null;
    }
    /** @hide */
    protected Button getNextButton() {
        return mNextButton;
    }
}
+906 B
Loading image diff...
+779 B
Loading image diff...
+48 −12
Original line number Diff line number Diff line
@@ -17,9 +17,45 @@
** limitations under the License.
*/
-->
<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list"
    android:layout_width="match_parent" 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"
        android:scrollbarAlwaysDrawVerticalTrack="true"
    />

    <RelativeLayout android:id="@+id/button_bar"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:layout_weight="0"
        android:background="@android:drawable/bottom_bar"
        android:visibility="gone">

        <Button android:id="@+id/back_button"
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:layout_margin="5dip"
            android:layout_alignParentLeft="true"
            android:drawableLeft="@drawable/ic_btn_back"
            android:drawablePadding="3dip"
            android:text="@string/back_button_label"
        />

        <Button android:id="@+id/next_button"
            android:layout_width="150dip"
            android:layout_height="wrap_content"
            android:layout_margin="5dip"
            android:layout_alignParentRight="true"
            android:drawableRight="@drawable/ic_btn_next"
            android:drawablePadding="3dip"
            android:text="@string/next_button_label"
        />
    </RelativeLayout>
</LinearLayout>
+4 −0
Original line number Diff line number Diff line
@@ -2257,4 +2257,8 @@
    <!-- Shown when the device is tethered -->
    <string name="tethered_notification_title">Tethering active</string>
    <string name="tethered_notification_message">Touch to configure</string>

    <!--  Strings for possible PreferenceActivity Back/Next buttons -->
    <string name="back_button_label">Back</string>
    <string name="next_button_label">Next</string>
</resources>