Search in sources :

Example 1 with PreferenceManager

use of android.support.v7.preference.PreferenceManager in project YourAppIdea by Michenux.

the class SettingsFragment method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle bundle, String rootKey) {
    ((YourApplication) getActivity().getApplication()).inject(this);
    addPreferencesFromResource(R.xml.preferences);
    PreferenceManager preferenceManager = getPreferenceManager();
    preferenceManager.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
Also used : YourApplication(org.michenux.yourappidea.YourApplication) PreferenceManager(android.support.v7.preference.PreferenceManager)

Example 2 with PreferenceManager

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

the class Utils method getNonIndexable.

public static List<String> getNonIndexable(int xml, Context context) {
    if (Looper.myLooper() == null) {
        // Hack to make sure Preferences can initialize.  Prefs expect a looper, but
        // don't actually use it for the basic stuff here.
        Looper.prepare();
    }
    final List<String> ret = new ArrayList<>();
    PreferenceManager manager = new PreferenceManager(context);
    PreferenceScreen screen = manager.inflateFromResource(context, xml, null);
    checkPrefs(screen, ret);
    return ret;
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) PreferenceManager(android.support.v7.preference.PreferenceManager)

Example 3 with PreferenceManager

use of android.support.v7.preference.PreferenceManager in project Lightning-Browser by anthonycr.

the class DownloadHandler method onDownloadStartNoStream.

/**
     * Notify the host application a download should be done, even if there is a
     * streaming viewer available for thise type.
     *
     * @param context            The context in which the download is requested.
     * @param url                The full url to the content that should be downloaded
     * @param userAgent          User agent of the downloading application.
     * @param contentDisposition Content-disposition http header, if present.
     * @param mimetype           The mimetype of the content reported by the server
     */
/* package */
private static void onDownloadStartNoStream(@NonNull final Activity context, @NonNull PreferenceManager preferences, String url, String userAgent, String contentDisposition, @Nullable String mimetype) {
    final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
    // Check to see if we have an SDCard
    String status = Environment.getExternalStorageState();
    if (!status.equals(Environment.MEDIA_MOUNTED)) {
        int title;
        String msg;
        // Check to see if the SDCard is busy, same as the music app
        if (status.equals(Environment.MEDIA_SHARED)) {
            msg = context.getString(R.string.download_sdcard_busy_dlg_msg);
            title = R.string.download_sdcard_busy_dlg_title;
        } else {
            msg = context.getString(R.string.download_no_sdcard_dlg_msg);
            title = R.string.download_no_sdcard_dlg_title;
        }
        Dialog dialog = new AlertDialog.Builder(context).setTitle(title).setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg).setPositiveButton(R.string.action_ok, null).show();
        BrowserDialog.setDialogSize(context, dialog);
        return;
    }
    // java.net.URI is a lot stricter than KURL so we have to encode some
    // extra characters. Fix for b 2538060 and b 1634719
    WebAddress webAddress;
    try {
        webAddress = new WebAddress(url);
        webAddress.setPath(encodePath(webAddress.getPath()));
    } catch (Exception e) {
        // This only happens for very bad urls, we want to catch the
        // exception here
        Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e);
        Utils.showSnackbar(context, R.string.problem_download);
        return;
    }
    String addressString = webAddress.toString();
    Uri uri = Uri.parse(addressString);
    final DownloadManager.Request request;
    try {
        request = new DownloadManager.Request(uri);
    } catch (IllegalArgumentException e) {
        Utils.showSnackbar(context, R.string.cannot_download);
        return;
    }
    // set downloaded file destination to /sdcard/Download.
    // or, should it be set to one of several Environment.DIRECTORY* dirs
    // depending on mimetype?
    String location = preferences.getDownloadDirectory();
    Uri downloadFolder;
    location = addNecessarySlashes(location);
    downloadFolder = Uri.parse(location);
    File dir = new File(downloadFolder.getPath());
    if (!dir.isDirectory() && !dir.mkdirs()) {
        // Cannot make the directory
        Utils.showSnackbar(context, R.string.problem_location_download);
        return;
    }
    if (!isWriteAccessAvailable(downloadFolder)) {
        Utils.showSnackbar(context, R.string.problem_location_download);
        return;
    }
    String newMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(Utils.guessFileExtension(filename));
    Log.d(TAG, "New mimetype: " + newMimeType);
    request.setMimeType(newMimeType);
    request.setDestinationUri(Uri.parse(Constants.FILE + location + filename));
    // let this downloaded file be scanned by MediaScanner - so that it can
    // show up in Gallery app, for example.
    request.setVisibleInDownloadsUi(true);
    request.allowScanningByMediaScanner();
    request.setDescription(webAddress.getHost());
    // XXX: Have to use the old url since the cookies were stored using the
    // old percent-encoded url.
    String cookies = CookieManager.getInstance().getCookie(url);
    request.addRequestHeader(COOKIE_REQUEST_HEADER, cookies);
    request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    //noinspection VariableNotUsedInsideIf
    if (mimetype == null) {
        Log.d(TAG, "Mimetype is null");
        if (TextUtils.isEmpty(addressString)) {
            return;
        }
        // We must have long pressed on a link or image to download it. We
        // are not sure of the mimetype in this case, so do a head request
        new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start();
    } else {
        Log.d(TAG, "Valid mimetype, attempting to download");
        final DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
        try {
            manager.enqueue(request);
        } catch (IllegalArgumentException e) {
            // Probably got a bad URL or something
            Log.e(TAG, "Unable to enqueue request", e);
            Utils.showSnackbar(context, R.string.cannot_download);
        } catch (SecurityException e) {
            // TODO write a download utility that downloads files rather than rely on the system
            // because the system can only handle Environment.getExternal... as a path
            Utils.showSnackbar(context, R.string.problem_location_download);
        }
        Utils.showSnackbar(context, context.getString(R.string.download_pending) + ' ' + filename);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Uri(android.net.Uri) DownloadManager(android.app.DownloadManager) IOException(java.io.IOException) ActivityNotFoundException(android.content.ActivityNotFoundException) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) File(java.io.File)

Example 4 with PreferenceManager

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

use of android.support.v7.preference.PreferenceManager 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

PreferenceManager (android.support.v7.preference.PreferenceManager)5 PreferenceScreen (android.support.v7.preference.PreferenceScreen)4 Preference (android.support.v7.preference.Preference)3 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)1 Dialog (android.app.Dialog)1 DownloadManager (android.app.DownloadManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 ListPreference (android.support.v7.preference.ListPreference)1 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1 SpannableString (android.text.SpannableString)1 PaymentAppInfo (com.android.settings.nfc.PaymentBackend.PaymentAppInfo)1 OtrClient (com.waz.api.OtrClient)1 Self (com.waz.api.Self)1 Subscriber (com.waz.api.Subscriber)1 ThemePreference (io.github.hidroh.materialistic.preference.ThemePreference)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1