androidx.preference.PreferenceCategory Java Examples

The following examples show how to use androidx.preference.PreferenceCategory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SettingsFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {
        @SuppressLint("RestrictedApi")
        @Override
        public void onBindViewHolder(PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);
            Preference preference = getItem(position);
            if (preference instanceof PreferenceCategory)
                setZeroPaddingToLayoutChildren(holder.itemView);
            else {
                View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
                if (iconFrame != null) {
                    iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
                }
            }
        }
    };
}
 
Example #2
Source File: MeasurementPreferences.java    From openScale with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.measurement_preferences, rootKey);

    setHasOptionsMenu(true);

    Preference deleteAll = findPreference(PREFERENCE_KEY_DELETE_ALL);
    deleteAll.setOnPreferenceClickListener(new onClickListenerDeleteAll());

    measurementCategory = (PreferenceCategory) findPreference(PREFERENCE_KEY_MEASUREMENTS);

    Preference resetOrder = findPreference(PREFERENCE_KEY_RESET_ORDER);
    resetOrder.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
                    .remove(MeasurementView.PREF_MEASUREMENT_ORDER).apply();
            updateMeasurementPreferences();
            return true;
        }
    });

    updateMeasurementPreferences();
}
 
Example #3
Source File: UsersPreferences.java    From openScale with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.users_preferences, rootKey);

    setHasOptionsMenu(true);

    Preference addUser = findPreference(PREFERENCE_KEY_ADD_USER);
    addUser.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            UsersPreferencesDirections.ActionNavUserPreferencesToNavUsersettings action = UsersPreferencesDirections.actionNavUserPreferencesToNavUsersettings();
            action.setMode(UserSettingsFragment.USER_SETTING_MODE.ADD);
            action.setTitle(getString(R.string.label_add_user));

            Navigation.findNavController(getActivity(), R.id.nav_host_fragment).navigate(action);
            return true;
        }
    });

    users = (PreferenceCategory) findPreference(PREFERENCE_KEY_USERS);
    updateUserPreferences();
}
 
Example #4
Source File: TalkBackSelectorPreferencesActivity.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Enables or disables the setting configuration preference category, depending on the on/off
 * state of the selector.
 */
private void enableOrDisableSelectorSettings(boolean enable) {
  PreferenceCategory settingsCategory =
      (PreferenceCategory)
          findPreference(getString(R.string.pref_category_selector_settings_configuration_key));
  if (settingsCategory == null) {
    return;
  }

  final int count = settingsCategory.getPreferenceCount();

  for (int i = 0; i < count; i++) {
    final Preference preference = settingsCategory.getPreference(i);

    if (preference instanceof TwoStatePreference) {
      TwoStatePreference switchPreference = (TwoStatePreference) preference;
      switchPreference.setEnabled(enable);
    }
  }
}
 
Example #5
Source File: SettingsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
private void setGDPR() {
  if (settingsManager.showGDPR()) {
    termsAndConditions = findPreference(TERMS_AND_CONDITIONS_PREFERENCE_KEY);
    privacyPolicy = findPreference(PRIVACY_POLICY_PREFERENCE_KEY);
  } else {
    PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("about");
    Preference termsAndConditionsPreference = findPreference("termsConditions");
    Preference privacyPolicyPreference = findPreference("privacyPolicy");
    if (termsAndConditionsPreference != null) {
      preferenceCategory.removePreference(termsAndConditionsPreference);
    }
    if (privacyPolicyPreference != null) {
      preferenceCategory.removePreference(privacyPolicyPreference);
    }
  }
}
 
Example #6
Source File: BasePreferenceFragment.java    From ColorPicker with Apache License 2.0 6 votes vote down vote up
@Override protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
  return new PreferenceGroupAdapter(preferenceScreen) {
    @SuppressLint("RestrictedApi") @Override public void onBindViewHolder(PreferenceViewHolder holder, int position) {
      super.onBindViewHolder(holder, position);
      Preference preference = getItem(position);
      if (preference instanceof PreferenceCategory) {
        setZeroPaddingToLayoutChildren(holder.itemView);
      } else {
        View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
        if (iconFrame != null) {
          iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
        }
      }
    }
  };
}
 
