private static boolean isFavoritesMigrated(Context context) {
    SharedPreferences settings = context.getSharedPreferences("sthlmtraveling", MODE_PRIVATE);
    boolean migrated = settings.getBoolean("converted_favorites", false);
    if (migrated) {
      Log.d(TAG, "Favorites converted.");
      return true;
    }

    FavoritesDbAdapter favoritesDbAdapter = null;
    try {
      favoritesDbAdapter = new FavoritesDbAdapter(context);
      favoritesDbAdapter.open();
      Cursor favoritesCursor = favoritesDbAdapter.fetch();
      if (favoritesCursor.getCount() == 0) {
        // Also mark it as migrated to avoid sending an intent.
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("converted_favorites", true);
        editor.apply();
        migrated = true;
      }
    } finally {
      if (favoritesDbAdapter != null) {
        favoritesDbAdapter.close();
      }
    }
    if (migrated) {
      Log.d(TAG, "No previous favorites, treat as converted.");
      return true;
    }

    String[] projection =
        new String[] {
          Journeys._ID, // 0
        };
    ContentResolver resolver = context.getContentResolver();
    Cursor journeyCursor = resolver.query(Journeys.CONTENT_URI, projection, null, null, null);
    if (journeyCursor.getCount() > 0) {
      journeyCursor.close();
      // Also mark it as migrated to avoid sending an intent.
      SharedPreferences.Editor editor = settings.edit();
      editor.putBoolean("converted_favorites", true);
      editor.apply();

      Log.d(TAG, "Existing journeys, treat as converted.");
      return true;
    }
    journeyCursor.close();

    return false;
  }
Example #2
0
  @Override
  public int delete(Uri uri, String where, String[] selectionArgs) {
    // Check access
    enforcePermission();

    if (sUriMatcher.match(uri) == TYPE_RESTRICTION) {
      int rows = 0;

      // Get argument
      int uid = Integer.parseInt(selectionArgs[0]);

      // Method restrictions
      SharedPreferences prefs =
          getContext().getSharedPreferences(PREF_RESTRICTION, Context.MODE_WORLD_READABLE);
      SharedPreferences.Editor editor = prefs.edit();
      for (String restrictionName : PrivacyManager.getRestrictions(true)) {
        for (PrivacyManager.MethodDescription md : PrivacyManager.getMethods(restrictionName)) {
          rows++;
          editor.remove(getExceptionPref(uid, restrictionName, md.getMethodName()));
        }
      }
      editor.apply();
      setPrefFileReadable(PREF_RESTRICTION);

      // Group restrictions
      for (String restrictionName : PrivacyManager.getRestrictions(true)) {
        rows++;
        updateRestriction(uid, restrictionName, null, true);
      }

      return rows;
    } else if (sUriMatcher.match(uri) == TYPE_SETTING && selectionArgs == null) {
      int rows = 0;
      SharedPreferences prefs =
          getContext().getSharedPreferences(PREF_SETTINGS, Context.MODE_WORLD_READABLE);
      SharedPreferences.Editor editor = prefs.edit();
      for (String pref : prefs.getAll().keySet()) {
        rows++;
        editor.remove(pref);
        Util.log(null, Log.INFO, "Removed setting=" + pref);
      }
      editor.apply();
      setPrefFileReadable(PREF_SETTINGS);
      return rows;
    }

    throw new IllegalArgumentException(uri.toString());
  }
