コード例 #1
0
    @Override
    public void onPermissionsDenied(
        @NonNull String[] grantedPermissions,
        @NonNull String[] deniedPermissions,
        @NonNull String[] declinedPermissions) {
      MainSettingsActivity activity = mMainSettingsActivityWeakReference.get();
      if (activity == null) return;
      // if the result is DENIED and the OS says "do not show rationale", it means the user has
      // ticked "Don't ask me again".
      final boolean userSaysDontAskAgain =
          !ActivityCompat.shouldShowRequestPermissionRationale(
              activity, Manifest.permission.READ_CONTACTS);
      // the user has denied us from reading the Contacts information.
      // I'll ask them to whether they want to grant anyway, or disable ContactDictionary
      AlertDialog.Builder builder = new AlertDialog.Builder(activity);
      builder.setCancelable(true);
      builder.setIcon(R.drawable.ic_notification_contacts_permission_required);
      builder.setTitle(R.string.notification_read_contacts_title);
      builder.setMessage(activity.getString(R.string.contacts_permissions_dialog_message));
      builder.setPositiveButton(
          activity.getString(
              userSaysDontAskAgain
                  ? R.string.navigate_to_app_permissions
                  : R.string.allow_permission),
          activity.mContactsDictionaryDialogListener);
      builder.setNegativeButton(
          activity.getString(R.string.turn_off_contacts_dictionary),
          activity.mContactsDictionaryDialogListener);

      if (activity.mAlertDialog != null && activity.mAlertDialog.isShowing())
        activity.mAlertDialog.dismiss();
      activity.mAlertDialog = builder.create();
      activity.mAlertDialog.show();
    }
コード例 #2
0
  @Test
  public void testOnCreateWhenASKNotEnabled() throws Exception {
    // mocking ASK as disabled and inactive
    ShadowSettings.ShadowSecure.putString(
        RuntimeEnvironment.application.getContentResolver(),
        Settings.Secure.ENABLED_INPUT_METHODS,
        new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString());
    ShadowSettings.ShadowSecure.putString(
        RuntimeEnvironment.application.getContentResolver(),
        Settings.Secure.DEFAULT_INPUT_METHOD,
        new ComponentName("net.some.one.else", "net.some.one.else.IME").flattenToString());

    Assert.assertNull(ShadowApplication.getInstance().getNextStartedActivity());
    ActivityController<LauncherSettingsActivity> controller =
        Robolectric.buildActivity(LauncherSettingsActivity.class).attach().create().resume();
    Intent startWizardActivityIntent = ShadowApplication.getInstance().getNextStartedActivity();
    Assert.assertNotNull(startWizardActivityIntent);

    Intent expectIntent =
        MainSettingsActivity.createStartActivityIntentForAddingFragmentToUi(
            controller.get(),
            MainSettingsActivity.class,
            new SetUpKeyboardWizardFragment(),
            TransitionExperiences.ROOT_FRAGMENT_EXPERIENCE_TRANSITION);

    Assert.assertEquals(expectIntent.getComponent(), startWizardActivityIntent.getComponent());
    Assert.assertEquals(expectIntent.getAction(), startWizardActivityIntent.getAction());
    Assert.assertEquals(
        expectIntent.getParcelableExtra("FragmentChauffeurActivity_KEY_FRAGMENT_ANIMATION"),
        startWizardActivityIntent.getParcelableExtra(
            "FragmentChauffeurActivity_KEY_FRAGMENT_ANIMATION"));
    Assert.assertEquals(
        expectIntent.getSerializableExtra("FragmentChauffeurActivity_KEY_FRAGMENT_CLASS_TO_ADD"),
        startWizardActivityIntent.getSerializableExtra(
            "FragmentChauffeurActivity_KEY_FRAGMENT_CLASS_TO_ADD"));
  }
コード例 #3
0
 @Override
 public void onStart() {
   super.onStart();
   MainSettingsActivity.setActivityTitle(this, getString(R.string.next_word_dict_settings));
   loadUsageStatistics();
 }