| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.preference; |
| 18 |
|
| 19 |
import android.annotation.Nullable; |
| 20 |
import android.annotation.SystemApi; |
| 21 |
import android.annotation.XmlRes; |
| 22 |
import android.app.Activity; |
| 23 |
import android.compat.annotation.UnsupportedAppUsage; |
| 24 |
import android.content.Context; |
| 25 |
import android.content.DialogInterface; |
| 26 |
import android.content.Intent; |
| 27 |
import android.content.SharedPreferences; |
| 28 |
import android.content.pm.ActivityInfo; |
| 29 |
import android.content.pm.PackageManager; |
| 30 |
import android.content.pm.PackageManager.NameNotFoundException; |
| 31 |
import android.content.pm.ResolveInfo; |
| 32 |
import android.content.res.XmlResourceParser; |
| 33 |
import android.os.Build; |
| 34 |
import android.os.Bundle; |
| 35 |
import android.util.Log; |
| 36 |
|
| 37 |
import java.util.ArrayList; |
| 38 |
import java.util.HashSet; |
| 39 |
import java.util.List; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
@Deprecated |
| 58 |
public class PreferenceManager { |
| 59 |
|
| 60 |
private static final String TAG = "PreferenceManager"; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public static final String METADATA_KEY_PREFERENCES = "android.preference"; |
| 66 |
|
| 67 |
public static final String KEY_HAS_SET_DEFAULT_VALUES = "_has_set_default_values"; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
@Nullable |
| 73 |
private Activity mActivity; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
@Nullable |
| 79 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 80 |
private PreferenceFragment mFragment; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
private Context mContext; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
private long mNextId = 0; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
private int mNextRequestCode; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
@Nullable |
| 103 |
@UnsupportedAppUsage |
| 104 |
private SharedPreferences mSharedPreferences; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
@Nullable |
| 111 |
private PreferenceDataStore mPreferenceDataStore; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
@Nullable |
| 118 |
private SharedPreferences.Editor mEditor; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
private boolean mNoCommit; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
private String mSharedPreferencesName; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
private int mSharedPreferencesMode; |
| 137 |
|
| 138 |
private static final int STORAGE_DEFAULT = 0; |
| 139 |
private static final int STORAGE_DEVICE_PROTECTED = 1; |
| 140 |
private static final int STORAGE_CREDENTIAL_PROTECTED = 2; |
| 141 |
|
| 142 |
private int mStorage = STORAGE_DEFAULT; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
@Nullable |
| 148 |
private PreferenceScreen mPreferenceScreen; |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
@Nullable |
| 154 |
private List<OnActivityResultListener> mActivityResultListeners; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
@Nullable |
| 160 |
private List<OnActivityStopListener> mActivityStopListeners; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
@Nullable |
| 166 |
@UnsupportedAppUsage |
| 167 |
private List<OnActivityDestroyListener> mActivityDestroyListeners; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
@Nullable |
| 174 |
private List<DialogInterface> mPreferencesScreens; |
| 175 |
|
| 176 |
@UnsupportedAppUsage |
| 177 |
private OnPreferenceTreeClickListener mOnPreferenceTreeClickListener; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
@UnsupportedAppUsage |
| 183 |
public PreferenceManager(Activity activity, int firstRequestCode) { |
| 184 |
mActivity = activity; |
| 185 |
mNextRequestCode = firstRequestCode; |
| 186 |
|
| 187 |
init(activity); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
@UnsupportedAppUsage |
| 199 |
PreferenceManager(Context context) { |
| 200 |
init(context); |
| 201 |
} |
| 202 |
|
| 203 |
private void init(Context context) { |
| 204 |
mContext = context; |
| 205 |
|
| 206 |
setSharedPreferencesName(getDefaultSharedPreferencesName(context)); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) |
| 213 |
void setFragment(PreferenceFragment fragment) { |
| 214 |
mFragment = fragment; |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
@Nullable |
| 221 |
@UnsupportedAppUsage |
| 222 |
PreferenceFragment getFragment() { |
| 223 |
return mFragment; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
public void setPreferenceDataStore(PreferenceDataStore dataStore) { |
| 237 |
mPreferenceDataStore = dataStore; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
@Nullable |
| 248 |
public PreferenceDataStore getPreferenceDataStore() { |
| 249 |
return mPreferenceDataStore; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
private List<ResolveInfo> queryIntentActivities(Intent queryIntent) { |
| 261 |
return mContext.getPackageManager().queryIntentActivities(queryIntent, |
| 262 |
PackageManager.GET_META_DATA); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
@UnsupportedAppUsage |
| 281 |
PreferenceScreen inflateFromIntent(Intent queryIntent, PreferenceScreen rootPreferences) { |
| 282 |
final List<ResolveInfo> activities = queryIntentActivities(queryIntent); |
| 283 |
final HashSet<String> inflatedRes = new HashSet<String>(); |
| 284 |
|
| 285 |
for (int i = activities.size() - 1; i >= 0; i--) { |
| 286 |
final ActivityInfo activityInfo = activities.get(i).activityInfo; |
| 287 |
final Bundle metaData = activityInfo.metaData; |
| 288 |
|
| 289 |
if ((metaData == null) || !metaData.containsKey(METADATA_KEY_PREFERENCES)) { |
| 290 |
continue; |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
final String uniqueResId = activityInfo.packageName + ":" |
| 296 |
+ activityInfo.metaData.getInt(METADATA_KEY_PREFERENCES); |
| 297 |
|
| 298 |
if (!inflatedRes.contains(uniqueResId)) { |
| 299 |
inflatedRes.add(uniqueResId); |
| 300 |
|
| 301 |
final Context context; |
| 302 |
try { |
| 303 |
context = mContext.createPackageContext(activityInfo.packageName, 0); |
| 304 |
} catch (NameNotFoundException e) { |
| 305 |
Log.w(TAG, "Could not create context for " + activityInfo.packageName + ": " |
| 306 |
+ Log.getStackTraceString(e)); |
| 307 |
continue; |
| 308 |
} |
| 309 |
|
| 310 |
final PreferenceInflater inflater = new PreferenceInflater(context, this); |
| 311 |
final XmlResourceParser parser = activityInfo.loadXmlMetaData(context |
| 312 |
.getPackageManager(), METADATA_KEY_PREFERENCES); |
| 313 |
rootPreferences = (PreferenceScreen) inflater |
| 314 |
.inflate(parser, rootPreferences, true); |
| 315 |
parser.close(); |
| 316 |
} |
| 317 |
} |
| 318 |
|
| 319 |
rootPreferences.onAttachedToHierarchy(this); |
| 320 |
|
| 321 |
return rootPreferences; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
@UnsupportedAppUsage |
| 337 |
public PreferenceScreen inflateFromResource(Context context, @XmlRes int resId, |
| 338 |
PreferenceScreen rootPreferences) { |
| 339 |
|
| 340 |
setNoCommit(true); |
| 341 |
|
| 342 |
final PreferenceInflater inflater = new PreferenceInflater(context, this); |
| 343 |
rootPreferences = (PreferenceScreen) inflater.inflate(resId, rootPreferences, true); |
| 344 |
rootPreferences.onAttachedToHierarchy(this); |
| 345 |
|
| 346 |
|
| 347 |
setNoCommit(false); |
| 348 |
|
| 349 |
return rootPreferences; |
| 350 |
} |
| 351 |
|
| 352 |
public PreferenceScreen createPreferenceScreen(Context context) { |
| 353 |
final PreferenceScreen preferenceScreen = new PreferenceScreen(context, null); |
| 354 |
preferenceScreen.onAttachedToHierarchy(this); |
| 355 |
return preferenceScreen; |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
long getNextId() { |
| 364 |
synchronized (this) { |
| 365 |
return mNextId++; |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
public String getSharedPreferencesName() { |
| 377 |
return mSharedPreferencesName; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
public void setSharedPreferencesName(String sharedPreferencesName) { |
| 391 |
mSharedPreferencesName = sharedPreferencesName; |
| 392 |
mSharedPreferences = null; |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
public int getSharedPreferencesMode() { |
| 403 |
return mSharedPreferencesMode; |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
public void setSharedPreferencesMode(int sharedPreferencesMode) { |
| 414 |
mSharedPreferencesMode = sharedPreferencesMode; |
| 415 |
mSharedPreferences = null; |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
public void setStorageDefault() { |
| 423 |
mStorage = STORAGE_DEFAULT; |
| 424 |
mSharedPreferences = null; |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
public void setStorageDeviceProtected() { |
| 445 |
mStorage = STORAGE_DEVICE_PROTECTED; |
| 446 |
mSharedPreferences = null; |
| 447 |
} |
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
@SystemApi |
| 463 |
public void setStorageCredentialProtected() { |
| 464 |
mStorage = STORAGE_CREDENTIAL_PROTECTED; |
| 465 |
mSharedPreferences = null; |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
public boolean isStorageDefault() { |
| 476 |
return mStorage == STORAGE_DEFAULT; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
public boolean isStorageDeviceProtected() { |
| 487 |
return mStorage == STORAGE_DEVICE_PROTECTED; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
@SystemApi |
| 499 |
public boolean isStorageCredentialProtected() { |
| 500 |
return mStorage == STORAGE_CREDENTIAL_PROTECTED; |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
public SharedPreferences getSharedPreferences() { |
| 511 |
if (mPreferenceDataStore != null) { |
| 512 |
return null; |
| 513 |
} |
| 514 |
|
| 515 |
if (mSharedPreferences == null) { |
| 516 |
final Context storageContext; |
| 517 |
switch (mStorage) { |
| 518 |
case STORAGE_DEVICE_PROTECTED: |
| 519 |
storageContext = mContext.createDeviceProtectedStorageContext(); |
| 520 |
break; |
| 521 |
case STORAGE_CREDENTIAL_PROTECTED: |
| 522 |
storageContext = mContext.createCredentialProtectedStorageContext(); |
| 523 |
break; |
| 524 |
default: |
| 525 |
storageContext = mContext; |
| 526 |
break; |
| 527 |
} |
| 528 |
|
| 529 |
mSharedPreferences = storageContext.getSharedPreferences(mSharedPreferencesName, |
| 530 |
mSharedPreferencesMode); |
| 531 |
} |
| 532 |
|
| 533 |
return mSharedPreferences; |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
public static SharedPreferences getDefaultSharedPreferences(Context context) { |
| 545 |
return context.getSharedPreferences(getDefaultSharedPreferencesName(context), |
| 546 |
getDefaultSharedPreferencesMode()); |
| 547 |
} |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
public static String getDefaultSharedPreferencesName(Context context) { |
| 555 |
return context.getPackageName() + "_preferences"; |
| 556 |
} |
| 557 |
|
| 558 |
private static int getDefaultSharedPreferencesMode() { |
| 559 |
return Context.MODE_PRIVATE; |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
@Nullable |
| 568 |
@UnsupportedAppUsage |
| 569 |
PreferenceScreen getPreferenceScreen() { |
| 570 |
return mPreferenceScreen; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
@UnsupportedAppUsage |
| 580 |
boolean setPreferences(PreferenceScreen preferenceScreen) { |
| 581 |
if (preferenceScreen != mPreferenceScreen) { |
| 582 |
mPreferenceScreen = preferenceScreen; |
| 583 |
return true; |
| 584 |
} |
| 585 |
|
| 586 |
return false; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
@Nullable |
| 597 |
public Preference findPreference(CharSequence key) { |
| 598 |
if (mPreferenceScreen == null) { |
| 599 |
return null; |
| 600 |
} |
| 601 |
|
| 602 |
return mPreferenceScreen.findPreference(key); |
| 603 |
} |
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain) { |
| 627 |
|
| 628 |
|
| 629 |
setDefaultValues(context, getDefaultSharedPreferencesName(context), |
| 630 |
getDefaultSharedPreferencesMode(), resId, readAgain); |
| 631 |
} |
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
public static void setDefaultValues(Context context, String sharedPreferencesName, |
| 662 |
int sharedPreferencesMode, int resId, boolean readAgain) { |
| 663 |
final SharedPreferences defaultValueSp = context.getSharedPreferences( |
| 664 |
KEY_HAS_SET_DEFAULT_VALUES, Context.MODE_PRIVATE); |
| 665 |
|
| 666 |
if (readAgain || !defaultValueSp.getBoolean(KEY_HAS_SET_DEFAULT_VALUES, false)) { |
| 667 |
final PreferenceManager pm = new PreferenceManager(context); |
| 668 |
pm.setSharedPreferencesName(sharedPreferencesName); |
| 669 |
pm.setSharedPreferencesMode(sharedPreferencesMode); |
| 670 |
pm.inflateFromResource(context, resId, null); |
| 671 |
|
| 672 |
SharedPreferences.Editor editor = |
| 673 |
defaultValueSp.edit().putBoolean(KEY_HAS_SET_DEFAULT_VALUES, true); |
| 674 |
try { |
| 675 |
editor.apply(); |
| 676 |
} catch (AbstractMethodError unused) { |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
editor.commit(); |
| 681 |
} |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
@UnsupportedAppUsage |
| 695 |
SharedPreferences.Editor getEditor() { |
| 696 |
if (mPreferenceDataStore != null) { |
| 697 |
return null; |
| 698 |
} |
| 699 |
|
| 700 |
if (mNoCommit) { |
| 701 |
if (mEditor == null) { |
| 702 |
mEditor = getSharedPreferences().edit(); |
| 703 |
} |
| 704 |
|
| 705 |
return mEditor; |
| 706 |
} else { |
| 707 |
return getSharedPreferences().edit(); |
| 708 |
} |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
@UnsupportedAppUsage |
| 721 |
boolean shouldCommit() { |
| 722 |
return !mNoCommit; |
| 723 |
} |
| 724 |
|
| 725 |
@UnsupportedAppUsage |
| 726 |
private void setNoCommit(boolean noCommit) { |
| 727 |
if (!noCommit && mEditor != null) { |
| 728 |
try { |
| 729 |
mEditor.apply(); |
| 730 |
} catch (AbstractMethodError unused) { |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
mEditor.commit(); |
| 735 |
} |
| 736 |
} |
| 737 |
mNoCommit = noCommit; |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
@Nullable |
| 752 |
@UnsupportedAppUsage |
| 753 |
Activity getActivity() { |
| 754 |
return mActivity; |
| 755 |
} |
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
Context getContext() { |
| 764 |
return mContext; |
| 765 |
} |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
@UnsupportedAppUsage |
| 773 |
void registerOnActivityResultListener(OnActivityResultListener listener) { |
| 774 |
synchronized (this) { |
| 775 |
if (mActivityResultListeners == null) { |
| 776 |
mActivityResultListeners = new ArrayList<OnActivityResultListener>(); |
| 777 |
} |
| 778 |
|
| 779 |
if (!mActivityResultListeners.contains(listener)) { |
| 780 |
mActivityResultListeners.add(listener); |
| 781 |
} |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
@UnsupportedAppUsage |
| 791 |
void unregisterOnActivityResultListener(OnActivityResultListener listener) { |
| 792 |
synchronized (this) { |
| 793 |
if (mActivityResultListeners != null) { |
| 794 |
mActivityResultListeners.remove(listener); |
| 795 |
} |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
@UnsupportedAppUsage |
| 803 |
void dispatchActivityResult(int requestCode, int resultCode, Intent data) { |
| 804 |
List<OnActivityResultListener> list; |
| 805 |
|
| 806 |
synchronized (this) { |
| 807 |
if (mActivityResultListeners == null) return; |
| 808 |
list = new ArrayList<OnActivityResultListener>(mActivityResultListeners); |
| 809 |
} |
| 810 |
|
| 811 |
final int N = list.size(); |
| 812 |
for (int i = 0; i < N; i++) { |
| 813 |
if (list.get(i).onActivityResult(requestCode, resultCode, data)) { |
| 814 |
break; |
| 815 |
} |
| 816 |
} |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
@UnsupportedAppUsage |
| 826 |
public void registerOnActivityStopListener(OnActivityStopListener listener) { |
| 827 |
synchronized (this) { |
| 828 |
if (mActivityStopListeners == null) { |
| 829 |
mActivityStopListeners = new ArrayList<OnActivityStopListener>(); |
| 830 |
} |
| 831 |
|
| 832 |
if (!mActivityStopListeners.contains(listener)) { |
| 833 |
mActivityStopListeners.add(listener); |
| 834 |
} |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
@UnsupportedAppUsage |
| 845 |
public void unregisterOnActivityStopListener(OnActivityStopListener listener) { |
| 846 |
synchronized (this) { |
| 847 |
if (mActivityStopListeners != null) { |
| 848 |
mActivityStopListeners.remove(listener); |
| 849 |
} |
| 850 |
} |
| 851 |
} |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
@UnsupportedAppUsage |
| 858 |
void dispatchActivityStop() { |
| 859 |
List<OnActivityStopListener> list; |
| 860 |
|
| 861 |
synchronized (this) { |
| 862 |
if (mActivityStopListeners == null) return; |
| 863 |
list = new ArrayList<OnActivityStopListener>(mActivityStopListeners); |
| 864 |
} |
| 865 |
|
| 866 |
final int N = list.size(); |
| 867 |
for (int i = 0; i < N; i++) { |
| 868 |
list.get(i).onActivityStop(); |
| 869 |
} |
| 870 |
} |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
@UnsupportedAppUsage |
| 878 |
void registerOnActivityDestroyListener(OnActivityDestroyListener listener) { |
| 879 |
synchronized (this) { |
| 880 |
if (mActivityDestroyListeners == null) { |
| 881 |
mActivityDestroyListeners = new ArrayList<OnActivityDestroyListener>(); |
| 882 |
} |
| 883 |
|
| 884 |
if (!mActivityDestroyListeners.contains(listener)) { |
| 885 |
mActivityDestroyListeners.add(listener); |
| 886 |
} |
| 887 |
} |
| 888 |
} |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
@UnsupportedAppUsage |
| 896 |
void unregisterOnActivityDestroyListener(OnActivityDestroyListener listener) { |
| 897 |
synchronized (this) { |
| 898 |
if (mActivityDestroyListeners != null) { |
| 899 |
mActivityDestroyListeners.remove(listener); |
| 900 |
} |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
@UnsupportedAppUsage |
| 909 |
void dispatchActivityDestroy() { |
| 910 |
List<OnActivityDestroyListener> list = null; |
| 911 |
|
| 912 |
synchronized (this) { |
| 913 |
if (mActivityDestroyListeners != null) { |
| 914 |
list = new ArrayList<OnActivityDestroyListener>(mActivityDestroyListeners); |
| 915 |
} |
| 916 |
} |
| 917 |
|
| 918 |
if (list != null) { |
| 919 |
final int N = list.size(); |
| 920 |
for (int i = 0; i < N; i++) { |
| 921 |
list.get(i).onActivityDestroy(); |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
dismissAllScreens(); |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
@UnsupportedAppUsage |
| 937 |
int getNextRequestCode() { |
| 938 |
synchronized (this) { |
| 939 |
return mNextRequestCode++; |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
void addPreferencesScreen(DialogInterface screen) { |
| 944 |
synchronized (this) { |
| 945 |
|
| 946 |
if (mPreferencesScreens == null) { |
| 947 |
mPreferencesScreens = new ArrayList<DialogInterface>(); |
| 948 |
} |
| 949 |
|
| 950 |
mPreferencesScreens.add(screen); |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
void removePreferencesScreen(DialogInterface screen) { |
| 955 |
synchronized (this) { |
| 956 |
|
| 957 |
if (mPreferencesScreens == null) { |
| 958 |
return; |
| 959 |
} |
| 960 |
|
| 961 |
mPreferencesScreens.remove(screen); |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
void dispatchNewIntent(Intent intent) { |
| 971 |
dismissAllScreens(); |
| 972 |
} |
| 973 |
|
| 974 |
private void dismissAllScreens() { |
| 975 |
|
| 976 |
ArrayList<DialogInterface> screensToDismiss; |
| 977 |
|
| 978 |
synchronized (this) { |
| 979 |
|
| 980 |
if (mPreferencesScreens == null) { |
| 981 |
return; |
| 982 |
} |
| 983 |
|
| 984 |
screensToDismiss = new ArrayList<DialogInterface>(mPreferencesScreens); |
| 985 |
mPreferencesScreens.clear(); |
| 986 |
} |
| 987 |
|
| 988 |
for (int i = screensToDismiss.size() - 1; i >= 0; i--) { |
| 989 |
screensToDismiss.get(i).dismiss(); |
| 990 |
} |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
void setOnPreferenceTreeClickListener(OnPreferenceTreeClickListener listener) { |
| 1000 |
mOnPreferenceTreeClickListener = listener; |
| 1001 |
} |
| 1002 |
|
| 1003 |
@Nullable |
| 1004 |
OnPreferenceTreeClickListener getOnPreferenceTreeClickListener() { |
| 1005 |
return mOnPreferenceTreeClickListener; |
| 1006 |
} |
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
@Deprecated |
| 1022 |
public interface OnPreferenceTreeClickListener { |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference); |
| 1033 |
} |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
@Deprecated |
| 1046 |
public interface OnActivityResultListener { |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
boolean onActivityResult(int requestCode, int resultCode, Intent data); |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
@Deprecated |
| 1068 |
public interface OnActivityStopListener { |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
void onActivityStop(); |
| 1074 |
} |
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
@Deprecated |
| 1087 |
public interface OnActivityDestroyListener { |
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
void onActivityDestroy(); |
| 1093 |
} |
| 1094 |
|
| 1095 |
} |