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);
}
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;
}
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);
}
}
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);
}
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);
}
});
}
Aggregations