private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
      root.removeAll();
    }
    // Location Settings
    addPreferencesFromResource(R.xml.location_settings);

    addPreferencesFromResource(R.xml.security_settings);
    root = getPreferenceScreen();

    // Location Settings
    mNetwork = (CheckBoxPreference) root.findPreference(KEY_LOCATION_NETWORK);
    mGps = (CheckBoxPreference) root.findPreference(KEY_LOCATION_GPS);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    if (GoogleLocationSettingHelper.isAvailable(getActivity())) {
      // GSF present, Add setting for 'Use My Location'
      CheckBoxPreference useLocation = new CheckBoxPreference(getActivity());
      useLocation.setKey(KEY_USE_LOCATION);
      useLocation.setTitle(R.string.use_location_title);
      useLocation.setSummary(R.string.use_location_summary);
      useLocation.setChecked(
          GoogleLocationSettingHelper.getUseLocationForServices(getActivity())
              == GoogleLocationSettingHelper.USE_LOCATION_FOR_SERVICES_ON);
      useLocation.setPersistent(false);
      useLocation.setOnPreferenceChangeListener(this);
      getPreferenceScreen().addPreference(useLocation);
      mUseLocation = useLocation;
    }

    // Change the summary for wifi-only devices
    if (Utils.isWifiOnly(getActivity())) {
      mNetwork.setSummaryOn(R.string.location_neighborhood_level_wifi);
    }

    // Security Settings
    // Add options for lock/unlock screen
    int resid = 0;
    if (!mLockPatternUtils.isSecure()) {
      if (mLockPatternUtils.isLockScreenDisabled()) {
        resid = R.xml.security_settings_lockscreen;
      } else {
        resid = R.xml.security_settings_chooser;
      }
    } else if (mLockPatternUtils.usingBiometricWeak()
        && mLockPatternUtils.isBiometricWeakInstalled()) {
      resid = R.xml.security_settings_biometric_weak;
    } else {
      switch (mLockPatternUtils.getKeyguardStoredPasswordQuality()) {
        case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
          resid = R.xml.security_settings_pattern;
          break;
        case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
          resid = R.xml.security_settings_pin;
          break;
        case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
        case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
        case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
          resid = R.xml.security_settings_password;
          break;
      }
    }
    addPreferencesFromResource(resid);

    boolean isSystemEmmcDetect = false;
    try {
      Class c = Class.forName(SYSTEM_DETECT_HANDLER);
      ISystemInfoDetectHandler handler = (ISystemInfoDetectHandler) c.newInstance();
      isSystemEmmcDetect = handler.isFileSystemAutoDetect();
      Log.i("SecuritySettings", "isSystemEmmcDetect = " + isSystemEmmcDetect);
    } catch (Exception e) {
      Log.i("SecuritySettings", "exception " + e);
      isSystemEmmcDetect = false;
    }
    if ((DefaultQuery.SYSTEM_INFO_DETECT_ENABLED == 1)
        || ((DefaultQuery.SYSTEM_INFO_DETECT_ENABLED == 2) && isSystemEmmcDetect)) {
      // Add options for device encryption
      DevicePolicyManager dpm =
          (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);

      switch (dpm.getStorageEncryptionStatus()) {
        case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
          // The device is currently encrypted.
          addPreferencesFromResource(R.xml.security_settings_encrypted);
          break;
        case DevicePolicyManager.ENCRYPTION_STATUS_INACTIVE:
          // This device supports encryption but isn't encrypted.
          addPreferencesFromResource(R.xml.security_settings_unencrypted);
          break;
      }
    }

    // lock after preference
    mLockAfter = (ListPreference) root.findPreference(KEY_LOCK_AFTER_TIMEOUT);
    if (mLockAfter != null) {
      setupLockAfterPreference();
      updateLockAfterPreferenceSummary();
    }

    // visible pattern
    mVisiblePattern = (CheckBoxPreference) root.findPreference(KEY_VISIBLE_PATTERN);

    // lock instantly on power key press
    mPowerButtonInstantlyLocks =
        (CheckBoxPreference) root.findPreference(KEY_POWER_INSTANTLY_LOCKS);

    // don't display visible pattern if biometric and backup is not
    // pattern
    if (resid == R.xml.security_settings_biometric_weak
        && mLockPatternUtils.getKeyguardStoredPasswordQuality()
            != DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
      PreferenceGroup securityCategory =
          (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
      if (securityCategory != null && mVisiblePattern != null) {
        securityCategory.removePreference(root.findPreference(KEY_VISIBLE_PATTERN));
      }
    }

    // tactile feedback. Should be common to all unlock preference
    // screens.
    mTactileFeedback = (CheckBoxPreference) root.findPreference(KEY_TACTILE_FEEDBACK_ENABLED);
    if (!((Vibrator) getSystemService(Context.VIBRATOR_SERVICE)).hasVibrator()) {
      PreferenceGroup securityCategory =
          (PreferenceGroup) root.findPreference(KEY_SECURITY_CATEGORY);
      if (securityCategory != null && mTactileFeedback != null) {
        securityCategory.removePreference(mTactileFeedback);
      }
    }

    // Append the rest of the settings
    addPreferencesFromResource(R.xml.security_settings_misc);

    MSimTelephonyManager tm = MSimTelephonyManager.getDefault();
    int numPhones = TelephonyManager.getDefault().getPhoneCount();
    boolean disableLock = false;
    for (int i = 0; i < numPhones; i++) {
      // Disable SIM lock if sim card is missing or unknown
      // notice:cdma can also set sim lock
      if ((tm.getSimState(i) == TelephonyManager.SIM_STATE_ABSENT)
          || (tm.getSimState(i) == TelephonyManager.SIM_STATE_UNKNOWN)) {
        disableLock = true;
      } else {
        disableLock = false;
        break;
      }
    }
    if (disableLock) {
      root.findPreference(KEY_SIM_LOCK).setEnabled(false);
    }

    // Show password
    mShowPassword = (CheckBoxPreference) root.findPreference(KEY_SHOW_PASSWORD);

    // SIM/RUIM lock
    Preference iccLock = (Preference) root.findPreference(KEY_SIM_LOCK_SETTINGS);

    Intent intent = new Intent();
    if (tm.isMultiSimEnabled()) {
      intent.setClassName(
          "com.android.settings", "com.android.settings.multisimsettings.MultiSimSettingTab");
      intent.putExtra(SelectSubscription.PACKAGE, "com.android.settings");
      intent.putExtra(SelectSubscription.TARGET_CLASS, "com.android.settings.IccLockSettings");
    } else {
      intent.setClassName("com.android.settings", "com.android.settings.IccLockSettings");
    }
    iccLock.setIntent(intent);

    // Credential storage
    mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);

    mToggleAppInstallation = (CheckBoxPreference) findPreference(KEY_TOGGLE_INSTALL_APPLICATIONS);
    mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());

    return root;
  }
  /**
   * Shows TalkBack's abbreviated version number in the action bar, and the full version number in
   * the Play Store button.
   */
  private void showTalkBackVersion() {
    try {
      final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);

      final ActionBar actionBar = getActionBar();
      if (actionBar != null) {
        actionBar.setSubtitle(
            getString(R.string.talkback_preferences_subtitle, packageInfo.versionName));
      }

      final Preference playStoreButton = findPreferenceByResId(R.string.pref_play_store_key);
      if (playStoreButton == null) {
        return;
      }

      if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) != ConnectionResult.SUCCESS) {
        // Not needed, but playing safe since this is hard to test outside of China
        playStoreButton.setIntent(null);
        final PreferenceGroup category =
            (PreferenceGroup) findPreferenceByResId(R.string.pref_category_miscellaneous_key);
        if (category != null) {
          category.removePreference(playStoreButton);
        }
      }

      if (playStoreButton.getIntent() != null
          && getPackageManager().queryIntentActivities(playStoreButton.getIntent(), 0).size()
              == 0) {
        // Not needed, but playing safe since this is hard to test outside of China
        playStoreButton.setIntent(null);
        final PreferenceGroup category =
            (PreferenceGroup) findPreferenceByResId(R.string.pref_category_miscellaneous_key);
        if (category != null) {
          category.removePreference(playStoreButton);
        }
      } else {
        final String versionNumber = String.valueOf(packageInfo.versionCode);
        final int length = versionNumber.length();

        playStoreButton.setSummary(
            getString(
                R.string.summary_pref_play_store,
                String.valueOf(Integer.parseInt(versionNumber.substring(0, length - 7)))
                    + "."
                    + String.valueOf(
                        Integer.parseInt(versionNumber.substring(length - 7, length - 5)))
                    + "."
                    + String.valueOf(
                        Integer.parseInt(versionNumber.substring(length - 5, length - 3)))
                    + "."
                    + String.valueOf(Integer.parseInt(versionNumber.substring(length - 3)))));
      }

    } catch (NameNotFoundException e) {
      // Nothing to do if we can't get the package name.
    }
  }
 private void updateUserDictionaryPreference(Preference userDictionaryPreference) {
   final Activity activity = getActivity();
   final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);
   if (null == localeList) {
     // The locale list is null if and only if the user dictionary service is
     // not present or disabled. In this case we need to remove the preference.
     getPreferenceScreen().removePreference(userDictionaryPreference);
   } else if (localeList.size() <= 1) {
     final Intent intent = new Intent(UserDictionaryList.USER_DICTIONARY_SETTINGS_INTENT_ACTION);
     userDictionaryPreference.setTitle(R.string.user_dict_single_settings_title);
     userDictionaryPreference.setIntent(intent);
     userDictionaryPreference.setFragment(
         com.android.settings.UserDictionarySettings.class.getName());
     // If the size of localeList is 0, we don't set the locale parameter in the
     // extras. This will be interpreted by the UserDictionarySettings class as
     // meaning "the current locale".
     // Note that with the current code for UserDictionaryList#getUserDictionaryLocalesSet()
     // the locale list always has at least one element, since it always includes the current
     // locale explicitly. @see UserDictionaryList.getUserDictionaryLocalesSet().
     if (localeList.size() == 1) {
       final String locale = (String) localeList.toArray()[0];
       userDictionaryPreference.getExtras().putString("locale", locale);
     }
   } else {
     userDictionaryPreference.setTitle(R.string.user_dict_multiple_settings_title);
     userDictionaryPreference.setFragment(UserDictionaryList.class.getName());
   }
 }
  /**
   * Touch exploration preference management code specific to devices running Jelly Bean and above.
   *
   * @param category The touch exploration category.
   */
  @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  private void checkTouchExplorationSupportInner(PreferenceGroup category) {
    final CheckBoxPreference prefTouchExploration =
        (CheckBoxPreference) findPreferenceByResId(R.string.pref_explore_by_touch_reflect_key);
    if (prefTouchExploration == null) {
      return;
    }

    // Remove single-tap preference if it's not supported on this device.
    final CheckBoxPreference prefSingleTap =
        (CheckBoxPreference) findPreferenceByResId(R.string.pref_single_tap_key);
    if ((prefSingleTap != null)
        && (Build.VERSION.SDK_INT < ProcessorFocusAndSingleTap.MIN_API_LEVEL_SINGLE_TAP)) {
      category.removePreference(prefSingleTap);
    }

    // Ensure that changes to the reflected preference's checked state never
    // trigger content observers.
    prefTouchExploration.setPersistent(false);

    // Synchronize the reflected state.
    updateTouchExplorationState();

    // Set up listeners that will keep the state synchronized.
    prefTouchExploration.setOnPreferenceChangeListener(mTouchExplorationChangeListener);

    // Hook in the external PreferenceActivity for gesture management
    final Preference shortcutsScreen =
        findPreferenceByResId(R.string.pref_category_manage_gestures_key);
    final Intent shortcutsIntent = new Intent(this, TalkBackShortcutPreferencesActivity.class);
    shortcutsScreen.setIntent(shortcutsIntent);
  }
