Java Code Examples for android.preference.Preference#setKey()

The following examples show how to use android.preference.Preference#setKey() . 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: DeveloperPreferences.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.developer_preferences);

        findPreference("disable").setOnPreferenceClickListener(this);

//        mLogging = (CheckBoxPreference) findPreference("logging_enabled");
//        mLogging.setChecked(GlobalApplication.getUser().loggingEnabled);

        if (BuildConfig.DEBUG) {
            Preference pref = new Preference(this);
            pref.setTitle("Prepare for screenshots");
            pref.setSummary("Clears all data and adds entries for screenshots");
            pref.setKey("screenshots");
            pref.setOnPreferenceClickListener(this);
            getPreferenceScreen().addPreference(pref);
        }
    }
 
Example 2
Source File: Preferences.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create the preference for allow adding new accounts
 */
private void createAddAccountPreference() {
    Preference addAccountPref = new Preference(this);
    addAccountPref.setKey("add_account");
    addAccountPref.setTitle(getString(R.string.prefs_add_account));
    mAccountsPrefCategory.addPreference(addAccountPref);

    addAccountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            AccountManager am = AccountManager.get(getApplicationContext());
            am.addAccount(MainApp.getAccountType(), null, null, null, Preferences.this,
                    null, null);
            return true;
        }
    });

}
 
Example 3
Source File: AutofillAndPaymentsPreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    PreferenceUtils.addPreferencesFromResource(this, R.xml.autofill_and_payments_preferences);
    getActivity().setTitle(R.string.prefs_autofill_and_payments);

    ChromeSwitchPreference autofillSwitch =
            (ChromeSwitchPreference) findPreference(PREF_AUTOFILL_SWITCH);
    autofillSwitch.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PersonalDataManager.setAutofillEnabled((boolean) newValue);
            return true;
        }
    });

    if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_PAYMENT_APPS)) {
        Preference pref = new Preference(getActivity());
        pref.setTitle(getActivity().getString(R.string.payment_apps_title));
        pref.setFragment(AndroidPaymentAppsFragment.class.getCanonicalName());
        pref.setShouldDisableView(true);
        pref.setKey(PREF_ANDROID_PAYMENT_APPS);
        getPreferenceScreen().addPreference(pref);
    }
}
 
Example 4
Source File: SettingActivity.java    From screenstandby with GNU General Public License v2.0 6 votes vote down vote up
private void displayAutoCallerAction() {
	screenAutoCaller.removeAll();
	phoneCallActions = CallAction.GetActions(settings);
	for(String phoneNo: phoneCallActions.keySet())
	{
		CallAction ca = phoneCallActions.get(phoneNo);
		Preference p = new Preference(context);
		if (ca.assignedAction < 3)
			p.setTitle(autoCallerActions[ca.assignedAction]);
		else
			p.setTitle("Launch " + ca.assignedAppLabel);
		p.setSummary("Dial number: " + ca.assignedPhoneNo);
		p.setKey(ca.assignedPhoneNo);
		p.setOnPreferenceClickListener(autoCallerModifyClick);
		screenAutoCaller.addPreference(p);
		p.setDependency(puseautodialer.getKey());
	}
}
 
Example 5
Source File: NumberGroups.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onResume() {
    super.onResume();

    PreferenceScreen ps = (PreferenceScreen) findPreference("container");
    ps.removeAll();
    Cursor c = getContentResolver().query(DataProvider.NumbersGroup.CONTENT_URI,
            DataProvider.NumbersGroup.PROJECTION, null, null, null);
    if (c.moveToFirst()) {
        do {
            Preference p = new Preference(this);
            p.setPersistent(false);
            p.setTitle(c.getString(DataProvider.NumbersGroup.INDEX_NAME));
            p.setKey("group_" + c.getInt(DataProvider.NumbersGroup.INDEX_ID));
            p.setOnPreferenceClickListener(this);
            ps.addPreference(p);
        } while (c.moveToNext());
    }
    c.close();
}
 
Example 6
Source File: HourGroups.java    From callmeter with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onResume() {
    super.onResume();

    PreferenceScreen ps = (PreferenceScreen) findPreference("container");
    ps.removeAll();
    Cursor c = getContentResolver().query(DataProvider.HoursGroup.CONTENT_URI,
            DataProvider.HoursGroup.PROJECTION, null, null, null);
    if (c.moveToFirst()) {
        do {
            Preference p = new Preference(this);
            p.setPersistent(false);
            p.setTitle(c.getString(DataProvider.HoursGroup.INDEX_NAME));
            p.setKey("group_" + c.getInt(DataProvider.HoursGroup.INDEX_ID));
            p.setOnPreferenceClickListener(this);
            ps.addPreference(p);
        } while (c.moveToNext());
    }
    c.close();
}
 