Example #3
0
  // set CallId SharedPreference
  @SuppressLint("NewApi")
  public void setCallId(String callId) {

    callEditor.putString(callId, callId);

    callEditor.apply();
  }
 private void saveUsername(String username) {
   SharedPreferences sharedPreferences =
       getSharedPreferences("TarotAppFeedback", Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = sharedPreferences.edit();
   editor.putString("user", username);
   editor.apply();
 }
 public void clearUserColor(final long userId) {
   if (userId < 0) return;
   mUserColors.remove(userId);
   final SharedPreferences.Editor editor = mColorPreferences.edit();
   editor.remove(Long.toString(userId));
   editor.apply();
 }
  public void toggleService(boolean isChecked) {
    Intent service = new Intent(this, MainService.class);
    spe.putBoolean(CHECKBOX_SERVICE_CHECKED, isChecked);
    while (!spe.commit()) {}
    spe.apply();

    if (isChecked) {
      // Start service
      if (!isMyServiceRunning()) {
        startService(service);
      }
    } else {
      // Stop service
      stopService(service);
    }

    checkBoxVolumeButtonHack.setEnabled(isChecked);

    checkBoxMusicHack.setEnabled(isChecked && checkBoxVolumeButtonHack.isChecked());
    checkBoxVoiceCallHack.setEnabled(isChecked && checkBoxVolumeButtonHack.isChecked());
    checkBoxRingHack.setEnabled(isChecked && checkBoxVolumeButtonHack.isChecked());

    checkBoxToggleSafety.setEnabled(isChecked);
    // seekBarSafetyLevel.setEnabled(checkBoxToggleSafety.isChecked() &&
    // checkBoxToggleSafety.isEnabled());
  }
Example #7
0
  @Override
  public void onCreate() {
    super.onCreate();

    LeakCanary.install(this);

    String apiPrefKey = getString(R.string.pref_apiendpoint_key);
    String versionCodePrefKey = getString(R.string.pref_versioncode_key);
    String apiDefaultValue = getString(R.string.pref_apiendpoint_default);

    String server;
    try {
      PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
      int versionCode = packageInfo.versionCode;
      int lastVersionCode =
          PreferenceManager.getDefaultSharedPreferences(this).getInt(versionCodePrefKey, 0);
      if (lastVersionCode < versionCode) {
        // Update detected
        server = apiDefaultValue;
        SharedPreferences.Editor editor =
            PreferenceManager.getDefaultSharedPreferences(this).edit();
        editor.putInt(versionCodePrefKey, versionCode);
        editor.putString(apiPrefKey, apiDefaultValue);
        editor.apply();
      } else {
        server =
            PreferenceManager.getDefaultSharedPreferences(this)
                .getString(apiPrefKey, apiDefaultValue);
      }
    } catch (PackageManager.NameNotFoundException e) {
      server = apiDefaultValue;
    }

    DrinksProvider.updateServer(server);
  }
 @Override
 public void onClick(View v) {
   int id = v.getId();
   if (id == R.id.cling_dismiss_migration_use_default) {
     // Disable the migration cling
     dismissMigrationCling();
   } else if (id == R.id.cling_dismiss_migration_copy_apps) {
     // Copy the shortcuts from the old database
     LauncherModel model = mLauncher.getModel();
     model.resetLoadedState(false, true);
     model.startLoader(
         false,
         PagedView.INVALID_RESTORE_PAGE,
         LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE | LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
     // Set the flag to skip the folder cling
     String spKey = LauncherAppState.getSharedPreferencesKey();
     SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
     SharedPreferences.Editor editor = sp.edit();
     editor.putBoolean(Launcher.USER_HAS_MIGRATED, true);
     editor.apply();
     // Disable the migration cling
     dismissMigrationCling();
   } else if (id == R.id.cling_dismiss_longpress_info) {
     dismissLongPressCling();
   }
 }
  private void savePreferences(final String prefKey, final boolean isPositiveResponse) {
    if (mCheckbox != null) {
      final SharedPreferences.Editor editor = mPrefs.prefs.edit();
      final boolean dontShow = mCheckbox.isChecked();
      if (dontShow) {
        Toast.makeText(getActivity(), R.string.pref_dialog_selection_reset_desc, Toast.LENGTH_LONG)
            .show();
        editor.putString(
            prefKey, getString(isPositiveResponse ? PREFERENCE_ALWAYS_ID : PREFERENCE_NEVER_ID));
      } else {
        editor.putString(prefKey, getString(PREFERENCE_ASK_ID));
      }

      editor.apply();

      HitBuilders.EventBuilder eventBuilder =
          new HitBuilders.EventBuilder()
              .setCategory(GAUtils.Category.PREFERENCE_DIALOGS)
              .setAction(getArguments().getString(EXTRA_TITLE))
              .setLabel(
                  "Response: "
                      + (isPositiveResponse ? "Yes" : "No")
                      + (dontShow ? " (Always)" : " (Just once)"));
      GAUtils.sendEvent(eventBuilder);
    }
  }
Example #10
0
 /** 保存第一次引导页信息 * */
 public void saveFirstEnter(Context context) {
   SharedPreferences preferences =
       context.getSharedPreferences("ldi_first_enter", Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = preferences.edit();
   editor.putBoolean("first", false);
   editor.apply();
 }
Example #11
0
 private void writeToSharedPref(SharedPreferences prefs) {
   SharedPreferences.Editor editor = prefs.edit();
   editor.putLong(Stopwatches.PREF_START_TIME, mStartTime);
   editor.putLong(Stopwatches.PREF_ACCUM_TIME, mAccumulatedTime);
   editor.putInt(Stopwatches.PREF_STATE, mState);
   if (mLapsAdapter != null) {
     long[] laps = mLapsAdapter.getLapTimes();
     if (laps != null) {
       editor.putInt(Stopwatches.PREF_LAP_NUM, laps.length);
       for (int i = 0; i < laps.length; i++) {
         String key = Stopwatches.PREF_LAP_TIME + Integer.toString(laps.length - i);
         editor.putLong(key, laps[i]);
       }
     }
   }
   if (mState == Stopwatches.STOPWATCH_RUNNING) {
     editor.putLong(Stopwatches.NOTIF_CLOCK_BASE, mStartTime - mAccumulatedTime);
     editor.putLong(Stopwatches.NOTIF_CLOCK_ELAPSED, -1);
     editor.putBoolean(Stopwatches.NOTIF_CLOCK_RUNNING, true);
   } else if (mState == Stopwatches.STOPWATCH_STOPPED) {
     editor.putLong(Stopwatches.NOTIF_CLOCK_ELAPSED, mAccumulatedTime);
     editor.putLong(Stopwatches.NOTIF_CLOCK_BASE, -1);
     editor.putBoolean(Stopwatches.NOTIF_CLOCK_RUNNING, false);
   } else if (mState == Stopwatches.STOPWATCH_RESET) {
     editor.remove(Stopwatches.NOTIF_CLOCK_BASE);
     editor.remove(Stopwatches.NOTIF_CLOCK_RUNNING);
     editor.remove(Stopwatches.NOTIF_CLOCK_ELAPSED);
   }
   editor.putBoolean(Stopwatches.PREF_UPDATE_CIRCLE, false);
   editor.apply();
 }
 /**
  * Sets the last trip, which we can retrieve at a later point
  *
  * @param trip the last {@link co.smartreceipts.android.model.Trip} to persist
  */
 public synchronized void setLastTrip(@NonNull Trip trip) {
   final SharedPreferences preferences = mContext.getSharedPreferences(PREFERENCES_FILENAME, 0);
   final SharedPreferences.Editor editor = preferences.edit();
   editor.putString(PREFERENCE_TRIP_NAME, trip.getName());
   editor.apply();
   mTrip = trip;
 }
 private void storeVoiceMailNumber(String number) {
   SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
   SharedPreferences.Editor editor = sp.edit();
   editor.putString(VM_NUMBER, number);
   editor.apply();
   setVmSimImsi(getSubscriberId());
 }
 /**
  * Сохранение настройки
  *
  * @param ctx
  * @param pref
  * @param val
  */
 public static void save(Context ctx, String pref, String val) {
   SharedPreferences sPref =
       ctx.getApplicationContext().getSharedPreferences("SettingsApp", ctx.MODE_MULTI_PROCESS);
   SharedPreferences.Editor ed = sPref.edit();
   ed.putString(pref, val);
   ed.apply();
 }
Example #15
0
  // set Records SharedPreference
  @SuppressLint("NewApi")
  public void setRecordDate(String callId, String value) {

    recordEditor.putString(callId, value);

    recordEditor.apply();
  }
Example #16
0
  private void updateRestriction(
      int uid, String restrictionName, String methodName, boolean allowed) {
    // Get restrictions
    SharedPreferences prefs =
        getContext().getSharedPreferences(PREF_RESTRICTION, Context.MODE_WORLD_READABLE);
    String restrictions = prefs.getString(getRestrictionPref(restrictionName), "*");

    // Decode restrictions
    List<String> listRestriction = new ArrayList<String>(Arrays.asList(restrictions.split(",")));
    boolean defaultAllowed = listRestriction.get(0).equals("*");

    // Allow or deny
    String sUid = Integer.toString(uid);
    if (defaultAllowed ? allowed : !allowed) listRestriction.remove(sUid);
    if (defaultAllowed ? !allowed : allowed)
      if (!listRestriction.contains(sUid)) listRestriction.add(sUid);

    // Encode restrictions
    restrictions = TextUtils.join(",", listRestriction.toArray(new String[0]));

    // Update restriction
    SharedPreferences.Editor editor = prefs.edit();
    if (methodName == null || !allowed)
      editor.putString(getRestrictionPref(restrictionName), restrictions);
    if (methodName != null)
      editor.putBoolean(getExceptionPref(uid, restrictionName, methodName), allowed);
    editor.apply();
    setPrefFileReadable(PREF_RESTRICTION);
  }
 private void apply(SharedPreferences.Editor editor) {
   if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
     editor.apply();
   } else {
     editor.commit();
   }
 }
Example #18
0
  public void Save(View v) {
    Pixels = (TextView) findViewById(R.id.pixelsValue);
    String s = Pixels.getText().toString();
    iPixels = Float.parseFloat(s);

    PhoneHeightToCamera = (EditText) findViewById(R.id.PhoneHeightToCamera);
    s = PhoneHeightToCamera.getText().toString();
    fPhoneHeightToCamera = Float.parseFloat(s);

    PhoneHeight = (EditText) findViewById(R.id.PhoneHeight);
    s = PhoneHeight.getText().toString();
    fPhoneHeight = Float.parseFloat(s);

    ShoulderHeight = (EditText) findViewById(R.id.ShoulderHeight);
    s = ShoulderHeight.getText().toString();
    fShoulderHeight = Float.parseFloat(s);

    SharedPreferences settings = getApplicationContext().getSharedPreferences(DATA, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putFloat("Pixels", iPixels);
    editor.putFloat("Phone Height to Camera", fPhoneHeightToCamera);
    editor.putFloat("Phone Height", fPhoneHeight);
    editor.putFloat("Shoulder Height", fShoulderHeight);
    // Apply the edits!
    editor.apply();
  }
Example #19
0
  private void setMyFlag(int position) {
    // Save country to preferences
    this.myCountry = position;
    SharedPreferences.Editor editor = mSharedPreferences.edit();
    editor.putInt(MY_COUNTRY, myCountry);
    editor.apply();

    ImageView imageView = (ImageView) findViewById(R.id.myflag);
    imageView.setImageResource(flags.getResourceId(position, 0));

    ImageView imageView2 = (ImageView) findViewById(R.id.flag);

    //		mView.setImageResource(flags.getResourceId(myCountry, 0));
    //		mView.setRotation(90);
    // Bypass because setRotation in not available before API level 11
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), flags.getResourceId(myCountry, 0));
    // Getting width & height of the given image.
    int w = bmp.getWidth();
    int h = bmp.getHeight();
    // Setting post rotate to 90
    Matrix mtx = new Matrix();
    mtx.postRotate(90);
    // Rotating Bitmap
    Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
    BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
    imageView2.setImageDrawable(bmd);

    TextView mTextView = (TextView) findViewById(R.id.mycountry);
    mTextView.setText(countries[position]);

    TextView mTextView1 = (TextView) findViewById(R.id.comment);
    mTextView1.setText(R.string.flag_set);
  }
Example #20
0
  public void goToProfileView(View view) {

    EditText etUser = (EditText) this.findViewById(R.id.et_user);
    String user = etUser.getText().toString();

    EditText etPasword = (EditText) this.findViewById(R.id.et_password);
    String password = etPasword.getText().toString();

    if (!authenticate(user, password)) {

      Toast.makeText(this, "Wrong user or password", Toast.LENGTH_LONG).show();
      ;
      return;
    }

    SharedPreferences preferences = this.getSharedPreferences(SHARED_DATA, MODE_PRIVATE);
    SharedPreferences.Editor edit = preferences.edit();

    edit.putString(ACTIVE_USER, user);
    edit.apply();

    Intent changePage = new Intent(this, ProfileView.class);
    changePage.putExtra(CURRENT_USER, user);

    this.startActivity(changePage);
  }
  private void refresh() {

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    String paths = preferences.getString(USER_MAPS_PATHS, "");
    TreeSet<String> pathSet = toSet(paths);
    File file = new File(customPath.trim());
    if (file.exists() && file.isDirectory()) pathSet.add(file.getAbsolutePath());

    // add to preferences
    String prefString = toString(pathSet);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(USER_MAPS_PATHS, prefString);
    editor.apply();

    mapsFoldersList.clear();
    mapsFoldersList.addAll(pathSet);

    ArrayAdapter<String> adapter =
        new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, mapsFoldersList);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    guessedPathsSpinner.setAdapter(adapter);
    if (customPath != null) {
      file = new File(customPath.trim());
      for (int i = 0; i < mapsFoldersList.size(); i++) {
        if (mapsFoldersList.get(i).equals(file.getAbsolutePath())) {
          guessedPathsSpinner.setSelection(i);
          break;
        }
      }
    }
  }
 private void removeRegistrationId(Context context) {
   final SharedPreferences prefs = getGCMPreferences(context);
   Log.i(TAG, "Clearing registrationId");
   SharedPreferences.Editor editor = prefs.edit();
   editor.remove(PROPERTY_REG_ID);
   editor.apply();
 }
