The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.preference; |
| 18 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 19 | import com.android.internal.util.XmlUtils; |
| 20 | |
| 21 | import org.xmlpull.v1.XmlPullParser; |
| 22 | import org.xmlpull.v1.XmlPullParserException; |
| 23 | |
| 24 | import android.app.Fragment; |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 25 | import android.app.FragmentBreadCrumbs; |
Dianne Hackborn | 3a57fb9 | 2010-11-15 17:58:52 -0800 | [diff] [blame] | 26 | import android.app.FragmentManager; |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 27 | import android.app.FragmentTransaction; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.app.ListActivity; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 29 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.content.Intent; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 32 | import android.content.res.Resources; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 33 | import android.content.res.TypedArray; |
| 34 | import android.content.res.XmlResourceParser; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.os.Bundle; |
| 36 | import android.os.Handler; |
| 37 | import android.os.Message; |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 38 | import android.os.Parcel; |
| 39 | import android.os.Parcelable; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 40 | import android.text.TextUtils; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 41 | import android.util.AttributeSet; |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 42 | import android.util.TypedValue; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 43 | import android.util.Xml; |
| 44 | import android.view.LayoutInflater; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.view.View; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 46 | import android.view.View.OnClickListener; |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 47 | import android.view.ViewGroup; |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 48 | import android.widget.AbsListView; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 49 | import android.widget.ArrayAdapter; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 50 | import android.widget.Button; |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 51 | import android.widget.FrameLayout; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 52 | import android.widget.ImageView; |
| 53 | import android.widget.ListView; |
| 54 | import android.widget.TextView; |
| 55 | |
| 56 | import java.io.IOException; |
| 57 | import java.util.ArrayList; |
| 58 | import java.util.List; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 61 | * This is the base class for an activity to show a hierarchy of preferences |
| 62 | * to the user. Prior to {@link android.os.Build.VERSION_CODES#HONEYCOMB} |
| 63 | * this class only allowed the display of a single set of preference; this |
| 64 | * functionality should now be found in the new {@link PreferenceFragment} |
| 65 | * class. If you are using PreferenceActivity in its old mode, the documentation |
| 66 | * there applies to the deprecated APIs here. |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 67 | * |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 68 | * <p>This activity shows one or more headers of preferences, each of with |
| 69 | * is associated with a {@link PreferenceFragment} to display the preferences |
| 70 | * of that header. The actual layout and display of these associations can |
| 71 | * however vary; currently there are two major approaches it may take: |
| 72 | * |
| 73 | * <ul> |
| 74 | * <li>On a small screen it may display only the headers as a single list |
| 75 | * when first launched. Selecting one of the header items will re-launch |
| 76 | * the activity with it only showing the PreferenceFragment of that header. |
| 77 | * <li>On a large screen in may display both the headers and current |
| 78 | * PreferenceFragment together as panes. Selecting a header item switches |
| 79 | * to showing the correct PreferenceFragment for that item. |
| 80 | * </ul> |
| 81 | * |
| 82 | * <p>Subclasses of PreferenceActivity should implement |
| 83 | * {@link #onBuildHeaders} to populate the header list with the desired |
| 84 | * items. Doing this implicitly switches the class into its new "headers |
| 85 | * + fragments" mode rather than the old style of just showing a single |
| 86 | * preferences list. |
| 87 | * |
| 88 | * <a name="SampleCode"></a> |
| 89 | * <h3>Sample Code</h3> |
| 90 | * |
| 91 | * <p>The following sample code shows a simple preference activity that |
| 92 | * has two different sets of preferences. The implementation, consisting |
| 93 | * of the activity itself as well as its two preference fragments is:</p> |
| 94 | * |
| 95 | * {@sample development/samples/ApiDemos/src/com/example/android/apis/preference/PreferenceWithHeaders.java |
| 96 | * activity} |
| 97 | * |
| 98 | * <p>The preference_headers resource describes the headers to be displayed |
| 99 | * and the fragments associated with them. It is: |
| 100 | * |
| 101 | * {@sample development/samples/ApiDemos/res/xml/preference_headers.xml headers} |
| 102 | * |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 103 | * <p>The first header is shown by Prefs1Fragment, which populates itself |
| 104 | * from the following XML resource:</p> |
| 105 | * |
| 106 | * {@sample development/samples/ApiDemos/res/xml/fragmented_preferences.xml preferences} |
| 107 | * |
| 108 | * <p>Note that this XML resource contains a preference screen holding another |
| 109 | * fragment, the Prefs1FragmentInner implemented here. This allows the user |
| 110 | * to traverse down a hierarchy of preferences; pressing back will pop each |
| 111 | * fragment off the stack to return to the previous preferences. |
| 112 | * |
| 113 | * <p>See {@link PreferenceFragment} for information on implementing the |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 114 | * fragments themselves. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | */ |
| 116 | public abstract class PreferenceActivity extends ListActivity implements |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 117 | PreferenceManager.OnPreferenceTreeClickListener, |
| 118 | PreferenceFragment.OnPreferenceStartFragmentCallback { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 119 | private static final String TAG = "PreferenceActivity"; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 120 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 121 | // Constants for state save/restore |
| 122 | private static final String HEADERS_TAG = ":android:headers"; |
| 123 | private static final String CUR_HEADER_TAG = ":android:cur_header"; |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 124 | private static final String PREFERENCES_TAG = ":android:preferences"; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 125 | |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 126 | /** |
| 127 | * When starting this activity, the invoking Intent can contain this extra |
| 128 | * string to specify which fragment should be initially displayed. |
| 129 | */ |
| 130 | public static final String EXTRA_SHOW_FRAGMENT = ":android:show_fragment"; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 131 | |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 132 | /** |
| 133 | * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, |
| 134 | * this extra can also be specify to supply a Bundle of arguments to pass |
| 135 | * to that fragment when it is instantiated during the initial creation |
| 136 | * of PreferenceActivity. |
| 137 | */ |
| 138 | public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":android:show_fragment_args"; |
| 139 | |
| 140 | /** |
| 141 | * When starting this activity, the invoking Intent can contain this extra |
| 142 | * boolean that the header list should not be displayed. This is most often |
| 143 | * used in conjunction with {@link #EXTRA_SHOW_FRAGMENT} to launch |
| 144 | * the activity to display a specific fragment that the user has navigated |
| 145 | * to. |
| 146 | */ |
| 147 | public static final String EXTRA_NO_HEADERS = ":android:no_headers"; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 148 | |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 149 | private static final String BACK_STACK_PREFS = ":android:prefs"; |
| 150 | |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 151 | // extras that allow any preference activity to be launched as part of a wizard |
| 152 | |
| 153 | // show Back and Next buttons? takes boolean parameter |
| 154 | // Back will then return RESULT_CANCELED and Next RESULT_OK |
| 155 | private static final String EXTRA_PREFS_SHOW_BUTTON_BAR = "extra_prefs_show_button_bar"; |
| 156 | |
Freeman Ng | 09dbf18 | 2010-08-11 15:45:01 -0700 | [diff] [blame] | 157 | // add a Skip button? |
| 158 | private static final String EXTRA_PREFS_SHOW_SKIP = "extra_prefs_show_skip"; |
| 159 | |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 160 | // specify custom text for the Back or Next buttons, or cause a button to not appear |
| 161 | // at all by setting it to null |
| 162 | private static final String EXTRA_PREFS_SET_NEXT_TEXT = "extra_prefs_set_next_text"; |
| 163 | private static final String EXTRA_PREFS_SET_BACK_TEXT = "extra_prefs_set_back_text"; |
| 164 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 165 | // --- State for new mode when showing a list of headers + prefs fragment |
| 166 | |
| 167 | private final ArrayList<Header> mHeaders = new ArrayList<Header>(); |
| 168 | |
| 169 | private HeaderAdapter mAdapter; |
| 170 | |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 171 | private FrameLayout mListFooter; |
| 172 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 173 | private View mPrefsContainer; |
| 174 | |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 175 | private FragmentBreadCrumbs mFragmentBreadCrumbs; |
| 176 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 177 | private boolean mSinglePane; |
| 178 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 179 | private Header mCurHeader; |
| 180 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 181 | // --- State for old mode when showing a single preference list |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 182 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | private PreferenceManager mPreferenceManager; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 184 | |
Adam Powell | e7fea45 | 2010-03-18 14:51:39 -0700 | [diff] [blame] | 185 | private Bundle mSavedInstanceState; |
| 186 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 187 | // --- Common state |
| 188 | |
| 189 | private Button mNextButton; |
| 190 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | /** |
| 192 | * The starting request code given out to preference framework. |
| 193 | */ |
| 194 | private static final int FIRST_REQUEST_CODE = 100; |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 195 | |
Dianne Hackborn | 3e449ce | 2010-09-11 20:52:31 -0700 | [diff] [blame] | 196 | private static final int MSG_BIND_PREFERENCES = 1; |
| 197 | private static final int MSG_BUILD_HEADERS = 2; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | private Handler mHandler = new Handler() { |
| 199 | @Override |
| 200 | public void handleMessage(Message msg) { |
| 201 | switch (msg.what) { |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 202 | case MSG_BIND_PREFERENCES: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | bindPreferences(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 204 | } break; |
| 205 | case MSG_BUILD_HEADERS: { |
| 206 | ArrayList<Header> oldHeaders = new ArrayList<Header>(mHeaders); |
| 207 | mHeaders.clear(); |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 208 | onBuildHeaders(mHeaders); |
Andrew Stadler | 83681eb | 2010-11-04 15:49:05 -0700 | [diff] [blame] | 209 | if (mAdapter != null) { |
| 210 | mAdapter.notifyDataSetChanged(); |
| 211 | } |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 212 | Header header = onGetNewHeader(); |
| 213 | if (header != null && header.fragment != null) { |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 214 | Header mappedHeader = findBestMatchingHeader(header, oldHeaders); |
| 215 | if (mappedHeader == null || mCurHeader != mappedHeader) { |
| 216 | switchToHeader(header); |
| 217 | } |
| 218 | } else if (mCurHeader != null) { |
| 219 | Header mappedHeader = findBestMatchingHeader(mCurHeader, mHeaders); |
| 220 | if (mappedHeader != null) { |
| 221 | setSelectedHeader(mappedHeader); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 222 | } |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 223 | } |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 224 | } break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | }; |
| 228 | |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 229 | private static class HeaderAdapter extends ArrayAdapter<Header> { |
| 230 | private static class HeaderViewHolder { |
| 231 | ImageView icon; |
| 232 | TextView title; |
| 233 | TextView summary; |
| 234 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 235 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 236 | private LayoutInflater mInflater; |
| 237 | |
| 238 | public HeaderAdapter(Context context, List<Header> objects) { |
| 239 | super(context, 0, objects); |
| 240 | mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public View getView(int position, View convertView, ViewGroup parent) { |
| 245 | HeaderViewHolder holder; |
| 246 | View view; |
| 247 | |
| 248 | if (convertView == null) { |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 249 | view = mInflater.inflate(com.android.internal.R.layout.preference_header_item, |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 250 | parent, false); |
| 251 | holder = new HeaderViewHolder(); |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 252 | holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon); |
| 253 | holder.title = (TextView) view.findViewById(com.android.internal.R.id.title); |
| 254 | holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 255 | view.setTag(holder); |
| 256 | } else { |
| 257 | view = convertView; |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 258 | holder = (HeaderViewHolder) view.getTag(); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 261 | // All view fields must be updated every time, because the view may be recycled |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 262 | Header header = getItem(position); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 263 | holder.icon.setImageResource(header.iconRes); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 264 | holder.title.setText(header.getTitle(getContext().getResources())); |
| 265 | CharSequence summary = header.getSummary(getContext().getResources()); |
| 266 | if (!TextUtils.isEmpty(summary)) { |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 267 | holder.summary.setVisibility(View.VISIBLE); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 268 | holder.summary.setText(summary); |
| 269 | } else { |
| 270 | holder.summary.setVisibility(View.GONE); |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 271 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 272 | |
| 273 | return view; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 278 | * Default value for {@link Header#id Header.id} indicating that no |
| 279 | * identifier value is set. All other values (including those below -1) |
| 280 | * are valid. |
| 281 | */ |
| 282 | public static final long HEADER_ID_UNDEFINED = -1; |
| 283 | |
| 284 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 285 | * Description of a single Header item that the user can select. |
| 286 | */ |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 287 | public static final class Header implements Parcelable { |
| 288 | /** |
| 289 | * Identifier for this header, to correlate with a new list when |
| 290 | * it is updated. The default value is |
| 291 | * {@link PreferenceActivity#HEADER_ID_UNDEFINED}, meaning no id. |
| 292 | * @attr ref android.R.styleable#PreferenceHeader_id |
| 293 | */ |
| 294 | public long id = HEADER_ID_UNDEFINED; |
| 295 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 296 | /** |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 297 | * Resource ID of title of the header that is shown to the user. |
| 298 | * @attr ref android.R.styleable#PreferenceHeader_title |
| 299 | */ |
| 300 | public int titleRes; |
| 301 | |
| 302 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 303 | * Title of the header that is shown to the user. |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 304 | * @attr ref android.R.styleable#PreferenceHeader_title |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 305 | */ |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 306 | public CharSequence title; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 307 | |
| 308 | /** |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 309 | * Resource ID of optional summary describing what this header controls. |
| 310 | * @attr ref android.R.styleable#PreferenceHeader_summary |
| 311 | */ |
| 312 | public int summaryRes; |
| 313 | |
| 314 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 315 | * Optional summary describing what this header controls. |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 316 | * @attr ref android.R.styleable#PreferenceHeader_summary |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 317 | */ |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 318 | public CharSequence summary; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 319 | |
| 320 | /** |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 321 | * Resource ID of optional text to show as the title in the bread crumb. |
| 322 | * @attr ref android.R.styleable#PreferenceHeader_breadCrumbTitle |
| 323 | */ |
| 324 | public int breadCrumbTitleRes; |
| 325 | |
| 326 | /** |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 327 | * Optional text to show as the title in the bread crumb. |
| 328 | * @attr ref android.R.styleable#PreferenceHeader_breadCrumbTitle |
| 329 | */ |
| 330 | public CharSequence breadCrumbTitle; |
| 331 | |
| 332 | /** |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 333 | * Resource ID of optional text to show as the short title in the bread crumb. |
| 334 | * @attr ref android.R.styleable#PreferenceHeader_breadCrumbShortTitle |
| 335 | */ |
| 336 | public int breadCrumbShortTitleRes; |
| 337 | |
| 338 | /** |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 339 | * Optional text to show as the short title in the bread crumb. |
| 340 | * @attr ref android.R.styleable#PreferenceHeader_breadCrumbShortTitle |
| 341 | */ |
| 342 | public CharSequence breadCrumbShortTitle; |
| 343 | |
| 344 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 345 | * Optional icon resource to show for this header. |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 346 | * @attr ref android.R.styleable#PreferenceHeader_icon |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 347 | */ |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 348 | public int iconRes; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 349 | |
| 350 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 351 | * Full class name of the fragment to display when this header is |
| 352 | * selected. |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 353 | * @attr ref android.R.styleable#PreferenceHeader_fragment |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 354 | */ |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 355 | public String fragment; |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 356 | |
| 357 | /** |
| 358 | * Optional arguments to supply to the fragment when it is |
| 359 | * instantiated. |
| 360 | */ |
Andrew Stadler | 468c323 | 2010-08-17 16:16:42 -0700 | [diff] [blame] | 361 | public Bundle fragmentArguments; |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 362 | |
| 363 | /** |
| 364 | * Intent to launch when the preference is selected. |
| 365 | */ |
| 366 | public Intent intent; |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * Optional additional data for use by subclasses of PreferenceActivity. |
| 370 | */ |
| 371 | public Bundle extras; |
| 372 | |
| 373 | public Header() { |
| 374 | } |
| 375 | |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 376 | /** |
| 377 | * Return the currently set title. If {@link #titleRes} is set, |
| 378 | * this resource is loaded from <var>res</var> and returned. Otherwise |
| 379 | * {@link #title} is returned. |
| 380 | */ |
| 381 | public CharSequence getTitle(Resources res) { |
| 382 | if (titleRes != 0) { |
| 383 | return res.getText(titleRes); |
| 384 | } |
| 385 | return title; |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Return the currently set summary. If {@link #summaryRes} is set, |
| 390 | * this resource is loaded from <var>res</var> and returned. Otherwise |
| 391 | * {@link #summary} is returned. |
| 392 | */ |
| 393 | public CharSequence getSummary(Resources res) { |
| 394 | if (summaryRes != 0) { |
| 395 | return res.getText(summaryRes); |
| 396 | } |
| 397 | return title; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Return the currently set bread crumb title. If {@link #breadCrumbTitleRes} is set, |
| 402 | * this resource is loaded from <var>res</var> and returned. Otherwise |
| 403 | * {@link #breadCrumbTitle} is returned. |
| 404 | */ |
| 405 | public CharSequence getBreadCrumbTitle(Resources res) { |
| 406 | if (breadCrumbTitleRes != 0) { |
| 407 | return res.getText(breadCrumbTitleRes); |
| 408 | } |
| 409 | return breadCrumbTitle; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Return the currently set bread crumb short title. If |
| 414 | * {@link #breadCrumbShortTitleRes} is set, |
| 415 | * this resource is loaded from <var>res</var> and returned. Otherwise |
| 416 | * {@link #breadCrumbShortTitle} is returned. |
| 417 | */ |
| 418 | public CharSequence getBreadCrumbShortTitle(Resources res) { |
| 419 | if (breadCrumbShortTitleRes != 0) { |
| 420 | return res.getText(breadCrumbShortTitleRes); |
| 421 | } |
| 422 | return breadCrumbShortTitle; |
| 423 | } |
| 424 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 425 | @Override |
| 426 | public int describeContents() { |
| 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | @Override |
| 431 | public void writeToParcel(Parcel dest, int flags) { |
| 432 | dest.writeLong(id); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 433 | dest.writeInt(titleRes); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 434 | TextUtils.writeToParcel(title, dest, flags); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 435 | dest.writeInt(summaryRes); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 436 | TextUtils.writeToParcel(summary, dest, flags); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 437 | dest.writeInt(breadCrumbTitleRes); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 438 | TextUtils.writeToParcel(breadCrumbTitle, dest, flags); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 439 | dest.writeInt(breadCrumbShortTitleRes); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 440 | TextUtils.writeToParcel(breadCrumbShortTitle, dest, flags); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 441 | dest.writeInt(iconRes); |
| 442 | dest.writeString(fragment); |
| 443 | dest.writeBundle(fragmentArguments); |
| 444 | if (intent != null) { |
| 445 | dest.writeInt(1); |
| 446 | intent.writeToParcel(dest, flags); |
| 447 | } else { |
| 448 | dest.writeInt(0); |
| 449 | } |
| 450 | dest.writeBundle(extras); |
| 451 | } |
| 452 | |
| 453 | public void readFromParcel(Parcel in) { |
| 454 | id = in.readLong(); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 455 | titleRes = in.readInt(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 456 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 457 | summaryRes = in.readInt(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 458 | summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 459 | breadCrumbTitleRes = in.readInt(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 460 | breadCrumbTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 461 | breadCrumbShortTitleRes = in.readInt(); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 462 | breadCrumbShortTitle = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 463 | iconRes = in.readInt(); |
| 464 | fragment = in.readString(); |
| 465 | fragmentArguments = in.readBundle(); |
| 466 | if (in.readInt() != 0) { |
| 467 | intent = Intent.CREATOR.createFromParcel(in); |
| 468 | } |
| 469 | extras = in.readBundle(); |
| 470 | } |
| 471 | |
| 472 | Header(Parcel in) { |
| 473 | readFromParcel(in); |
| 474 | } |
| 475 | |
| 476 | public static final Creator<Header> CREATOR = new Creator<Header>() { |
| 477 | public Header createFromParcel(Parcel source) { |
| 478 | return new Header(source); |
| 479 | } |
| 480 | public Header[] newArray(int size) { |
| 481 | return new Header[size]; |
| 482 | } |
| 483 | }; |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 484 | } |
| 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | @Override |
| 487 | protected void onCreate(Bundle savedInstanceState) { |
| 488 | super.onCreate(savedInstanceState); |
| 489 | |
| 490 | setContentView(com.android.internal.R.layout.preference_list_content); |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 491 | |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 492 | mListFooter = (FrameLayout)findViewById(com.android.internal.R.id.list_footer); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 493 | mPrefsContainer = findViewById(com.android.internal.R.id.prefs); |
| 494 | boolean hidingHeaders = onIsHidingHeaders(); |
| 495 | mSinglePane = hidingHeaders || !onIsMultiPane(); |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 496 | String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT); |
| 497 | Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 498 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 499 | if (savedInstanceState != null) { |
| 500 | // We are restarting from a previous saved state; used that to |
| 501 | // initialize, instead of starting fresh. |
| 502 | ArrayList<Header> headers = savedInstanceState.getParcelableArrayList(HEADERS_TAG); |
| 503 | if (headers != null) { |
| 504 | mHeaders.addAll(headers); |
| 505 | int curHeader = savedInstanceState.getInt(CUR_HEADER_TAG, |
| 506 | (int)HEADER_ID_UNDEFINED); |
| 507 | if (curHeader >= 0 && curHeader < mHeaders.size()) { |
| 508 | setSelectedHeader(mHeaders.get(curHeader)); |
| 509 | } |
| 510 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 511 | |
| 512 | } else { |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 513 | if (initialFragment != null && mSinglePane) { |
| 514 | // If we are just showing a fragment, we want to run in |
| 515 | // new fragment mode, but don't need to compute and show |
| 516 | // the headers. |
| 517 | switchToHeader(initialFragment, initialArguments); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 518 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 519 | } else { |
| 520 | // We need to try to build the headers. |
| 521 | onBuildHeaders(mHeaders); |
| 522 | |
| 523 | // If there are headers, then at this point we need to show |
| 524 | // them and, depending on the screen, we may also show in-line |
| 525 | // the currently selected preference fragment. |
| 526 | if (mHeaders.size() > 0) { |
| 527 | if (!mSinglePane) { |
| 528 | if (initialFragment == null) { |
| 529 | Header h = onGetInitialHeader(); |
| 530 | switchToHeader(h); |
| 531 | } else { |
| 532 | switchToHeader(initialFragment, initialArguments); |
| 533 | } |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 534 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 535 | } |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 538 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 539 | // The default configuration is to only show the list view. Adjust |
| 540 | // visibility for other configurations. |
| 541 | if (initialFragment != null && mSinglePane) { |
| 542 | // Single pane, showing just a prefs fragment. |
Amith Yamasani | 05fbc31 | 2010-09-26 13:29:01 -0700 | [diff] [blame] | 543 | findViewById(com.android.internal.R.id.headers).setVisibility(View.GONE); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 544 | mPrefsContainer.setVisibility(View.VISIBLE); |
| 545 | } else if (mHeaders.size() > 0) { |
| 546 | mAdapter = new HeaderAdapter(this, mHeaders); |
| 547 | setListAdapter(mAdapter); |
| 548 | if (!mSinglePane) { |
| 549 | // Multi-pane. |
| 550 | getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); |
Dianne Hackborn | d0fa371 | 2010-09-14 18:57:14 -0700 | [diff] [blame] | 551 | if (mCurHeader != null) { |
| 552 | setSelectedHeader(mCurHeader); |
| 553 | } |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 554 | mPrefsContainer.setVisibility(View.VISIBLE); |
| 555 | } |
| 556 | } else { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 557 | // If there are no headers, we are in the old "just show a screen |
| 558 | // of preferences" mode. |
Amith Yamasani | 8da3529 | 2010-11-05 09:15:51 -0700 | [diff] [blame] | 559 | setContentView(com.android.internal.R.layout.preference_list_content_single); |
| 560 | mListFooter = (FrameLayout) findViewById(com.android.internal.R.id.list_footer); |
| 561 | mPrefsContainer = findViewById(com.android.internal.R.id.prefs); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 562 | mPreferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE); |
| 563 | mPreferenceManager.setOnPreferenceTreeClickListener(this); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | getListView().setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); |
| 567 | |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 568 | // see if we should show Back/Next buttons |
| 569 | Intent intent = getIntent(); |
| 570 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) { |
| 571 | |
| 572 | findViewById(com.android.internal.R.id.button_bar).setVisibility(View.VISIBLE); |
| 573 | |
| 574 | Button backButton = (Button)findViewById(com.android.internal.R.id.back_button); |
| 575 | backButton.setOnClickListener(new OnClickListener() { |
| 576 | public void onClick(View v) { |
| 577 | setResult(RESULT_CANCELED); |
| 578 | finish(); |
| 579 | } |
| 580 | }); |
Freeman Ng | 09dbf18 | 2010-08-11 15:45:01 -0700 | [diff] [blame] | 581 | Button skipButton = (Button)findViewById(com.android.internal.R.id.skip_button); |
| 582 | skipButton.setOnClickListener(new OnClickListener() { |
| 583 | public void onClick(View v) { |
| 584 | setResult(RESULT_OK); |
| 585 | finish(); |
| 586 | } |
| 587 | }); |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 588 | mNextButton = (Button)findViewById(com.android.internal.R.id.next_button); |
| 589 | mNextButton.setOnClickListener(new OnClickListener() { |
| 590 | public void onClick(View v) { |
| 591 | setResult(RESULT_OK); |
| 592 | finish(); |
| 593 | } |
| 594 | }); |
| 595 | |
| 596 | // set our various button parameters |
| 597 | if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) { |
| 598 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT); |
| 599 | if (TextUtils.isEmpty(buttonText)) { |
| 600 | mNextButton.setVisibility(View.GONE); |
| 601 | } |
| 602 | else { |
| 603 | mNextButton.setText(buttonText); |
| 604 | } |
| 605 | } |
| 606 | if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) { |
| 607 | String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT); |
| 608 | if (TextUtils.isEmpty(buttonText)) { |
| 609 | backButton.setVisibility(View.GONE); |
| 610 | } |
| 611 | else { |
| 612 | backButton.setText(buttonText); |
| 613 | } |
| 614 | } |
Freeman Ng | 09dbf18 | 2010-08-11 15:45:01 -0700 | [diff] [blame] | 615 | if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) { |
| 616 | skipButton.setVisibility(View.VISIBLE); |
| 617 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 618 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 619 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 620 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 621 | /** |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 622 | * Returns true if this activity is currently showing the header list. |
| 623 | */ |
| 624 | public boolean hasHeaders() { |
| 625 | return getListView().getVisibility() == View.VISIBLE |
| 626 | && mPreferenceManager == null; |
| 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Returns true if this activity is showing multiple panes -- the headers |
| 631 | * and a preference fragment. |
| 632 | */ |
| 633 | public boolean isMultiPane() { |
| 634 | return hasHeaders() && mPrefsContainer.getVisibility() == View.VISIBLE; |
| 635 | } |
| 636 | |
| 637 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 638 | * Called to determine if the activity should run in multi-pane mode. |
| 639 | * The default implementation returns true if the screen is large |
| 640 | * enough. |
| 641 | */ |
| 642 | public boolean onIsMultiPane() { |
| 643 | Configuration config = getResources().getConfiguration(); |
| 644 | if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 645 | == Configuration.SCREENLAYOUT_SIZE_XLARGE) { |
| 646 | return true; |
| 647 | } |
| 648 | if ((config.screenLayout&Configuration.SCREENLAYOUT_SIZE_MASK) |
| 649 | == Configuration.SCREENLAYOUT_SIZE_LARGE |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 650 | && config.orientation == Configuration.ORIENTATION_LANDSCAPE) { |
| 651 | return true; |
| 652 | } |
| 653 | return false; |
| 654 | } |
| 655 | |
| 656 | /** |
Dianne Hackborn | 291905e | 2010-08-17 15:17:15 -0700 | [diff] [blame] | 657 | * Called to determine whether the header list should be hidden. |
| 658 | * The default implementation returns the |
| 659 | * value given in {@link #EXTRA_NO_HEADERS} or false if it is not supplied. |
| 660 | * This is set to false, for example, when the activity is being re-launched |
| 661 | * to show a particular preference activity. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 662 | */ |
| 663 | public boolean onIsHidingHeaders() { |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 664 | return getIntent().getBooleanExtra(EXTRA_NO_HEADERS, false); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 668 | * Called to determine the initial header to be shown. The default |
| 669 | * implementation simply returns the fragment of the first header. Note |
| 670 | * that the returned Header object does not actually need to exist in |
| 671 | * your header list -- whatever its fragment is will simply be used to |
| 672 | * show for the initial UI. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 673 | */ |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 674 | public Header onGetInitialHeader() { |
| 675 | return mHeaders.get(0); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 679 | * Called after the header list has been updated ({@link #onBuildHeaders} |
| 680 | * has been called and returned due to {@link #invalidateHeaders()}) to |
| 681 | * specify the header that should now be selected. The default implementation |
| 682 | * returns null to keep whatever header is currently selected. |
| 683 | */ |
| 684 | public Header onGetNewHeader() { |
| 685 | return null; |
| 686 | } |
| 687 | |
| 688 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 689 | * Called when the activity needs its list of headers build. By |
| 690 | * implementing this and adding at least one item to the list, you |
| 691 | * will cause the activity to run in its modern fragment mode. Note |
| 692 | * that this function may not always be called; for example, if the |
| 693 | * activity has been asked to display a particular fragment without |
| 694 | * the header list, there is no need to build the headers. |
| 695 | * |
| 696 | * <p>Typical implementations will use {@link #loadHeadersFromResource} |
| 697 | * to fill in the list from a resource. |
| 698 | * |
| 699 | * @param target The list in which to place the headers. |
| 700 | */ |
| 701 | public void onBuildHeaders(List<Header> target) { |
| 702 | } |
| 703 | |
| 704 | /** |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 705 | * Call when you need to change the headers being displayed. Will result |
| 706 | * in onBuildHeaders() later being called to retrieve the new list. |
| 707 | */ |
| 708 | public void invalidateHeaders() { |
| 709 | if (!mHandler.hasMessages(MSG_BUILD_HEADERS)) { |
| 710 | mHandler.sendEmptyMessage(MSG_BUILD_HEADERS); |
| 711 | } |
| 712 | } |
| 713 | |
| 714 | /** |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 715 | * Parse the given XML file as a header description, adding each |
| 716 | * parsed Header into the target list. |
| 717 | * |
| 718 | * @param resid The XML resource to load and parse. |
| 719 | * @param target The list in which the parsed headers should be placed. |
| 720 | */ |
| 721 | public void loadHeadersFromResource(int resid, List<Header> target) { |
| 722 | XmlResourceParser parser = null; |
| 723 | try { |
| 724 | parser = getResources().getXml(resid); |
| 725 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 726 | |
| 727 | int type; |
| 728 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 729 | && type != XmlPullParser.START_TAG) { |
| 730 | } |
| 731 | |
| 732 | String nodeName = parser.getName(); |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 733 | if (!"preference-headers".equals(nodeName)) { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 734 | throw new RuntimeException( |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 735 | "XML document must start with <preference-headers> tag; found" |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 736 | + nodeName + " at " + parser.getPositionDescription()); |
| 737 | } |
| 738 | |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 739 | Bundle curBundle = null; |
| 740 | |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 741 | final int outerDepth = parser.getDepth(); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 742 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 743 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 744 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 745 | continue; |
| 746 | } |
| 747 | |
| 748 | nodeName = parser.getName(); |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 749 | if ("header".equals(nodeName)) { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 750 | Header header = new Header(); |
| 751 | |
| 752 | TypedArray sa = getResources().obtainAttributes(attrs, |
| 753 | com.android.internal.R.styleable.PreferenceHeader); |
Amith Yamasani | ed13cde | 2010-09-17 16:56:47 -0700 | [diff] [blame] | 754 | header.id = sa.getResourceId( |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 755 | com.android.internal.R.styleable.PreferenceHeader_id, |
| 756 | (int)HEADER_ID_UNDEFINED); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 757 | TypedValue tv = sa.peekValue( |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 758 | com.android.internal.R.styleable.PreferenceHeader_title); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 759 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 760 | if (tv.resourceId != 0) { |
| 761 | header.titleRes = tv.resourceId; |
| 762 | } else { |
| 763 | header.title = tv.string; |
| 764 | } |
| 765 | } |
| 766 | tv = sa.peekValue( |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 767 | com.android.internal.R.styleable.PreferenceHeader_summary); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 768 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 769 | if (tv.resourceId != 0) { |
| 770 | header.summaryRes = tv.resourceId; |
| 771 | } else { |
| 772 | header.summary = tv.string; |
| 773 | } |
| 774 | } |
| 775 | tv = sa.peekValue( |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 776 | com.android.internal.R.styleable.PreferenceHeader_breadCrumbTitle); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 777 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 778 | if (tv.resourceId != 0) { |
| 779 | header.breadCrumbTitleRes = tv.resourceId; |
| 780 | } else { |
| 781 | header.breadCrumbTitle = tv.string; |
| 782 | } |
| 783 | } |
| 784 | tv = sa.peekValue( |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 785 | com.android.internal.R.styleable.PreferenceHeader_breadCrumbShortTitle); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 786 | if (tv != null && tv.type == TypedValue.TYPE_STRING) { |
| 787 | if (tv.resourceId != 0) { |
| 788 | header.breadCrumbShortTitleRes = tv.resourceId; |
| 789 | } else { |
| 790 | header.breadCrumbShortTitle = tv.string; |
| 791 | } |
| 792 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 793 | header.iconRes = sa.getResourceId( |
| 794 | com.android.internal.R.styleable.PreferenceHeader_icon, 0); |
| 795 | header.fragment = sa.getString( |
| 796 | com.android.internal.R.styleable.PreferenceHeader_fragment); |
| 797 | sa.recycle(); |
| 798 | |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 799 | if (curBundle == null) { |
| 800 | curBundle = new Bundle(); |
| 801 | } |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 802 | |
| 803 | final int innerDepth = parser.getDepth(); |
| 804 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 805 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 806 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 807 | continue; |
| 808 | } |
| 809 | |
| 810 | String innerNodeName = parser.getName(); |
| 811 | if (innerNodeName.equals("extra")) { |
| 812 | getResources().parseBundleExtra("extra", attrs, curBundle); |
| 813 | XmlUtils.skipCurrentTag(parser); |
| 814 | |
| 815 | } else if (innerNodeName.equals("intent")) { |
| 816 | header.intent = Intent.parseIntent(getResources(), parser, attrs); |
| 817 | |
| 818 | } else { |
| 819 | XmlUtils.skipCurrentTag(parser); |
| 820 | } |
| 821 | } |
| 822 | |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 823 | if (curBundle.size() > 0) { |
| 824 | header.fragmentArguments = curBundle; |
| 825 | curBundle = null; |
| 826 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 827 | |
Dianne Hackborn | def1537 | 2010-08-15 12:43:52 -0700 | [diff] [blame] | 828 | target.add(header); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 829 | } else { |
| 830 | XmlUtils.skipCurrentTag(parser); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | } catch (XmlPullParserException e) { |
| 835 | throw new RuntimeException("Error parsing headers", e); |
| 836 | } catch (IOException e) { |
| 837 | throw new RuntimeException("Error parsing headers", e); |
| 838 | } finally { |
| 839 | if (parser != null) parser.close(); |
| 840 | } |
| 841 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 844 | /** |
| 845 | * Set a footer that should be shown at the bottom of the header list. |
| 846 | */ |
| 847 | public void setListFooter(View view) { |
| 848 | mListFooter.removeAllViews(); |
| 849 | mListFooter.addView(view, new FrameLayout.LayoutParams( |
| 850 | FrameLayout.LayoutParams.MATCH_PARENT, |
| 851 | FrameLayout.LayoutParams.WRAP_CONTENT)); |
| 852 | } |
| 853 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | @Override |
| 855 | protected void onStop() { |
| 856 | super.onStop(); |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 857 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 858 | if (mPreferenceManager != null) { |
| 859 | mPreferenceManager.dispatchActivityStop(); |
| 860 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | @Override |
| 864 | protected void onDestroy() { |
| 865 | super.onDestroy(); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 866 | |
| 867 | if (mPreferenceManager != null) { |
| 868 | mPreferenceManager.dispatchActivityDestroy(); |
| 869 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | @Override |
| 873 | protected void onSaveInstanceState(Bundle outState) { |
| 874 | super.onSaveInstanceState(outState); |
| 875 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 876 | if (mHeaders.size() > 0) { |
| 877 | outState.putParcelableArrayList(HEADERS_TAG, mHeaders); |
| 878 | if (mCurHeader != null) { |
| 879 | int index = mHeaders.indexOf(mCurHeader); |
| 880 | if (index >= 0) { |
| 881 | outState.putInt(CUR_HEADER_TAG, index); |
| 882 | } |
| 883 | } |
| 884 | } |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 885 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 886 | if (mPreferenceManager != null) { |
| 887 | final PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 888 | if (preferenceScreen != null) { |
| 889 | Bundle container = new Bundle(); |
| 890 | preferenceScreen.saveHierarchyState(container); |
| 891 | outState.putBundle(PREFERENCES_TAG, container); |
| 892 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
| 896 | @Override |
| 897 | protected void onRestoreInstanceState(Bundle state) { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 898 | if (mPreferenceManager != null) { |
| 899 | Bundle container = state.getBundle(PREFERENCES_TAG); |
| 900 | if (container != null) { |
| 901 | final PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 902 | if (preferenceScreen != null) { |
| 903 | preferenceScreen.restoreHierarchyState(container); |
| 904 | mSavedInstanceState = state; |
| 905 | return; |
| 906 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | } |
| 908 | } |
Adam Powell | e7fea45 | 2010-03-18 14:51:39 -0700 | [diff] [blame] | 909 | |
| 910 | // Only call this if we didn't save the instance state for later. |
| 911 | // If we did save it, it will be restored when we bind the adapter. |
| 912 | super.onRestoreInstanceState(state); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | @Override |
| 916 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 917 | super.onActivityResult(requestCode, resultCode, data); |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 918 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 919 | if (mPreferenceManager != null) { |
| 920 | mPreferenceManager.dispatchActivityResult(requestCode, resultCode, data); |
| 921 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | @Override |
| 925 | public void onContentChanged() { |
| 926 | super.onContentChanged(); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 927 | |
| 928 | if (mPreferenceManager != null) { |
| 929 | postBindPreferences(); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | @Override |
| 934 | protected void onListItemClick(ListView l, View v, int position, long id) { |
| 935 | super.onListItemClick(l, v, position, id); |
| 936 | |
| 937 | if (mAdapter != null) { |
| 938 | onHeaderClick(mHeaders.get(position), position); |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * Called when the user selects an item in the header list. The default |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 944 | * implementation will call either {@link #startWithFragment(String, Bundle, Fragment, int)} |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 945 | * or {@link #switchToHeader(Header)} as appropriate. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 946 | * |
| 947 | * @param header The header that was selected. |
| 948 | * @param position The header's position in the list. |
| 949 | */ |
| 950 | public void onHeaderClick(Header header, int position) { |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 951 | if (header.fragment != null) { |
| 952 | if (mSinglePane) { |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 953 | startWithFragment(header.fragment, header.fragmentArguments, null, 0); |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 954 | } else { |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 955 | switchToHeader(header); |
Dianne Hackborn | 5c769a4 | 2010-08-26 17:08:08 -0700 | [diff] [blame] | 956 | } |
| 957 | } else if (header.intent != null) { |
| 958 | startActivity(header.intent); |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * Start a new instance of this activity, showing only the given |
| 964 | * preference fragment. When launched in this mode, the header list |
| 965 | * will be hidden and the given preference fragment will be instantiated |
| 966 | * and fill the entire activity. |
| 967 | * |
| 968 | * @param fragmentName The name of the fragment to display. |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 969 | * @param args Optional arguments to supply to the fragment. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 970 | */ |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 971 | public void startWithFragment(String fragmentName, Bundle args, |
| 972 | Fragment resultTo, int resultRequestCode) { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 973 | Intent intent = new Intent(Intent.ACTION_MAIN); |
| 974 | intent.setClass(this, getClass()); |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 975 | intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName); |
| 976 | intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); |
| 977 | intent.putExtra(EXTRA_NO_HEADERS, true); |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 978 | if (resultTo == null) { |
| 979 | startActivity(intent); |
| 980 | } else { |
| 981 | resultTo.startActivityForResult(intent, resultRequestCode); |
| 982 | } |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 983 | } |
| 984 | |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 985 | /** |
| 986 | * Change the base title of the bread crumbs for the current preferences. |
| 987 | * This will normally be called for you. See |
| 988 | * {@link android.app.FragmentBreadCrumbs} for more information. |
| 989 | */ |
| 990 | public void showBreadCrumbs(CharSequence title, CharSequence shortTitle) { |
| 991 | if (mFragmentBreadCrumbs == null) { |
| 992 | mFragmentBreadCrumbs = new FragmentBreadCrumbs(this); |
| 993 | mFragmentBreadCrumbs.setActivity(this); |
| 994 | getActionBar().setCustomNavigationMode(mFragmentBreadCrumbs); |
| 995 | } |
| 996 | mFragmentBreadCrumbs.setTitle(title, shortTitle); |
| 997 | } |
| 998 | |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 999 | void setSelectedHeader(Header header) { |
| 1000 | mCurHeader = header; |
| 1001 | int index = mHeaders.indexOf(header); |
| 1002 | if (index >= 0) { |
| 1003 | getListView().setItemChecked(index, true); |
| 1004 | } else { |
| 1005 | getListView().clearChoices(); |
| 1006 | } |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1007 | if (header != null) { |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 1008 | CharSequence title = header.getBreadCrumbTitle(getResources()); |
| 1009 | if (title == null) title = header.getTitle(getResources()); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1010 | if (title == null) title = getTitle(); |
Dianne Hackborn | 50ed829 | 2010-12-03 12:30:21 -0800 | [diff] [blame^] | 1011 | showBreadCrumbs(title, header.getBreadCrumbShortTitle(getResources())); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1012 | } else { |
| 1013 | showBreadCrumbs(getTitle(), null); |
| 1014 | } |
| 1015 | } |
| 1016 | |
Amith Yamasani | f5cbaed | 2010-10-27 16:14:20 -0700 | [diff] [blame] | 1017 | private void switchToHeaderInner(String fragmentName, Bundle args, int direction) { |
Dianne Hackborn | 3a57fb9 | 2010-11-15 17:58:52 -0800 | [diff] [blame] | 1018 | getFragmentManager().popBackStack(BACK_STACK_PREFS, |
| 1019 | FragmentManager.POP_BACK_STACK_INCLUSIVE); |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1020 | Fragment f = Fragment.instantiate(this, fragmentName, args); |
Chet Haase | 9ff82bf | 2010-10-05 14:30:51 -0700 | [diff] [blame] | 1021 | FragmentTransaction transaction = getFragmentManager().openTransaction(); |
Amith Yamasani | f5cbaed | 2010-10-27 16:14:20 -0700 | [diff] [blame] | 1022 | transaction.setTransition(direction == 0 ? FragmentTransaction.TRANSIT_NONE |
| 1023 | : direction > 0 ? FragmentTransaction.TRANSIT_FRAGMENT_NEXT |
| 1024 | : FragmentTransaction.TRANSIT_FRAGMENT_PREV); |
Chet Haase | 9ff82bf | 2010-10-05 14:30:51 -0700 | [diff] [blame] | 1025 | transaction.replace(com.android.internal.R.id.prefs, f); |
| 1026 | transaction.commit(); |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1029 | /** |
| 1030 | * When in two-pane mode, switch the fragment pane to show the given |
| 1031 | * preference fragment. |
| 1032 | * |
| 1033 | * @param fragmentName The name of the fragment to display. |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 1034 | * @param args Optional arguments to supply to the fragment. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1035 | */ |
Dianne Hackborn | b7a2e47 | 2010-08-12 16:20:42 -0700 | [diff] [blame] | 1036 | public void switchToHeader(String fragmentName, Bundle args) { |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 1037 | setSelectedHeader(null); |
Amith Yamasani | f5cbaed | 2010-10-27 16:14:20 -0700 | [diff] [blame] | 1038 | switchToHeaderInner(fragmentName, args, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 1041 | /** |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 1042 | * When in two-pane mode, switch to the fragment pane to show the given |
| 1043 | * preference fragment. |
| 1044 | * |
| 1045 | * @param header The new header to display. |
| 1046 | */ |
| 1047 | public void switchToHeader(Header header) { |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1048 | if (mCurHeader == header) { |
| 1049 | // This is the header we are currently displaying. Just make sure |
| 1050 | // to pop the stack up to its root state. |
Dianne Hackborn | 3a57fb9 | 2010-11-15 17:58:52 -0800 | [diff] [blame] | 1051 | getFragmentManager().popBackStack(BACK_STACK_PREFS, |
| 1052 | FragmentManager.POP_BACK_STACK_INCLUSIVE); |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1053 | } else { |
| 1054 | int direction = mHeaders.indexOf(header) - mHeaders.indexOf(mCurHeader); |
| 1055 | switchToHeaderInner(header.fragment, header.fragmentArguments, direction); |
| 1056 | setSelectedHeader(header); |
| 1057 | } |
Dianne Hackborn | a21e3da | 2010-09-12 19:27:46 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | Header findBestMatchingHeader(Header cur, ArrayList<Header> from) { |
| 1061 | ArrayList<Header> matches = new ArrayList<Header>(); |
| 1062 | for (int j=0; j<from.size(); j++) { |
| 1063 | Header oh = from.get(j); |
| 1064 | if (cur == oh || (cur.id != HEADER_ID_UNDEFINED && cur.id == oh.id)) { |
| 1065 | // Must be this one. |
| 1066 | matches.clear(); |
| 1067 | matches.add(oh); |
| 1068 | break; |
| 1069 | } |
| 1070 | if (cur.fragment != null) { |
| 1071 | if (cur.fragment.equals(oh.fragment)) { |
| 1072 | matches.add(oh); |
| 1073 | } |
| 1074 | } else if (cur.intent != null) { |
| 1075 | if (cur.intent.equals(oh.intent)) { |
| 1076 | matches.add(oh); |
| 1077 | } |
| 1078 | } else if (cur.title != null) { |
| 1079 | if (cur.title.equals(oh.title)) { |
| 1080 | matches.add(oh); |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | final int NM = matches.size(); |
| 1085 | if (NM == 1) { |
| 1086 | return matches.get(0); |
| 1087 | } else if (NM > 1) { |
| 1088 | for (int j=0; j<NM; j++) { |
| 1089 | Header oh = matches.get(j); |
| 1090 | if (cur.fragmentArguments != null && |
| 1091 | cur.fragmentArguments.equals(oh.fragmentArguments)) { |
| 1092 | return oh; |
| 1093 | } |
| 1094 | if (cur.extras != null && cur.extras.equals(oh.extras)) { |
| 1095 | return oh; |
| 1096 | } |
| 1097 | if (cur.title != null && cur.title.equals(oh.title)) { |
| 1098 | return oh; |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | return null; |
| 1103 | } |
| 1104 | |
| 1105 | /** |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 1106 | * Start a new fragment. |
| 1107 | * |
| 1108 | * @param fragment The fragment to start |
| 1109 | * @param push If true, the current fragment will be pushed onto the back stack. If false, |
| 1110 | * the current fragment will be replaced. |
| 1111 | */ |
| 1112 | public void startPreferenceFragment(Fragment fragment, boolean push) { |
| 1113 | FragmentTransaction transaction = getFragmentManager().openTransaction(); |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1114 | transaction.replace(com.android.internal.R.id.prefs, fragment); |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 1115 | if (push) { |
Chet Haase | 9ff82bf | 2010-10-05 14:30:51 -0700 | [diff] [blame] | 1116 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 1117 | transaction.addToBackStack(BACK_STACK_PREFS); |
Chet Haase | 9ff82bf | 2010-10-05 14:30:51 -0700 | [diff] [blame] | 1118 | } else { |
| 1119 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_NEXT); |
Andrew Stadler | aa904f4 | 2010-09-02 14:50:08 -0700 | [diff] [blame] | 1120 | } |
| 1121 | transaction.commit(); |
| 1122 | } |
| 1123 | |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1124 | /** |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1125 | * Start a new fragment containing a preference panel. If the prefences |
| 1126 | * are being displayed in multi-pane mode, the given fragment class will |
| 1127 | * be instantiated and placed in the appropriate pane. If running in |
| 1128 | * single-pane mode, a new activity will be launched in which to show the |
| 1129 | * fragment. |
| 1130 | * |
| 1131 | * @param fragmentClass Full name of the class implementing the fragment. |
| 1132 | * @param args Any desired arguments to supply to the fragment. |
| 1133 | * @param titleRes Optional resource identifier of the title of this |
| 1134 | * fragment. |
| 1135 | * @param titleText Optional text of the title of this fragment. |
| 1136 | * @param resultTo Optional fragment that result data should be sent to. |
| 1137 | * If non-null, resultTo.onActivityResult() will be called when this |
| 1138 | * preference panel is done. The launched panel must use |
| 1139 | * {@link #finishPreferencePanel(Fragment, int, Intent)} when done. |
| 1140 | * @param resultRequestCode If resultTo is non-null, this is the caller's |
| 1141 | * request code to be received with the resut. |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1142 | */ |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1143 | public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, |
| 1144 | CharSequence titleText, Fragment resultTo, int resultRequestCode) { |
| 1145 | if (mSinglePane) { |
| 1146 | startWithFragment(fragmentClass, args, resultTo, resultRequestCode); |
| 1147 | } else { |
| 1148 | Fragment f = Fragment.instantiate(this, fragmentClass, args); |
| 1149 | if (resultTo != null) { |
| 1150 | f.setTargetFragment(resultTo, resultRequestCode); |
| 1151 | } |
| 1152 | FragmentTransaction transaction = getFragmentManager().openTransaction(); |
| 1153 | transaction.replace(com.android.internal.R.id.prefs, f); |
| 1154 | if (titleRes != 0) { |
| 1155 | transaction.setBreadCrumbTitle(titleRes); |
| 1156 | } else if (titleText != null) { |
| 1157 | transaction.setBreadCrumbTitle(titleText); |
| 1158 | } |
| 1159 | transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); |
| 1160 | transaction.addToBackStack(BACK_STACK_PREFS); |
| 1161 | transaction.commit(); |
| 1162 | } |
Dianne Hackborn | c6669ca | 2010-09-16 01:33:24 -0700 | [diff] [blame] | 1163 | } |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1164 | |
| 1165 | /** |
| 1166 | * Called by a preference panel fragment to finish itself. |
| 1167 | * |
| 1168 | * @param caller The fragment that is asking to be finished. |
| 1169 | * @param resultCode Optional result code to send back to the original |
| 1170 | * launching fragment. |
| 1171 | * @param resultData Optional result data to send back to the original |
| 1172 | * launching fragment. |
| 1173 | */ |
| 1174 | public void finishPreferencePanel(Fragment caller, int resultCode, Intent resultData) { |
| 1175 | if (mSinglePane) { |
| 1176 | setResult(resultCode, resultData); |
| 1177 | finish(); |
| 1178 | } else { |
Dianne Hackborn | 3a57fb9 | 2010-11-15 17:58:52 -0800 | [diff] [blame] | 1179 | // XXX be smarter about popping the stack. |
| 1180 | onBackPressed(); |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1181 | if (caller != null) { |
| 1182 | if (caller.getTargetFragment() != null) { |
| 1183 | caller.getTargetFragment().onActivityResult(caller.getTargetRequestCode(), |
| 1184 | resultCode, resultData); |
| 1185 | } |
| 1186 | } |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1187 | } |
| 1188 | } |
| 1189 | |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 1190 | @Override |
| 1191 | public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { |
Dianne Hackborn | 8eb2e24 | 2010-11-01 12:31:24 -0700 | [diff] [blame] | 1192 | startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, pref.getTitle(), null, 0); |
Dianne Hackborn | b3cf10f | 2010-08-03 13:07:11 -0700 | [diff] [blame] | 1193 | return true; |
| 1194 | } |
| 1195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1196 | /** |
| 1197 | * Posts a message to bind the preferences to the list view. |
| 1198 | * <p> |
| 1199 | * Binding late is preferred as any custom preference types created in |
| 1200 | * {@link #onCreate(Bundle)} are able to have their views recycled. |
| 1201 | */ |
| 1202 | private void postBindPreferences() { |
| 1203 | if (mHandler.hasMessages(MSG_BIND_PREFERENCES)) return; |
| 1204 | mHandler.obtainMessage(MSG_BIND_PREFERENCES).sendToTarget(); |
| 1205 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1206 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1207 | private void bindPreferences() { |
| 1208 | final PreferenceScreen preferenceScreen = getPreferenceScreen(); |
| 1209 | if (preferenceScreen != null) { |
| 1210 | preferenceScreen.bind(getListView()); |
Adam Powell | e7fea45 | 2010-03-18 14:51:39 -0700 | [diff] [blame] | 1211 | if (mSavedInstanceState != null) { |
| 1212 | super.onRestoreInstanceState(mSavedInstanceState); |
| 1213 | mSavedInstanceState = null; |
| 1214 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1215 | } |
| 1216 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1217 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1219 | * Returns the {@link PreferenceManager} used by this activity. |
| 1220 | * @return The {@link PreferenceManager}. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1221 | * |
| 1222 | * @deprecated This function is not relevant for a modern fragment-based |
| 1223 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1224 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1225 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1226 | public PreferenceManager getPreferenceManager() { |
| 1227 | return mPreferenceManager; |
| 1228 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1229 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1230 | private void requirePreferenceManager() { |
| 1231 | if (mPreferenceManager == null) { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1232 | if (mAdapter == null) { |
| 1233 | throw new RuntimeException("This should be called after super.onCreate."); |
| 1234 | } |
| 1235 | throw new RuntimeException( |
| 1236 | "Modern two-pane PreferenceActivity requires use of a PreferenceFragment"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | /** |
| 1241 | * Sets the root of the preference hierarchy that this activity is showing. |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1242 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1243 | * @param preferenceScreen The root {@link PreferenceScreen} of the preference hierarchy. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1244 | * |
| 1245 | * @deprecated This function is not relevant for a modern fragment-based |
| 1246 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1247 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1248 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1249 | public void setPreferenceScreen(PreferenceScreen preferenceScreen) { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1250 | requirePreferenceManager(); |
| 1251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1252 | if (mPreferenceManager.setPreferences(preferenceScreen) && preferenceScreen != null) { |
| 1253 | postBindPreferences(); |
| 1254 | CharSequence title = getPreferenceScreen().getTitle(); |
| 1255 | // Set the title of the activity |
| 1256 | if (title != null) { |
| 1257 | setTitle(title); |
| 1258 | } |
| 1259 | } |
| 1260 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1261 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | /** |
| 1263 | * Gets the root of the preference hierarchy that this activity is showing. |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1264 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | * @return The {@link PreferenceScreen} that is the root of the preference |
| 1266 | * hierarchy. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1267 | * |
| 1268 | * @deprecated This function is not relevant for a modern fragment-based |
| 1269 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1270 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1271 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1272 | public PreferenceScreen getPreferenceScreen() { |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1273 | if (mPreferenceManager != null) { |
| 1274 | return mPreferenceManager.getPreferenceScreen(); |
| 1275 | } |
| 1276 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1279 | /** |
| 1280 | * Adds preferences from activities that match the given {@link Intent}. |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1281 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1282 | * @param intent The {@link Intent} to query activities. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1283 | * |
| 1284 | * @deprecated This function is not relevant for a modern fragment-based |
| 1285 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1287 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | public void addPreferencesFromIntent(Intent intent) { |
| 1289 | requirePreferenceManager(); |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | setPreferenceScreen(mPreferenceManager.inflateFromIntent(intent, getPreferenceScreen())); |
| 1292 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1293 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | /** |
| 1295 | * Inflates the given XML resource and adds the preference hierarchy to the current |
| 1296 | * preference hierarchy. |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1297 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | * @param preferencesResId The XML resource ID to inflate. |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1299 | * |
| 1300 | * @deprecated This function is not relevant for a modern fragment-based |
| 1301 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1302 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1303 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | public void addPreferencesFromResource(int preferencesResId) { |
| 1305 | requirePreferenceManager(); |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1306 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | setPreferenceScreen(mPreferenceManager.inflateFromResource(this, preferencesResId, |
| 1308 | getPreferenceScreen())); |
| 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * {@inheritDoc} |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1313 | * |
| 1314 | * @deprecated This function is not relevant for a modern fragment-based |
| 1315 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1317 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { |
| 1319 | return false; |
| 1320 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1321 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1322 | /** |
| 1323 | * Finds a {@link Preference} based on its key. |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1324 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | * @param key The key of the preference to retrieve. |
| 1326 | * @return The {@link Preference} with the key, or null. |
| 1327 | * @see PreferenceGroup#findPreference(CharSequence) |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1328 | * |
| 1329 | * @deprecated This function is not relevant for a modern fragment-based |
| 1330 | * PreferenceActivity. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | */ |
Dianne Hackborn | b1ad597 | 2010-08-02 17:30:33 -0700 | [diff] [blame] | 1332 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | public Preference findPreference(CharSequence key) { |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1334 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1335 | if (mPreferenceManager == null) { |
| 1336 | return null; |
| 1337 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1338 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1339 | return mPreferenceManager.findPreference(key); |
| 1340 | } |
| 1341 | |
| 1342 | @Override |
| 1343 | protected void onNewIntent(Intent intent) { |
| 1344 | if (mPreferenceManager != null) { |
| 1345 | mPreferenceManager.dispatchNewIntent(intent); |
| 1346 | } |
| 1347 | } |
Freeman Ng | 19ea2e0 | 2010-03-25 15:09:00 -0700 | [diff] [blame] | 1348 | |
| 1349 | // give subclasses access to the Next button |
| 1350 | /** @hide */ |
| 1351 | protected boolean hasNextButton() { |
| 1352 | return mNextButton != null; |
| 1353 | } |
| 1354 | /** @hide */ |
| 1355 | protected Button getNextButton() { |
| 1356 | return mNextButton; |
| 1357 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1358 | } |