Example #7
Source File: SettingsFragment.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressLint("RestrictedApi")
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
    return new PreferenceGroupAdapter(preferenceScreen) {
        @Override
        public void onBindViewHolder(@NonNull PreferenceViewHolder holder, int position) {
            super.onBindViewHolder(holder, position);
            Preference preference = getItem(position);
            if (preference instanceof PreferenceCategory)
                setZeroPaddingToLayoutChildren(holder.itemView);
            else {
                View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
                if (iconFrame != null) {
                    iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
                }
            }
        }
    };
}
 
Example #8
Source File: PreferencesCommonFragment.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
private void manageLANDeviceAddressPreference() {

        PreferenceCategory hotspotSettingsCategory = findPreference("HOTSPOT");
        Preference localEthernetDeviceAddress = findPreference("pref_common_local_eth_device_addr");

        if (getActivity() == null || hotspotSettingsCategory == null || localEthernetDeviceAddress == null) {
            return;
        }

        if (Utils.INSTANCE.getScreenOrientation(getActivity()) == Configuration.ORIENTATION_PORTRAIT
                || !Utils.INSTANCE.isLANInterfaceExist()) {
            hotspotSettingsCategory.removePreference(localEthernetDeviceAddress);
        } else {
            String deviceIP = Utils.INSTANCE.getDeviceIP();
            String summary = String.format(getString(R.string.pref_common_local_eth_device_addr_summ), deviceIP, deviceIP);
            localEthernetDeviceAddress.setSummary(summary);
        }


    }
 
Example #9
Source File: CorrectedPreferenceFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressLint("RestrictedApi")
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
  return new PreferenceGroupAdapter(preferenceScreen) {
    @Override
    public void onBindViewHolder(PreferenceViewHolder holder, int position) {
      super.onBindViewHolder(holder, position);
      Preference preference = getItem(position);
      if (preference instanceof PreferenceCategory) {
        setZeroPaddingToLayoutChildren(holder.itemView);
      } else {
        View iconFrame = holder.itemView.findViewById(R.id.icon_frame);
        if (iconFrame != null) {
          iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
        }
      }
    }
  };
}
 
Example #10
Source File: PreferencesTorFragment.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
private void changePreferencesForGPVersion() {
    PreferenceCategory torSettingsCategory = findPreference("tor_settings");

    if (torSettingsCategory != null) {
        ArrayList<Preference> preferences = new ArrayList<>();
        preferences.add(findPreference("AvoidDiskWrites"));
        preferences.add(findPreference("ConnectionPadding"));
        preferences.add(findPreference("ReducedConnectionPadding"));
        preferences.add(findPreference("Enable SOCKS proxy"));
        preferences.add(findPreference("Enable HTTPTunnel"));
        preferences.add(findPreference("Enable Transparent proxy"));
        preferences.add(findPreference("Enable DNS"));

        for (Preference preference : preferences) {
            if (preference != null) {
                torSettingsCategory.removePreference(preference);
            }
        }
    }

    PreferenceCategory otherCategory = findPreference("pref_tor_other");
    Preference editTorConfDirectly = findPreference("editTorConfDirectly");
    if (otherCategory != null && editTorConfDirectly != null) {
        otherCategory.removePreference(editTorConfDirectly);
    }
}
 
Example #11
Source File: GeneralPreferenceFragment.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupUsageStatisticsAvailability() {
    boolean available = BuildConfig.ANALYTICS_AVAILABLE;
    if (!available) {
        PreferenceCategory settingsCategoryPreference = findPreference(getString(R.string.preferences_general_category_settings_key));
        SwitchPreferenceCompat trackingPreference = findPreference(getString(R.string.preferences_tracking_enabled_key));
        settingsCategoryPreference.removePreference(trackingPreference);

        // We have only one help preference so the whole category is to be removed
        PreferenceScreen generalScreenPreference = getPreferenceScreen();
        PreferenceCategory helpCategoryPreference = findPreference(getString(R.string.preferences_general_category_help_key));
        generalScreenPreference.removePreference(helpCategoryPreference);
    } else {
        setupUsageStatisticsDialog();
    }
}
 
