@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());
  }
  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);
    }
  }
示例#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);
   }
 }
示例#5
0
 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);
   }
 }
  /**
   * 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);
    }
  }
  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);
    }
  }
示例#9
0
  private static void setupPreferences(PreferenceActivity context) {
    // create Categories
    PreferenceScreen prefScreen = context.getPreferenceManager().createPreferenceScreen(context);
    prefScreen.removeAll();

    // selected location category
    PreferenceCategory selectedCat = new PreferenceCategory(context);
    selectedCat.setTitle(R.string.selected_location_str);
    // location list category
    PreferenceCategory locationListCat = new PreferenceCategory(context);
    locationListCat.setTitle(R.string.location_list_str);
    // general category
    PreferenceCategory generalCat = new PreferenceCategory(context);
    generalCat.setTitle(R.string.general_preferences_str);
    //		//gesture category
    //		PreferenceCategory gestureCat = new PreferenceCategory(context);
    //		gestureCat.setTitle(R.string.gesture_settings_str);

    // add categories to preference screen
    prefScreen.addPreference(selectedCat);
    prefScreen.addPreference(locationListCat);
    //		prefScreen.addPreference(gestureCat);
    prefScreen.addPreference(generalCat);

    // Create add and delete location preferences and add to location list
    locationListCat.addPreference(
        createAddLocationPreference(
            context,
            context.getString(R.string.add_location_str),
            context.getString(R.string.add_location_description_str)));
    locationListCat.addPreference(
        createDeleteLocationPreference(
            context,
            context.getString(R.string.delete_location_str),
            context.getString(R.string.delete_location_description_str)));

    // create apptheme action preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_APP_THEME,
            R.string.pref_app_theme,
            R.string.pref_app_theme_description,
            R.array.app_theme_strings,
            R.array.app_theme_values,
            "0"));

    // create mythfrontend update status interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_STATUS_UPDATE_INTERVAL,
            R.string.status_update_interval_str,
            R.string.status_update_interval_description_str,
            R.array.status_Update_Interval_strings,
            R.array.status_Update_Interval_values,
            "0"));

    // create haptic feedback shared preference
    generalCat.addPreference(
        createCheckBox(
            context,
            PREF_HAPTIC_FEEDBACK_ENABLED,
            R.string.haptic_feedback_enabled_str,
            R.string.haptic_feedback_enabled_description_str,
            false));

    // create longpress action preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_LONGPRESS_ACTION,
            R.string.longpress_action_str,
            R.string.longpress_action_description_str,
            R.array.longpress_action_strings,
            R.array.longpress_action_values,
            "0"));

    // create key repeat interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_KEY_REPEAT_INTERVAL,
            R.string.key_repeat_interval_str,
            R.string.key_repeat_interval_description_str,
            R.array.key_repeat_interval_strings,
            R.array.key_repeat_interval_values,
            "100"));

    // create connection timeout interval preference
    generalCat.addPreference(
        createIntListPreference(
            context,
            PREF_CONNECTION_TIMEOUT_INTERVAL,
            R.string.conection_timeout_interval_str,
            R.string.conection_timeout_interval_description_str,
            R.array.connection_timeout_interval_strings,
            R.array.connection_timeout_interval_values,
            "5000"));

    // create donate button visible checkbox
    generalCat.addPreference(
        createCheckBox(
            context,
            PREF_SHOW_DONATE_MENU_ITEM,
            R.string.show_donate_menu_item_str,
            R.string.show_donate_menu_item_str,
            true));

    //		//create gestures enabled
    //		gestureCat.addPreference(createCheckBox(context,
    //				PREF_GESTURES_ENABLED,
    //				R.string.gestures_enabled_str,
    //				R.string.gestures_enabled_str, false));
    //
    //		//gesture list preference
    //		Preference gestureList = createGestureListPreference(context);
    //		gestureCat.addPreference(gestureList);

    // open DB
    MythMoteDbManager _dbAdapter = new MythMoteDbManager(context);
    _dbAdapter.open();

    // get list of locations
    Cursor cursor = _dbAdapter.fetchAllFrontendLocations();

    // get column indexes
    sIdIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ROWID);
    sAddressIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_ADDRESS);
    sNameIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_NAME);
    sPortIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_PORT);
    sMacIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_MAC);
    sWifiOnlyIndex = cursor.getColumnIndex(MythMoteDbHelper.KEY_WIFIONLY);

    // determine if we have locations saved
    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
      // get selected frontend id
      int selected =
          context
              .getSharedPreferences(MYTHMOTE_SHARED_PREFERENCES_ID, MODE_PRIVATE)
              .getInt(MythMotePreferences.PREF_SELECTED_LOCATION, -1);

      // if selected failed
      if (selected == -1) {
        // set to first in list
        selected = cursor.getInt(sIdIndex);
        // save (defaulted) selected location
        SaveSelectedLocationId(context, selected);
      }

      // put each location in the preference list
      for (int i = 0; i < count; i++) {
        locationListCat.addPreference(
            MythMotePreferences.createLocationPreference(
                context,
                cursor.getString(sIdIndex),
                cursor.getString(sNameIndex),
                cursor.getString(sAddressIndex)));

        if (cursor.getInt(sIdIndex) == selected) {
          // create preference for selected location
          selectedCat.addPreference(
              MythMotePreferences.createSelectedLocationPreference(
                  context,
                  context.getString(R.string.selected_location_str),
                  cursor.getString(sNameIndex)));
        }

        cursor.moveToNext();
      }

      // the saved selected location was not found just pick the first one
      if (selectedCat.getPreferenceCount() <= 0) {
        cursor.moveToFirst();
        selectedCat.addPreference(
            MythMotePreferences.createSelectedLocationPreference(
                context,
                context.getString(R.string.selected_location_str),
                cursor.getString(sNameIndex)));

        // save location ID so that it is for real
        SaveSelectedLocationId(context, cursor.getInt(sIdIndex));
      }
    } else {
      selectedCat.addPreference(
          MythMotePreferences.createSelectedLocationPreference(
              context,
              context.getString(R.string.selected_location_str),
              context.getString(R.string.no_frontend_locations_defined_str)));
    }

    cursor.close();
    _dbAdapter.close();

    // set preference screen
    context.setPreferenceScreen(prefScreen);

    // Assign dependences
    //		gestureList.setDependency(PREF_GESTURES_ENABLED);
  }