Search in sources :

Example 56 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen 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 57 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen in project AntennaPod by AntennaPod.

the class PreferenceController method buildAutodownloadSelectedNetworsPreference.

private void buildAutodownloadSelectedNetworsPreference() {
    final Activity activity = ui.getActivity();
    if (selectedNetworks != null) {
        clearAutodownloadSelectedNetworsPreference();
    }
    // get configured networks
    WifiManager wifiservice = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
    if (networks != null) {
        Collections.sort(networks, new Comparator<WifiConfiguration>() {

            @Override
            public int compare(WifiConfiguration x, WifiConfiguration y) {
                return x.SSID.compareTo(y.SSID);
            }
        });
        selectedNetworks = new CheckBoxPreference[networks.size()];
        List<String> prefValues = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
        PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN);
        Preference.OnPreferenceClickListener clickListener = preference -> {
            if (preference instanceof CheckBoxPreference) {
                String key = preference.getKey();
                List<String> prefValuesList = new ArrayList<>(Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks()));
                boolean newValue = ((CheckBoxPreference) preference).isChecked();
                Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
                int index = prefValuesList.indexOf(key);
                if (index >= 0 && !newValue) {
                    prefValuesList.remove(index);
                } else if (index < 0 && newValue) {
                    prefValuesList.add(key);
                }
                UserPreferences.setAutodownloadSelectedNetworks(prefValuesList.toArray(new String[prefValuesList.size()]));
                return true;
            } else {
                return false;
            }
        };
        // value
        for (int i = 0; i < networks.size(); i++) {
            WifiConfiguration config = networks.get(i);
            CheckBoxPreference pref = new CheckBoxPreference(activity);
            String key = Integer.toString(config.networkId);
            pref.setTitle(config.SSID);
            pref.setKey(key);
            pref.setOnPreferenceClickListener(clickListener);
            pref.setPersistent(false);
            pref.setChecked(prefValues.contains(key));
            selectedNetworks[i] = pref;
            prefScreen.addPreference(pref);
        }
    } else {
        Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
    }
}
Also used : Arrays(java.util.Arrays) DateUtils(android.text.format.DateUtils) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) FlattrUtils(de.danoeh.antennapod.core.util.flattr.FlattrUtils) PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Manifest(android.Manifest) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) Schedulers(rx.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) GpodnetSyncService(de.danoeh.antennapod.core.service.GpodnetSyncService) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) GpodnetSetHostnameDialog(de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog) GregorianCalendar(java.util.GregorianCalendar) ContextCompat(android.support.v4.content.ContextCompat) ActivityCompat(android.support.v4.app.ActivityCompat) DateFormat(android.text.format.DateFormat) ListPreference(android.preference.ListPreference) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) AutoFlattrPreferenceDialog(de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog) ListView(android.widget.ListView) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Subscription(rx.Subscription) TextWatcher(android.text.TextWatcher) Converter(de.danoeh.antennapod.core.util.Converter) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) ExportWriter(de.danoeh.antennapod.core.export.ExportWriter) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Observable(rx.Observable) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) SuppressLint(android.annotation.SuppressLint) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter) Calendar(java.util.Calendar) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Toast(android.widget.Toast) CrashReportWriter(de.danoeh.antennapod.CrashReportWriter) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Build(android.os.Build) ProxyDialog(de.danoeh.antennapod.dialog.ProxyDialog) R(de.danoeh.antennapod.R) PreferenceActivityGingerbread(de.danoeh.antennapod.activity.PreferenceActivityGingerbread) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) ProgressDialog(android.app.ProgressDialog) File(java.io.File) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) TimeUnit(java.util.concurrent.TimeUnit) WifiManager(android.net.wifi.WifiManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) GpodnetPreferences(de.danoeh.antennapod.core.preferences.GpodnetPreferences) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) MainActivity(de.danoeh.antennapod.activity.MainActivity) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) Activity(android.app.Activity) SuppressLint(android.annotation.SuppressLint) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) List(java.util.List) ArrayList(java.util.ArrayList)

Example 58 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen in project wire-android by wireapp.

