android.preference.PreferenceManager Java Examples

The following examples show how to use android.preference.PreferenceManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainMenuFragment.java    From JianDan_OkHttpWithVolley with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    //要显示妹子图而现在没显示,则重现设置适配器
    if (sp.getBoolean(SettingFragment.ENABLE_SISTER, false) && mAdapter.menuItems.size() == 4) {
        addAllMenuItems(mAdapter);
        mAdapter.notifyDataSetChanged();
    } else if (!sp.getBoolean(SettingFragment.ENABLE_SISTER, false) && mAdapter.menuItems.size()
            == 5) {
        addMenuItemsNoSister(mAdapter);
        mAdapter.notifyDataSetChanged();
    }

}
 
Example #2
Source File: HTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setUnits() {
	final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
	final int unit = Integer.parseInt(preferences.getString(SettingsFragment.SETTINGS_UNIT, String.valueOf(SettingsFragment.SETTINGS_UNIT_DEFAULT)));

	switch (unit) {
		case SettingsFragment.SETTINGS_UNIT_C:
			this.unitView.setText(R.string.hts_unit_celsius);
			break;
		case SettingsFragment.SETTINGS_UNIT_F:
			this.unitView.setText(R.string.hts_unit_fahrenheit);
			break;
		case SettingsFragment.SETTINGS_UNIT_K:
			this.unitView.setText(R.string.hts_unit_kelvin);
			break;
	}
}
 
Example #3
Source File: Notifications.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void ReadPerfs(Context context) {
    mContext = context;
    prefs = PreferenceManager.getDefaultSharedPreferences(context);
    bg_notifications = prefs.getBoolean("bg_notifications", true);
    bg_notifications_watch = PersistentStore.getBoolean("bg_notifications_watch");
    bg_persistent_high_alert_enabled_watch = PersistentStore.getBoolean("persistent_high_alert_enabled_watch");
    //bg_vibrate = prefs.getBoolean("bg_vibrate", true);
    //bg_lights = prefs.getBoolean("bg_lights", true);
    //bg_sound = prefs.getBoolean("bg_play_sound", true);
    bg_notification_sound = prefs.getString("bg_notification_sound", "content://settings/system/notification_sound");
    bg_sound_in_silent = prefs.getBoolean("bg_sound_in_silent", false);

    calibration_notifications = prefs.getBoolean("calibration_notifications", false);
    calibration_snooze = Integer.parseInt(prefs.getString("calibration_snooze", "20"));
    calibration_override_silent = prefs.getBoolean("calibration_alerts_override_silent", false);
    calibration_notification_sound = prefs.getString("calibration_notification_sound", "content://settings/system/notification_sound");
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);
    smart_snoozing = prefs.getBoolean("smart_snoozing", true);
    smart_alerting = prefs.getBoolean("smart_alerting", true);
    bg_ongoing = prefs.getBoolean("run_service_in_foreground", false);
}
 
Example #4
Source File: SunshinePreferences.java    From android-dev-challenge with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: BlackListFragment.java    From Botifier with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	mSharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
	setHasOptionsMenu(true);
	addPreferencesFromResource(R.xml.list_preference);
	mBlackList = (PreferenceCategory) findPreference(getString(R.string.cat_filterlist));
	Set<String> entries = mSharedPref.getStringSet(getString(R.string.pref_blacklist), null);
	if (entries == null) {
		mBlackListEntries = new HashSet<String>();
	} else {
		mBlackListEntries = new HashSet<String>(entries);
	}
	for (String blackitem : mBlackListEntries) {
		Preference test = new Preference(getActivity());
		test.setTitle(blackitem);
		mBlackList.addPreference(test);
	}
}
 
Example #6
Source File: BackgroundService.java    From BackPackTrackII with GNU General Public License v3.0 6 votes vote down vote up
private boolean isBetterLocation(Location prev, Location current) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean pref_altitude = prefs.getBoolean(SettingsFragment.PREF_ALTITUDE, SettingsFragment.DEFAULT_ALTITUDE);
    return (prev == null ||
            ((!pref_altitude || !prev.hasAltitude() || current.hasAltitude()) &&
                    (current.hasAccuracy() ? current.getAccuracy() : Float.MAX_VALUE) <
                            (prev.hasAccuracy() ? prev.getAccuracy() : Float.MAX_VALUE)));
}
 