Пример #5
0
    @Override
    public void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.preference_screen);

      for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
        initSummary(getPreferenceScreen().getPreference(i));
      }

      // Set start/stop service intents
      Preference startPreference = findPreference("PREF_START_SERVICE");
      Intent startIntent = new Intent(getActivity().getApplication(), ServiceLauncher.class);
      startIntent.putExtra("Action", "Start");
      startPreference.setIntent(startIntent);

      Preference stopPreference = findPreference("PREF_STOP_SERVICE");
      Intent stopIntent = new Intent(getActivity().getApplication(), ServiceLauncher.class);
      stopIntent.putExtra("Action", "Stop");
      stopPreference.setIntent(stopIntent);
    }
  private void assignWebIntentToPreference(int preferenceId, String url) {
    Preference pref = findPreferenceByResId(preferenceId);
    if (pref == null) {
      return;
    }

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    if (!canHandleIntent(intent)) {
      intent = new Intent(this, WebActivity.class);
      intent.setData(Uri.parse(url));
    }

    pref.setIntent(intent);
  }
Пример #7
0
 private void handleManageSimMsg() {
   int phoneCount = mTelephonyManagers.size();
   Log.e("SimListActivity", "handleManageSimMsg: phoneCount=" + phoneCount);
   for (int i = 0; i < phoneCount; ++i) {
     if (mTelephonyManagers.get(i).hasIccCard()
         && mTelephonyManagers.get(i).getSimState() == TelephonyManager.SIM_STATE_READY) {
       Preference preference = new Preference(this);
       String simName = generateSimName(i);
       preference.setTitle(simName);
       preference.setSummary(R.string.pref_title_manage_sim_messages);
       Intent intent = new Intent(this, ManageSimMessages.class);
       intent.putExtra(Phone.PHONE_ID, i);
       preference.setIntent(intent);
       mScreen.addPreference(preference);
     }
   }
 }
  /** Assigns the appropriate intent to the label manager preference. */
  private void assignLabelManagerIntent() {
    final PreferenceGroup category =
        (PreferenceGroup) findPreferenceByResId(R.string.pref_category_touch_exploration_key);
    final Preference prefManageLabels = findPreferenceByResId(R.string.pref_manage_labels_key);

    if ((category == null) || (prefManageLabels == null)) {
      return;
    }

    if (Build.VERSION.SDK_INT < LabelManagerSummaryActivity.MIN_API_LEVEL) {
      category.removePreference(prefManageLabels);
      return;
    }

    final Intent labelManagerIntent = new Intent(this, LabelManagerSummaryActivity.class);
    labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    prefManageLabels.setIntent(labelManagerIntent);
  }
  /** Assigns the appropriate intent to the tutorial preference. */
  private void assignTutorialIntent() {
    final PreferenceGroup category =
        (PreferenceGroup) findPreferenceByResId(R.string.pref_category_miscellaneous_key);
    final Preference prefTutorial = findPreferenceByResId(R.string.pref_tutorial_key);

    if ((category == null) || (prefTutorial == null)) {
      return;
    }

    final int touchscreenState = getResources().getConfiguration().touchscreen;
    if (touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) {
      category.removePreference(prefTutorial);
      return;
    }

    final Intent tutorialIntent = new Intent(this, AccessibilityTutorialActivity.class);
    tutorialIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    tutorialIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    prefTutorial.setIntent(tutorialIntent);
  }
  /** Assigns the appropriate intent to the keyboard shortcut preference. */
  private void assignKeyboardShortcutIntent() {
    final PreferenceGroup category =
        (PreferenceGroup) findPreferenceByResId(R.string.pref_category_miscellaneous_key);
    final Preference keyboardShortcutPref =
        findPreferenceByResId(R.string.pref_category_manage_keyboard_shortcut_key);

    if ((category == null) || (keyboardShortcutPref == null)) {
      return;
    }

    if (Build.VERSION.SDK_INT < KeyComboManager.MIN_API_LEVEL) {
      category.removePreference(keyboardShortcutPref);
      return;
    }

    final Intent labelManagerIntent =
        new Intent(this, TalkBackKeyboardShortcutPreferencesActivity.class);
    labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    labelManagerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    keyboardShortcutPref.setIntent(labelManagerIntent);
  }