Example #23
0
 /** Set the theme of the Activity, and restart it by creating a new Activity of the same type. */
 public static void changeToTheme(Activity activity, EGCThemeEnum themeEnum) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
   SharedPreferences.Editor editor = prefs.edit();
   editor.putString(THEME_KEY, themeEnum.toString());
   editor.apply();
   refreshActivity(activity);
 }
  /**
   * Writes Facebook profile information into preferences
   *
   * @param profile Facebook profile
   */
  private void writeProfileToPrefs(@Nullable Profile profile) {
    if (profile != null) {
      String id = profile.getId();
      String name = profile.getName();
      String firstName = profile.getFirstName();
      String lastName = profile.getLastName();
      Uri profileUri = profile.getLinkUri();
      Uri profilePictureUri = profile.getProfilePictureUri(100, 100);

      Resources res = LoginActivity.this.getResources();
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      SharedPreferences.Editor editor = prefs.edit();

      editor.putBoolean(res.getString(R.string.pref_fb_logged_in), true);
      editor.putString(res.getString(R.string.pref_fb_facebook_id), id);
      editor.putString(res.getString(R.string.pref_fb_username), name);
      editor.putString(res.getString(R.string.pref_fb_firstname), firstName);
      editor.putString(res.getString(R.string.pref_fb_lastname), lastName);
      editor.putString(
          res.getString(R.string.pref_fb_email), id + res.getString(R.string.at_weconnect_berlin));
      editor.putString(res.getString(R.string.pref_fb_profile_uri), profileUri.getPath());
      editor.putString(
          res.getString(R.string.pref_fb_profile_picture_uri), profilePictureUri.getPath());
      editor.apply();
    }
  }
 private void removeFromPersistence(URI uri, List<HttpCookie> cookiesToRemove) {
   SharedPreferences.Editor editor = sharedPreferences.edit();
   for (HttpCookie cookieToRemove : cookiesToRemove) {
     editor.remove(uri.toString() + SP_KEY_DELIMITER + cookieToRemove.getName());
   }
   editor.apply();
 }
 public void setUserColor(final long userId, final int color) {
   if (userId < 0) return;
   mUserColors.put(userId, color);
   final SharedPreferences.Editor editor = mColorPreferences.edit();
   editor.putInt(String.valueOf(userId), color);
   editor.apply();
 }
 @Override
 protected void onPostExecute(Exception e) {
   super.onPostExecute(e);
   pd.dismiss();
   if (e == null) {
     Toast.makeText(SshKeyGen.this, "SSH-key generated", Toast.LENGTH_LONG).show();
     DialogFragment df = new ShowSshKeyFragment();
     df.show(getFragmentManager(), "public_key");
     SharedPreferences prefs =
         PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
     SharedPreferences.Editor editor = prefs.edit();
     editor.putBoolean("use_generated_key", true);
     editor.apply();
   } else {
     new AlertDialog.Builder(SshKeyGen.this)
         .setTitle("Error while trying to generate the ssh-key")
         .setMessage(
             getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage())
         .setPositiveButton(
             getResources().getString(R.string.dialog_ok),
             new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialogInterface, int i) {
                 // pass
               }
             })
         .show();
   }
 }