Example #12
Source File: PreferencesFastFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void changePreferencesWithProxyMode() {

        PreferenceCategory torSettingsCategory = findPreference("Tor Settings");

        List<Preference> preferencesList = new ArrayList<>();

        preferencesList.add(findPreference("pref_fast_all_through_tor"));
        preferencesList.add(findPreference("prefTorSiteUnlock"));
        preferencesList.add(findPreference("prefTorAppUnlock"));
        preferencesList.add(findPreference("prefTorSiteExclude"));
        preferencesList.add(findPreference("prefTorAppExclude"));
        preferencesList.add(findPreference("pref_fast_site_refresh_interval"));

        for (Preference preference : preferencesList) {
            if (preference != null) {
                if (torSettingsCategory != null) {
                    torSettingsCategory.removePreference(preference);
                }
            }
        }

        PreferenceCategory fastUpdateCategory = findPreference("fast_update");
        Preference updateThroughTor = findPreference("pref_fast through_tor_update");
        if (fastUpdateCategory != null && updateThroughTor != null) {
            fastUpdateCategory.removePreference(updateThroughTor);
        }

        PreferenceCategory fastOtherCategory = findPreference("fast_other");

        Preference blockHttp = findPreference("pref_fast_block_http");
        if (fastOtherCategory != null && blockHttp != null) {
            fastOtherCategory.removePreference(blockHttp);
        }
    }
 
Example #13
Source File: UsersPreferences.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
UserPreference(Context context, PreferenceCategory category, ScaleUser scaleUser) {
    super(context);

    preferenceCategory = category;
    this.scaleUser = scaleUser;

    setTitle(scaleUser.getUserName());
    setWidgetLayoutResource(R.layout.user_preference_widget_layout);
}
 
Example #14
Source File: AdvancedPreferenceFragment.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupErrorReportingAvailability() {
    boolean available = BuildConfig.ACRA_SETTINGS_AVAILABLE;
    if (!available) {
        PreferenceCategory settingsCategoryPreference = findPreference(getString(R.string.preferences_advanced_category_settings_key));
        SwitchPreferenceCompat errorReportingSilentPreference = findPreference(getString(R.string.preferences_error_reporting_silent_key));
        settingsCategoryPreference.removePreference(errorReportingSilentPreference);
    }
}
 
Example #15
Source File: CollectorPreferenceFragment.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
private void setupHideCollectorNotificationAvailability() {
    boolean available = Build.VERSION.SDK_INT < Build.VERSION_CODES.O;
    if (!available) {
        PreferenceCategory settingsCategoryPreference = findPreference(getString(R.string.preferences_general_category_settings_key));
        SwitchPreferenceCompat hideCollectorNotificationPreference = findPreference(getString(R.string.preferences_hide_collector_notification_key));
        settingsCategoryPreference.removePreference(hideCollectorNotificationPreference);
    }
}
 
Example #16
Source File: PreferencesFastFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void changePreferencesForFDVersion() {
    PreferenceScreen preferencesFast = findPreference("fast_preferences");
    PreferenceCategory fastUpdateCategory = findPreference("fast_update");
    if (preferencesFast != null && fastUpdateCategory != null) {
        preferencesFast.removePreference(fastUpdateCategory);
    }
}
 
Example #17
Source File: SettingsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void setAdultContentViews() {
  if (settingsManager.showAdultContent()) {
    adultContentPreferenceView =
        (SwitchPreferenceCompat) findPreference(ADULT_CONTENT_PREFERENCE_VIEW_KEY);
    adultContentWithPinPreferenceView =
        (SwitchPreferenceCompat) findPreference(ADULT_CONTENT_WITH_PIN_PREFERENCE_VIEW_KEY);
    pinPreferenceView = findPreference(ADULT_CONTENT_PIN_PREFERENCE_VIEW_KEY);
    removePinPreferenceView = findPreference(REMOVE_ADULT_CONTENT_PIN_PREFERENCE_VIEW_KEY);
  } else {
    PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("adultContent");
    if (preferenceCategory != null) {
      getPreferenceScreen().removePreference(preferenceCategory);
    }
  }
}
 