Пример #11
0
    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
      if (key.equals(KEY_PREF_SERVER_IP)) {
        Preference PrefIP = findPreference(key);
        PrefIP.setSummary(sharedPreferences.getString(key, ""));

        Preference PrefGetAPIKey = findPreference(key);
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(
            Uri.parse(
                sharedPreferences.getString(KEY_PREF_SERVER_IP, "")
                    + ":"
                    + sharedPreferences.getString(KEY_PREF_SERVER_PORT, "")
                    + "/config/general/"));
        PrefGetAPIKey.setIntent(i);
      } else if (key.equals(KEY_PREF_SERVER_PORT)) {
        Preference Pref = findPreference(key);
        Pref.setSummary(sharedPreferences.getString(key, ""));
      } else if (key.equals(KEY_PREF_API_KEY)) {
        Preference Pref = findPreference(key);
        Pref.setSummary(sharedPreferences.getString(key, ""));
      } else if (key.equals(KEY_PREF_PAUSE_DURATION1)) {
        Preference Pref = findPreference(key);
        Pref.setSummary(sharedPreferences.getString(key, ""));
      } else if (key.equals(KEY_PREF_PAUSE_DURATION2)) {
        Preference Pref = findPreference(key);
        Pref.setSummary(sharedPreferences.getString(key, ""));
      } else if (key.equals(KEY_PREF_PAUSE_DURATION3)) {
        Preference Pref = findPreference(key);
        Pref.setSummary(sharedPreferences.getString(key, ""));
      } else if (key.equals(KEY_PREF_REFRESH_INTERVAL)) {
        Preference Pref = findPreference(key);
        Pref.setSummary(sharedPreferences.getString(key, ""));
      }
      try {
        PreferencesStore.getInstance().refreshSettings();
      } catch (Exception e) {

      }
    }