Example #28
0
 public void putAllDetails(User user) {
   SharedPreferences.Editor spEditor = sharedPreferences.edit();
   spEditor.putString("username", user.getUsername());
   spEditor.putString("name", user.getName());
   spEditor.putString("password", user.getPassword());
   spEditor.putString("age", user.getAge());
   spEditor.putString("email", user.getEmail());
   spEditor.putString("phone", user.getPhone());
   spEditor.putString("position", user.getPosition());
   spEditor.putString("experience", user.getExperience());
   spEditor.putString("curloc", user.getCurloc());
   spEditor.putString("desloc", user.getDesloc());
   spEditor.putString("imageuri", user.getImageUri());
   spEditor.putString("com1name", user.getCom1name());
   spEditor.putString("com1pos", user.getCom1pos());
   spEditor.putString("com1from", user.getCom1from());
   spEditor.putString("com1to", user.getCom1to());
   spEditor.putString("com1resp", user.getCom1resp());
   spEditor.putString("com2name", user.getCom2name());
   spEditor.putString("com2pos", user.getCom2pos());
   spEditor.putString("com2from", user.getCom2from());
   spEditor.putString("com2to", user.getCom2to());
   spEditor.putString("com2resp", user.getCom2resp());
   spEditor.putString("com3name", user.getCom3name());
   spEditor.putString("com3pos", user.getCom3pos());
   spEditor.putString("com3from", user.getCom3from());
   spEditor.putString("com3to", user.getCom3to());
   spEditor.putString("com3resp", user.getCom3resp());
   spEditor.apply();
 }
Example #29
0
  // set Float SharedPreference
  @SuppressLint("NewApi")
  public void setFloat(boolean isChecked) {

    settingsEditor.putBoolean(EXTRA_FLOAT, isChecked);

    settingsEditor.apply();
  }