Example #18
Source File: PreferencesDNSFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void removePreferencesWithGPVersion() {
    PreferenceScreen dnscryptSettings = findPreference("dnscrypt_settings");

    ArrayList<PreferenceCategory> categories = new ArrayList<>();
    categories.add(findPreference("pref_dnscrypt_forwarding_rules"));
    categories.add(findPreference("pref_dnscrypt_cloaking_rules"));
    categories.add(findPreference("pref_dnscrypt_blacklist"));
    categories.add(findPreference("pref_dnscrypt_ipblacklist"));
    categories.add(findPreference("pref_dnscrypt_whitelist"));
    categories.add(findPreference("pref_dnscrypt_other"));

    for (PreferenceCategory category : categories) {
        if (dnscryptSettings != null && category != null) {
            dnscryptSettings.removePreference(category);
        }
    }

    PreferenceCategory requireServersCategory = findPreference("dnscrypt_require_servers_prop_summ");
    Preference requireNofilter = findPreference("require_nofilter");

    if (requireServersCategory != null && requireNofilter != null) {
        requireServersCategory.removePreference(requireNofilter);
    }

    PreferenceCategory queryLogCategory = findPreference("pref_dnscrypt_query_log");
    Preference ignoredQtypes = findPreference("ignored_qtypes");

    if (queryLogCategory != null && ignoredQtypes != null) {
        queryLogCategory.removePreference(ignoredQtypes);
    }
}
 
Example #19
Source File: PreferencesFastFragment.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void changePreferencesForGPVersion() {
    PreferenceScreen preferencesFast = findPreference("fast_preferences");
    PreferenceCategory fastUpdateCategory = findPreference("fast_update");
    if (preferencesFast != null && fastUpdateCategory != null) {
        preferencesFast.removePreference(fastUpdateCategory);
    }

    PreferenceCategory fastOtherCategory = findPreference("fast_other");

    Preference blockHttp = findPreference("pref_fast_block_http");
    if (fastOtherCategory != null && blockHttp != null) {
        fastOtherCategory.removePreference(blockHttp);
    }
}
 
Example #20
Source File: NotificationsFragment.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
    super.onCreatePreferences(savedInstanceState, rootKey);
    Context activityContext = getActivity();

    final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(activityContext);
    setPreferenceScreen(preferenceScreen);

    final TypedValue themeTypedValue = new TypedValue();
    activityContext.getTheme().resolveAttribute(R.attr.preferenceTheme, themeTypedValue, true);
    mContextThemeWrapper = new ContextThemeWrapper(activityContext, themeTypedValue.resourceId);
    mEmptyNotifications = new PreferenceCategory(mContextThemeWrapper);
    mEmptyNotifications.setTitle(R.string.id_your_notifications_will_be);
}
 
Example #21
Source File: PreferencesFastFragment.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
private void changePreferencesWithVPNMode(Context context) {
    Preference pref_fast_all_through_tor = findPreference("pref_fast_all_through_tor");
    if (pref_fast_all_through_tor != null) {
        //pref_fast_all_through_tor.setTitle(R.string.pref_fast_all_through_ipro);
        pref_fast_all_through_tor.setOnPreferenceChangeListener(this);
    }

    Preference pref_fast_block_http = findPreference("pref_fast_block_http");
    if (pref_fast_block_http != null) {
        pref_fast_block_http.setOnPreferenceChangeListener(this);
    }

    SharedPreferences shPref = PreferenceManager.getDefaultSharedPreferences(context);
    Preference prefTorAppUnlock = findPreference("prefTorAppUnlock");

    /*if (prefTorAppUnlock != null) {
        prefTorAppUnlock.setSummary(R.string.pref_fast_unlock_apps_with_ipro_summ);
    }*/

    if (shPref.getBoolean("pref_fast_all_through_tor", true)) {
        if (prefTorAppUnlock != null) {
            prefTorAppUnlock.setEnabled(false);
        }
    } else {
        if (prefTorAppUnlock != null) {
            prefTorAppUnlock.setEnabled(true);
        }
    }

    /*Preference prefTorAppExclude = findPreference("prefTorAppExclude");
    if (prefTorAppExclude != null) {
        prefTorAppExclude.setSummary(R.string.pref_fast_exclude_apps_from_ipro_summ);
    }*/

    PreferenceCategory torSettingsCategory = findPreference("Tor Settings");
    /*if (torSettingsCategory != null) {
        torSettingsCategory.setTitle(R.string.pref_fast_routing);
    }*/

    List<Preference> preferencesList = new ArrayList<>();

    preferencesList.add(findPreference("prefTorSiteUnlock"));
    preferencesList.add(findPreference("prefTorSiteExclude"));
    preferencesList.add(findPreference("pref_fast_site_refresh_interval"));

    for (Preference preference : preferencesList) {
        if (preference != null) {
            if (torSettingsCategory != null) {
                torSettingsCategory.removePreference(preference);
            }
        }
    }

    PreferenceCategory fastUpdateCategory = findPreference("fast_update");
    Preference updateThroughTor = findPreference("pref_fast through_tor_update");
    if (fastUpdateCategory != null && updateThroughTor != null) {
        fastUpdateCategory.removePreference(updateThroughTor);
    }
}
 