Пример #12
0
  private void addPluginPreferences(PreferenceScreen screen) {
    Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList =
        pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    int length = resolveInfoList.size();
    LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
        new LinkedHashMap<String, ArrayList<Preference>>();

    // Loop through a list of all packages (including plugins, addons)
    // that have a settings action
    for (int i = 0; i < length; i++) {
      ResolveInfo resolveInfo = resolveInfoList.get(i);
      Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
      intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);

      if (MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && !MilkUtilities.INSTANCE.isLoggedIn()) continue;

      Preference preference = new Preference(this);
      preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
      preference.setIntent(intent);

      String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);

      if (!categoryPreferences.containsKey(category))
        categoryPreferences.put(category, new ArrayList<Preference>());
      ArrayList<Preference> arrayList = categoryPreferences.get(category);
      arrayList.add(preference);
    }

    for (Entry<String, ArrayList<Preference>> entry : categoryPreferences.entrySet()) {
      Preference header = new Preference(this);
      header.setLayoutResource(android.R.layout.preference_category);
      header.setTitle(entry.getKey());
      screen.addPreference(header);

      for (Preference preference : entry.getValue()) screen.addPreference(preference);
    }
  }
Пример #13
0
 private void setPreferenceScreenType(Class<?> classObj, String key, int type) {
   Preference pf = findPreference(key);
   Intent it = new Intent(this, classObj);
   it.putExtra(PrefsLogic.EXTRA_PREFERENCE_TYPE, type);
   pf.setIntent(it);
 }