Example #7
Source File: AddNotesActivity.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addNote(double lon, double lat, double elev, long timestamp, String note, boolean alsoAsBookmark) {
    try {
        DaoNotes.addNote(lon, lat, elev, timestamp, note, "POI", "", null);
        if (alsoAsBookmark) {
            final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
            double[] mapCenterFromPreferences = PositionUtilities.getMapCenterFromPreferences(preferences, false, false);
            int zoom = 16;
            if (mapCenterFromPreferences != null) {
                zoom = (int) mapCenterFromPreferences[2];
            }
            DaoBookmarks.addBookmark(lon, lat, note, zoom);
        }
        boolean returnToViewAfterNote = returnToViewAfterNoteCheckBox.isChecked();
        if (!returnToViewAfterNote) {
            finish();
        }
    } catch (Exception e) {
        GPLog.error(this, null, e);
        GPDialogs.warningDialog(this, getString(eu.geopaparazzi.library.R.string.notenonsaved), null);
    }
}
 
Example #8
Source File: NotificationSender.java    From PressureNet with GNU General Public License v3.0 6 votes vote down vote up
private String displayDistance(double distance) {
	SharedPreferences sharedPreferences = PreferenceManager
			.getDefaultSharedPreferences(mContext);
	String preferredDistanceUnit = sharedPreferences.getString("distance_units", "Kilometers (km)");
	
	// Use km instead of m, even if preference is m
	if (preferredDistanceUnit.equals("Meters (m)")) {
		preferredDistanceUnit = "Kilometers (km)";
	}
	
	// Use mi instead of ft, even if preference is ft
	if (preferredDistanceUnit.equals("Feet (ft)")) {
		preferredDistanceUnit = "Miles (mi)";
	}
	
	DecimalFormat df = new DecimalFormat("##");
	DistanceUnit unit = new DistanceUnit(preferredDistanceUnit);
	unit.setValue(distance);
	unit.setAbbreviation(preferredDistanceUnit);
	double distanceInPreferredUnit = unit.convertToPreferredUnit();
	return df.format(distanceInPreferredUnit) + unit.fullToAbbrev();
}
 
Example #9
Source File: StopSensor.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public void addListenerOnButton() {

        button = (Button)findViewById(R.id.stop_sensor);

        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Sensor.stopSensor();
                AlertPlayer.getPlayer().stopAlert(getApplicationContext(), true, false);

                Toast.makeText(getApplicationContext(), "Sensor stopped", Toast.LENGTH_LONG).show();

                //If Sensor is stopped for G5, we need to prevent further BLE scanning.
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
                if(collection_method.compareTo("DexcomG5") == 0) {
                    Intent serviceIntent = new Intent(getApplicationContext(), G5CollectionService.class);
                    startService(serviceIntent);
                }

                Intent intent = new Intent(getApplicationContext(), Home.class);
                startActivity(intent);
                finish();
            }

        });
    }
 
Example #10
Source File: IntroHelper.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
public static void showIntro(Activity activity, boolean mode_multi) {
    Thread t = new Thread(() -> {
        SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext());
        String activityname = activity.getClass().getSimpleName();
        String INTRO = "intro_shown_on_activity_" + activityname + "_MultiMode_" + mode_multi;
        boolean SHOW_INTRO = getPrefs.getBoolean(INTRO, true);

        if (SHOW_INTRO && Config.SHOW_INTRO) {
            final Intent i = new Intent(activity, IntroActivity.class);
            i.putExtra(ACTIVITY, activityname);
            i.putExtra(MULTICHAT, mode_multi);
            activity.runOnUiThread(() -> activity.startActivity(i));
        }
    });
    t.start();
}
 
Example #11
Source File: PreferencesActivity.java    From AndroidPirateBox with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	activity = this;
	preferences = PreferenceManager.getDefaultSharedPreferences(this);
	addPreferencesFromResource(R.xml.preferences);
	
	updateExternalServerPreference();
	
	CheckBoxPreference extServerCheckBoxPref = (CheckBoxPreference) findPreference(Constants.PREF_USE_EXTERNAL_SERVER);
	extServerCheckBoxPref.setOnPreferenceClickListener(
			new OnPreferenceClickListener() {

				@Override
				public boolean onPreferenceClick(
						Preference preference) {
					updateExternalServerPreference();

					return true;
				}
			});
}
 