the class DeviceDetailPreferences method updateOtrClientDetails.

private void updateOtrClientDetails() {
    // Name
    Preference preference = findPreference(getString(R.string.pref_device_details_device_key));
    preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), otrClient));
    preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), otrClient, true));
    // Fingerprint
    final FingerprintPreference fingerPrintPreference = (FingerprintPreference) findPreference(getString(R.string.pref_device_details_fingerprint_key));
    if (fingerprint == null) {
        fingerprint = otrClient.getFingerprint();
        fingerprintSubscription = fingerprint.subscribe(new Subscriber<Fingerprint>() {

            @Override
            public void next(Fingerprint fingerprint) {
                fingerPrintPreference.setFingerprint(fingerprint);
            }
        });
    }
    //Trust
    final SwitchPreference verifySwitchPreference = (SwitchPreference) findPreference(getString(R.string.pref_device_details_trust_key));
    if (currentDevice) {
        PreferenceCategory group = (PreferenceCategory) findPreference(getString(R.string.pref_device_details_fingerprint_category_key));
        group.removePreference(verifySwitchPreference);
    } else {
        verifySwitchPreference.setChecked(otrClient.getVerified() == Verification.VERIFIED);
        // Note: Using OnPreferenceClickListener as it was some issues with getting
        //       OnPreferenceChangeListener to work.
        verifySwitchPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                boolean newVerifiredValue = otrClient.getVerified() != Verification.VERIFIED;
                otrClient.setVerified(newVerifiredValue);
                verifySwitchPreference.setChecked(newVerifiredValue);
                trackVerified(newVerifiredValue);
                return true;
            }
        });
    }
    // Remove
    if (currentDevice) {
        Preference actionsPreference = findPreference(getString(R.string.pref_device_details_actions_category_key));
        PreferenceScreen screen = (PreferenceScreen) findPreference(getString(R.string.pref_device_details_screen_key));
        screen.removePreference(actionsPreference);
    } else {
        Preference resetSessionPreference = findPreference(getString(R.string.pref_device_details_reset_session_key));
        resetSessionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                resetSession();
                return true;
            }
        });
        preference = findPreference(getString(R.string.pref_device_details_remove_key));
        preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new NetworkAction() {

                    @Override
                    public void execute(NetworkMode networkMode) {
                        if (getControllerFactory().getPasswordController().hasPassword()) {
                            deleteCurrentDevice();
                        } else {
                            showRemoveDeviceDialog();
                        }
                    }

                    @Override
                    public void onNoNetwork() {
                        ViewUtils.showAlertDialog(DeviceDetailPreferences.this.getActivity(), R.string.otr__remove_device__no_internet__title, R.string.otr__remove_device__no_internet__message, R.string.otr__remove_device__no_internet__button, null, true);
                    }
                });
                return true;
            }
        });
    }
}
Also used : Fingerprint(com.waz.api.Fingerprint) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(net.xpece.android.support.preference.SwitchPreference) Preference(android.support.v7.preference.Preference) Subscriber(com.waz.api.Subscriber) SwitchPreference(net.xpece.android.support.preference.SwitchPreference) PreferenceCategory(net.xpece.android.support.preference.PreferenceCategory) NetworkMode(com.waz.api.NetworkMode) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Example 59 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen in project wire-android by wireapp.

the class DevicesPreferences method addClientToGroup.

private void addClientToGroup(final OtrClient otrClient, PreferenceGroup preferenceGroup) {
    DevicePreference preference = new DevicePreference(getContext());
    preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), otrClient));
    preference.setKey(getString(R.string.pref_device_details_screen_key));
    preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), otrClient, false));
    preference.setVerified(otrClient.getVerified() == Verification.VERIFIED);
    final PreferenceScreen preferenceScreen = new PreferenceScreen(getContext(), null);
    preferenceScreen.getExtras().putParcelable(DeviceDetailPreferences.PREFS_OTR_CLIENT, otrClient);
    preferenceScreen.setTitle(preference.getTitle());
    preferenceScreen.setKey(preference.getKey());
    preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            PreferenceManager preferenceManager = getPreferenceManager();
            if (preferenceManager != null) {
                PreferenceManager.OnNavigateToScreenListener listener = preferenceManager.getOnNavigateToScreenListener();
                if (listener != null) {
                    listener.onNavigateToScreen(preferenceScreen);
                    return true;
                }
            }
            return false;
        }
    });
    preferenceGroup.addPreference(preference);
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) PreferenceManager(android.support.v7.preference.PreferenceManager)