Пример #14
0
  private void addPluginPreferences(PreferenceScreen screen) {
    Intent queryIntent = new Intent(AstridApiConstants.ACTION_SETTINGS);
    PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList =
        pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    int length = resolveInfoList.size();
    LinkedHashMap<String, ArrayList<Preference>> categoryPreferences =
        new LinkedHashMap<String, ArrayList<Preference>>();

    // Loop through a list of all packages (including plugins, addons)
    // that have a settings action
    String labsTitle = getString(R.string.EPr_labs_header);
    for (int i = 0; i < length; i++) {
      ResolveInfo resolveInfo = resolveInfoList.get(i);
      final Intent intent = new Intent(AstridApiConstants.ACTION_SETTINGS);
      intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);

      if (MilkPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && !MilkUtilities.INSTANCE.isLoggedIn()) continue;

      if (GtasksPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && AmazonMarketStrategy.isKindleFire()) continue;

      if (ProducteevPreferences.class.getName().equals(resolveInfo.activityInfo.name)
          && !Preferences.getBoolean(R.string.p_third_party_addons, false)
          && !ProducteevUtilities.INSTANCE.isLoggedIn()) continue;

      Preference preference = new Preference(this);
      preference.setTitle(resolveInfo.activityInfo.loadLabel(pm));
      if (labsTitle.equals(preference.getTitle())) preference.setSummary(R.string.EPr_labs_desc);
      try {
        Class<?> intentComponent = Class.forName(intent.getComponent().getClassName());
        if (intentComponent.getSuperclass().equals(SyncProviderPreferences.class))
          intentComponent = SyncProviderPreferences.class;
        if (PREFERENCE_REQUEST_CODES.containsKey(intentComponent)) {
          final int code = PREFERENCE_REQUEST_CODES.get(intentComponent);
          preference.setOnPreferenceClickListener(
              new OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference pref) {
                  startActivityForResult(intent, code);
                  return true;
                }
              });
        } else {
          preference.setIntent(intent);
        }
      } catch (ClassNotFoundException e) {
        preference.setIntent(intent);
      }

      String category = MetadataHelper.resolveActivityCategoryName(resolveInfo, pm);

      if (!categoryPreferences.containsKey(category))
        categoryPreferences.put(category, new ArrayList<Preference>());
      ArrayList<Preference> arrayList = categoryPreferences.get(category);
      arrayList.add(preference);
    }

    for (Entry<String, ArrayList<Preference>> entry : categoryPreferences.entrySet()) {
      Preference header = new Preference(this);
      header.setLayoutResource(android.R.layout.preference_category);
      header.setTitle(entry.getKey());
      screen.addPreference(header);

      for (Preference preference : entry.getValue()) screen.addPreference(preference);
    }
  }
