@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.voltage_control);
    setHasOptionsMenu(true);

    mCategory = (PreferenceCategory) findPreference("uv_category");

    if (Utils.fileExists(VoltageUtils.UV_TABLE_FILE)) {
      if (mCategory.getPreferenceCount() != 0) {
        mCategory.removeAll();
      }
      addPreferences(true);
      isVdd = false;
    } else {
      if (Utils.fileExists(VoltageUtils.VDD_TABLE_FILE)) {
        if (mCategory.getPreferenceCount() != 0) {
          mCategory.removeAll();
        }
        addPreferences(false);
        isVdd = true;
      } else {
        if (mCategory.getPreferenceCount() != 0) {
          mCategory.removeAll();
        }
      }
    }

    isSupported(getPreferenceScreen(), getActivity());
  }
  // update the channel list ui by channel array
  private void updateChannelUIList() {
    MmsLog.d(LOG_TAG, "updateChannelUIList start");
    mChannelListPreference.removeAll();
    int length = mChannelArray.size();
    for (int i = 0; i < length; i++) {
      Preference channel = new Preference(this);
      int keyId = mChannelArray.get(i).getKeyId();
      String channelName = mChannelArray.get(i).getChannelName();
      int channelId = mChannelArray.get(i).getChannelId();
      boolean channelState = mChannelArray.get(i).getChannelState();
      String title = channelName + "(" + String.valueOf(channelId) + ")";
      channel.setTitle(title);
      final CellBroadcastChannel oldChannel =
          new CellBroadcastChannel(keyId, channelId, channelName, channelState);
      if (channelState) {
        channel.setSummary(R.string.enable);
      } else {
        channel.setSummary(R.string.disable);
      }

      channel.setOnPreferenceClickListener(
          new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference arg0) {
              showEditChannelDialog(oldChannel);
              return false;
            }
          });
      mChannelListPreference.addPreference(channel);
    }
    MmsLog.d(LOG_TAG, "updateChannelUIList end");
  }
  private void loadAccountPreference() {
    mAccountCategory.removeAll();

    Preference accountPref = new Preference(this);
    final String defaultAccount = getSyncAccountName(this);
    accountPref.setTitle(getString(R.string.preferences_account_title));
    accountPref.setSummary(getString(R.string.preferences_account_summary));
    accountPref.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            if (!GTaskSyncService.isSyncing()) {
              if (TextUtils.isEmpty(defaultAccount)) {
                // the first time to set account
                showSelectAccountAlertDialog();
              } else {
                // if the account has already been set, we need to promp
                // user about the risk
                showChangeAccountConfirmAlertDialog();
              }
            } else {
              Toast.makeText(
                      NotesPreferenceActivity.this,
                      R.string.preferences_toast_cannot_change_account,
                      Toast.LENGTH_SHORT)
                  .show();
            }
            return true;
          }
        });

    mAccountCategory.addPreference(accountPref);
  }
 private void hideGPSCategory() {
   PreferenceScreen preferenceScreen = getPreferenceScreen();
   PreferenceCategory preferenceCategory =
       (PreferenceCategory) findPreference(getResources().getString(R.string.pref_gps_category));
   if (preferenceCategory != null) {
     preferenceCategory.removeAll();
     preferenceScreen.removePreference((Preference) preferenceCategory);
   }
 }
  private void updateNetworks(Context context) {
    if (SHOW_MOBILE_CATEGORY && hasReadyMobileRadio(context)) {
      mMobileCategory.removeAll();
      mMobileCategory.addPreference(buildMobilePref(context));
    } else {
      getPreferenceScreen().removePreference(mMobileCategory);
    }

    mWifiCategory.removeAll();
    if (hasWifiRadio(context) && mWifiManager.isWifiEnabled()) {
      for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
        if (config.SSID != null) {
          mWifiCategory.addPreference(buildWifiPref(context, config));
        }
      }
    } else {
      mWifiCategory.addPreference(mWifiDisabled);
    }
  }
        public void onIabPurchaseFinished(IabResult result, Purchase purchase) {

          if (result.isFailure()) {
            Toast.makeText(mContext, R.string.unable_to_purchase, Toast.LENGTH_LONG).show();
            sharedPreferences.edit().putBoolean("TRIAL", true).commit();
            return;
          } else if (purchase.getSku().equals(ITEM_SKU)) {

            Toast.makeText(mContext, R.string.ALMusic_trial_time_removed, Toast.LENGTH_LONG).show();
            mApp.getSharedPreferences().edit().putBoolean("TRIAL", false).commit();
            PreferenceCategory upgradePrefCategory =
                (PreferenceCategory) preferenceManager.findPreference("upgrade_pref_category");
            upgradePrefCategory.removeAll();
          }
        }
  private void updateServicesPreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.

    // Generate.
    mServicesCategory.removeAll();

    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());

    List<AccessibilityServiceInfo> installedServices =
        accessibilityManager.getInstalledAccessibilityServiceList();
    Set<ComponentName> enabledServices = getEnabledServicesFromSettings(getActivity());

    final boolean accessibilityEnabled =
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;

    for (int i = 0, count = installedServices.size(); i < count; ++i) {
      AccessibilityServiceInfo info = installedServices.get(i);

      PreferenceScreen preference = getPreferenceManager().createPreferenceScreen(getActivity());
      String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();

      ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
      ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);

      preference.setKey(componentName.flattenToString());

      preference.setTitle(title);
      final boolean serviceEnabled =
          accessibilityEnabled && enabledServices.contains(componentName);
      if (serviceEnabled) {
        preference.setSummary(getString(R.string.accessibility_service_state_on));
      } else {
        preference.setSummary(getString(R.string.accessibility_service_state_off));
      }

      preference.setOrder(i);
      preference.setFragment(ToggleAccessibilityServiceFragment.class.getName());
      preference.setPersistent(true);

      Bundle extras = preference.getExtras();
      extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
      extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
      extras.putString(EXTRA_TITLE, title);

      String description = info.getDescription();
      if (TextUtils.isEmpty(description)) {
        description = getString(R.string.accessibility_service_default_description);
      }
      extras.putString(EXTRA_SUMMARY, description);

      CharSequence applicationLabel = info.getResolveInfo().loadLabel(getPackageManager());

      extras.putString(
          EXTRA_ENABLE_WARNING_TITLE,
          getString(R.string.accessibility_service_security_warning_title, applicationLabel));
      extras.putString(
          EXTRA_ENABLE_WARNING_MESSAGE,
          getString(R.string.accessibility_service_security_warning_summary, applicationLabel));

      extras.putString(
          EXTRA_DISABLE_WARNING_TITLE,
          getString(R.string.accessibility_service_disable_warning_title, applicationLabel));
      extras.putString(
          EXTRA_DISABLE_WARNING_MESSAGE,
          getString(R.string.accessibility_service_disable_warning_summary, applicationLabel));

      String settingsClassName = info.getSettingsActivityName();
      if (!TextUtils.isEmpty(settingsClassName)) {
        extras.putString(
            EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
        extras.putString(
            EXTRA_SETTINGS_COMPONENT_NAME,
            new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName)
                .flattenToString());
      }

      mServicesCategory.addPreference(preference);
    }

    if (mServicesCategory.getPreferenceCount() == 0) {
      if (mNoServicesMessagePreference == null) {
        mNoServicesMessagePreference =
            new Preference(getActivity()) {
              @Override
              protected void onBindView(View view) {
                super.onBindView(view);

                LinearLayout containerView =
                    (LinearLayout) view.findViewById(R.id.message_container);
                containerView.setGravity(Gravity.CENTER);

                TextView summaryView = (TextView) view.findViewById(R.id.summary);
                String title = getString(R.string.accessibility_no_services_installed);
                summaryView.setText(title);
              }
            };
        mNoServicesMessagePreference.setPersistent(false);
        mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
        mNoServicesMessagePreference.setSelectable(false);
      }
      mServicesCategory.addPreference(mNoServicesMessagePreference);
    }
  }
  private void updateServicesPreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.

    // Generate.
    mServicesCategory.removeAll();

    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());

    List<AccessibilityServiceInfo> installedServices =
        accessibilityManager.getInstalledAccessibilityServiceList();
    Set<ComponentName> enabledServices =
        AccessibilityUtils.getEnabledServicesFromSettings(getActivity());
    List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId());
    final boolean accessibilityEnabled =
        Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;

    for (int i = 0, count = installedServices.size(); i < count; ++i) {
      AccessibilityServiceInfo info = installedServices.get(i);

      PreferenceScreen preference = getPreferenceManager().createPreferenceScreen(getActivity());
      String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();

      ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
      ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);

      preference.setKey(componentName.flattenToString());

      preference.setTitle(title);
      final boolean serviceEnabled =
          accessibilityEnabled && enabledServices.contains(componentName);
      String serviceEnabledString;
      if (serviceEnabled) {
        serviceEnabledString = getString(R.string.accessibility_feature_state_on);
      } else {
        serviceEnabledString = getString(R.string.accessibility_feature_state_off);
      }

      // Disable all accessibility services that are not permitted.
      String packageName = serviceInfo.packageName;
      boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
      preference.setEnabled(serviceAllowed || serviceEnabled);

      String summaryString;
      if (serviceAllowed) {
        summaryString = serviceEnabledString;
      } else {
        summaryString = getString(R.string.accessibility_feature_or_input_method_not_allowed);
      }
      preference.setSummary(summaryString);

      preference.setOrder(i);
      preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName());
      preference.setPersistent(true);

      Bundle extras = preference.getExtras();
      extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
      extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
      extras.putString(EXTRA_TITLE, title);

      String description = info.loadDescription(getPackageManager());
      if (TextUtils.isEmpty(description)) {
        description = getString(R.string.accessibility_service_default_description);
      }
      extras.putString(EXTRA_SUMMARY, description);

      String settingsClassName = info.getSettingsActivityName();
      if (!TextUtils.isEmpty(settingsClassName)) {
        extras.putString(
            EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
        extras.putString(
            EXTRA_SETTINGS_COMPONENT_NAME,
            new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName)
                .flattenToString());
      }

      extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);

      mServicesCategory.addPreference(preference);
    }

    if (mServicesCategory.getPreferenceCount() == 0) {
      if (mNoServicesMessagePreference == null) {
        mNoServicesMessagePreference = new Preference(getActivity());
        mNoServicesMessagePreference.setPersistent(false);
        mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
        mNoServicesMessagePreference.setSelectable(false);
        mNoServicesMessagePreference.setSummary(
            getString(R.string.accessibility_no_services_installed));
      }
      mServicesCategory.addPreference(mNoServicesMessagePreference);
    }
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    addPreferencesFromResource(R.xml.language_settings);

    try {
      mDefaultInputMethodSelectorVisibility =
          Integer.valueOf(getString(R.string.input_method_selector_visibility_default_value));
    } catch (NumberFormatException e) {
    }

    if (getActivity().getAssets().getLocales().length == 1) {
      // No "Select language" pref if there's only one system locale available.
      getPreferenceScreen().removePreference(findPreference(KEY_PHONE_LANGUAGE));
    } else {
      mLanguagePref = findPreference(KEY_PHONE_LANGUAGE);
    }
    if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
      mShowInputMethodSelectorPref = (ListPreference) findPreference(KEY_INPUT_METHOD_SELECTOR);
      mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this);
      // TODO: Update current input method name on summary
      updateInputMethodSelectorSummary(loadInputMethodSelectorVisibility());
    }

    new VoiceInputOutputSettings(this).onCreate();

    // Get references to dynamically constructed categories.
    mHardKeyboardCategory = (PreferenceCategory) findPreference("hard_keyboard");
    mKeyboardSettingsCategory = (PreferenceCategory) findPreference("keyboard_settings_category");
    mGameControllerCategory =
        (PreferenceCategory) findPreference("game_controller_settings_category");

    // Filter out irrelevant features if invoked from IME settings button.
    mIsOnlyImeSettings =
        Settings.ACTION_INPUT_METHOD_SETTINGS.equals(getActivity().getIntent().getAction());
    getActivity().getIntent().setAction(null);
    if (mIsOnlyImeSettings) {
      getPreferenceScreen().removeAll();
      getPreferenceScreen().addPreference(mHardKeyboardCategory);
      if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) {
        getPreferenceScreen().addPreference(mShowInputMethodSelectorPref);
      }
      getPreferenceScreen().addPreference(mKeyboardSettingsCategory);
    }

    // Build IME preference category.
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    mImis = mImm.getInputMethodList();

    mKeyboardSettingsCategory.removeAll();
    if (!mIsOnlyImeSettings) {
      final PreferenceScreen currentIme = new PreferenceScreen(getActivity(), null);
      currentIme.setKey(KEY_CURRENT_INPUT_METHOD);
      currentIme.setTitle(getResources().getString(R.string.current_input_method));
      mKeyboardSettingsCategory.addPreference(currentIme);
    }

    mInputMethodPreferenceList.clear();
    final int N = (mImis == null ? 0 : mImis.size());
    for (int i = 0; i < N; ++i) {
      final InputMethodInfo imi = mImis.get(i);
      final InputMethodPreference pref = getInputMethodPreference(imi, N);
      mInputMethodPreferenceList.add(pref);
    }

    if (!mInputMethodPreferenceList.isEmpty()) {
      Collections.sort(mInputMethodPreferenceList);
      for (int i = 0; i < N; ++i) {
        mKeyboardSettingsCategory.addPreference(mInputMethodPreferenceList.get(i));
      }
    }

    // Build hard keyboard and game controller preference categories.
    mIm = (InputManager) getActivity().getSystemService(Context.INPUT_SERVICE);
    updateInputDevices();

    // Enable or disable mStatusBarImeSwitcher based on boolean value: config_show_cmIMESwitcher
    final Preference keyImeSwitcherPref = findPreference(KEY_IME_SWITCHER);
    if (keyImeSwitcherPref != null) {
      if (!getResources().getBoolean(com.android.internal.R.bool.config_show_cmIMESwitcher)) {
        getPreferenceScreen().removePreference(keyImeSwitcherPref);
      } else {
        mStatusBarImeSwitcher = (CheckBoxPreference) keyImeSwitcherPref;
      }
    }

    // Spell Checker
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setClass(getActivity(), SpellCheckersSettingsActivity.class);
    final SpellCheckersPreference scp =
        ((SpellCheckersPreference) findPreference("spellcheckers_settings"));
    if (scp != null) {
      scp.setFragmentIntent(this, intent);
    }

    mVolumeKeyCursorControl = (ListPreference) findPreference(VOLUME_KEY_CURSOR_CONTROL);
    if (mVolumeKeyCursorControl != null) {
      mVolumeKeyCursorControl.setOnPreferenceChangeListener(this);
      mVolumeKeyCursorControl.setValue(
          Integer.toString(
              Settings.System.getInt(
                  getActivity().getContentResolver(),
                  Settings.System.VOLUME_KEY_CURSOR_CONTROL,
                  0)));
      mVolumeKeyCursorControl.setSummary(mVolumeKeyCursorControl.getEntry());
    }

    mHandler = new Handler();
    mSettingsObserver = new SettingsObserver(mHandler, getActivity());
  }
 private void prepareRoutingPrefs(PreferenceScreen screen) {
   PreferenceCategory cat = (PreferenceCategory) screen.findPreference("routing_preferences");
   cat.removeAll();
   CheckBoxPreference fastRoute =
       createCheckBoxPreference(
           settings.FAST_ROUTE_MODE, R.string.fast_route_mode, R.string.fast_route_mode_descr);
   if (settings.ROUTER_SERVICE.get() != RouteService.OSMAND) {
     cat.addPreference(fastRoute);
   } else {
     ApplicationMode am = settings.getApplicationMode();
     GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
     clearParameters();
     if (router != null) {
       Map<String, RoutingParameter> parameters = router.getParameters();
       if (parameters.containsKey("short_way")) {
         cat.addPreference(fastRoute);
       }
       List<RoutingParameter> others = new ArrayList<GeneralRouter.RoutingParameter>();
       for (Map.Entry<String, RoutingParameter> e : parameters.entrySet()) {
         String param = e.getKey();
         if (param.startsWith("avoid_")) {
           avoidParameters.add(e.getValue());
         } else if (param.startsWith("prefer_")) {
           preferParameters.add(e.getValue());
         } else if (!param.equals("short_way")) {
           others.add(e.getValue());
         }
       }
       if (avoidParameters.size() > 0) {
         avoidRouting = new Preference(this);
         avoidRouting.setTitle(R.string.avoid_in_routing_title);
         avoidRouting.setSummary(R.string.avoid_in_routing_descr);
         avoidRouting.setOnPreferenceClickListener(this);
         cat.addPreference(avoidRouting);
       }
       if (preferParameters.size() > 0) {
         preferRouting = new Preference(this);
         preferRouting.setTitle(R.string.prefer_in_routing_title);
         preferRouting.setSummary(R.string.prefer_in_routing_descr);
         preferRouting.setOnPreferenceClickListener(this);
         cat.addPreference(preferRouting);
       }
       for (RoutingParameter p : others) {
         Preference basePref;
         if (p.getType() == RoutingParameterType.BOOLEAN) {
           basePref =
               createCheckBoxPreference(settings.getCustomRoutingBooleanProperty(p.getId()));
         } else {
           Object[] vls = p.getPossibleValues();
           String[] svlss = new String[vls.length];
           int i = 0;
           for (Object o : vls) {
             svlss[i++] = o.toString();
           }
           basePref =
               createListPreference(
                   settings.getCustomRoutingProperty(
                       p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-"),
                   p.getPossibleValueDescriptions(),
                   svlss,
                   SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()),
                   SettingsBaseActivity.getRoutingStringPropertyDescription(
                       this, p.getId(), p.getDescription()));
         }
         basePref.setTitle(
             SettingsBaseActivity.getRoutingStringPropertyName(this, p.getId(), p.getName()));
         basePref.setSummary(
             SettingsBaseActivity.getRoutingStringPropertyDescription(
                 this, p.getId(), p.getDescription()));
         cat.addPreference(basePref);
       }
     }
     ApplicationMode mode = getMyApplication().getSettings().getApplicationMode();
     if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
       PreferenceCategory category =
           (PreferenceCategory) screen.findPreference("guidance_preferences");
       category.addPreference(speedLimitExceed);
     } else {
       PreferenceCategory category =
           (PreferenceCategory) screen.findPreference("guidance_preferences");
       category.removePreference(speedLimitExceed);
     }
   }
 }