Example #12
Source File: AmbientLightManager.java    From CodeScaner with MIT License 5 votes vote down vote up
void start(CameraManager cameraManager) {
  this.cameraManager = cameraManager;
  SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
  if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    if (lightSensor != null) {
      sensorManager.registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
    }
  }
}
 
Example #13
Source File: RecognitionActivity.java    From Android-Face-Recognition-with-Deep-Learning-Test-Framework with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG,"called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.recognition_layout);
    progressBar = (ProgressBar)findViewById(R.id.progressBar);
    fh = new FileHelper();
    File folder = new File(fh.getFolderPath());
    if(folder.mkdir() || folder.isDirectory()){
        Log.i(TAG,"New directory for photos created");
    } else {
        Log.i(TAG,"Photos directory already existing");
    }
    mRecognitionView = (CustomCameraView) findViewById(R.id.RecognitionView);
    // Use camera which is selected in settings
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    front_camera = sharedPref.getBoolean("key_front_camera", true);
    night_portrait = sharedPref.getBoolean("key_night_portrait", false);
    exposure_compensation = Integer.valueOf(sharedPref.getString("key_exposure_compensation", "20"));

    if (front_camera){
        mRecognitionView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_FRONT);
    } else {
        mRecognitionView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_BACK);
    }
    mRecognitionView.setVisibility(SurfaceView.VISIBLE);
    mRecognitionView.setCvCameraViewListener(this);

    int maxCameraViewWidth = Integer.parseInt(sharedPref.getString("key_maximum_camera_view_width", "640"));
    int maxCameraViewHeight = Integer.parseInt(sharedPref.getString("key_maximum_camera_view_height", "480"));
    mRecognitionView.setMaxFrameSize(maxCameraViewWidth, maxCameraViewHeight);
}
 
Example #14
Source File: ClientPreferences.java    From 4pdaClient-plus with Apache License 2.0 5 votes vote down vote up
public static void setTime(Context context, String key, int hourOfDay, int minute) {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().putLong(key, cal.getTimeInMillis()).apply();
}
 
Example #15
Source File: Preferences.java    From Home-Assistant-Launcher with Apache License 2.0 5 votes vote down vote up
public static void load(Context context){
    mLockScreen = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(KEY_LOCK_SCREEN, true);
    mBackKeyBehavior = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(KEY_BACK_KEY_BEHAVIOR, true);
    mHideAdminMenuItems = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(KEY_HIDE_ADMIN_MENU_ITEMS, true);
    mHideToolbar = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(KEY_HIDE_TOOLBAR, false);
    mUrl = PreferenceManager.getDefaultSharedPreferences(context).getString(KEY_URL, null);
}
 
Example #16
Source File: DbHelper.java    From GPS2SMS with GNU General Public License v3.0 5 votes vote down vote up
public static void updateFavIcon(Context context, ImageButton btn) {

        try {

            SharedPreferences localPrefs = PreferenceManager.getDefaultSharedPreferences(context);
            String act = localPrefs.getString("prefFavAct", "");

            if (act.equalsIgnoreCase("")) {
                return;
            }

            Intent icon_intent = new Intent(android.content.Intent.ACTION_SEND);
            icon_intent.setType("text/plain");

            List<ResolveInfo> resInfo = context.getPackageManager().queryIntentActivities(icon_intent, 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    if (info.activityInfo.name.toLowerCase().equalsIgnoreCase(act)) {
                        Drawable icon = info.activityInfo.loadIcon(context.getPackageManager());
                        btn.setImageDrawable(icon);
                        break;
                    }
                }
            }

        } catch (Exception e) {
            //
        }

    }
 
Example #17
Source File: WifiCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
    foregroundServiceStarter = new ForegroundServiceStarter(getApplicationContext(), this);
    foregroundServiceStarter.start();
    //mContext = getApplicationContext();
    dexCollectionService = this;
    prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    listenForChangeInSettings();
    // bgToSpeech = BgToSpeech.setupTTS(mContext); //keep reference to not being garbage collected
    Log.i(TAG, "onCreate: STARTING SERVICE");
    lastState = "Starting up " + JoH.hourMinuteString();
}
 
