Search in sources :

Example 51 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsInjector method getInjectedSettings.

/**
     * Gets a list of preferences that other apps have injected.
     *
     * @param profileId Identifier of the user/profile to obtain the injected settings for or
     *                  UserHandle.USER_CURRENT for all profiles associated with current user.
     */
public List<Preference> getInjectedSettings(final int profileId) {
    final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    final List<UserHandle> profiles = um.getUserProfiles();
    ArrayList<Preference> prefs = new ArrayList<Preference>();
    final int profileCount = profiles.size();
    for (int i = 0; i < profileCount; ++i) {
        final UserHandle userHandle = profiles.get(i);
        if (profileId == UserHandle.USER_CURRENT || profileId == userHandle.getIdentifier()) {
            Iterable<InjectedSetting> settings = getSettings(userHandle);
            for (InjectedSetting setting : settings) {
                Preference pref = addServiceSetting(prefs, setting);
                mSettings.add(new Setting(setting, pref));
            }
        }
    }
    reloadStatusMessages();
    return prefs;
}
Also used : DimmableIconPreference(com.android.settings.DimmableIconPreference) Preference(android.support.v7.preference.Preference) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList)

Example 52 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiP2pSettings method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    addPreferencesFromResource(R.xml.wifi_p2p_settings);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_DISCOVERY_CHANGED_ACTION);
    mIntentFilter.addAction(WifiP2pManager.WIFI_P2P_PERSISTENT_GROUPS_CHANGED_ACTION);
    final Activity activity = getActivity();
    mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    if (mWifiP2pManager != null) {
        mChannel = mWifiP2pManager.initialize(activity, getActivity().getMainLooper(), null);
        if (mChannel == null) {
            //Failure to set up connection
            Log.e(TAG, "Failed to set up connection with wifi p2p service");
            mWifiP2pManager = null;
        }
    } else {
        Log.e(TAG, "mWifiP2pManager is null !");
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DIALOG_PEER)) {
        WifiP2pDevice device = savedInstanceState.getParcelable(SAVE_DIALOG_PEER);
        mSelectedWifiPeer = new WifiP2pPeer(getActivity(), device);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DEVICE_NAME)) {
        mSavedDeviceName = savedInstanceState.getString(SAVE_DEVICE_NAME);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_SELECTED_GROUP)) {
        mSelectedGroupName = savedInstanceState.getString(SAVE_SELECTED_GROUP);
    }
    mRenameListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    String name = mDeviceNameText.getText().toString();
                    if (name != null) {
                        for (int i = 0; i < name.length(); i++) {
                            char cur = name.charAt(i);
                            if (!Character.isDigit(cur) && !Character.isLetter(cur) && cur != '-' && cur != '_' && cur != ' ') {
                                Toast.makeText(getActivity(), R.string.wifi_p2p_failed_rename_message, Toast.LENGTH_LONG).show();
                                return;
                            }
                        }
                    }
                    mWifiP2pManager.setDeviceName(mChannel, mDeviceNameText.getText().toString(), new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " device rename success");
                        }

                        public void onFailure(int reason) {
                            Toast.makeText(getActivity(), R.string.wifi_p2p_failed_rename_message, Toast.LENGTH_LONG).show();
                        }
                    });
                }
            }
        }
    };
    //disconnect dialog listener
    mDisconnectListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " remove group success");
                        }

                        public void onFailure(int reason) {
                            if (DBG)
                                Log.d(TAG, " remove group fail " + reason);
                        }
                    });
                }
            }
        }
    };
    //cancel connect dialog listener
    mCancelConnectListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.cancelConnect(mChannel, new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " cancel connect success");
                        }

                        public void onFailure(int reason) {
                            if (DBG)
                                Log.d(TAG, " cancel connect fail " + reason);
                        }
                    });
                }
            }
        }
    };
    //delete persistent group dialog listener
    mDeleteGroupListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    if (mSelectedGroup != null) {
                        if (DBG)
                            Log.d(TAG, " deleting group " + mSelectedGroup.getGroupName());
                        mWifiP2pManager.deletePersistentGroup(mChannel, mSelectedGroup.getNetworkId(), new WifiP2pManager.ActionListener() {

                            public void onSuccess() {
                                if (DBG)
                                    Log.d(TAG, " delete group success");
                            }

                            public void onFailure(int reason) {
                                if (DBG)
                                    Log.d(TAG, " delete group fail " + reason);
                            }
                        });
                        mSelectedGroup = null;
                    } else {
                        if (DBG)
                            Log.w(TAG, " No selected group to delete!");
                    }
                }
            } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                if (DBG) {
                    Log.d(TAG, " forgetting selected group " + mSelectedGroup.getGroupName());
                }
                mSelectedGroup = null;
            }
        }
    };
    setHasOptionsMenu(true);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    preferenceScreen.removeAll();
    preferenceScreen.setOrderingAsAdded(true);
    mThisDevicePref = new Preference(getPrefContext());
    mThisDevicePref.setPersistent(false);
    mThisDevicePref.setSelectable(false);
    preferenceScreen.addPreference(mThisDevicePref);
    mPeersGroup = new PreferenceCategory(getPrefContext());
    mPeersGroup.setTitle(R.string.wifi_p2p_peer_devices);
    preferenceScreen.addPreference(mPeersGroup);
    mPersistentGroup = new PreferenceCategory(getPrefContext());
    mPersistentGroup.setTitle(R.string.wifi_p2p_remembered_groups);
    preferenceScreen.addPreference(mPersistentGroup);
    super.onActivityCreated(savedInstanceState);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice) DialogInterface(android.content.DialogInterface) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 53 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CryptKeeperSettings method showFinalConfirmation.

