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);
    }
  }
Пример #2
0
  @SuppressWarnings("deprecation")
  public PreferenceScreen preferenceScreen(final PreferenceActivity activity) {
    PreferenceManager manager = activity.getPreferenceManager();

    PreferenceScreen screen = manager.createPreferenceScreen(activity);
    screen.setTitle(this._name);

    String type = activity.getString(R.string.type_trigger_unknown);

    if (this instanceof ProbeTrigger) type = activity.getString(R.string.type_trigger_probe);
    if (this instanceof DateTrigger) type = activity.getString(R.string.type_trigger_datetime);

    screen.setSummary(type);

    final Trigger me = this;

    Preference viewAction = new Preference(activity);
    viewAction.setTitle(R.string.label_trigger_show_action);
    viewAction.setSummary(R.string.label_trigger_show_action_desc);
    viewAction.setOrder(Integer.MAX_VALUE);

    viewAction.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(activity, CodeViewerActivity.class);
            intent.putExtra(CodeViewerActivity.SOURCE_CODE, me._action);
            intent.putExtra(CodeViewerActivity.TITLE, me.name());

            activity.startActivity(intent);

            return true;
          }
        });

    screen.addPreference(viewAction);

    CheckBoxPreference enabled = new CheckBoxPreference(activity);
    enabled.setTitle(R.string.label_trigger_enable_action);
    enabled.setSummary(R.string.label_trigger_enable_action_desc);
    enabled.setKey(this.enabledKey());
    enabled.setDefaultValue(true);

    enabled.setOrder(Integer.MAX_VALUE);

    enabled.setOnPreferenceChangeListener(
        new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            return true;
          }
        });

    screen.addPreference(enabled);

    Preference fireNow = new Preference(activity);
    fireNow.setTitle(R.string.label_trigger_fire_now);
    fireNow.setSummary(R.string.label_trigger_fire_now_desc);
    fireNow.setOrder(Integer.MAX_VALUE / 2);

    fireNow.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          public boolean onPreferenceClick(Preference preference) {
            me.execute(activity, true);

            return true;
          }
        });

    screen.addPreference(fireNow);

    return screen;
  }
