Beispiel #1
0
 public static void setCountryIconsEnabled(Context context, boolean enabled) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
   Editor editor = prefs.edit();
   editor.putBoolean(PREFERENCE_ENABLE_COUNTRY_ICONS, enabled);
   editor.commit();
   ObjectRelation.addRelation(editor, context);
 }
  /**
   * Removes the registration name and id association from local storage
   *
   * @param registrationName The registration name of the association to remove from local storage
   * @throws Exception
   */
  private void removeRegistrationId(String registrationName) throws Exception {
    Editor editor = mSharedPreferences.edit();

    editor.remove(STORAGE_PREFIX + REGISTRATION_NAME_STORAGE_KEY + registrationName);

    editor.commit();
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
      return true;
    }
    if (id == R.id.action_logout) {

      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
      String name = sharedPreferences.getString("username", "ab");

      Editor editor = sharedPreferences.edit();

      Toast.makeText(SearchLoggedInActivity.this, "Goodbye " + name, Toast.LENGTH_LONG).show();

      editor.clear();
      editor.commit();

      Intent intent = new Intent(SearchLoggedInActivity.this, MainActivity.class);
      startActivity(intent);
      finish();
    }
    return super.onOptionsItemSelected(item);
  }
 // package
 static void clearRegistrationId(Context context) {
   final SharedPreferences prefs = context.getSharedPreferences(PREFERENCE, Context.MODE_PRIVATE);
   Editor editor = prefs.edit();
   editor.putString("dm_registration", "");
   editor.putLong(LAST_REGISTRATION_CHANGE, System.currentTimeMillis());
   editor.commit();
 }
 /**
  * 保存accesstoken到SharedPreferences
  *
  * @param context Activity 上下文环墄1�7
  * @param token Oauth2AccessToken
  */
 public static void keepAccessToken(Context context, Oauth2AccessToken token) {
   SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND);
   Editor editor = pref.edit();
   editor.putString("token", token.getToken());
   editor.putLong("expiresTime", token.getExpiresTime());
   editor.commit();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.game);

    mQuestionImage = (ImageSwitcher) findViewById(R.id.ImageSwitcher_QuestionImage);
    mQuestionImage.setFactory(new MyImageSwitcherFactory());

    mQuestionText = (TextSwitcher) findViewById(R.id.TextSwitcher_QuestionText);
    mQuestionText.setFactory(new MyTextSwitcherFactory());

    mQuestions = new Hashtable<Integer, Question>(QUESTION_BATCH_SIZE);

    mGameSettings = getSharedPreferences(GAME_PREFERENCES, Context.MODE_PRIVATE);
    int staringQuestionNumber = mGameSettings.getInt(GAME_PREFERENCES_CURRENT_QUESTION, 0);
    if (staringQuestionNumber == 0) {
      Editor editor = mGameSettings.edit();
      editor.putInt(GAME_PREFERENCES_CURRENT_QUESTION, 1);
      editor.commit();
      staringQuestionNumber = 1;
    }
    downloader = new QuizTask();
    downloader.execute(TRIVIA_SERVER_QUESTIONS, staringQuestionNumber);
  }
 /**
  * 写入整型数据
  *
  * @param context 上下文
  * @param key 键
  * @param value 值
  */
 public static void wirteInt(Context context, String key, int value) {
   SharedPreferences preference =
       context.getSharedPreferences(AppConstant.SHARPREFER_FILENAME, Context.MODE_PRIVATE);
   Editor editor = preference.edit();
   editor.putInt(key, value);
   editor.commit();
 }
Beispiel #8
0
 public void saveToPreferences(SharedPreferences preferences) {
   Editor editor = preferences.edit();
   editor.putInt(USER_ID, userId);
   editor.putString(USERNAME, username);
   editor.putString(TOKEN, token);
   editor.commit();
 }
  @Override
  public void RemoveStoredKeyValuePairs(String[] keynames) {
    List<String> successfullKeyPairs = new ArrayList<String>();
    List<String> failedKeyPairs = new ArrayList<String>();
    SharedPreferences settings = GetOtherAppSharedPreferences();
    if (settings != null) {
      for (String keyname : keynames) {
        if (settings.contains(keyname)) {
          Editor ed = settings.edit();
          ed.remove(keyname);
          ed.commit();
          successfullKeyPairs.add(keyname);
        } else failedKeyPairs.add(keyname);
      }
    } else {
      LOGGER.logError("RemoveStoredKeyValuePairs", "Storage Unit is null.");
    }

    LOGGER.logInfo(
        "RemoveStoredKeyValuePairs",
        "Keys removed from storage unit: "
            + successfullKeyPairs.size()
            + "; Keys Not removed from storage unit: "
            + failedKeyPairs.size());
    IActivityManager am =
        (IActivityManager)
            AndroidServiceLocator.GetInstance()
                .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    am.executeJS(
        "Unity.OnKeyValuePairsRemoveCompleted",
        new Object[] {successfullKeyPairs.toArray(), failedKeyPairs.toArray()});
  }
