Search in sources :

Example 56 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class SecuritySettingsTest method testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification.

@Test
public void testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification() {
    final Preference preference = mock(Preference.class);
    final PreferenceGroup group = mock(PreferenceGroup.class);
    when(group.findPreference(SecuritySettings.KEY_LOCKSCREEN_PREFERENCES)).thenReturn(preference);
    final LockScreenNotificationPreferenceController controller = mock(LockScreenNotificationPreferenceController.class);
    final SecuritySettings securitySettings = new SecuritySettings();
    ReflectionHelpers.setField(securitySettings, "mLockScreenNotificationPreferenceController", controller);
    when(controller.getSummaryResource()).thenReturn(1234);
    securitySettings.setLockscreenPreferencesSummary(group);
    verify(preference).setSummary(1234);
}
Also used : Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) LockScreenNotificationPreferenceController(com.android.settings.notification.LockScreenNotificationPreferenceController) Test(org.junit.Test)

Example 57 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by DirtyUnicorns.

the class ChannelNotificationSettings method updateDependents.

void updateDependents(boolean banned) {
    PreferenceGroup parent;
    if (mShowLegacyChannelConfig) {
        parent = getPreferenceScreen();
        setVisible(mImportanceToggle, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    } else {
        setVisible(mAdvanced, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
        setVisible(mImportance, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
        setVisible(mAdvanced, mLights, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight());
        setVisible(mVibrate, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
        setVisible(mRingtone, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT));
        parent = mAdvanced;
    }
    setVisible(parent, mBadge, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    setVisible(parent, mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && mDndVisualEffectsSuppressed));
    setVisible(parent, mVisibilityOverride, isLockScreenSecure() && checkCanBeVisible(NotificationManager.IMPORTANCE_LOW));
    setVisible(mBlockedDesc, mChannel.getImportance() == IMPORTANCE_NONE);
    if (mAppLink != null) {
        setVisible(mAppLink, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    }
    if (mFooter != null) {
        setVisible(mFooter, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN));
    }
}
Also used : PreferenceGroup(android.support.v7.preference.PreferenceGroup)

Example 58 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.

the class ManageDomainUrls method onRebuildComplete.

@Override
public void onRebuildComplete(ArrayList<AppEntry> apps) {
    if (getContext() == null) {
        return;
    }
    final boolean disableWebActions = Global.getInt(getContext().getContentResolver(), Global.ENABLE_EPHEMERAL_FEATURE, 1) == 0;
    if (disableWebActions) {
        mDomainAppList = getPreferenceScreen();
    } else {
        final PreferenceGroup preferenceScreen = getPreferenceScreen();
        if (preferenceScreen.getPreferenceCount() == 0) {
            // add preferences
            final PreferenceCategory webActionCategory = new PreferenceCategory(getPrefContext());
            webActionCategory.setTitle(R.string.web_action_section_title);
            preferenceScreen.addPreference(webActionCategory);
            // toggle to enable / disable Web Actions [aka Instant Apps]
            mWebAction = new SwitchPreference(getPrefContext());
            mWebAction.setTitle(R.string.web_action_enable_title);
            mWebAction.setSummary(R.string.web_action_enable_summary);
            mWebAction.setChecked(Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTANT_APPS_ENABLED, 1) != 0);
            mWebAction.setOnPreferenceChangeListener(this);
            webActionCategory.addPreference(mWebAction);
            // Determine whether we should show the instant apps account chooser setting
            ComponentName instantAppSettingsComponent = getActivity().getPackageManager().getInstantAppResolverSettingsComponent();
            Intent instantAppSettingsIntent = null;
            if (instantAppSettingsComponent != null) {
                instantAppSettingsIntent = new Intent().setComponent(instantAppSettingsComponent);
            }
            if (instantAppSettingsIntent != null) {
                final Intent launchIntent = instantAppSettingsIntent;
                // TODO: Make this button actually launch the account chooser.
                mInstantAppAccountPreference = new Preference(getPrefContext());
                mInstantAppAccountPreference.setTitle(R.string.instant_apps_settings);
                mInstantAppAccountPreference.setOnPreferenceClickListener(pref -> {
                    startActivity(launchIntent);
                    return true;
                });
                webActionCategory.addPreference(mInstantAppAccountPreference);
            }
            // list to manage link handling per app
            mDomainAppList = new PreferenceCategory(getPrefContext());
            mDomainAppList.setTitle(R.string.domain_url_section_title);
            preferenceScreen.addPreference(mDomainAppList);
        }
    }
    rebuildAppList(mDomainAppList, apps);
}
Also used : PreferenceCategory(android.support.v7.preference.PreferenceCategory) SwitchPreference(android.support.v14.preference.SwitchPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 59 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.

the class SecondaryUserController method displayPreference.

@Override
public void displayPreference(PreferenceScreen screen) {
    if (mStoragePreference == null) {
        mStoragePreference = new StorageItemPreference(screen.getContext());
        PreferenceGroup group = (PreferenceGroup) screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
        mStoragePreference.setTitle(mUser.name);
        mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
        if (mSize != SIZE_NOT_SET) {
            mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
        }
        group.setVisible(true);
        group.addPreference(mStoragePreference);
        maybeSetIcon();
    }
}
Also used : PreferenceGroup(android.support.v7.preference.PreferenceGroup) StorageItemPreference(com.android.settings.deviceinfo.StorageItemPreference)

Example 60 with PreferenceGroup

use of android.support.v7.preference.PreferenceGroup in project platform_packages_apps_Settings by BlissRoms.

the class AccountTypePreferenceLoader method updatePreferenceIntents.

/**
 * Recursively filters through the preference list provided by GoogleLoginService.
 *
 * This method removes all the invalid intent from the list, adds account name as extra into the
 * intent, and hack the location settings to start it as a fragment.
 */
public void updatePreferenceIntents(PreferenceGroup prefs, final String acccountType, Account account) {
    final PackageManager pm = mFragment.getActivity().getPackageManager();
    for (int i = 0; i < prefs.getPreferenceCount(); ) {
        Preference pref = prefs.getPreference(i);
        if (pref instanceof PreferenceGroup) {
            updatePreferenceIntents((PreferenceGroup) pref, acccountType, account);
        }
        Intent intent = pref.getIntent();
        if (intent != null) {
            // preference click event here directly.
            if (intent.getAction().equals(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)) {
                // The OnPreferenceClickListener overrides the click event completely. No intent
                // will get fired.
                pref.setOnPreferenceClickListener(new FragmentStarter(LocationSettings.class.getName(), R.string.location_settings_title));
            } else {
                ResolveInfo ri = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY, mUserHandle.getIdentifier());
                if (ri == null) {
                    prefs.removePreference(pref);
                    continue;
                }
                intent.putExtra(ACCOUNT_KEY, account);
                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
                pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                    @Override
                    public boolean onPreferenceClick(Preference preference) {
                        Intent prefIntent = preference.getIntent();
                        /*
                                 * Check the intent to see if it resolves to a exported=false
                                 * activity that doesn't share a uid with the authenticator.
                                 *
                                 * Otherwise the intent is considered unsafe in that it will be
                                 * exploiting the fact that settings has system privileges.
                                 */
                        if (isSafeIntent(pm, prefIntent, acccountType)) {
                            mFragment.getActivity().startActivityAsUser(prefIntent, mUserHandle);
                        } else {
                            Log.e(TAG, "Refusing to launch authenticator intent because" + "it exploits Settings permissions: " + prefIntent);
                        }
                        return true;
                    }
                });
            }
        }
        i++;
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) Intent(android.content.Intent)

Aggregations

PreferenceGroup (android.support.v7.preference.PreferenceGroup)104 Preference (android.support.v7.preference.Preference)70 Context (android.content.Context)28 PreferenceScreen (android.support.v7.preference.PreferenceScreen)28 Test (org.junit.Test)26 PreferenceManager (android.support.v7.preference.PreferenceManager)22 SwitchPreference (android.support.v14.preference.SwitchPreference)19 ArrayList (java.util.ArrayList)19 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 UserInfo (android.content.pm.UserInfo)16 Intent (android.content.Intent)14 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)14 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)14 Account (android.accounts.Account)12 AuthenticatorDescription (android.accounts.AuthenticatorDescription)12 UserHandle (android.os.UserHandle)12 TelephonyManager (android.telephony.TelephonyManager)12 Activity (android.app.Activity)11 RestrictedPreference (com.android.settingslib.RestrictedPreference)11 RemoteException (android.os.RemoteException)8