Example #22
Source File: AdvancedPrefsFragment.java    From mimi-reader with Apache License 2.0 4 votes vote down vote up
private void setupPrefs() {
    final PreferenceCategory category = (PreferenceCategory) findPreference(getString(R.string.advanced_preference_category));

    final Preference clearHiddenThreadsPref = findPreference(getString(R.string.clear_hidden_threads_pref));
    if (clearHiddenThreadsPref != null) {
        clearHiddenThreadsPref.setOnPreferenceClickListener(preference -> {
            final Disposable dis = HiddenThreadTableConnection.clearAll()
                    .compose(DatabaseUtils.applySingleSchedulers())
                    .subscribe(success -> {
                        Log.d(LOG_TAG, "Clearing hidden threads: success=" + success);

                        int msgResId = R.string.all_hidden_threads_cleared;
                        if (!success) {
                            msgResId = R.string.failed_to_clear_hidden_threads;
                        }

                        Toast.makeText(MimiApplication.getInstance(), msgResId, Toast.LENGTH_SHORT).show();

                    }, throwable -> {
                        Log.w(LOG_TAG, "Could not clear hidden threads", throwable);

                        Toast.makeText(MimiApplication.getInstance(), R.string.failed_to_clear_hidden_threads, Toast.LENGTH_SHORT).show();
                    });

            return true;
        });
    }

    final Preference httpBufferSizePref = findPreference(getString(R.string.http_buffer_size_pref));
    httpBufferSizePref.setOnPreferenceChangeListener((preference, o) -> {
        HttpClientFactory.getInstance().reset();
        return true;
    });

    final Preference chanpassLogin = findPreference(getString(R.string.chanpass_login_pref));
    if (MimiUtil.getInstance().isLoggedIn()) {
        chanpassLogin.setTitle(R.string.chanpass_logout);
        chanpassLogin.setOnPreferenceClickListener(preference -> {
            final MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(getActivity());
            dialogBuilder.setTitle(R.string.chanpass_logout);
            dialogBuilder.setMessage(R.string.are_you_sure);
            dialogBuilder.setPositiveButton(R.string.yes, (dialog, which) -> {
                MimiUtil.getInstance().logout();
                chanpassLogin.setTitle(R.string.chanpass_login);
            });
            dialogBuilder.setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss());

            dialogBuilder.show();
            return true;
        });
    } else {
        chanpassLogin.setTitle(R.string.chanpass_login);
        chanpassLogin.setOnPreferenceClickListener(preference -> {
            final Intent intent = new Intent(getActivity(), LoginActivity.class);
            startActivity(intent);

            getActivity().finish();
            return true;
        });
    }
}
 