Beispiel #10
0
 /**
  * Moves sorting prefs to public pref store
  *
  * @param context
  */
 private void upgrade3To3_6(final Context context) {
   SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(context);
   Editor editor = publicPrefs.edit();
   editor.putInt(SortHelper.PREF_SORT_FLAGS, Preferences.getInt(SortHelper.PREF_SORT_FLAGS, 0));
   editor.putInt(SortHelper.PREF_SORT_SORT, Preferences.getInt(SortHelper.PREF_SORT_SORT, 0));
   editor.commit();
 }
Beispiel #11
0
 private static boolean a(Context context, String str) {
   boolean z = false;
   synchronized (g) {
     SharedPreferences j = m.a(context).j();
     if (c == null) {
       String[] split = j.getString("pref_msg_ids", com.xiaomi.e.a.f).split(f.i);
       c = new LinkedList();
       for (Object add : split) {
         c.add(add);
       }
     }
     if (c.contains(str)) {
       z = true;
     } else {
       c.add(str);
       if (c.size() > 10) {
         c.poll();
       }
       String a = d.a(c, f.i);
       Editor edit = j.edit();
       edit.putString("pref_msg_ids", a);
       edit.commit();
     }
   }
   return z;
 }
 /**
  * 本地保存channel & 对应版本号
  *
  * @param context
  * @param channel
  */
 private static void saveChannelBySharedPreferences(Context context, String channel) {
   SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
   Editor editor = sp.edit();
   editor.putString(CHANNEL_KEY, channel);
   editor.putInt(CHANNEL_VERSION_KEY, getVersionCode(context));
   editor.commit();
 }
Beispiel #13
0
 public static void setAcceptedEULA(Context context, boolean accepted) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
   Editor editor = prefs.edit();
   editor.putBoolean(PREFERENCE_IS_EULA_ACCEPTED, accepted);
   editor.commit();
   ObjectRelation.addRelation(editor, context);
 }
Beispiel #14
0
 public static void setUpdateDate(Context context, long timestamp) {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
   Editor editor = prefs.edit();
   editor.putLong(PREFERENCE_ONLINE_CATALOG_UPDATE_DATE, timestamp);
   editor.commit();
   ObjectRelation.addRelation(editor, context);
 }
