Java Code Examples for android.support.v7.preference.PreferenceGroup#addPreference()

The following examples show how to use android.support.v7.preference.PreferenceGroup#addPreference() . 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: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        //<5.1// CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        /*>5.1*/ SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 2
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static CheckBoxPreference addPreference(PreferenceFragment fragment) {
//>5.1// static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        /*<5.1*/ CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        //>5.1// SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 3
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static CheckBoxPreference addPreference(PreferenceFragment fragment) {
//>5.1// static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        /*<5.1*/ CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        //>5.1// SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 4
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        //<5.1// CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        /*>5.1*/ SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 5
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        //<5.1// CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        /*>5.1*/ SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 6
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        //<5.1// CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        /*>5.1*/ SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 7
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static CheckBoxPreference addPreference(PreferenceFragment fragment) {
//>5.1// static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        /*<5.1*/ CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        //>5.1// SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 8
Source File: FakeSignatureGlobalUI.java    From haystack with GNU General Public License v3.0 6 votes vote down vote up
static SwitchPreference addPreference(PreferenceFragment fragment) {
    PreferenceGroup pg = (PreferenceGroup) fragment.findPreference(PREFERENCE_CATEGORY_KEY);
    if (pg != null) {
        //<5.1// CheckBoxPreference p = new CheckBoxPreference(pg.getContext());
        /*>5.1*/ SwitchPreference p = new SwitchPreference(pg.getContext());
        p.setKey(PREFERENCE_KEY);
        p.setTitle(PREFERENCE_TITLE);
        p.setSummary(PREFERENCE_SUMMARY);
        p.setPersistent(false);
        pg.addPreference(p);
        return p;
    } else {
        Log.e("FakeSignatureGlobalUI", "cannot find '" + PREFERENCE_CATEGORY_KEY +"' preference category");
        return null;
    }
}
 
Example 9
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void addEditAccountAction(
        final IGISApplication application,
        final Account account,
        PreferenceGroup actionCategory)
{
    Preference preferenceEdit = new Preference(mStyledContext);
    preferenceEdit.setTitle(R.string.edit_account);
    preferenceEdit.setSummary(R.string.edit_account_summary);

    String url = application.getAccountUrl(account);
    String login = application.getAccountLogin(account);

    Intent intent = new Intent(mStyledContext, NGWLoginActivity.class);
    intent.putExtra(NGWLoginActivity.FOR_NEW_ACCOUNT, false);
    intent.putExtra(NGWLoginActivity.ACCOUNT_URL_TEXT, url);
    intent.putExtra(NGWLoginActivity.ACCOUNT_LOGIN_TEXT, login);
    intent.putExtra(NGWLoginActivity.CHANGE_ACCOUNT_URL, false);
    intent.putExtra(NGWLoginActivity.CHANGE_ACCOUNT_LOGIN, true);
    preferenceEdit.setIntent(intent);

    actionCategory.addPreference(preferenceEdit);
}
 
Example 10
Source File: GsPreferenceFragmentCompat.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Append a pref to given {@code target}. If target is null, the current screen is taken
 * The pref icon is tint according to color
 *
 * @param pref   Preference to add
 * @param target The target to add the pref to, or null for current screen
 * @return true if successfully added
 */
protected boolean appendPreference(Preference pref, @Nullable PreferenceGroup target) {
    if (target == null) {
        if ((target = getPreferenceScreen()) == null) {
            return false;
        }
    }
    if (getIconTintColor() != null && pref.getIcon() != null && isAllowedToTint(pref)) {
        pref.setIcon(_cu.tintDrawable(pref.getIcon(), getIconTintColor()));
    }
    return target.addPreference(pref);
}
 
Example 11
Source File: GsPreferenceFragmentCompat.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Append a pref to given {@code target}. If target is null, the current screen is taken
 * The pref icon is tint according to color
 *
 * @param pref   Preference to add
 * @param target The target to add the pref to, or null for current screen
 * @return true if successfully added
 */
protected boolean appendPreference(Preference pref, @Nullable PreferenceGroup target) {
    if (target == null) {
        if ((target = getPreferenceScreen()) == null) {
            return false;
        }
    }
    if (getIconTintColor() != null && pref.getIcon() != null && isAllowedToTint(pref)) {
        pref.setIcon(_cu.tintDrawable(pref.getIcon(), getIconTintColor()));
    }
    return target.addPreference(pref);
}
 
Example 12
Source File: GsPreferenceFragmentCompat.java    From Stringlate with MIT License 5 votes vote down vote up
/**
 * Append a pref to given {@code target}. If target is null, the current screen is taken
 * The pref icon is tint according to color
 *
 * @param pref   Preference to add
 * @param target The target to add the pref to, or null for current screen
 * @return true if successfully added
 */
protected boolean appendPreference(Preference pref, @Nullable PreferenceGroup target) {
    if (target == null) {
        if ((target = getPreferenceScreen()) == null) {
            return false;
        }
    }
    if (getIconTintColor() != null && pref.getIcon() != null && isAllowedToTint(pref)) {
        pref.setIcon(_cu.tintDrawable(pref.getIcon(), getIconTintColor()));
    }
    return target.addPreference(pref);
}
 
Example 13
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void fillAccountPreferences(
            PreferenceGroup screen,
            final Account account)
    {
        final IGISApplication appContext = (IGISApplication) mStyledContext.getApplicationContext();

        // add sync settings group
        PreferenceCategory syncCategory = new PreferenceCategory(mStyledContext);
        syncCategory.setTitle(R.string.sync);
        screen.addPreference(syncCategory);

        // add auto sync property
        addAutoSyncProperty(appContext, account, syncCategory);

        // add time for periodic sync
        addPeriodicSyncTime(appContext, account, syncCategory);

        // add account layers
        addAccountLayers(screen, appContext, account);

        // add actions group
        PreferenceCategory actionCategory = new PreferenceCategory(mStyledContext);
        actionCategory.setTitle(R.string.actions);
        screen.addPreference(actionCategory);

        // add "Edit account" action
        addEditAccountAction(appContext, account, actionCategory);

        // add delete account action
        addDeleteAccountAction(appContext, account, actionCategory);

// TODO: for isMultiPane() change title of Settings fragment, not of Activity
//        if (mChangeTitle && !NGPreferenceActivity.isMultiPane(mActivity)) {
        if (mChangeTitle) {
            ActionBar ab = mActivity.getSupportActionBar();
            if (null != ab) {
                ab.setTitle(account.name);
            }
        }
    }
 
Example 14
Source File: NGWSettingsFragment.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void addAutoSyncProperty(
        final IGISApplication application,
        final Account account,
        PreferenceGroup syncCategory)
{
    final String accountNameHash = "_" + account.name.hashCode();
    SharedPreferences sharedPreferences =
            mStyledContext.getSharedPreferences(Constants.PREFERENCES, Context.MODE_MULTI_PROCESS);

    CheckBoxPreference enablePeriodicSync = new CheckBoxPreference(mStyledContext);
    enablePeriodicSync.setKey(KEY_SYNC);
    enablePeriodicSync.setPersistent(false);
    enablePeriodicSync.setTitle(R.string.auto_sync);

    boolean isAccountSyncEnabled = isAccountSyncEnabled(account, application.getAuthority());
    enablePeriodicSync.setChecked(isAccountSyncEnabled);
    enablePeriodicSync.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
    {
        @Override
        public boolean onPreferenceChange(
                Preference preference,
                Object newValue)
        {
            boolean isChecked = (boolean) newValue;
            setAccountSyncEnabled(account, application.getAuthority(), isChecked);
            return true;
        }
    });

    long timeStamp = sharedPreferences.getLong(
            com.nextgis.maplib.util.SettingsConstants.KEY_PREF_LAST_SYNC_TIMESTAMP
                    + accountNameHash, 0);
    if (isAccountSyncEnabled && timeStamp > 0) {
        enablePeriodicSync.setSummary(ControlHelper.getSyncTime(mStyledContext, timeStamp));
    } else {
        enablePeriodicSync.setSummary(R.string.auto_sync_summary);
    }
    syncCategory.addPreference(enablePeriodicSync);
}
 
Example 15
Source File: GsPreferenceFragmentCompat.java    From kimai-android with MIT License 5 votes vote down vote up
/**
 * Append a pref to given {@code target}. If target is null, the current screen is taken
 * The pref icon is tint according to color
 *
 * @param pref   Preference to add
 * @param target The target to add the pref to, or null for current screen
 * @return true if successfully added
 */
protected boolean appendPreference(Preference pref, @Nullable PreferenceGroup target) {
    if (target == null) {
        if ((target = getPreferenceScreen()) == null) {
            return false;
        }
    }
    if (getIconTintColor() != null && pref.getIcon() != null && isAllowedToTint(pref)) {
        pref.setIcon(_cu.tintDrawable(pref.getIcon(), getIconTintColor()));
    }
    return target.addPreference(pref);
}
 
Example 16
Source File: GcmFragment.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private static void addPreferencesSorted(List<Preference> prefs, PreferenceGroup container) {
    // If there's some items to display, sort the items and add them to the container.
    Collections.sort(prefs, new Comparator<Preference>() {
        @Override
        public int compare(Preference lhs, Preference rhs) {
            return lhs.getTitle().toString().toLowerCase().compareTo(rhs.getTitle().toString().toLowerCase());
        }
    });
    for (Preference entry : prefs) {
        container.addPreference(entry);
    }
}