Example #23
Source File: ConditionFragment.java    From PresencePublisher with MIT License 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    context = getPreferenceManager().getContext();
    beaconsSupported = ((Application) context.getApplicationContext()).supportsBeacons();
    SharedPreferences preference = getPreferenceManager().getSharedPreferences();
    currentNetworks = Collections.unmodifiableSet(preference.getStringSet(SSID_LIST, Collections.emptySet()));
    currentBeacons = Collections.unmodifiableSet(preference.getStringSet(BEACON_LIST, Collections.emptySet()));

    PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);

    Preference contentHelp = new ContentHelpDummy(context, R.string.condition_help_summary);
    Preference sendViaMobileNetwork = new SendViaMobileNetworkPreference(context);
    wifiCategory = new MyPreferenceCategory(context, R.string.category_wifi);
    beaconCategory = new MyPreferenceCategory(context, R.string.category_beacon_regions);
    PreferenceCategory offlineCategory = new MyPreferenceCategory(context, R.string.category_offline);

    screen.addPreference(contentHelp);
    screen.addPreference(sendViaMobileNetwork);
    screen.addPreference(wifiCategory);
    screen.addPreference(beaconCategory);
    screen.addPreference(offlineCategory);

    wifiCategory.setOrderingAsAdded(false);
    addNetworkChoice = new AddNetworkChoicePreferenceDummy(context, preference, this);
    for (String ssid : currentNetworks) {
        wifiCategory.addPreference(new WifiNetworkPreference(context, ssid, preference, this));
    }
    wifiCategory.addPreference(addNetworkChoice);

    beaconCategory.setOrderingAsAdded(false);
    // to make linter happy
    if (beaconsSupported && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        addBeaconChoice = new AddBeaconChoicePreferenceDummy(context, this);
        for (String beaconId : currentBeacons) {
            beaconCategory.addPreference(new BeaconPreference(context, beaconId, this));
        }
        beaconCategory.addPreference(addBeaconChoice);
    } else {
        beaconCategory.addPreference(new ContentHelpDummy(context, R.string.no_bluetooth_explanation));
    }

    Preference offlineContent = new OfflineContentPreference(context);
    offlineCategory.addPreference(new SendOfflineMessagePreference(context));
    offlineCategory.addPreference(offlineContent);

    setPreferenceScreen(screen);

    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(listener);

    offlineContent.setDependency(SEND_OFFLINE_MESSAGE);
}
 
Example #24
Source File: SettingsFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@Override
    public void onCreatePreferences(Bundle bundle, String s) {
        addPreferencesFromResource(R.xml.settings);

        SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
        if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
            getPreferenceScreen().removePreference(forceEnglish);
        } else {
            forceEnglish.setOnPreferenceChangeListener(this);
        }
/*
        if (Utils.hideStartActivity()) {
            ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                    .removePreference(findPreference(KEY_MATERIAL_ICON));
        } else {
            findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
        }
*/
        findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
        findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
        findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
        findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
        findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
        findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
        findPreference(KEY_PRIMARY_COLOR).setOnPreferenceClickListener(this);
        findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
        findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
        findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
        findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);

        if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
            findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
        } else {
            ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(
                    findPreference(KEY_LAST_KMSG));
        }

        findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
        findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
        findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
                || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
            ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(
                    findPreference(KEY_FINGERPRINT));
        } else {
            mFingerprint = findPreference(KEY_FINGERPRINT);
            mFingerprint.setEnabled(!AppSettings.getPassword(getActivity()).isEmpty());
        }

        NavigationActivity activity = (NavigationActivity) getActivity();
        PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
        for (NavigationActivity.NavigationFragment navigationFragment : activity.getFragments()) {
            Class<? extends Fragment> fragmentClass = navigationFragment.mFragmentClass;
            int id = navigationFragment.mId;

            if (fragmentClass != null && fragmentClass != SettingsFragment.class) {
                SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(
                        new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
                switchPreference.setSummary(getString(id));
                switchPreference.setKey(fragmentClass.getSimpleName() + "_enabled");
                switchPreference.setChecked(AppSettings.isFragmentEnabled(fragmentClass, getActivity()));
                switchPreference.setOnPreferenceChangeListener(this);
                switchPreference.setPersistent(true);
                sectionsCategory.addPreference(switchPreference);
            }
        }
    }
 
