private void initSummary(Preference p) {
   if (p instanceof PreferenceCategory) {
     PreferenceCategory pCat = (PreferenceCategory) p;
     for (int i = 0; i < pCat.getPreferenceCount(); i++) {
       if (!pCat.getPreference(i).getKey().equals(KEY_PREF_SERVER_PASS)) {
         initSummary(pCat.getPreference(i));
       }
     }
   } else {
     updatePrefSummary(p);
   }
 }
  private void changeVoltage(final boolean isPlus) {
    final int prefsIndex = mCategory.getPreferenceCount();
    CustomPreference pref;
    String value;
    boolean isCurrent = false;
    for (int i = 0; i < prefsIndex; i++) {
      pref = (CustomPreference) mCategory.getPreference(i);
      if (pref != null) {
        if (isVdd) {
          if (isPlus) {
            pref.setCustomSummaryKeyPlus(25000);
          } else {
            pref.setCustomSummaryKeyMinus(25000);
          }
        } else {
          if (isPlus) {
            pref.setCustomSummaryKeyPlus(25);
          } else {
            pref.setCustomSummaryKeyMinus(25);
          }
        }
        value = pref.getKey();
        if (value != null) {
          isCurrent = value.equals(mValues[i]);
        }
      }
    }

    if (isCurrent) {
      mButtonLayout.setVisibility(View.GONE);
    } else {
      mButtonLayout.setVisibility(View.VISIBLE);
    }
  }
  private void updateHardKeyboards() {
    mHardKeyboardPreferenceList.clear();
    if (getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY) {
      final int[] devices = InputDevice.getDeviceIds();
      for (int i = 0; i < devices.length; i++) {
        InputDevice device = InputDevice.getDevice(devices[i]);
        if (device != null && !device.isVirtual() && device.isFullKeyboard()) {
          final String inputDeviceDescriptor = device.getDescriptor();
          final String keyboardLayoutDescriptor =
              mIm.getCurrentKeyboardLayoutForInputDevice(inputDeviceDescriptor);
          final KeyboardLayout keyboardLayout =
              keyboardLayoutDescriptor != null
                  ? mIm.getKeyboardLayout(keyboardLayoutDescriptor)
                  : null;

          final PreferenceScreen pref = new PreferenceScreen(getActivity(), null);
          pref.setTitle(device.getName());
          if (keyboardLayout != null) {
            pref.setSummary(keyboardLayout.toString());
          } else {
            pref.setSummary(R.string.keyboard_layout_default_label);
          }
          pref.setOnPreferenceClickListener(
              new Preference.OnPreferenceClickListener() {
                @Override
                public boolean onPreferenceClick(Preference preference) {
                  showKeyboardLayoutDialog(inputDeviceDescriptor);
                  return true;
                }
              });
          mHardKeyboardPreferenceList.add(pref);
        }
      }
    }

    if (!mHardKeyboardPreferenceList.isEmpty()) {
      for (int i = mHardKeyboardCategory.getPreferenceCount(); i-- > 0; ) {
        final Preference pref = mHardKeyboardCategory.getPreference(i);
        if (pref.getOrder() < 1000) {
          mHardKeyboardCategory.removePreference(pref);
        }
      }

      Collections.sort(mHardKeyboardPreferenceList);
      final int count = mHardKeyboardPreferenceList.size();
      for (int i = 0; i < count; i++) {
        final Preference pref = mHardKeyboardPreferenceList.get(i);
        pref.setOrder(i);
        mHardKeyboardCategory.addPreference(pref);
      }

      getPreferenceScreen().addPreference(mHardKeyboardCategory);
    } else {
      getPreferenceScreen().removePreference(mHardKeyboardCategory);
    }
  }