Example #18
Source File: DispatchService.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private final void resetSync(Uri uri) {
    final String METHOD = "resetSync(Uri)";

    SharedPreferences preferences =
            PreferenceManager.getDefaultSharedPreferences(DispatchService.this);

    String key = null;
    switch (Uris.getDescriptor(uri)) {
        default:
            key = "last_sync";
    }
    preferences.edit().putLong(key, new Date().getTime()).commit();
}
 
Example #19
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
      protected void onPostExecute(String result) {try {
	getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "Prompted Uninstall");
} catch (UnsupportedEncodingException e) {
	 
	e.printStackTrace();
}        }
 
Example #20
Source File: MainActivity.java    From nubo-test with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Context context = getApplicationContext();

    setContentView(R.layout.activity_main);
    this.mUsernameTV = (TextView) findViewById(R.id.main_username);
    this.mTextMessageTV = (TextView) findViewById(R.id.message_textview);
    this.mTextMessageET = (EditText) findViewById(R.id.main_text_message);
    this.mTextMessageTV.setText("");
    executor = new LooperExecutor();
    executor.requestStart();
    SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    Constants.SERVER_ADDRESS_SET_BY_USER = mSharedPreferences.getString(Constants.SERVER_NAME, Constants.DEFAULT_SERVER);
    wsUri = mSharedPreferences.getString(Constants.SERVER_NAME, Constants.DEFAULT_SERVER);
    kurentoRoomAPI = new KurentoRoomAPI(executor, wsUri, this);
    mHandler = new Handler();

    this.username     = mSharedPreferences.getString(Constants.USER_NAME, "");
    this.roomname     = mSharedPreferences.getString(Constants.ROOM_NAME, "");
    Log.i(TAG, "username: "+this.username);
    Log.i(TAG, "roomname: "+this.roomname);

    // Load test certificate from assets
    CertificateFactory cf;
    try {
        cf = CertificateFactory.getInstance("X.509");
        InputStream caInput = new BufferedInputStream(context.getAssets().open("kurento_room_base64.cer"));
        Certificate ca = cf.generateCertificate(caInput);
        kurentoRoomAPI.addTrustedCertificate("ca", ca);
    } catch (CertificateException|IOException e) {
        e.printStackTrace();
    }
    kurentoRoomAPI.useSelfSignedCertificate(true);
}
 
Example #21
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void checkForRisingAllert(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Boolean rising_alert = prefs.getBoolean("rising_alert", false);
    if(!rising_alert) {
        return;
    }
    if(prefs.getLong("alerts_disabled_until", 0) > new Date().getTime()){
        Log.i("NOTIFICATIONS", "checkForRisingAllert: Notifications are currently disabled!!");
        return;
    }

    String riseRate = prefs.getString("rising_bg_val", "2");
    float friseRate = 2;

    try
    {
        friseRate = Float.parseFloat(riseRate);
    }
    catch (NumberFormatException nfe)
    {
        Log.e(TAG_ALERT, "checkForRisingAllert reading falling_bg_val failed, continuing with 2", nfe);
    }
    Log.d(TAG_ALERT, "checkForRisingAllert will check for rate of " + friseRate);

    boolean riseAlert = checkForDropRiseAllert(friseRate, false);
    Notifications.RisingAlert(context, riseAlert);
}
 
Example #22
Source File: MainActivity.java    From ToDay with MIT License 5 votes vote down vote up
@Override
protected void onDestroy() {
    super.onDestroy();
    mCalendarView.deactivate();
    mTodayView.setAdapter(null); // force detaching adapter
    PreferenceManager.getDefaultSharedPreferences(this)
            .edit()
            .putString(CalendarUtils.PREF_CALENDAR_EXCLUSIONS,
                    TextUtils.join(SEPARATOR, mExcludedCalendarIds))
            .apply();
}
 
Example #23
Source File: CameraConfigurationManager.java    From YZxing with Apache License 2.0 5 votes vote down vote up
void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

        Camera theCamera = camera.getCamera();
        Camera.Parameters parameters = theCamera.getParameters();

        if (parameters == null) {
            Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
            return;
        }

        Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

        if (safeMode) {
            Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
        }

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        CameraConfigurationUtils.setFocus(
                parameters,
                prefs.getBoolean(Constant.KEY_AUTO_FOCUS, true),
                prefs.getBoolean(Constant.KEY_DISABLE_CONTINUOUS_FOCUS, true),
                safeMode);

        parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

        theCamera.setParameters(parameters);
        //设置屏幕方向为垂直方向
        theCamera.setDisplayOrientation(90);
    }
 