Example #25
Source File: PreferencesCommonFragment.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if (getActivity() == null) {
        super.onCreateView(inflater, container, savedInstanceState);
    }

    getActivity().setTitle(R.string.drawer_menu_commonSettings);

    PreferenceCategory others = findPreference("common_other");
    Preference swShowNotification = findPreference("swShowNotification");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        if (others != null && swShowNotification != null) {
            others.removePreference(swShowNotification);
        }
    } else {
        if (swShowNotification != null) {
            swShowNotification.setOnPreferenceChangeListener(this);
        }
    }

    if (ModulesStatus.getInstance().getMode() == ROOT_MODE) {
        registerPreferences();
    } else {
        removePreferences();
    }

    manageLANDeviceAddressPreference();

    PreferenceCategory otherSettingsCategory = findPreference("common_other");
    Preference shellControl = findPreference("pref_common_shell_control");

    if (appVersion.startsWith("g")) {
        PreferenceCategory hotspotSettingsCategory = findPreference("HOTSPOT");
        Preference blockHTTP = findPreference("pref_common_block_http");
        if (hotspotSettingsCategory != null && blockHTTP != null) {
            hotspotSettingsCategory.removePreference(blockHTTP);
        }

        if (otherSettingsCategory != null && shellControl != null) {
            otherSettingsCategory.removePreference(shellControl);
        }

    } else if (shellControl != null){
        shellControl.setSummary(String.format(getString(R.string.pref_common_shell_control_summ), getActivity().getPackageName()));
    }

    return super.onCreateView(inflater, container, savedInstanceState);
}
 
Example #26
Source File: SettingsFragment.java    From c3nav-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    setPreferencesFromResource(R.xml.preferences, rootKey);

    useWifiLocating = (CheckBoxPreference)this.findPreference(getString(R.string.use_wifi_locating_key));
    sharePrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    if (sharePrefs.getBoolean(getString(R.string.use_wifi_locating_key), true) && !checkLocationPermisson()) {
        useWifiLocating.setChecked(false);
    }
    useWifiLocating.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!(boolean)newValue) {
                // always let user disable wifi locating
                return true;
            }

            boolean permissionAsked = false;
            while (permissionAsked == false) {
                if (checkLocationPermisson()) {
                    return true;
                }
                permissionAsked = true;
                ActivityCompat.requestPermissions(getActivity(),
                        new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                        MainActivity.PERM_REQUEST);
            }
            return false;
        }
    });

    developerSettings = (PreferenceCategory)findPreference(getString(R.string.developer_settings_key));
    developerModeEnabled = (SwitchPreference)findPreference(getString(R.string.developer_mode_enabled_key));
    developerInstanceUrl = (EditTextPreference)findPreference(getString(R.string.developer_instance_url_key));
    developerHttpUser = (EditTextPreference)findPreference(getString(R.string.developer_http_user_key));
    developerHttpPassword = (EditTextPreference)findPreference(getString(R.string.developer_http_password_key));

    developerSettings.setVisible(BuildConfig.DEBUG);
    developerModeEnabled.setVisible(BuildConfig.DEBUG);
    developerInstanceUrl.setVisible(BuildConfig.DEBUG);
    developerHttpUser.setVisible(BuildConfig.DEBUG);
    developerHttpPassword.setVisible(BuildConfig.DEBUG);
}
 