Beispiel #4
0
 private void initSummary(Preference p) {
   if (p instanceof PreferenceCategory) {
     PreferenceCategory pCat = (PreferenceCategory) p;
     for (int i = 0; i < pCat.getPreferenceCount(); i++) {
       initSummary(pCat.getPreference(i));
     }
   } else {
     updatePrefSummary(p);
   }
 }
 private void offerInstallAccessibilitySerivceOnce() {
   // There is always one preference - if no services it is just a message.
   if (mServicesCategory.getPreference(0) != mNoServicesMessagePreference) {
     return;
   }
   SharedPreferences preferences = getActivity().getPreferences(Context.MODE_PRIVATE);
   final boolean offerInstallService =
       !preferences.getBoolean(KEY_INSTALL_ACCESSIBILITY_SERVICE_OFFERED_ONCE, false);
   if (offerInstallService) {
     preferences.edit().putBoolean(KEY_INSTALL_ACCESSIBILITY_SERVICE_OFFERED_ONCE, true).commit();
     // Notify user that they do not have any accessibility
     // services installed and direct them to Market to get TalkBack.
     showDialog(DIALOG_ID_NO_ACCESSIBILITY_SERVICES);
   }
 }
  @Override
  public void onResume() {
    super.onResume();
    loadInstalledServices();
    updateAllPreferences();
    if (mServicesCategory.getPreference(0) == mNoServicesMessagePreference) {
      offerInstallAccessibilitySerivceOnce();
    }
    mSettingsPackageMonitor.register(getActivity(), false);

    getContentResolver()
        .registerContentObserver(
            Settings.System.getUriFor(Settings.System.ACCELEROMETER_ROTATION),
            true,
            mRotationObserver);
  }
  /**
   * Iterate through debug buttons, adding a special debug preference click listener to each of
   * them.
   */
  protected void connectDebugButtons() {
    // Separate listener to really separate debug logic from main code paths.
    final OnPreferenceClickListener listener = new DebugPreferenceClickListener();

    // We don't want to use Android resource strings for debug UI, so we just
    // use the keys throughout.
    final PreferenceCategory debugCategory =
        (PreferenceCategory) ensureFindPreference("debug_category");
    debugCategory.setTitle(debugCategory.getKey());

    for (int i = 0; i < debugCategory.getPreferenceCount(); i++) {
      final Preference button = debugCategory.getPreference(i);
      button.setTitle(button.getKey()); // Not very friendly, but this is for debugging only!
      button.setOnPreferenceClickListener(listener);
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new StartupService().onStartupApplication(this);
    ContextManager.setContext(this);

    PreferenceScreen screen = getPreferenceScreen();
    voiceInputAssistant = new VoiceInputAssistant(this);

    addPluginPreferences(screen);

    screen.getPreference(POWER_PACK_PREFERENCE).setEnabled(addOnService.hasPowerPack());

    final Resources r = getResources();

    // first-order preferences
    Preference preference = screen.findPreference(getString(R.string.p_about));
    preference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference p) {
            showAbout();
            return true;
          }
        });

    preference = screen.findPreference(getString(R.string.p_tutorial));
    preference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference p) {
            Intent showWelcomeLogin = new Intent(EditPreferences.this, WelcomeWalkthrough.class);
            showWelcomeLogin.putExtra(ActFmLoginActivity.SHOW_TOAST, false);
            showWelcomeLogin.putExtra(WelcomeWalkthrough.TOKEN_MANUAL_SHOW, true);
            startActivity(showWelcomeLogin);
            return true;
          }
        });

    preference = screen.findPreference(getString(R.string.p_help));
    preference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference p) {
            showSupport();
            return true;
          }
        });

    preference = screen.findPreference(getString(R.string.p_forums));
    preference.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference p) {
            showForums();
            return true;
          }
        });

    PreferenceCategory appearance =
        (PreferenceCategory) screen.getPreference(APPEARANCE_PREFERENCE);
    Preference beastMode = appearance.getPreference(1);
    beastMode.setTitle(r.getString(R.string.EPr_beastMode_title));
    beastMode.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference p) {
            showBeastMode();
            return true;
          }
        });

    addDebugPreferences();

    addPreferenceListeners();
  }