blob: 67432c0f9f5577988b048d656a183d646c9009d5 [file] [log] [blame]
Amith Yamasanid7993472010-08-18 13:59:28 -07001/*
2 * Copyright (C) 2010 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
17package com.android.settings;
18
19import android.app.Dialog;
20import android.app.DialogFragment;
Daisuke Miyakawab5647c52010-09-10 18:04:02 -070021import android.app.Fragment;
Amith Yamasanid7993472010-08-18 13:59:28 -070022import android.content.ContentResolver;
Amith Yamasani350938e2013-04-09 10:22:47 -070023import android.content.Context;
Hung-ying Tyan0ee51e02011-01-25 16:42:14 +080024import android.content.DialogInterface;
Amith Yamasanid7993472010-08-18 13:59:28 -070025import android.content.pm.PackageManager;
Fabrice Di Meglioc853a422014-04-18 19:40:40 -070026import android.database.DataSetObserver;
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070027import android.graphics.drawable.Drawable;
Amith Yamasanid7993472010-08-18 13:59:28 -070028import android.os.Bundle;
Amith Yamasani9627a8e2012-09-23 12:54:14 -070029import android.preference.Preference;
Amith Yamasanid7993472010-08-18 13:59:28 -070030import android.preference.PreferenceFragment;
Fabrice Di Meglioc1457322014-04-04 19:07:50 -070031import android.preference.PreferenceGroupAdapter;
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070032import android.text.TextUtils;
Amith Yamasanid7993472010-08-18 13:59:28 -070033import android.util.Log;
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070034import android.view.Menu;
35import android.view.MenuInflater;
36import android.view.MenuItem;
Fabrice Di Megliof2a52262014-04-17 17:20:27 -070037import android.view.View;
38import android.view.ViewGroup;
Daisuke Miyakawa9c8bde52010-08-25 11:58:37 -070039import android.widget.Button;
Fabrice Di Meglioc1457322014-04-04 19:07:50 -070040import android.widget.ListAdapter;
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070041import android.widget.ListView;
Amith Yamasanid7993472010-08-18 13:59:28 -070042
Daisuke Miyakawaf58090d2010-09-12 17:27:33 -070043/**
Amith Yamasanid7993472010-08-18 13:59:28 -070044 * Base class for Settings fragments, with some helper functions and dialog management.
45 */
Gilles Debunne64650542011-08-23 11:01:35 -070046public class SettingsPreferenceFragment extends PreferenceFragment implements DialogCreatable {
Amith Yamasanid7993472010-08-18 13:59:28 -070047
48 private static final String TAG = "SettingsPreferenceFragment";
49
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070050 private static final int MENU_HELP = Menu.FIRST + 100;
Fabrice Di Meglioc853a422014-04-18 19:40:40 -070051 private static final int DELAY_HIGHLIGHT_DURATION_MILLIS = 400;
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070052
53 private static final String SAVE_HIGHLIGHTED_KEY = "android:preference_highlighted";
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070054
Amith Yamasanid7993472010-08-18 13:59:28 -070055 private SettingsDialogFragment mDialogFragment;
56
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070057 private String mHelpUrl;
58
Amith Yamasani350938e2013-04-09 10:22:47 -070059 // Cache the content resolver for async callbacks
60 private ContentResolver mContentResolver;
61
Fabrice Di Megliof2a52262014-04-17 17:20:27 -070062 private String mPreferenceKey;
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070063 private boolean mPreferenceHighlighted = false;
Fabrice Di Meglio4a2ee7e2014-05-21 16:19:41 -070064 private Drawable mHighlightDrawable;
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070065
Fabrice Di Meglio829c8fb2014-04-21 11:40:21 -070066 private boolean mIsDataSetObserverRegistered = false;
Fabrice Di Meglioc853a422014-04-18 19:40:40 -070067 private DataSetObserver mDataSetObserver = new DataSetObserver() {
68 @Override
69 public void onChanged() {
70 highlightPreferenceIfNeeded();
71 }
72
73 @Override
74 public void onInvalidated() {
75 highlightPreferenceIfNeeded();
76 }
77 };
78
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070079 @Override
80 public void onCreate(Bundle icicle) {
81 super.onCreate(icicle);
82
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070083 if (icicle != null) {
84 mPreferenceHighlighted = icicle.getBoolean(SAVE_HIGHLIGHTED_KEY);
85 }
86
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070087 // Prepare help url and enable menu if necessary
88 int helpResource = getHelpResource();
89 if (helpResource != 0) {
90 mHelpUrl = getResources().getString(helpResource);
Amith Yamasanib0b37ae2012-04-23 15:35:36 -070091 }
92 }
93
Daisuke Miyakawab5647c52010-09-10 18:04:02 -070094 @Override
Fabrice Di Meglio6602d022014-04-15 16:45:20 -070095 public void onSaveInstanceState(Bundle outState) {
96 super.onSaveInstanceState(outState);
97
98 outState.putBoolean(SAVE_HIGHLIGHTED_KEY, mPreferenceHighlighted);
99 }
100
101 @Override
Amith Yamasanid7993472010-08-18 13:59:28 -0700102 public void onActivityCreated(Bundle savedInstanceState) {
103 super.onActivityCreated(savedInstanceState);
Amith Yamasanib3a593e2012-04-23 18:03:52 -0700104 if (!TextUtils.isEmpty(mHelpUrl)) {
105 setHasOptionsMenu(true);
106 }
Fabrice Di Meglio4a2ee7e2014-05-21 16:19:41 -0700107 }
108
109 @Override
110 public void onResume() {
111 super.onResume();
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700112
113 final Bundle args = getArguments();
114 if (args != null) {
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700115 mPreferenceKey = args.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
116 highlightPreferenceIfNeeded();
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700117 }
118 }
119
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700120 @Override
121 protected void onBindPreferences() {
Fabrice Di Meglio405febf2014-04-24 10:13:59 -0700122 registerObserverIfNeeded();
123 }
124
125 @Override
126 public void onStop() {
127 super.onStop();
128
129 unregisterObserverIfNeeded();
130 }
131
132 public void registerObserverIfNeeded() {
Fabrice Di Meglio829c8fb2014-04-21 11:40:21 -0700133 if (!mIsDataSetObserverRegistered) {
134 getPreferenceScreen().getRootAdapter().registerDataSetObserver(mDataSetObserver);
135 mIsDataSetObserverRegistered = true;
136 }
Fabrice Di Meglioc853a422014-04-18 19:40:40 -0700137 }
138
Fabrice Di Meglio405febf2014-04-24 10:13:59 -0700139 public void unregisterObserverIfNeeded() {
Fabrice Di Meglio829c8fb2014-04-21 11:40:21 -0700140 if (mIsDataSetObserverRegistered) {
141 getPreferenceScreen().getRootAdapter().unregisterDataSetObserver(mDataSetObserver);
142 mIsDataSetObserverRegistered = false;
143 }
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700144 }
Fabrice Di Meglio6602d022014-04-15 16:45:20 -0700145
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700146 public void highlightPreferenceIfNeeded() {
Fabrice Di Meglioc853a422014-04-18 19:40:40 -0700147 if (isAdded() && !mPreferenceHighlighted &&!TextUtils.isEmpty(mPreferenceKey)) {
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700148 highlightPreference(mPreferenceKey);
Fabrice Di Meglio6602d022014-04-15 16:45:20 -0700149 }
Fabrice Di Meglio6602d022014-04-15 16:45:20 -0700150 }
151
152 private Drawable getHighlightDrawable() {
Fabrice Di Meglio4a2ee7e2014-05-21 16:19:41 -0700153 if (mHighlightDrawable == null) {
154 mHighlightDrawable = getActivity().getDrawable(R.drawable.preference_highlight);
155 }
156 return mHighlightDrawable;
Fabrice Di Meglio6602d022014-04-15 16:45:20 -0700157 }
158
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700159 /**
160 * Return a valid ListView position or -1 if none is found
161 */
162 private int canUseListViewForHighLighting(String key) {
163 if (!hasListView()) {
164 return -1;
165 }
166
167 ListView listView = getListView();
168 ListAdapter adapter = listView.getAdapter();
169
170 if (adapter != null && adapter instanceof PreferenceGroupAdapter) {
171 return findListPositionFromKey(adapter, key);
172 }
173
174 return -1;
175 }
176
177 private void highlightPreference(String key) {
178 final Drawable highlight = getHighlightDrawable();
179
180 final int position = canUseListViewForHighLighting(key);
181 if (position >= 0) {
Fabrice Di Meglio4a2ee7e2014-05-21 16:19:41 -0700182 mPreferenceHighlighted = true;
183
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700184 final ListView listView = getListView();
185 final ListAdapter adapter = listView.getAdapter();
186
187 ((PreferenceGroupAdapter) adapter).setHighlightedDrawable(highlight);
188 ((PreferenceGroupAdapter) adapter).setHighlighted(position);
189
190 listView.post(new Runnable() {
191 @Override
192 public void run() {
193 listView.setSelection(position);
194 listView.postDelayed(new Runnable() {
195 @Override
196 public void run() {
Alan Viveretteba348ca2014-05-19 15:10:36 -0700197 final View v = listView.getChildAt(0);
198 final int centerX = v.getWidth() / 2;
199 final int centerY = v.getHeight() / 2;
200 highlight.setHotspot(centerX, centerY);
201 v.setPressed(true);
202 v.setPressed(false);
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700203 }
204 }, DELAY_HIGHLIGHT_DURATION_MILLIS);
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700205 }
206 });
207 } else {
208 // Try locating the Preference View thru its tag
209 View preferenceView = findPreferenceViewForKey(getView(), key);
210 if (preferenceView != null ) {
Fabrice Di Meglio4a2ee7e2014-05-21 16:19:41 -0700211 mPreferenceHighlighted = true;
212
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700213 preferenceView.setBackground(highlight);
214 final int centerX = preferenceView.getWidth() / 2;
215 final int centerY = preferenceView.getHeight() / 2;
Alan Viveretteba348ca2014-05-19 15:10:36 -0700216 highlight.setHotspot(centerX, centerY);
217 preferenceView.setPressed(true);
218 preferenceView.setPressed(false);
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700219 }
220 }
221 }
222
223 private int findListPositionFromKey(ListAdapter adapter, String key) {
224 final int count = adapter.getCount();
225 for (int n = 0; n < count; n++) {
226 final Object item = adapter.getItem(n);
227 if (item instanceof Preference) {
228 Preference preference = (Preference) item;
229 final String preferenceKey = preference.getKey();
230 if (preferenceKey != null && preferenceKey.equals(key)) {
231 return n;
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700232 }
Fabrice Di Meglioc1457322014-04-04 19:07:50 -0700233 }
234 }
235 return -1;
Amith Yamasanid7993472010-08-18 13:59:28 -0700236 }
237
Fabrice Di Megliof2a52262014-04-17 17:20:27 -0700238 private View findPreferenceViewForKey(View root, String key) {
239 if (checkTag(root, key)) {
240 return root;
241 }
242 if (root instanceof ViewGroup) {
243 final ViewGroup group = (ViewGroup) root;
244 final int count = group.getChildCount();
245 for (int n = 0; n < count; n++) {
246 final View child = group.getChildAt(n);
247 final View view = findPreferenceViewForKey(child, key);
248 if (view != null) {
249 return view;
250 }
251 }
252 }
253 return null;
254 }
255
256 private boolean checkTag(View view, String key) {
257 final Object tag = view.getTag();
258 if (tag == null || !(tag instanceof String)) {
259 return false;
260 }
261 final String prefKey = (String) tag;
262 return (!TextUtils.isEmpty(prefKey) && prefKey.equals(key));
263 }
264
Amith Yamasani9627a8e2012-09-23 12:54:14 -0700265 protected void removePreference(String key) {
266 Preference pref = findPreference(key);
267 if (pref != null) {
268 getPreferenceScreen().removePreference(pref);
269 }
270 }
271
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700272 /**
273 * Override this if you want to show a help item in the menu, by returning the resource id.
274 * @return the resource id for the help url
275 */
276 protected int getHelpResource() {
277 return 0;
278 }
279
280 @Override
281 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Amith Yamasaniaeb57ed2012-12-06 14:40:51 -0800282 if (mHelpUrl != null && getActivity() != null) {
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700283 MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label);
Amith Yamasaniaeb57ed2012-12-06 14:40:51 -0800284 HelpUtils.prepareHelpMenuItem(getActivity(), helpItem, mHelpUrl);
Amith Yamasanib0b37ae2012-04-23 15:35:36 -0700285 }
286 }
287
Daisuke Miyakawab5647c52010-09-10 18:04:02 -0700288 /*
289 * The name is intentionally made different from Activity#finish(), so that
290 * users won't misunderstand its meaning.
291 */
292 public final void finishFragment() {
293 getActivity().onBackPressed();
294 }
295
Amith Yamasanid7993472010-08-18 13:59:28 -0700296 // Some helpers for functions used by the settings fragments when they were activities
297
298 /**
299 * Returns the ContentResolver from the owning Activity.
300 */
301 protected ContentResolver getContentResolver() {
Amith Yamasani350938e2013-04-09 10:22:47 -0700302 Context context = getActivity();
303 if (context != null) {
304 mContentResolver = context.getContentResolver();
305 }
306 return mContentResolver;
Amith Yamasanid7993472010-08-18 13:59:28 -0700307 }
308
309 /**
310 * Returns the specified system service from the owning Activity.
311 */
312 protected Object getSystemService(final String name) {
313 return getActivity().getSystemService(name);
314 }
315
316 /**
Amith Yamasanid7993472010-08-18 13:59:28 -0700317 * Returns the PackageManager from the owning Activity.
318 */
319 protected PackageManager getPackageManager() {
320 return getActivity().getPackageManager();
321 }
322
Dianne Hackborn0385cf12011-01-24 16:22:13 -0800323 @Override
324 public void onDetach() {
325 if (isRemoving()) {
326 if (mDialogFragment != null) {
327 mDialogFragment.dismiss();
328 mDialogFragment = null;
329 }
330 }
331 super.onDetach();
332 }
333
Amith Yamasanid7993472010-08-18 13:59:28 -0700334 // Dialog management
335
336 protected void showDialog(int dialogId) {
337 if (mDialogFragment != null) {
338 Log.e(TAG, "Old dialog fragment not null!");
339 }
340 mDialogFragment = new SettingsDialogFragment(this, dialogId);
Fabrice Di Meglio377dd622014-02-12 20:05:57 -0800341 mDialogFragment.show(getChildFragmentManager(), Integer.toString(dialogId));
Amith Yamasanid7993472010-08-18 13:59:28 -0700342 }
343
344 public Dialog onCreateDialog(int dialogId) {
345 return null;
346 }
347
348 protected void removeDialog(int dialogId) {
Hung-ying Tyanadc83d82011-01-24 15:05:27 +0800349 // mDialogFragment may not be visible yet in parent fragment's onResume().
350 // To be able to dismiss dialog at that time, don't check
351 // mDialogFragment.isVisible().
352 if (mDialogFragment != null && mDialogFragment.getDialogId() == dialogId) {
Amith Yamasanid7993472010-08-18 13:59:28 -0700353 mDialogFragment.dismiss();
354 }
355 mDialogFragment = null;
356 }
357
Hung-ying Tyan0ee51e02011-01-25 16:42:14 +0800358 /**
359 * Sets the OnCancelListener of the dialog shown. This method can only be
360 * called after showDialog(int) and before removeDialog(int). The method
361 * does nothing otherwise.
362 */
363 protected void setOnCancelListener(DialogInterface.OnCancelListener listener) {
364 if (mDialogFragment != null) {
365 mDialogFragment.mOnCancelListener = listener;
366 }
367 }
368
369 /**
370 * Sets the OnDismissListener of the dialog shown. This method can only be
371 * called after showDialog(int) and before removeDialog(int). The method
372 * does nothing otherwise.
373 */
374 protected void setOnDismissListener(DialogInterface.OnDismissListener listener) {
375 if (mDialogFragment != null) {
376 mDialogFragment.mOnDismissListener = listener;
377 }
378 }
379
Amith Yamasanic861cf82012-10-02 14:51:46 -0700380 public void onDialogShowing() {
381 // override in subclass to attach a dismiss listener, for instance
382 }
383
Amith Yamasani43c69782010-12-01 09:04:36 -0800384 public static class SettingsDialogFragment extends DialogFragment {
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800385 private static final String KEY_DIALOG_ID = "key_dialog_id";
386 private static final String KEY_PARENT_FRAGMENT_ID = "key_parent_fragment_id";
387
Amith Yamasanid7993472010-08-18 13:59:28 -0700388 private int mDialogId;
389
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800390 private Fragment mParentFragment;
391
Hung-ying Tyan0ee51e02011-01-25 16:42:14 +0800392 private DialogInterface.OnCancelListener mOnCancelListener;
393 private DialogInterface.OnDismissListener mOnDismissListener;
394
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800395 public SettingsDialogFragment() {
396 /* do nothing */
397 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700398
Amith Yamasani43c69782010-12-01 09:04:36 -0800399 public SettingsDialogFragment(DialogCreatable fragment, int dialogId) {
Amith Yamasanid7993472010-08-18 13:59:28 -0700400 mDialogId = dialogId;
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800401 if (!(fragment instanceof Fragment)) {
402 throw new IllegalArgumentException("fragment argument must be an instance of "
403 + Fragment.class.getName());
404 }
405 mParentFragment = (Fragment) fragment;
406 }
407
408 @Override
Dianne Hackborn300768f2011-01-27 20:39:21 -0800409 public void onSaveInstanceState(Bundle outState) {
410 super.onSaveInstanceState(outState);
411 if (mParentFragment != null) {
412 outState.putInt(KEY_DIALOG_ID, mDialogId);
413 outState.putInt(KEY_PARENT_FRAGMENT_ID, mParentFragment.getId());
414 }
415 }
416
417 @Override
Amith Yamasanic861cf82012-10-02 14:51:46 -0700418 public void onStart() {
419 super.onStart();
420
421 if (mParentFragment != null && mParentFragment instanceof SettingsPreferenceFragment) {
422 ((SettingsPreferenceFragment) mParentFragment).onDialogShowing();
423 }
424 }
425
426 @Override
Dianne Hackborn300768f2011-01-27 20:39:21 -0800427 public Dialog onCreateDialog(Bundle savedInstanceState) {
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800428 if (savedInstanceState != null) {
429 mDialogId = savedInstanceState.getInt(KEY_DIALOG_ID, 0);
Fabrice Di Meglio377dd622014-02-12 20:05:57 -0800430 mParentFragment = getParentFragment();
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800431 int mParentFragmentId = savedInstanceState.getInt(KEY_PARENT_FRAGMENT_ID, -1);
Fabrice Di Meglio377dd622014-02-12 20:05:57 -0800432 if (!(mParentFragment instanceof DialogCreatable)) {
433 throw new IllegalArgumentException(
434 (mParentFragment != null
435 ? mParentFragment.getClass().getName()
436 : mParentFragmentId)
437 + " must implement "
438 + DialogCreatable.class.getName());
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800439 }
Amith Yamasani8875ede2011-01-31 12:46:57 -0800440 // This dialog fragment could be created from non-SettingsPreferenceFragment
441 if (mParentFragment instanceof SettingsPreferenceFragment) {
442 // restore mDialogFragment in mParentFragment
443 ((SettingsPreferenceFragment) mParentFragment).mDialogFragment = this;
444 }
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800445 }
Svetoslav Ganov749ba652010-12-09 14:53:02 -0800446 return ((DialogCreatable) mParentFragment).onCreateDialog(mDialogId);
Amith Yamasanid7993472010-08-18 13:59:28 -0700447 }
448
Hung-ying Tyan0ee51e02011-01-25 16:42:14 +0800449 @Override
450 public void onCancel(DialogInterface dialog) {
451 super.onCancel(dialog);
452 if (mOnCancelListener != null) {
453 mOnCancelListener.onCancel(dialog);
454 }
455 }
456
457 @Override
458 public void onDismiss(DialogInterface dialog) {
459 super.onDismiss(dialog);
460 if (mOnDismissListener != null) {
461 mOnDismissListener.onDismiss(dialog);
462 }
463 }
Amith Yamasani8875ede2011-01-31 12:46:57 -0800464
Amith Yamasanid7993472010-08-18 13:59:28 -0700465 public int getDialogId() {
466 return mDialogId;
467 }
Hung-ying Tyan18eb39d2011-01-28 16:17:27 +0800468
469 @Override
470 public void onDetach() {
471 super.onDetach();
472
Amith Yamasani8875ede2011-01-31 12:46:57 -0800473 // This dialog fragment could be created from non-SettingsPreferenceFragment
474 if (mParentFragment instanceof SettingsPreferenceFragment) {
475 // in case the dialog is not explicitly removed by removeDialog()
476 if (((SettingsPreferenceFragment) mParentFragment).mDialogFragment == this) {
477 ((SettingsPreferenceFragment) mParentFragment).mDialogFragment = null;
478 }
Hung-ying Tyan18eb39d2011-01-28 16:17:27 +0800479 }
480 }
Amith Yamasanid7993472010-08-18 13:59:28 -0700481 }
Daisuke Miyakawa9c8bde52010-08-25 11:58:37 -0700482
483 protected boolean hasNextButton() {
Daisuke Miyakawa79c5fd92011-01-15 14:58:00 -0800484 return ((ButtonBarHandler)getActivity()).hasNextButton();
Daisuke Miyakawa9c8bde52010-08-25 11:58:37 -0700485 }
486
487 protected Button getNextButton() {
Daisuke Miyakawa79c5fd92011-01-15 14:58:00 -0800488 return ((ButtonBarHandler)getActivity()).getNextButton();
Daisuke Miyakawa9c8bde52010-08-25 11:58:37 -0700489 }
490
Daisuke Miyakawa6ebf8612010-09-10 09:48:51 -0700491 public void finish() {
492 getActivity().onBackPressed();
493 }
494
Daisuke Miyakawab5647c52010-09-10 18:04:02 -0700495 public boolean startFragment(
496 Fragment caller, String fragmentClass, int requestCode, Bundle extras) {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800497 if (getActivity() instanceof SettingsActivity) {
498 SettingsActivity sa = (SettingsActivity) getActivity();
499 sa.startPreferencePanel(fragmentClass, extras,
Gilles Debunne64650542011-08-23 11:01:35 -0700500 R.string.lock_settings_picker_title, null, caller, requestCode);
Daisuke Miyakawa25af1502010-09-24 11:29:31 -0700501 return true;
Daisuke Miyakawab5647c52010-09-10 18:04:02 -0700502 } else {
Fabrice Di Meglio263bcc82014-01-17 19:17:58 -0800503 Log.w(TAG, "Parent isn't Settings activity, thus there's no way to launch the "
Daisuke Miyakawa25af1502010-09-24 11:29:31 -0700504 + "given Fragment (name: " + fragmentClass + ", requestCode: " + requestCode
505 + ")");
Daisuke Miyakawab5647c52010-09-10 18:04:02 -0700506 return false;
507 }
508 }
509
Amith Yamasanid7993472010-08-18 13:59:28 -0700510}