Example #24
Source File: MediaNotification.java    From MediaNotification with Apache License 2.0 5 votes vote down vote up
public void showTutorial() {
    PreferenceManager.getDefaultSharedPreferences(this)
            .edit()
            .putBoolean(PreferenceUtils.PREF_TUTORIAL, true)
            .putBoolean(PreferenceUtils.PREF_TUTORIAL_PLAYERS, true)
            .apply();

    for (TutorialListener listener : listeners) {
        listener.onTutorial();
    }
}
 
Example #25
Source File: AdapterProducts.java    From fingen with Apache License 2.0 5 votes vote down vote up
public AdapterProducts(Transaction transaction, Activity activity, IProductChangedListener productChangedListener) {
    mActivity = activity;
    mTransaction = transaction;
    Account account = AccountsDAO.getInstance(activity).getAccountByID(transaction.getAccountID());
    Cabbage cabbage = CabbagesDAO.getInstance(activity).getCabbageByID(account.getCabbageId());
    mCabbageFormatter = new CabbageFormatter(cabbage);
    mProductChangedListener = productChangedListener;
    mTagTextSize = ScreenUtils.PxToDp(activity, activity.getResources().getDimension(R.dimen.text_size_micro));
    mColorTag = ContextCompat.getColor(activity, R.color.ColorAccent);
    isTagsColored = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean(FgConst.PREF_COLORED_TAGS, true);
}
 
Example #26
Source File: MainActivity.java    From rcloneExplorer with MIT License 5 votes vote down vote up
@Override
protected void onPostExecute(Boolean success) {
    super.onPostExecute(success);
    if (loadingDialog.isStateSaved()) {
        loadingDialog.dismissAllowingStateLoss();
    } else {
        loadingDialog.dismiss();
    }
    if (!success) {
        return;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.remove(getString(R.string.shared_preferences_pinned_remotes));
    editor.remove(getString(R.string.shared_preferences_drawer_pinned_remotes));
    editor.remove(getString(R.string.shared_preferences_hidden_remotes));
    editor.apply();

    if (rclone.isConfigEncrypted()) {
        pinRemotesToDrawer(); // this will clear any previous pinned remotes
        askForConfigPassword();
    } else {
        AppShortcutsHelper.removeAllAppShortcuts(context);
        AppShortcutsHelper.populateAppShortcuts(context, rclone.getRemotes());
        pinRemotesToDrawer();
        startRemotesFragment();
    }
}
 
Example #27
Source File: LibraryQuery.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String getSorting() {
    SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(mContext);

    return sharedPreferences.getString(SharedPreferencesKeys.SP_LIBRARY_SORTING, "ASC");
}
 
Example #28
Source File: SettingsFragment.java    From FreezeYou with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    if (!sp.getBoolean("displayListDivider", false)) {
        ListView lv = getActivity().findViewById(android.R.id.list);
        if (lv != null) {
            lv.setDivider(getResources().getDrawable(R.color.realTranslucent));
            lv.setDividerHeight(2);
        }
    }
}
 
Example #29
Source File: SnooperStopperDeviceAdminReceiver.java    From SnooperStopper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPasswordFailed(Context context, Intent intent) {
    super.onPasswordFailed(context, intent);
    failedPasswordAttempts += 1;
    Log.d(TAG, "onPasswordFailed: " + failedPasswordAttempts);
    SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(context);
    int pref_key_max_attempts_limit = Integer.parseInt(SP.getString("pref_key_max_attempts_limit", "3"));
    if (failedPasswordAttempts >= pref_key_max_attempts_limit) {
        Log.d(TAG, "TOO MANY FAILED UNLOCK ATTEMPTS!!! SHUTTING DOWN!");
        failedPasswordAttempts = 0;
        if (!SuShell.shutdown()) {
            Log.d(TAG, "COULDN'T SHUT DOWN!");
        }
    }
}
 
Example #30
Source File: SettingsActivity.java    From privacy-friendly-passwordgenerator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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(), ""));
}