Example 60 with PreferenceScreen

use of android.support.v7.preference.PreferenceScreen in project wire-android by wireapp.

the class DevicesPreferences method setupOtrDevices.

private void setupOtrDevices() {
    if (getStoreFactory() == null || getStoreFactory().isTornDown()) {
        return;
    }
    Self self = getStoreFactory().getZMessagingApiStore().getApi().getSelf();
    if (otrClient == null) {
        otrClient = self.getOtrClient();
    }
    if (otherClients == null) {
        otherClients = self.getOtherOtrClients();
        otherClients.addUpdateListener(otrClientsUpdateListener);
    }
    updateOtrDevices();
    final PreferenceGroup currentOtrClientPreferenceGroup = (PreferenceGroup) findPreference(getString(R.string.pref_devices_current_device_category_key));
    otrClientSubscription = otrClient.subscribe(new Subscriber<OtrClient>() {

        @Override
        public void next(OtrClient value) {
            if (getActivity() == null) {
                return;
            }
            currentOtrClientPreferenceGroup.setTitle(getString(R.string.pref_devices_current_device_category_title));
            currentOtrClientPreferenceGroup.removeAll();
            net.xpece.android.support.preference.Preference preference = new net.xpece.android.support.preference.Preference(getContext());
            preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), value));
            preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), value, false));
            preference.setKey(getString(R.string.pref_device_details_screen_key));
            final PreferenceScreen preferenceScreen = new PreferenceScreen(getContext(), null);
            preferenceScreen.getExtras().putParcelable(DeviceDetailPreferences.PREFS_OTR_CLIENT, value);
            preferenceScreen.getExtras().putBoolean(DeviceDetailPreferences.PREFS_CURRENT_DEVICE, true);
            preferenceScreen.setTitle(preference.getTitle());
            preferenceScreen.setKey(preference.getKey());
            preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    PreferenceManager preferenceManager = getPreferenceManager();
                    if (preferenceManager != null) {
                        PreferenceManager.OnNavigateToScreenListener listener = preferenceManager.getOnNavigateToScreenListener();
                        if (listener != null) {
                            listener.onNavigateToScreen(preferenceScreen);
                            return true;
                        }
                    }
                    return false;
                }
            });
            currentOtrClientPreferenceGroup.addPreference(preference);
        }
    });
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Self(com.waz.api.Self) PreferenceManager(android.support.v7.preference.PreferenceManager) Subscriber(com.waz.api.Subscriber) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) OtrClient(com.waz.api.OtrClient)

Aggregations

PreferenceScreen (android.support.v7.preference.PreferenceScreen)107 Preference (android.support.v7.preference.Preference)38 ContentResolver (android.content.ContentResolver)33 SwitchPreference (android.support.v14.preference.SwitchPreference)21 Context (android.content.Context)18 Resources (android.content.res.Resources)15 PreferenceCategory (android.support.v7.preference.PreferenceCategory)12 Intent (android.content.Intent)11 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 PreferenceGroup (android.support.v7.preference.PreferenceGroup)7 ArrayList (java.util.ArrayList)7 PackageManager (android.content.pm.PackageManager)6 ListPreference (android.support.v7.preference.ListPreference)6 OnPreferenceClickListener (android.support.v7.preference.Preference.OnPreferenceClickListener)6 Activity (android.app.Activity)5 PreferenceManager (android.support.v7.preference.PreferenceManager)5 InputMethodInfo (android.view.inputmethod.InputMethodInfo)4 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)4 ComponentName (android.content.ComponentName)3 IntentFilter (android.content.IntentFilter)3