private void showFinalConfirmation(int type, String password) {
    Preference preference = new Preference(getPreferenceManager().getContext());
    preference.setFragment(CryptKeeperConfirm.class.getName());
    preference.setTitle(R.string.crypt_keeper_confirm_title);
    addEncryptionInfoToPreference(preference, type, password);
    ((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference);
}
Also used : Preference(android.support.v7.preference.Preference)

Example 54 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsPreferenceFragment method cacheRemoveAllPrefs.

protected void cacheRemoveAllPrefs(PreferenceGroup group) {
    mPreferenceCache = new ArrayMap<String, Preference>();
    final int N = group.getPreferenceCount();
    for (int i = 0; i < N; i++) {
        Preference p = group.getPreference(i);
        if (TextUtils.isEmpty(p.getKey())) {
            continue;
        }
        mPreferenceCache.put(p.getKey(), p);
    }
}
Also used : LayoutPreference(com.android.settings.applications.LayoutPreference) Preference(android.support.v7.preference.Preference)

Example 55 with Preference

use of android.support.v7.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AccessibilitySettings method updateServicesPreferences.

private void updateServicesPreferences() {
    // Since services category is auto generated we have to do a pass
    // to generate it since services can come and go and then based on
    // the global accessibility state to decided whether it is enabled.
    // Generate.
    mServicesCategory.removeAll();
    AccessibilityManager accessibilityManager = AccessibilityManager.getInstance(getActivity());
    List<AccessibilityServiceInfo> installedServices = accessibilityManager.getInstalledAccessibilityServiceList();
    Set<ComponentName> enabledServices = AccessibilityUtils.getEnabledServicesFromSettings(getActivity());
    List<String> permittedServices = mDpm.getPermittedAccessibilityServices(UserHandle.myUserId());
    final boolean accessibilityEnabled = Settings.Secure.getInt(getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
    for (int i = 0, count = installedServices.size(); i < count; ++i) {
        AccessibilityServiceInfo info = installedServices.get(i);
        RestrictedPreference preference = new RestrictedPreference(getActivity());
        String title = info.getResolveInfo().loadLabel(getPackageManager()).toString();
        ServiceInfo serviceInfo = info.getResolveInfo().serviceInfo;
        ComponentName componentName = new ComponentName(serviceInfo.packageName, serviceInfo.name);
        preference.setKey(componentName.flattenToString());
        preference.setTitle(title);
        final boolean serviceEnabled = accessibilityEnabled && enabledServices.contains(componentName);
        String serviceEnabledString;
        if (serviceEnabled) {
            serviceEnabledString = getString(R.string.accessibility_feature_state_on);
        } else {
            serviceEnabledString = getString(R.string.accessibility_feature_state_off);
        }
        // Disable all accessibility services that are not permitted.
        String packageName = serviceInfo.packageName;
        boolean serviceAllowed = permittedServices == null || permittedServices.contains(packageName);
        if (!serviceAllowed && !serviceEnabled) {
            EnforcedAdmin admin = RestrictedLockUtils.checkIfAccessibilityServiceDisallowed(getActivity(), serviceInfo.packageName, UserHandle.myUserId());
            if (admin != null) {
                preference.setDisabledByAdmin(admin);
            } else {
                preference.setEnabled(false);
            }
        } else {
            preference.setEnabled(true);
        }
        preference.setSummary(serviceEnabledString);
        preference.setOrder(i);
        preference.setFragment(ToggleAccessibilityServicePreferenceFragment.class.getName());
        preference.setPersistent(true);
        Bundle extras = preference.getExtras();
        extras.putString(EXTRA_PREFERENCE_KEY, preference.getKey());
        extras.putBoolean(EXTRA_CHECKED, serviceEnabled);
        extras.putString(EXTRA_TITLE, title);
        String description = info.loadDescription(getPackageManager());
        if (TextUtils.isEmpty(description)) {
            description = getString(R.string.accessibility_service_default_description);
        }
        extras.putString(EXTRA_SUMMARY, description);
        String settingsClassName = info.getSettingsActivityName();
        if (!TextUtils.isEmpty(settingsClassName)) {
            extras.putString(EXTRA_SETTINGS_TITLE, getString(R.string.accessibility_menu_item_settings));
            extras.putString(EXTRA_SETTINGS_COMPONENT_NAME, new ComponentName(info.getResolveInfo().serviceInfo.packageName, settingsClassName).flattenToString());
        }
        extras.putParcelable(EXTRA_COMPONENT_NAME, componentName);
        mServicesCategory.addPreference(preference);
    }
    if (mServicesCategory.getPreferenceCount() == 0) {
        if (mNoServicesMessagePreference == null) {
            mNoServicesMessagePreference = new Preference(getPrefContext());
            mNoServicesMessagePreference.setPersistent(false);
            mNoServicesMessagePreference.setLayoutResource(R.layout.text_description_preference);
            mNoServicesMessagePreference.setSelectable(false);
            mNoServicesMessagePreference.setSummary(getString(R.string.accessibility_no_services_installed));
        }
        mServicesCategory.addPreference(mNoServicesMessagePreference);
    }
}
Also used : Bundle(android.os.Bundle) EnforcedAdmin(com.android.settingslib.RestrictedLockUtils.EnforcedAdmin) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) AccessibilityServiceInfo(android.accessibilityservice.AccessibilityServiceInfo) AccessibilityManager(android.view.accessibility.AccessibilityManager) RestrictedPreference(com.android.settingslib.RestrictedPreference) ListPreference(android.support.v7.preference.ListPreference) RestrictedPreference(com.android.settingslib.RestrictedPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) ComponentName(android.content.ComponentName)

Aggregations

Preference (android.support.v7.preference.Preference)122 PreferenceScreen (android.support.v7.preference.PreferenceScreen)44 SwitchPreference (android.support.v14.preference.SwitchPreference)33 Intent (android.content.Intent)27 ListPreference (android.support.v7.preference.ListPreference)27 Context (android.content.Context)17 PreferenceCategory (android.support.v7.preference.PreferenceCategory)17 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)15 ArrayList (java.util.ArrayList)14 PackageManager (android.content.pm.PackageManager)11 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)11 PreferenceGroup (android.support.v7.preference.PreferenceGroup)11 TwoStatePreference (android.support.v7.preference.TwoStatePreference)11 Activity (android.app.Activity)10 View (android.view.View)10 Bundle (android.os.Bundle)9 TextView (android.widget.TextView)8 AlertDialog (android.support.v7.app.AlertDialog)7 CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)7 DimmableIconPreference (com.android.settings.DimmableIconPreference)7