Пример #3
0
  public void registerAll(Context context) {
    super.registerAll(context);

    manualSearch = social.canSearchUsers();

    NicedPreferences.NiceDisplayTextPreference dp;
    NicedPreferences.NiceSearchPreference sp;
    NicedPreferences.NiceListPreference lp;

    categoryPref = new NicedPreferences.NiceInfoPreference(context);
    categoryPref.setTitle(R.string.pref_social_account);
    categoryPref.setSummary(accountSummary);
    categoryPref.setEnabled(enabled);

    preferences.add(categoryPref);

    userPref = new NicedPreferences.NiceDisplayTextPreference(context);
    userPref.setTitle(R.string.pref_social_user);
    userPref.setEnabled(enabled);

    preferences.add(userPref);

    expirationPref = new NicedPreferences.NiceDisplayTextPreference(context);
    expirationPref.setTitle(R.string.pref_social_validuntil);
    expirationPref.setEnabled(enabled);

    preferences.add(expirationPref);

    loginPref = new NicedPreferences.NiceDisplayTextPreference(context);

    loginPref.setTitle(
        social.isLoggedIn() ? R.string.pref_social_logout : R.string.pref_social_login);

    loginPref.setText(
        Simple.getTrans(
            social.isLoggedIn()
                ? R.string.pref_social_isloggedin
                : R.string.pref_social_isloggedout));

    loginPref.setEnabled(enabled);

    loginPref.setOnPreferenceClickListener(
        new Preference.OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference preference) {
            if (social.isLoggedIn()) {
              social.logout();
            } else {
              social.login();
            }

            return false;
          }
        });

    preferences.add(loginPref);

    Simple.removeSharedPref("social." + social.getPlatform() + ".mode");

    lp = new NicedPreferences.NiceListPreference(context);
    lp.setKey("social." + social.getPlatform() + ".owner.mode");
    lp.setTitle("Anzeige");
    lp.setEntryValues(R.array.pref_social_newfriends_keys);
    lp.setEntries(R.array.pref_social_newfriends_vals);
    lp.setDefaultValue("feed+folder");
    lp.setEnabled(enabled);

    preferences.add(lp);

    if (GlobalConfigs.BetaFlag) {
      apicallsPref = new NicedPreferences.NiceDisplayTextPreference(context);
      apicallsPref.setTitle("API Calls");
      apicallsPref.setEnabled(enabled);

      preferences.add(apicallsPref);

      dp = new NicedPreferences.NiceDisplayTextPreference(context);
      dp.setTitle("Etwas testen");
      dp.setEnabled(enabled);

      dp.setOnPreferenceClickListener(
          new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
              social.getTest();

              return false;
            }
          });

      preferences.add(dp);
    }

    //
    // Define preference order.
    //

    int order = 1;

    for (Preference pref : preferences) {
      pref.setOrder(order++);
    }

    //
    // Preset all current friends and likes preferences.
    //

    social.reconfigureFriendsAndLikes();

    registerFriends(context, true);
    registerLikes(context, true);

    //
    // Manual search.
    //

    if (manualSearch) {
      sp = new NicedPreferences.NiceSearchPreference(context);

      sp.setTitle("Suchen");
      sp.setOrder(1000000);

      sp.setSearchCallback(
          new NicedPreferences.NiceSearchPreference.SearchCallback() {
            @Override
            public void onSearchCancel(String prefkey) {}

            @Override
            public void onSearchRequest(String prefkey, String query) {
              performSearch(query);
            }
          });

      preferences.add(sp);
    }

    monitorPrefs.run();
  }
  public void init() {
    final Context context = getContext();

    final UserInfo currentUser;
    try {
      currentUser = ActivityManagerNative.getDefault().getCurrentUser();
    } catch (RemoteException e) {
      throw new RuntimeException("Failed to get current user");
    }

    final List<UserInfo> otherUsers = getUsersExcluding(currentUser);
    final boolean showUsers = mVolume == null && otherUsers.size() > 0;

    mUsageBarPreference = new UsageBarPreference(context);
    mUsageBarPreference.setOrder(ORDER_USAGE_BAR);
    addPreference(mUsageBarPreference);

    mItemTotal = buildItem(R.string.memory_size, 0);
    mItemAvailable = buildItem(R.string.memory_available, R.color.memory_avail);
    addPreference(mItemTotal);
    addPreference(mItemAvailable);

    mItemApps = buildItem(R.string.memory_apps_usage, R.color.memory_apps_usage);
    mItemDcim = buildItem(R.string.memory_dcim_usage, R.color.memory_dcim);
    mItemMusic = buildItem(R.string.memory_music_usage, R.color.memory_music);
    mItemDownloads = buildItem(R.string.memory_downloads_usage, R.color.memory_downloads);
    mItemCache = buildItem(R.string.memory_media_cache_usage, R.color.memory_cache);
    mItemMisc = buildItem(R.string.memory_media_misc_usage, R.color.memory_misc);

    mItemCache.setKey(KEY_CACHE);

    final boolean showDetails = mVolume == null || mVolume.isPrimary();
    if (showDetails) {
      if (showUsers) {
        addPreference(new PreferenceHeader(context, currentUser.name));
      }

      addPreference(mItemApps);
      addPreference(mItemDcim);
      addPreference(mItemMusic);
      addPreference(mItemDownloads);
      addPreference(mItemCache);
      addPreference(mItemMisc);

      if (showUsers) {
        addPreference(new PreferenceHeader(context, R.string.storage_other_users));

        int count = 0;
        for (UserInfo info : otherUsers) {
          final int colorRes =
              count++ % 2 == 0 ? R.color.memory_user_light : R.color.memory_user_dark;
          final StorageItemPreference userPref =
              new StorageItemPreference(getContext(), info.name, colorRes, info.id);
          mItemUsers.add(userPref);
          addPreference(userPref);
        }
      }
    }

    final boolean isRemovable = mVolume != null ? mVolume.isRemovable() : false;
    if (isRemovable) {
      mMountTogglePreference = new Preference(context);
      mMountTogglePreference.setTitle(R.string.sd_eject);
      mMountTogglePreference.setSummary(R.string.sd_eject_summary);
      addPreference(mMountTogglePreference);
    }

    // Only allow formatting of primary physical storage
    // TODO: enable for non-primary volumes once MTP is fixed
    final boolean allowFormat = mVolume != null ? mVolume.isPrimary() : false;
    if (allowFormat) {
      mFormatPreference = new Preference(context);
      mFormatPreference.setTitle(R.string.sd_format);
      mFormatPreference.setSummary(R.string.sd_format_summary);
      addPreference(mFormatPreference);
    }

    final IPackageManager pm = ActivityThread.getPackageManager();
    try {
      if (pm.isStorageLow()) {
        mStorageLow = new Preference(context);
        mStorageLow.setOrder(ORDER_STORAGE_LOW);
        mStorageLow.setTitle(R.string.storage_low_title);
        mStorageLow.setSummary(R.string.storage_low_summary);
        addPreference(mStorageLow);
      } else if (mStorageLow != null) {
        removePreference(mStorageLow);
        mStorageLow = null;
      }
    } catch (RemoteException e) {
    }
  }