Example 7
Source File: SettingsFragment.java    From NewsPushMonitor with Apache License 2.0 5 votes vote down vote up
private void addMonitorApp(String pkg) {
    if (TextUtils.isEmpty(pkg)) {
        return;
    }

    PreferenceManager manager = getPreferenceManager();
    try {
        PreferenceScreen screen = (PreferenceScreen) RefUtil.callDeclaredMethod(manager,
                "inflateFromResource",
                new Class[]{Context.class, int.class, PreferenceScreen.class},
                getActivity(), R.xml.prefs_monitor_apps, null);
        screen.setKey(pkg);
        screen.setTitle(pkg);
        screen.setSummary(getMonitorAppSummary(pkg, null));

        PreferenceGroup appConfigPref = (PreferenceGroup) screen.findPreference("monitor_app_config_pref");
        appConfigPref.setTitle(pkg);

        Preference titleViewIdPref = appConfigPref.findPreference("title_view_id_pref");
        titleViewIdPref.setKey(GlobalConfig.getSharedPrefKeyForTitleId(pkg));
        titleViewIdPref.getExtras().putString(KEY_PREF_EXTRA, pkg);
        titleViewIdPref.setOnPreferenceChangeListener(mOnPreferenceChangeListener);

        Preference contentViewIdPref = appConfigPref.findPreference("content_view_id_pref");
        contentViewIdPref.setKey(GlobalConfig.getSharedPrefKeyForContentId(pkg));
        contentViewIdPref.getExtras().putString(KEY_PREF_EXTRA, pkg);
        contentViewIdPref.setOnPreferenceChangeListener(mOnPreferenceChangeListener);

        PreferenceCategory container = (PreferenceCategory)
                getPreferenceManager().findPreference("monitor_apps_pref");
        container.addPreference(screen);
    } catch (Exception e) {
        LogWriter.e(TAG, "Add monitor ppp to preference error!", e);
    }
}
 
Example 8
Source File: SettingsFragment.java    From phphub-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    if (Utils.hasLoggedIn(getActivity(), accountManager) && (findPreference(LOGOUT_KEY) == null)) {
        Preference logoutPreference = new Preference(getActivity());
        logoutPreference.setKey(LOGOUT_KEY);
        logoutPreference.setLayoutResource(R.layout.common_logout);
        logoutPreference.setOnPreferenceClickListener(this);
        getPreferenceScreen().addPreference(logoutPreference);
    }
}
 
Example 9
Source File: OpenFitActivity.java    From OpenFit with MIT License 5 votes vote down vote up
public Preference createAppPreference(final String packageName, final String appName) {
    Preference app = new Preference(getActivity());
    app.setTitle(appName);
    app.setKey(packageName);
    app.setIcon(appManager.loadIcon(packageName));
    return app;
}
 
Example 10
Source File: SettingsFragment.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create a preference for the SKU.
 *
 * @param skuPurchase    The SKU to be added.
 * @param isSubscription Flag indicating if it is subscription or in-app product
 * @return the preference.
 */
private Preference createSkuPreference(final SkuPurchase skuPurchase, final boolean isSubscription) {
	Preference skuPreference = new Preference(getActivity());
	final SkuDetails skuDetails = skuPurchase.getSkuDetails();
	if (skuPurchase.isPurchased()) {
		skuPreference.setTitle(getString(isSubscription
				? R.string.googlebilling_subscription_title_purchased : R.string.googlebilling_onetime_title_purchased));
	}
	else if (skuPurchase.isPending()) {
		skuPreference.setTitle(getString(isSubscription
				? R.string.googlebilling_subscription_title_pending : R.string.googlebilling_onetime_title_pending));
	}
	else {
		skuPreference.setTitle(getString(isSubscription
				? R.string.googlebilling_subscription_title : R.string.googlebilling_onetime_title, skuDetails.getPrice()));
	}

	skuPreference.setKey(SKU_KEY_PREFIX + skuDetails.getSku());
	String descriptionResourceString = getString(isSubscription ? R.string.googlebilling_subscription_text : R.string.googlebilling_onetime_text);
	skuPreference.setSummary(String.format(descriptionResourceString, skuDetails.getPrice()));

	skuPreference.setEnabled(!skuPurchase.isPurchased() && !skuPurchase.isPending());

	if (!skuPurchase.isPurchased() && !skuPurchase.isPending()) {
		skuPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			@Override
			public boolean onPreferenceClick(@NonNull final Preference preference) {
				GoogleBillingHelper.getInstance(getActivity()).launchPurchaseFlow(getActivity(), skuDetails, mOnPurchaseSuccessListener);
				return false;
			}
		});
	}
	return skuPreference;
}
 
