@Override public void onReceive(Context context, Intent intent) { int reminderId = intent.getIntExtra("NOTIFICATION_ID", 0); if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("checkBoxNagging", false)) { Intent alarmIntent = new Intent(context, NagReceiver.class); AlarmUtil.cancelAlarm(context, alarmIntent, reminderId); } // Close notification tray Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); context.sendBroadcast(closeIntent); Intent snoozeIntent = new Intent(context, SnoozeDialogActivity.class); snoozeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); snoozeIntent.putExtra("NOTIFICATION_ID", reminderId); context.startActivity(snoozeIntent); }
/** * Returns true if the user prefers to see notifications from Sunshine, false otherwise. This * preference can be changed by the user within the SettingsFragment. * * @param context Used to access SharedPreferences * @return true if the user prefers to see notifications, false otherwise */ public static boolean areNotificationsEnabled(Context context) { /* Key for accessing the preference for showing notifications */ String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key); /* * In Sunshine, the user has the ability to say whether she would like notifications * enabled or not. If no preference has been chosen, we want to be able to determine * whether or not to show them. To do this, we reference a bool stored in bools.xml. */ boolean shouldDisplayNotificationsByDefault = context .getResources() .getBoolean(R.bool.show_notifications_by_default); /* As usual, we use the default SharedPreferences to access the user's preferences */ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); /* If a value is stored with the key, we extract it here. If not, use a default. */ boolean shouldDisplayNotifications = sp .getBoolean(displayNotificationsKey, shouldDisplayNotificationsByDefault); return shouldDisplayNotifications; }
private String GetText(float res) { if (!PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("DECIMAL_USE", true)) { DecimalFormat decimalFormat = new DecimalFormat("###############"); return decimalFormat.format(res); } else { switch (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("ROUNDIND_INFO", "0"))) { case 0: return String.valueOf(res); case 1: DecimalFormat single = new DecimalFormat("########.#"); return single.format(res); case 2: DecimalFormat Double = new DecimalFormat("########.##"); return Double.format(res); case 3: DecimalFormat triple = new DecimalFormat("########.###"); return triple.format(res); default: return String.valueOf(res); } } }
/** * Returns the location coordinates associated with the location. Note that there is a * possibility that these coordinates may not be set, which results in (0,0) being returned. * Interestingly, (0,0) is in the middle of the ocean off the west coast of Africa. * * @param context used to access SharedPreferences * @return an array containing the two coordinate values for the user's preferred location */ public static double[] getLocationCoordinates(Context context) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); double[] preferredCoordinates = new double[2]; /* * This is a hack we have to resort to since you can't store doubles in SharedPreferences. * * Double.doubleToLongBits returns an integer corresponding to the bits of the given * IEEE 754 double precision value. * * Double.longBitsToDouble does the opposite, converting a long (that represents a double) * into the double itself. */ preferredCoordinates[0] = Double .longBitsToDouble(sp.getLong(PREF_COORD_LAT, Double.doubleToRawLongBits(0.0))); preferredCoordinates[1] = Double .longBitsToDouble(sp.getLong(PREF_COORD_LONG, Double.doubleToRawLongBits(0.0))); return preferredCoordinates; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); frameLayout = (FrameLayout) getActivity().findViewById(R.id.content_frame); try { mahEncryptor = MAHEncryptor.newInstance(sharedPref.getString("saved_key", "")); } catch (Exception e) { e.printStackTrace(); Snackbar.make(frameLayout, getString(R.string.toast_error), Snackbar.LENGTH_LONG).show(); } addPreferencesFromResource(R.xml.user_settings_data); addBackup_dbListener(); addWhiteListListener(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Sets up user interface elements. setContentView(R.layout.main); mCustomConfig = (CheckBox) findViewById(R.id.custom_app_limits); final boolean customChecked = PreferenceManager.getDefaultSharedPreferences(this).getBoolean( CUSTOM_CONFIG_KEY, false); if (customChecked) mCustomConfig.setChecked(true); mMultiEntryValue = (TextView) findViewById(R.id.multi_entry_id); mChoiceEntryValue = (TextView) findViewById(R.id.choice_entry_id); mBooleanEntryValue = (TextView) findViewById(R.id.boolean_entry_id); }
protected void readNetworkType(String fileName) { NetworkType defaultNetworkType; File directory = RobotConfigFileManager.CONFIG_FILES_DIR; File networkTypeFile = new File(directory, fileName); if (!networkTypeFile.exists()) { if (Build.MODEL.equals(Device.MODEL_410C)) { defaultNetworkType = NetworkType.SOFTAP; } else { defaultNetworkType = NetworkType.WIFIDIRECT; } writeNetworkTypeFile(NETWORK_TYPE_FILENAME, defaultNetworkType.toString()); } String fileContents = readFile(networkTypeFile); networkType = NetworkConnectionFactory.getTypeFromString(fileContents); programmingModeController.setCurrentNetworkType(networkType); // update the preferences SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = preferences.edit(); editor.putString(NetworkConnectionFactory.NETWORK_CONNECTION_TYPE, networkType.toString()); editor.commit(); }
public String getUserName() { String ret = ""; SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); String userstring = sharedPreferences.getString("trakt_user", ""); try { JSONObject trakt_user = new JSONObject(userstring); ret = trakt_user.getJSONObject("user").getString("username"); } catch (JSONException e) { e.printStackTrace(); } return ret; }
/** * Returns the last time that a notification was shown (in UNIX time) * * @param context Used to access SharedPreferences * @return UNIX time of when the last notification was shown */ public static long getLastNotificationTimeInMillis(Context context) { /* Key for accessing the time at which Sunshine last displayed a notification */ String lastNotificationKey = context.getString(R.string.pref_last_notification); /* As usual, we use the default SharedPreferences to access the user's preferences */ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); /* * Here, we retrieve the time in milliseconds when the last notification was shown. If * SharedPreferences doesn't have a value for lastNotificationKey, we return 0. The reason * we return 0 is because we compare the value returned from this method to the current * system time. If the difference between the last notification time and the current time * is greater than one day, we will show a notification again. When we compare the two * values, we subtract the last notification time from the current system time. If the * time of the last notification was 0, the difference will always be greater than the * number of milliseconds in a day and we will show another notification. */ long lastNotificationTime = sp.getLong(lastNotificationKey, 0); return lastNotificationTime; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.splash); // Here, this is the current activity PreferenceManager.setDefaultValues(this, R.xml.pref_settings, false); if (!permissionGranted()) { requestPermissions(); } else { if (systemInstalled()) { startMainActivity(); } else { installSystem(); } } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_lists, container, false); setHasOptionsMenu(true); sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); editText = (EditText) getActivity().findViewById(R.id.editText); listBar = (TextView) getActivity().findViewById(R.id.listBar); listView = (ListView)rootView.findViewById(R.id.list); viewPager = (class_CustomViewPager) getActivity().findViewById(R.id.viewpager); //calling Notes_DbAdapter db = new DbAdapter_Reports(getActivity()); db.open(); return rootView; }
/** 设置Key对应的String值 */ public static boolean setStringValue(Context context,String key, String value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = prefs.edit(); editor.putString(key, value); return editor.commit(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PreferenceManager.setDefaultValues(this, R.xml.main_preferences, false); getFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); }
/** * Saves location co-ordinates as string * @param context ¯\_(ツ)_/¯ * @param longitude Longitude to be saved * @param latitude Latitude to be saved */ public static void putLocation(Context context, double longitude, double latitude) { PreferenceManager.getDefaultSharedPreferences(context) .edit() .putString(Constants.LAST_LOC_LONGITUDE, "" + longitude) .putString(Constants.LAST_LOC_LATITUDE, "" + latitude) .apply(); }
/** * Returns true if the latitude and longitude values are available. The latitude and * longitude will not be available until the lesson where the PlacePicker API is taught. * * @param context used to get the SharedPreferences * @return true if lat/long are saved in SharedPreferences */ public static boolean isLocationLatLonAvailable(Context context) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); boolean spContainLatitude = sp.contains(PREF_COORD_LAT); boolean spContainLongitude = sp.contains(PREF_COORD_LONG); boolean spContainBothLatitudeAndLongitude = false; if (spContainLatitude && spContainLongitude) { spContainBothLatitudeAndLongitude = true; } return spContainBothLatitudeAndLongitude; }
public int getLength() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean v = preferences.getBoolean("EXTRA_SMALL_FONT", false); if (v) return 8; else return 6; }
private void bindPreferenceSummaryToValue(Preference preference) { preference.setOnPreferenceChangeListener(this); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(preference.getContext()); String preferenceString = preferences.getString(preference.getKey(), ""); onPreferenceChange(preference, preferenceString); }
public static boolean isTV(Context ct){ SharedPreferences mPreferences = PreferenceManager.getDefaultSharedPreferences(ct); String mode = mPreferences.getString("uimode", "0"); if (mode.equals("1")) return false; if (mode.equals("2")) return true; return ArchosFeatures.isTV(ct); }
@Override public void onReceive(Context context, Intent intent) { context = MakiApplication.getContextOfApplication(); Intent startIntent = new Intent(context, MakiNotifications.class); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (preferences.getBoolean("notifications_activated", false) || preferences.getBoolean("messages_activated", false)) { context.startService(startIntent); Log.d("NotificationReceiver", "Notifications started"); }else { context.stopService(startIntent); Log.d("PollReceiver", "Notifications canceled"); } }
/** * Resets the location coordinates stores in SharedPreferences. * * @param context Context used to get the SharedPreferences */ public static void resetLocationCoordinates(Context context) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sp.edit(); editor.remove(PREF_COORD_LAT); editor.remove(PREF_COORD_LONG); editor.apply(); }
public static void editText_searchWeb (final EditText editText, final Activity activity) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity); List<String> listItems = new ArrayList<>(); if (sharedPref.getBoolean("Google", true)) { listItems.add("Google"); }if (sharedPref.getBoolean("Kiddle", true)) { listItems.add("Kiddle"); }if (sharedPref.getBoolean("Kidrex", true)) { listItems.add("Kidrex"); }if (sharedPref.getBoolean("Youtube", true)) { listItems.add("Youtube"); } final CharSequence[] options = listItems.toArray(new CharSequence[listItems.size()]); new AlertDialog.Builder(activity) .setTitle(R.string.action_searchChooseTitle) .setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals("Google")) { editText.setText(".G "); } if (options[item].equals("Kidrex")) { editText.setText(".R "); } if (options[item].equals("Kiddle")) { editText.setText(".K "); } if (options[item].equals("Youtube")) { editText.setText(".Y "); } editText.setSelection(editText.length()); } }).show(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getSupportActionBar().setDisplayHomeAsUpEnabled(true); overridePendingTransition(0, 0); PreferenceManager.setDefaultValues(this, R.xml.settings_xml, false); getFragmentManager().beginTransaction() .replace(android.R.id.content, new GeneralPreferenceFragment()) .commit(); }
private void initView(Context context) { preferences = PreferenceManager.getDefaultSharedPreferences(context); // 初始情况,设置下拉刷新view高度为0 LayoutParams lp = new LayoutParams( LayoutParams.FILL_PARENT, 0); mContainer = (LinearLayout) LayoutInflater.from(context).inflate( R.layout.lfrecyclerview_header, null); addView(mContainer, lp); setGravity(Gravity.BOTTOM); mArrowImageView = findViewById(R.id.lfrecyclerview_header_arrow); mHintTextView = findViewById(R.id.lfrecyclerview_header_hint_textview); mProgressBar = findViewById(R.id.lfrecyclerview_header_progressbar); lfrecyclerview_header_time= findViewById(R.id.lfrecyclerview_header_time); mRotateUpAnim = new RotateAnimation(0.0f, -180.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateUpAnim.setDuration(ROTATE_ANIM_DURATION); mRotateUpAnim.setFillAfter(true); mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); mRotateDownAnim.setDuration(ROTATE_ANIM_DURATION); mRotateDownAnim.setFillAfter(true); }
@Override public void onResume() { super.onResume(); //this will refresh the osmdroid configuration on resuming. //if you make changes to the configuration, use //SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); //Configuration.getInstance().save(this, prefs); Configuration.getInstance().load(getDialog().getContext(), PreferenceManager.getDefaultSharedPreferences(getDialog().getContext())); }
/** * Binds a preference's summary to its value. More specifically, when the * preference's value is changed, its summary (line of text below the * preference title) is updated to reflect the value. The summary is also * immediately updated upon calling this method. The exact display format is * dependent on the type of preference. * * @see #sBindPreferenceSummaryToValueListener */ private static void bindPreferenceSummaryToValue(Preference preference) { // Set the listener to watch for value changes. preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); // Trigger the listener immediately with the preference's // current value. sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, PreferenceManager .getDefaultSharedPreferences(preference.getContext()) .getString(preference.getKey(), "")); }
@Override public void onReceive(Context context, Intent intent) { if (PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()) .getBoolean("key_enable",false)) { Utils.setEnable(true, context); } }
@Override protected void onPreExecute() { userClassControl = UserClassControl.getInstance(getApplicationContext()); SharedPreferences session = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()); email = session.getString("userEmail",""); }
public static boolean isAutosaveEnabled(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return prefs.getBoolean( "autosave", true ); }
private void processSubscriptionRequest(Bundle data) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); long pubId = preferences.getLong(MobileClient.PUBLISHER_ID, 0); // The id must be parsed, as it is in fact a String long subId = Long.parseLong(data.getString(SUBSCRIBER_ID)); String subUsername = data.getString(SUBSCRIBER_USERNAME); int notificationId = 1; // Pending Intent for the Reject action PendingIntent rejectPendingIntent = createPendingIntentForActions( NotificationProcessorReceiver.ACTION_REJECT, pubId, subId, subUsername, notificationId); // Pending Intent for the Accept action PendingIntent acceptPendingIntent = createPendingIntentForActions( NotificationProcessorReceiver.ACTION_ACCEPT, pubId, subId, subUsername, notificationId); Notification.Builder notificationBuilder = new Notification.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("MAGPIE Notification") .setContentText("Subscription request from " + subUsername) .addAction(R.drawable.abc_ic_clear_material, "Reject", rejectPendingIntent) .addAction(R.drawable.ic_done_black_24dp, "Accept", acceptPendingIntent); Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_NO_CLEAR; NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, notification); }
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { TelemetryAutofillCallback.INSTANCE.register(getContext()); } }
@Override protected void init() { super.init(); btn_submit.setText("查看变量"); editText=new EditText(getActivity()); checkBox=new CheckBox(getActivity()); checkBox.setText("是否为男性"); container.addView(checkBox); container.addView(editText); //创建实例 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); RxSharedPreferences rxPreferences = RxSharedPreferences.create(preferences); //创建个人 pre_username = rxPreferences.getString("username"); pre_sex= rxPreferences.getBoolean("sex", true); //绑定 RxCompoundButton.checkedChanges(checkBox) .subscribe(pre_sex.asAction()); RxTextView.textChanges(editText) .flatMap(new Func1<CharSequence, Observable<String>>() { @Override public Observable<String> call(final CharSequence charSequence) { return Observable.create(new Observable.OnSubscribe<String>() { @Override public void call(Subscriber<? super String> subscriber) { subscriber.onNext(charSequence.toString()); subscriber.onCompleted(); } }); } }) .subscribe(pre_username.asAction()); }
private void update() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean lockdown = prefs.getBoolean("lockdown", false); Tile tile = getQsTile(); if (tile != null) { tile.setState(lockdown ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); tile.updateTile(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); locationInfo = ConfigPreferences.getLocationConfig(getActivity()); //disable and enable praying notification related setting if (ConfigPreferences.getPrayingNotification(getActivity()) == false) { getPreferenceScreen().findPreference("silent").setEnabled(false); getPreferenceScreen().findPreference("vibration").setEnabled(false); getPreferenceScreen().findPreference("led").setEnabled(false); } //disable or enable silent related settings if(ConfigPreferences.getSilentMood(getActivity()) == false){ getPreferenceScreen().findPreference("vibration").setEnabled(false); } if (locationInfo != null) { Log.i("DATA_SETTING" ,"locationInfo.dls : "+(locationInfo.dls > 0)); CheckBoxPreference checked = (CheckBoxPreference) getPreferenceScreen().findPreference("day_light"); checked.setChecked(locationInfo.dls > 0); ListPreference wayPref = (ListPreference) getPreferenceScreen().findPreference("calculations"); Log.i("DATA_SETTING" ,"locationInfo.way : "+locationInfo.way); wayPref.setValueIndex(locationInfo.way); ListPreference mazhapPref = (ListPreference) getPreferenceScreen().findPreference("mazhab"); mazhapPref.setValueIndex(locationInfo.mazhab); Log.i("DATA_SETTING" ,"locationInfo.mazhab : "+locationInfo.mazhab); } listPreference = (ListPreference) findPreference("language"); String lang = ConfigPreferences.getApplicationLanguage(getActivity()).equalsIgnoreCase("en") ? "English" : "العربية"; listPreference.setSummary(getString(R.string.language_summary) + " (" + lang + ") "); }
@NightMode @Override public int getNightMode() { String mode = PreferenceManager.getDefaultSharedPreferences(app) .getString("night_switch", String.valueOf(NightMode.DISABLE)); //noinspection ResourceType return Integer.parseInt(mode); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getString("weather", null) != null) { Intent intent = new Intent(this, WeatherActivity.class); startActivity(intent); finish(); } }
public void selectEditorTheme() { String[] themes = mEditor.getAvailableThemes(); int i = Arrays.asList(themes).indexOf(mEditor.getTheme()); new MaterialDialog.Builder(getContext()) .title(R.string.text_editor_theme) .items((CharSequence[]) themes) .itemsCallbackSingleChoice(i, (dialog, itemView, which, text) -> { PreferenceManager.getDefaultSharedPreferences(getContext()).edit() .putString(KEY_EDITOR_THEME, text.toString()) .apply(); setTheme(text.toString()); return true; }) .show(); }
/** * 设置根目录回调 */ @Override public void onActivityResult(int request_code, int result_code, Intent intent) { if (request_code == RC_SET_FILE_ROOT) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); boolean value = preferences.getBoolean("list_folders_first", true); if (value != foldersUp) { showDirectoryContents(currentPath); } } }
private int getKeyboardPortraitHeight() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); int keyboardHeight = prefs.getInt("keyboard_height_portrait", defaultCustomKeyboardSize); return clamp(keyboardHeight, minCustomKeyboardSize, getRootView().getHeight() - minCustomKeyboardTopMargin); }