Example #27
Source File: RecipientPreferenceActivity.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
private void setSummaries(Recipient recipient) {
  CheckBoxPreference    mutePreference            = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
  Preference            customPreference          = this.findPreference(PREFERENCE_CUSTOM_NOTIFICATIONS);
  Preference            ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE);
  Preference            ringtoneCallPreference    = this.findPreference(PREFERENCE_CALL_TONE);
  ListPreference        vibrateMessagePreference  = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE);
  ListPreference        vibrateCallPreference     = (ListPreference) this.findPreference(PREFERENCE_CALL_VIBRATE);
  ColorPickerPreference colorPreference           = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR);
  Preference            blockPreference           = this.findPreference(PREFERENCE_BLOCK);
  Preference            identityPreference        = this.findPreference(PREFERENCE_IDENTITY);
  PreferenceCategory    callCategory              = (PreferenceCategory)this.findPreference("call_settings");
  PreferenceCategory    aboutCategory             = (PreferenceCategory)this.findPreference("about");
  PreferenceCategory    aboutDivider              = (PreferenceCategory)this.findPreference("about_divider");
  ContactPreference     aboutPreference           = (ContactPreference)this.findPreference(PREFERENCE_ABOUT);
  PreferenceCategory    privacyCategory           = (PreferenceCategory) this.findPreference("privacy_settings");
  PreferenceCategory    divider                   = (PreferenceCategory) this.findPreference("divider");

  mutePreference.setChecked(recipient.isMuted());

  ringtoneMessagePreference.setSummary(ringtoneMessagePreference.isEnabled() ? getRingtoneSummary(getContext(), recipient.getMessageRingtone()) : "");
  ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone()));

  Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate());
  Pair<String, Integer> vibrateCallSummary    = getVibrateSummary(getContext(), recipient.getCallVibrate());

  vibrateMessagePreference.setSummary(vibrateMessagePreference.isEnabled() ? vibrateMessageSummary.first : "");
  vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second);

  vibrateCallPreference.setSummary(vibrateCallSummary.first);
  vibrateCallPreference.setValueIndex(vibrateCallSummary.second);

  blockPreference.setVisible(RecipientUtil.isBlockable(recipient));
  if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock);
  else                       blockPreference.setTitle(R.string.RecipientPreferenceActivity_block);

  if (recipient.isLocalNumber()) {
    mutePreference.setVisible(false);
    customPreference.setVisible(false);
    ringtoneMessagePreference.setVisible(false);
    vibrateMessagePreference.setVisible(false);

    if (identityPreference != null) identityPreference.setVisible(false);
    if (aboutCategory      != null) aboutCategory.setVisible(false);
    if (aboutDivider       != null) aboutDivider.setVisible(false);
    if (privacyCategory    != null) privacyCategory.setVisible(false);
    if (divider            != null) divider.setVisible(false);
    if (callCategory       != null) callCategory.setVisible(false);
  }

  if (recipient.isGroup()) {
    if (colorPreference    != null) colorPreference.setVisible(false);
    if (identityPreference != null) identityPreference.setVisible(false);
    if (callCategory       != null) callCategory.setVisible(false);
    if (aboutCategory      != null) aboutCategory.setVisible(false);
    if (aboutDivider       != null) aboutDivider.setVisible(false);
    if (divider            != null) divider.setVisible(false);
  } else {
    colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireActivity()));
    colorPreference.setColor(recipient.getColor().toActionBarColor(requireActivity()));

    if (FeatureFlags.profileDisplay()) {
      aboutPreference.setTitle(recipient.getDisplayName(requireContext()));
      aboutPreference.setSummary(recipient.resolve().getE164().or(""));
    } else {
      aboutPreference.setTitle(formatRecipient(recipient));
      aboutPreference.setSummary(recipient.getCustomLabel());
    }

    aboutPreference.setState(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED, recipient.isBlocked());

    IdentityUtil.getRemoteIdentityKey(getActivity(), recipient).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() {
      @Override
      public void onSuccess(Optional<IdentityRecord> result) {
        if (result.isPresent()) {
          if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get()));
          if (identityPreference != null) identityPreference.setEnabled(true);
        } else if (canHaveSafetyNumber) {
          if (identityPreference != null) identityPreference.setSummary(R.string.RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received);
          if (identityPreference != null) identityPreference.setEnabled(false);
        } else {
          if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
        }
      }

      @Override
      public void onFailure(ExecutionException e) {
        if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference);
      }
    });
  }

  if (recipient.isMmsGroup() && privacyCategory != null) {
    privacyCategory.setVisible(false);
  }
}
 
Example #28
Source File: PreferenceAdapter.java    From AndroidPreferenceActivity with Apache License 2.0 3 votes vote down vote up
/**
 * The method, which is invoked, when a specific preference is visualized. This method may be
 * overridden by subclasses in order to modify the appearance of the preference.
 *
 * @param preference
 *         The preference, which is visualized, as an instance of the class Preference. The
 *         preference may not be null
 * @param viewHolder
 *         The view holder, which corresponds to the preference, as an instance of the class
 *         PreferenceViewHolder. The view holder may not be null
 */
@CallSuper
protected void onVisualizePreference(@NonNull final Preference preference,
                                     @NonNull final PreferenceViewHolder viewHolder) {
    if (preference instanceof PreferenceCategory) {
        RecyclerView.LayoutParams layoutParams =
                (RecyclerView.LayoutParams) viewHolder.itemView.getLayoutParams();
        layoutParams.height = TextUtils.isEmpty(preference.getTitle()) ? 0 :
                RecyclerView.LayoutParams.WRAP_CONTENT;
    }
}