Example 11
Source File: PickServerFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
private Preference createServerPreference(Server server) {
    Preference preference = new Preference(getActivity());
    preference.setKey(server.toKey());
    preference.setTitle(server.getNickname().isEmpty() ? server.getHostAndPort() : server.getNickname());
    preference.setPersistent(false);
    String authority = server.getUri().getAuthority();
    if(mRemembered.containsKey(authority) && authority.equals(Preferences.get(getActivity()).getAuthority())) {
        preference.setWidgetLayoutResource(R.layout.tick_image);
    }
    switch (server.getResponseCode()) {
        case HttpURLConnection.HTTP_UNAUTHORIZED:
            preference.setSummary(R.string.summary_unauthorized);
            preference.setIcon(R.drawable.ic_vlc_server_auth);
            break;
        case HttpURLConnection.HTTP_FORBIDDEN:
            preference.setSummary(R.string.summary_forbidden);
            preference.setIcon(R.drawable.ic_vlc_server_forbidden);
            break;
        default:
            if(server.hasUserInfo()) {
                preference.setIcon(R.drawable.ic_vlc_server_auth);
            } else {
                preference.setIcon(R.drawable.ic_vlc_server);
            }
    }
    return preference;
}
 
Example 12
Source File: HourGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reload numbers.
 */
@SuppressWarnings("deprecation")
private void reload() {
    Cursor c = getContentResolver().query(
            ContentUris.withAppendedId(DataProvider.HoursGroup.CONTENT_URI, gid),
            DataProvider.HoursGroup.PROJECTION, null, null, null);
    if (c.moveToFirst()) {
        CallMeter.setActivitySubtitle(this, c.getString(DataProvider.HoursGroup.INDEX_NAME));
    }
    c.close();
    PreferenceScreen ps = (PreferenceScreen) findPreference("container");
    ps.removeAll();
    c = getContentResolver().query(
            ContentUris.withAppendedId(DataProvider.Hours.GROUP_URI, gid),
            DataProvider.Hours.PROJECTION, null, null,
            DataProvider.Hours.DAY + ", " + DataProvider.Hours.HOUR);
    if (c.moveToFirst()) {
        do {
            Preference p = new Preference(this);
            p.setPersistent(false);
            final int day = c.getInt(DataProvider.Hours.INDEX_DAY);
            final int hour = c.getInt(DataProvider.Hours.INDEX_HOUR);
            p.setTitle(resDays[day] + ": " + resHours[hour]);
            p.setKey("item_" + c.getInt(DataProvider.Hours.INDEX_ID));
            p.setOnPreferenceClickListener(this);
            ps.addPreference(p);
        } while (c.moveToNext());
    }
    c.close();
}
 
Example 13
Source File: NumberGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Reload numbers.
 */
@SuppressWarnings("deprecation")
private void reload() {
    Cursor c = getContentResolver().query(
            ContentUris.withAppendedId(DataProvider.NumbersGroup.CONTENT_URI, gid),
            DataProvider.NumbersGroup.PROJECTION, null, null, null);
    if (c.moveToFirst()) {
        CallMeter.setActivitySubtitle(this, c.getString(DataProvider.NumbersGroup.INDEX_NAME));
    }
    c.close();
    PreferenceScreen ps = (PreferenceScreen) findPreference("container");
    ps.removeAll();
    c = getContentResolver().query(
            ContentUris.withAppendedId(DataProvider.Numbers.GROUP_URI, gid),
            DataProvider.Numbers.PROJECTION, null, null, DataProvider.Numbers.NUMBER);
    if (c.moveToFirst()) {
        do {
            Preference p = new Preference(this);
            p.setPersistent(false);
            String number = c.getString(DataProvider.Numbers.INDEX_NUMBER);
            p.setTitle(number);
            p.setKey("item_" + c.getInt(DataProvider.Numbers.INDEX_ID));
            p.setOnPreferenceClickListener(this);
            ps.addPreference(p);

            if (number != null && !number.contains("%")
                    && CallMeter.hasPermission(this, Manifest.permission.READ_CONTACTS)) {
                String name = CWRAPPER.getNameForNumber(getContentResolver(), number);
                if (!TextUtils.isEmpty(name)) {
                    p.setSummary(name);
                }
            }
        } while (c.moveToNext());
    }
    c.close();
}