Пример #15
-1
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ContentResolver resolver = getContentResolver();
    int activePhoneType = TelephonyManager.getDefault().getCurrentPhoneType();

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    addPreferencesFromResource(R.xml.sound_settings);

    if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType) {
      // device is not CDMA, do not display CDMA emergency_tone
      getPreferenceScreen().removePreference(findPreference(KEY_EMERGENCY_TONE));
    }

    mVolumeOverlay = (ListPreference) findPreference(KEY_VOLUME_OVERLAY);
    mVolumeOverlay.setOnPreferenceChangeListener(this);
    int volumeOverlay =
        Settings.System.getInt(
            getContentResolver(),
            Settings.System.MODE_VOLUME_OVERLAY,
            VolumePanel.VOLUME_OVERLAY_EXPANDABLE);
    mVolumeOverlay.setValue(Integer.toString(volumeOverlay));
    mVolumeOverlay.setSummary(mVolumeOverlay.getEntry());

    mRingMode = (ListPreference) findPreference(KEY_RING_MODE);
    if (!getResources().getBoolean(R.bool.has_silent_mode)) {
      getPreferenceScreen().removePreference(mRingMode);
      findPreference(KEY_RING_VOLUME).setDependency(null);
    } else {
      mRingMode.setOnPreferenceChangeListener(this);
    }

    if (getResources().getBoolean(com.android.internal.R.bool.config_useFixedVolume)) {
      // device with fixed volume policy, do not display volumes submenu
      getPreferenceScreen().removePreference(findPreference(KEY_RING_VOLUME));
    }

    mQuietHours = (PreferenceScreen) findPreference(KEY_QUIET_HOURS);
    updateQuietHoursSummary();

    mSoundEffects = (CheckBoxPreference) findPreference(KEY_SOUND_EFFECTS);

    if (!Utils.hasVolumeRocker(getActivity())) {
      getPreferenceScreen().removePreference(findPreference(KEY_VOLUME_ADJUST_SOUNDS));
    }

    mRingtonePreference = findPreference(KEY_RINGTONE);
    mNotificationPreference = findPreference(KEY_NOTIFICATION_SOUND);

    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
      removePreference(KEY_VIBRATE);
      removePreference(KEY_HAPTIC_FEEDBACK);
      removePreference(KEY_VIBRATION_INTENSITY);
      removePreference(KEY_CONVERT_SOUND_TO_VIBRATE);
      removePreference(KEY_VIBRATE_DURING_CALLS);
    } else if (!VibratorIntensity.isSupported()) {
      removePreference(KEY_VIBRATION_INTENSITY);
    }

    if (TelephonyManager.PHONE_TYPE_CDMA == activePhoneType) {
      ListPreference emergencyTonePreference = (ListPreference) findPreference(KEY_EMERGENCY_TONE);
      emergencyTonePreference.setValue(
          String.valueOf(
              Settings.Global.getInt(
                  resolver, Settings.Global.EMERGENCY_TONE, FALLBACK_EMERGENCY_TONE_VALUE)));
      emergencyTonePreference.setOnPreferenceChangeListener(this);
    }

    mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);

    mMusicFx = mSoundSettings.findPreference(KEY_MUSICFX);
    Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
    mMusicFx.setIntent(i);
    PackageManager p = getPackageManager();
    List<ResolveInfo> ris = p.queryIntentActivities(i, 0);
    if (ris.size() == 0) {
      mSoundSettings.removePreference(mMusicFx);
    } else if (ris.size() == 1) {
      mMusicFx.setSummary(ris.get(0).loadLabel(p));
    }

    if (!Utils.isVoiceCapable(getActivity())) {
      for (String prefKey : NEED_VOICE_CAPABILITY) {
        Preference pref = findPreference(prefKey);
        if (pref != null) {
          getPreferenceScreen().removePreference(pref);
        }
      }
      mRingtonePreference = null;
    }

    mRingtoneLookupRunnable =
        new Runnable() {
          public void run() {
            if (mRingtonePreference != null) {
              updateRingtoneName(
                  RingtoneManager.TYPE_RINGTONE, mRingtonePreference, MSG_UPDATE_RINGTONE_SUMMARY);
            }
            if (mNotificationPreference != null) {
              updateRingtoneName(
                  RingtoneManager.TYPE_NOTIFICATION,
                  mNotificationPreference,
                  MSG_UPDATE_NOTIFICATION_SUMMARY);
            }
          }
        };

    // power state change notification sounds
    mPowerSounds = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS);
    mPowerSounds.setChecked(
        Settings.Global.getInt(resolver, Settings.Global.POWER_NOTIFICATIONS_ENABLED, 0) != 0);
    mPowerSoundsVibrate = (CheckBoxPreference) findPreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
    mPowerSoundsVibrate.setChecked(
        Settings.Global.getInt(resolver, Settings.Global.POWER_NOTIFICATIONS_VIBRATE, 0) != 0);
    if (vibrator == null || !vibrator.hasVibrator()) {
      removePreference(KEY_POWER_NOTIFICATIONS_VIBRATE);
    }

    mPowerSoundsRingtone = findPreference(KEY_POWER_NOTIFICATIONS_RINGTONE);
    String currentPowerRingtonePath =
        Settings.Global.getString(resolver, Settings.Global.POWER_NOTIFICATIONS_RINGTONE);

    // set to default notification if we don't yet have one
    if (currentPowerRingtonePath == null) {
      currentPowerRingtonePath = Settings.System.DEFAULT_NOTIFICATION_URI.toString();
      Settings.Global.putString(
          getContentResolver(),
          Settings.Global.POWER_NOTIFICATIONS_RINGTONE,
          currentPowerRingtonePath);
    }
    // is it silent ?
    if (currentPowerRingtonePath.equals(POWER_NOTIFICATIONS_SILENT_URI)) {
      mPowerSoundsRingtone.setSummary(getString(R.string.power_notifications_ringtone_silent));
    } else {
      final Ringtone ringtone =
          RingtoneManager.getRingtone(getActivity(), Uri.parse(currentPowerRingtonePath));
      if (ringtone != null) {
        mPowerSoundsRingtone.setSummary(ringtone.getTitle(getActivity()));
      }
    }

    initDockSettings();
  }