Beispiel #15
0
  /**
   * Starts a new clock in with an offset if boolean is true, otherwise uses the current system
   * time. The offset is X minutes, IE closest 15 minutes or 30, chosen by the user under settings.
   *
   * @param boolean to start new clock in with user set offset.
   */
  protected void startNewClock(boolean offset) {

    Calendar cal = Calendar.getInstance();
    if (offset) {
      cal = roundCalendar(cal);
    }
    String DATE_FORMAT = "dd/MM/yyyy HH:mm";

    if (sp.getBoolean("prefs_time_24", true)) {
      DATE_FORMAT = "dd/MM/yyyy HH:mm";
    } else {
      DATE_FORMAT = "dd/MM/yyyy hh:mm a";
    }
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    String name = sdf.format(cal.getTime());
    dbhelper.open();
    long id =
        dbhelper.createClockIn(
            name, myCurrentAdress, myCurrentNeighborHood, cal.getTimeInMillis(), lastLocation);
    dbhelper.close();
    Editor edit = sp.edit();
    edit.putBoolean(Constants.KEY_IS_CLOCKED_IN, true);
    edit.putLong(Constants.KEY_CLOCKED_ID, id);
    edit.commit();
    checkClockedIn();
  }
 @Override
 public void StoreKeyValuePairs(KeyPair[] keypairs) {
   List<String> successfullKeyPairs = new ArrayList<String>();
   List<String> failedKeyPairs = new ArrayList<String>();
   SharedPreferences settings = GetOtherAppSharedPreferences();
   if (settings != null) {
     for (int i = 0; i < keypairs.length; i++) {
       try {
         String keyname = keypairs[i].getKey();
         String keyvalue = keypairs[i].getValue();
         Editor ed = settings.edit();
         ed.putString(keyname, keyvalue);
         ed.commit();
         successfullKeyPairs.add(keyname);
       } catch (Exception ex) {
         failedKeyPairs.add(keypairs[i].getKey());
       }
     }
   } else {
     LOGGER.logError("StoreKeyValuePairs", "Storage Unit is null.");
   }
   LOGGER.logInfo(
       "StoredKeyValuePairs",
       "Key stored in storage unit: "
           + successfullKeyPairs.size()
           + "; Keys Not stored in storage unit: "
           + failedKeyPairs.size());
   IActivityManager am =
       (IActivityManager)
           AndroidServiceLocator.GetInstance()
               .GetService(AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
   am.executeJS(
       "Unity.OnKeyValuePairsStoreCompleted",
       new Object[] {successfullKeyPairs.toArray(), failedKeyPairs.toArray()});
 }
Beispiel #17
0
 public static void savePreferences(Activity activity, String key, boolean value) {
   SharedPreferences sp =
       PreferenceManager.getDefaultSharedPreferences(activity.getApplicationContext());
   Editor editor = sp.edit();
   editor.putBoolean(key, value);
   editor.commit();
 }
 private void clearKeys() {
   SharedPreferences prefs =
       parentActivity.getSharedPreferences(ACCOUNT_PREFS_NAME, Context.MODE_PRIVATE);
   Editor edit = prefs.edit();
   edit.clear();
   edit.commit();
 }
 public void save(Context context, String preferencesName) {
   SharedPreferences cfg = context.getSharedPreferences(preferencesName, MODE_PRIVATE);
   Editor editor = cfg.edit();
   editor.putString("quad_bootloader_url", mURL);
   editor.putString("quad_bootloader_path", mPath);
   editor.commit();
 }
 private void setLoggedin(boolean loggedIn) {
   SharedPreferences prefs =
       parentActivity.getSharedPreferences(ACCOUNT_PREFS_NAME, Context.MODE_PRIVATE);
   Editor edit = prefs.edit();
   edit.putBoolean(LOGIN_FLAG, loggedIn);
   edit.commit();
 }
Beispiel #21
0
  @SuppressWarnings("nls")
  private void upgrade3To3_3(final Context context) {
    // if RTM, store RTM to secondary preferences
    if (Preferences.getStringValue("rmilk_token") != null) {
      SharedPreferences settings = context.getSharedPreferences("rtm", Context.MODE_WORLD_READABLE);
      Editor editor = settings.edit();
      editor.putString("rmilk_token", Preferences.getStringValue("rmilk_token"));
      editor.putLong("rmilk_last_sync", Preferences.getLong("rmilk_last_sync", 0));
      editor.commit();

      final String message =
          "Hi, it looks like you are a Remember the Milk user! "
              + "In this version of Astrid, RTM is now a community-supported "
              + "add-on. Please go to the Android market to install it!";
      if (context instanceof Activity) {
        ((Activity) context)
            .runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    new AlertDialog.Builder(context)
                        .setTitle(com.todoroo.astrid.api.R.string.DLG_information_title)
                        .setMessage(message)
                        .setPositiveButton(
                            "Go To Market",
                            new AddOnService.MarketClickListener(context, "org.weloveastrid.rmilk"))
                        .setNegativeButton("Later", null)
                        .show();
                  }
                });
      }
    }
  }
 public void handleIntent(Intent intent) {
   if (intent == null) {
     return;
   }
   try {
     Intent firstIntent = getIntent();
     int type = intent.getIntExtra("ntype", 0);
     ;
     switch (type) {
       case ENotification.F_TYPE_PUSH:
         if (null != mBrowser) {
           String data = intent.getStringExtra("data");
           String pushMessage = intent.getStringExtra("message");
           SharedPreferences sp =
               getSharedPreferences(PushReportConstants.PUSH_DATA_SHAREPRE, Context.MODE_PRIVATE);
           Editor editor = sp.edit();
           editor.putString(PushReportConstants.PUSH_DATA_SHAREPRE_DATA, data);
           editor.putString(PushReportConstants.PUSH_DATA_SHAREPRE_MESSAGE, pushMessage);
           editor.commit();
           mBrowser.pushNotify();
         }
         break;
       case ENotification.F_TYPE_USER:
         break;
       case ENotification.F_TYPE_SYS:
         break;
       default:
         getIntentData(intent);
         firstIntent.putExtras(intent);
         break;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
  /** Create login session */
  public void createLocationsSession(String locations) {

    editor.putBoolean(IS_LOADED, true);
    editor.putString(KEY_LOCATIONS, locations);
    // commit changes
    editor.commit();
  }
Beispiel #24
0
 public void setCountryNo(String id) {
   if (id == null) return;
   SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
   Editor edit = pref.edit();
   edit.putString("countryNo", id);
   edit.commit();
 }
 public void saveArchivedTodoList(TodoList tl) throws IOException {
   SharedPreferences settings =
       context.getSharedPreferences(prefArchivedTodoFile, Context.MODE_PRIVATE);
   Editor editor = settings.edit();
   editor.putString(atlkey, todoListToString(tl));
   editor.commit();
 }
  public void onTabSelected(Tab tab, FragmentTransaction ft) {

    ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);

    switch (tab.getPosition()) {
      case 0:
        ft.show(adaptiveFragment);
        break;
      case 1:
        ft.show(gaugesFragment);
        break;
      case 2:
        if (connected != null && connected.isAlive()) {
          progress = ProgressDialog.show(ctx, "Fuel Map", "Reading map values 0/512...");

          mapOffset = 0;
          mapMode = true;
          sendRequest(mapOffset);
        }

        ft.show(fuelFragment);
        break;
    }

    // we don't want to overwrite our pref if we're in onCreate
    if (lvDevices != null) {
      Editor edit = prefs.edit();
      edit.putInt("prefs_last_tab", tab.getPosition());
      edit.commit();
    }
  }
 void saveVolume() {
   if (restored) {
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putInt("volume" + speakermode, am.getStreamVolume(stream()));
     edit.commit();
   }
 }
  /** Deletes the currentSelectedConnection from the list of connections and saves it. */
  private void deleteConnection() {
    // Only if this is a new connection do we need to add it to the list
    if (!newConnection) {

      String newListOfConnections = new String();
      if (connectionsArray != null) {
        for (int i = 0; i < connectionsArray.length; i++) {
          if (!connectionsArray[i].equals(currentSelectedConnection)) {
            newListOfConnections += " " + connectionsArray[i];
          }
        }

        android.util.Log.d(TAG, "Deleted connection, current list: " + newListOfConnections);
        SharedPreferences sp =
            appContext.getSharedPreferences("generalSettings", Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString("connections", newListOfConnections.trim());
        editor.apply();

        // Delete the screenshot associated with this connection.
        File toDelete = new File(getFilesDir() + "/" + currentSelectedConnection + ".png");
        toDelete.delete();

        // Reload the list of connections from preferences for consistency.
        loadConnections();
      }
    }
  }
Beispiel #29
0
  @Override
  public void onCreate() {
    ACRA.init(this);
    super.onCreate();
    this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
    this.prefs.registerOnSharedPreferenceChangeListener((OnSharedPreferenceChangeListener) this);

    // See if the user has the preference for opening up the last used database. If so, set the path
    // to it.
    if (this.prefs.getBoolean("openLastUsed", false)) {
      // First see if the path still exists if not then the user did something and we need to change
      // the user preference and not
      // try to open any file this time around.
      String path = this.prefs.getString("Full Path", "");
      if (fileExists(path)) setFullPath(path);
      else {
        Editor edit = this.prefs.edit();
        edit.putBoolean("openLastUsed", false);
        edit.putString("Full Path", "");
        edit.apply();
      }
    }

    String value = this.prefs.getString("updateFrequency", "0");
    if (value.equals("-1")) this.setAutoUpdate(true);
    else this.setAutoUpdate(false);
    Splits = new ArrayList<Split>();
    Splits.clear();
  }
    @Override
    protected void onPostExecute(SharedDeckDownload download) {
      Log.i(AnkiDroidApp.TAG, "onPostExecute");
      if (download.getStatus() == Download.STATUS_COMPLETE) {
        download.setStatus(SharedDeckDownload.STATUS_UPDATING);
        notifySharedDeckObservers();

        // Unzip deck and media
        String unzippedDeckName =
            unzipSharedDeckFile(
                mDestination + "/tmp/" + download.getTitle() + ".zip", download.getTitle());
        download.setTitle(unzippedDeckName);

        // Update all cards in deck
        SharedPreferences pref = PrefSettings.getSharedPrefs(getBaseContext());
        Editor editor = pref.edit();
        editor.putLong(
            "numUpdatedCards:" + mDestination + "/tmp/" + download.getTitle() + ".anki.updating",
            0);
        editor.commit();

        new UpdateDeckTask().execute(new Payload(new Object[] {download}));

      } else if (download.getStatus() == Download.STATUS_CANCELLED) {
        mSharedDeckDownloads.remove(download);
        notifySharedDeckObservers();
        stopIfFinished();
      }
    }