Ejemplo n.º 1
0
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.go_local:
       // 标记为本地媒体
       // editor.putBoolean("isLiveMedia", false);
       // 暂时去掉本地媒体播放,所以这里仍然设置为直播电视
       editor.putBoolean("isLiveMedia", true);
       editor.commit();
       startLocalMedia();
       break;
     case R.id.go_live:
       // 标记为直播电视媒体
       editor.putBoolean("isLiveMedia", true);
       editor.commit();
       startLiveMedia();
       break;
     case R.id.go_userdef:
       startUserLoadMedia();
       break;
     case R.id.go_setup:
       startSetupMedia();
       break;
     default:
       Log.d(LOGTAG, "not supported btn id");
   }
 }
    @Override
    protected Payload doInBackground(Payload... args) {

      Payload data = doInBackgroundLoadDeck(args);
      if (data.returnType == DeckTask.DECK_LOADED) {
        double now = System.currentTimeMillis();
        HashMap<String, Object> results = (HashMap<String, Object>) data.result;
        Deck deck = (Deck) results.get("deck");
        // deck.beforeUpdateCards();
        // deck.updateAllCards();
        SharedDeckDownload download = (SharedDeckDownload) args[0].data[0];
        SharedPreferences pref = PrefSettings.getSharedPrefs(getBaseContext());
        String updatedCardsPref =
            "numUpdatedCards:" + mDestination + "/tmp/" + download.getTitle() + ".anki.updating";
        long totalCards = deck.retrieveCardCount();
        download.setNumTotalCards((int) totalCards);
        long updatedCards = pref.getLong(updatedCardsPref, 0);
        download.setNumUpdatedCards((int) updatedCards);
        long batchSize = Math.max(100, totalCards / 200);
        mRecentBatchTimings = new long[sRunningAvgLength];
        mTotalBatches = ((double) totalCards) / batchSize;
        int currentBatch = (int) (updatedCards / batchSize);
        long runningAvgCount = 0;
        long batchStart;
        mElapsedTime = 0;
        while (updatedCards < totalCards
            && download.getStatus() == SharedDeckDownload.STATUS_UPDATING) {
          batchStart = System.currentTimeMillis();
          updatedCards = deck.updateAllCardsFromPosition(updatedCards, batchSize);
          Editor editor = pref.edit();
          editor.putLong(updatedCardsPref, updatedCards);
          editor.commit();
          download.setNumUpdatedCards((int) updatedCards);
          publishProgress();
          estimateTimeToCompletion(
              download, currentBatch, runningAvgCount, System.currentTimeMillis() - batchStart);
          currentBatch++;
          runningAvgCount++;
        }
        if (download.getStatus() == SharedDeckDownload.STATUS_UPDATING) {
          data.success = true;
        } else if (download.getStatus() == SharedDeckDownload.STATUS_PAUSED) {
          Editor editor = pref.edit();
          String pausedPref =
              "paused:" + mDestination + "/tmp/" + download.getTitle() + ".anki.updating";
          editor.putBoolean(pausedPref, true);
          editor.commit();
          data.success = false;
          Log.i(AnkiDroidApp.TAG, "pausing deck " + download.getTitle());
        } else if (download.getStatus() == SharedDeckDownload.STATUS_CANCELLED) {
          data.success = false;
        }
        // Log.i(AnkiDroidApp.TAG, "Time to update deck = " + download.getEstTimeToCompletion() + "
        // sec.");
        // deck.afterUpdateCards();
      } else {
        data.success = false;
      }
      return data;
    }
Ejemplo n.º 3
0
 public void checkAndRemindThemToGiveMeAGoodRating() {
   final SharedPreferences mPrefs =
       PDActivity.this.getSharedPreferences(SHARED_PREFERENCES_APPSTUFF, 0);
   long firstopened = mPrefs.getLong("firstopened", -1);
   if (firstopened < 0) {
     firstopened = System.currentTimeMillis();
     Editor e = mPrefs.edit();
     e.putLong("firstopened", firstopened);
     e.commit();
     return;
   }
   long timenow = System.currentTimeMillis();
   long elapsed = timenow - firstopened;
   long maxtime = 1000 * 60 * 15; // 15 minute
   if (!(mPrefs.getBoolean("popupshown", false))) {
     if (elapsed > maxtime) {
       //	        	if (System.currentTimeMillis() % 10 == 1) {
       if (getResources()
           .getBoolean(com.rj.processing.plasmasound.R.bool.should_bug_about_donate)) {
         showRatingDialog();
       }
       Editor e = mPrefs.edit();
       e.putBoolean("popupshown", true);
       e.commit();
     }
   }
 }
Ejemplo n.º 4
0
  /**
   * Shows keeping the access keys returned from Trusted Authenticator in a local store, rather than
   * storing user name & password, and re-authenticating each time (which is not to be done, ever).
   */
  private void storeAuth(AndroidAuthSession session) {
    // Store the OAuth 2 access token, if there is one.
    String oauth2AccessToken = session.getOAuth2AccessToken();
    Log.d(TAG, oauth2AccessToken);

    if (oauth2AccessToken != null) {
      SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
      Editor edit = prefs.edit();
      edit.putString(ACCESS_KEY_NAME, "oauth2:");
      edit.putString(ACCESS_SECRET_NAME, oauth2AccessToken);
      edit.commit();
      return;
    }
    // Store the OAuth 1 access token, if there is one.  This is only necessary if
    // you're still using OAuth 1.
    AccessTokenPair oauth1AccessToken = session.getAccessTokenPair();
    if (oauth1AccessToken != null) {
      SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
      Editor edit = prefs.edit();
      edit.putString(ACCESS_KEY_NAME, oauth1AccessToken.key);
      edit.putString(ACCESS_SECRET_NAME, oauth1AccessToken.secret);
      edit.commit();
      return;
    }
  }
 /** Listener for the On/Off switch */
 @Override
 public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
   if (key.equals(ONOFF_KEY)) {
     running = !running;
     Editor editor = sharedPreferences.edit();
     editor.putBoolean(IS_ON, running);
     editor.commit();
     if (running) {
       if (runNormal)
         SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext());
       else
         SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext());
     } else {
       if (runNormal)
         SensorPreferenceActivity.stop(SensorPreferenceActivity.this.getApplicationContext());
       else
         SensorPreferenceActivity.stopLite(SensorPreferenceActivity.this.getApplicationContext());
     }
   }
   if (key.equals(ANALYTIC_KEY)) {
     runNormal = !runNormal;
     Editor editor = sharedPreferences.edit();
     editor.putBoolean(ANALYTIC_ON, runNormal);
     editor.commit();
     if (running) {
       if (runNormal) {
         SensorPreferenceActivity.stopLite(SensorPreferenceActivity.this.getApplicationContext());
         SensorPreferenceActivity.start(SensorPreferenceActivity.this.getApplicationContext());
       } else {
         SensorPreferenceActivity.stop(SensorPreferenceActivity.this.getApplicationContext());
         SensorPreferenceActivity.startLite(SensorPreferenceActivity.this.getApplicationContext());
       }
     }
   }
 }
    @Override
    protected void onPostExecute(Payload result) {
      super.onPostExecute(result);
      HashMap<String, Object> results = (HashMap<String, Object>) result.result;
      Decks deck = (Decks) results.get("deck");
      // Close the previously opened deck.
      //            DeckManager.closeDeck(deck.getDeckPath());

      SharedDeckDownload download = (SharedDeckDownload) result.data[0];
      SharedPreferences pref = PrefSettings.getSharedPrefs(getBaseContext());
      Editor editor = pref.edit();

      Log.i(AnkiDroidApp.TAG, "Finished deck " + download.getFilename() + " " + result.success);
      if (result.success) {
        // Put updated cards to 0
        // TODO: Why do we need to zero the updated cards?
        editor.putLong(
            "numUpdatedCards:" + mDestination + "/tmp/" + download.getFilename() + ".anki.updating",
            0);
        editor.commit();
        // Move deck and media to the default deck path
        new File(mDestination + "/tmp/" + download.getFilename() + ".anki.updating")
            .renameTo(new File(mDestination + "/" + download.getFilename() + ".anki"));
        new File(mDestination + "/tmp/" + download.getFilename() + ".media/")
            .renameTo(new File(mDestination + "/" + download.getFilename() + ".media/"));
        mSharedDeckDownloads.remove(download);
        showNotification(download.getTitle(), download.getFilename());
      } else {
        // If paused do nothing, if cancelled clean up
        if (download.getStatus() == Download.STATUS_CANCELLED) {
          try {
            new File(mDestination + "/tmp/" + download.getFilename() + ".anki.updating").delete();
            File mediaFolder =
                new File(mDestination + "/tmp/" + download.getFilename() + ".media/");
            if (mediaFolder != null && mediaFolder.listFiles() != null) {
              for (File f : mediaFolder.listFiles()) {
                f.delete();
              }
              mediaFolder.delete();
            }
          } catch (SecurityException e) {
            Log.e(AnkiDroidApp.TAG, "SecurityException = " + e.getMessage());
            e.printStackTrace();
          }
          editor.remove(
              "numUpdatedCards:"
                  + mDestination
                  + "/tmp/"
                  + download.getFilename()
                  + ".anki.updating");
          editor.remove(
              "paused:" + mDestination + "/tmp/" + download.getFilename() + ".anki.updating");
          editor.commit();
          mSharedDeckDownloads.remove(download);
        }
      }
      notifySharedDeckObservers();
      stopIfFinished();
    }
Ejemplo n.º 7
0
  private boolean loadSharedPreferencesFromFile(File src) {
    // this should probably be in a thread if it ever gets big
    boolean res = false;
    ObjectInputStream input = null;
    try {
      input = new ObjectInputStream(new FileInputStream(src));
      Editor prefEdit = PreferenceManager.getDefaultSharedPreferences(this).edit();
      prefEdit.clear();
      // first object is preferences
      Map<String, ?> entries = (Map<String, ?>) input.readObject();
      for (Entry<String, ?> entry : entries.entrySet()) {
        Object v = entry.getValue();
        String key = entry.getKey();

        if (v instanceof Boolean) prefEdit.putBoolean(key, ((Boolean) v).booleanValue());
        else if (v instanceof Float) prefEdit.putFloat(key, ((Float) v).floatValue());
        else if (v instanceof Integer) prefEdit.putInt(key, ((Integer) v).intValue());
        else if (v instanceof Long) prefEdit.putLong(key, ((Long) v).longValue());
        else if (v instanceof String) prefEdit.putString(key, ((String) v));
      }
      prefEdit.commit();

      // second object is admin options
      Editor adminEdit = getSharedPreferences(AdminPreferencesActivity.ADMIN_PREFERENCES, 0).edit();
      adminEdit.clear();
      // first object is preferences
      Map<String, ?> adminEntries = (Map<String, ?>) input.readObject();
      for (Entry<String, ?> entry : adminEntries.entrySet()) {
        Object v = entry.getValue();
        String key = entry.getKey();

        if (v instanceof Boolean) adminEdit.putBoolean(key, ((Boolean) v).booleanValue());
        else if (v instanceof Float) adminEdit.putFloat(key, ((Float) v).floatValue());
        else if (v instanceof Integer) adminEdit.putInt(key, ((Integer) v).intValue());
        else if (v instanceof Long) adminEdit.putLong(key, ((Long) v).longValue());
        else if (v instanceof String) adminEdit.putString(key, ((String) v));
      }
      adminEdit.commit();

      res = true;
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } finally {
      try {
        if (input != null) {
          input.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
    return res;
  }
  @Override
  protected void onDialogClosed(boolean positiveResult) {
    super.onDialogClosed(positiveResult);

    if (positiveResult) {
      String alphaTag = mPhone.getLine1AlphaTag();
      if (TextUtils.isEmpty(alphaTag)) {
        // No tag, set it.
        alphaTag = getContext().getString(R.string.msisdn_alpha_tag);
      }

      mPhone.setLine1Number(
          alphaTag, getText(), mHandler.obtainMessage(MyHandler.MESSAGE_SET_MSISDN));
      if (mTcpListener != null) {
        mTcpListener.onStarted(this, false);
      }

      // Save the number
      SharedPreferences prefs = getSharedPreferences();
      Editor editor = prefs.edit();

      String phoneNum = getText().trim();
      String savedNum = prefs.getString(PHONE_NUMBER, null);

      // If there is no string, treat it as null
      if (phoneNum.length() == 0) {
        phoneNum = null;
      }

      if (phoneNum == null && savedNum == null) {
        Log.d(LOG_TAG, "No phone number set yet");
      } else if (TextUtils.equals(phoneNum, savedNum)) {
        /* Save phone number only if there is some number set and
        it is not equal to the already saved one */
        if (DBG) {
          Log.d(LOG_TAG, "Saving phone number: " + phoneNum);
        }

        editor.putString(PHONE_NUMBER, phoneNum);
        editor.commit();
      } else if (phoneNum == null && savedNum != null) {
        /* Remove saved number only if there is some saved and
        there is no number set */
        if (DBG) {
          Log.d(LOG_TAG, "Removing phone number");
        }

        editor.remove(PHONE_NUMBER);
        editor.commit();
      } else if (DBG) {
        Log.d(LOG_TAG, "No change");
      }
    }
  }
Ejemplo n.º 9
0
  private void setDefaultValues() {
    settings = getSharedPreferences(sharedPrefsFile, MODE_PRIVATE);

    for (int i = 0; i < SipdroidEngine.LINES; i++) {
      String j = (i != 0 ? "" + i : "");
      if (settings.getString(PREF_SERVER + j, "").equals("")) {
        CheckBoxPreference cb =
            (CheckBoxPreference) getPreferenceScreen().findPreference(PREF_WLAN + j);
        cb.setChecked(true);
        Editor edit = settings.edit();

        edit.putString(PREF_PORT + j, DEFAULT_PORT);
        edit.putString(PREF_SERVER + j, DEFAULT_SERVER);
        edit.putString(PREF_PREF + j, DEFAULT_PREF);
        edit.putString(PREF_PROTOCOL + j, DEFAULT_PROTOCOL);
        edit.commit();
        Receiver.engine(this).updateDNS();
        reload();
      }
    }
    if (settings.getString(PREF_STUN_SERVER, "").equals("")) {
      Editor edit = settings.edit();

      edit.putString(PREF_STUN_SERVER, DEFAULT_STUN_SERVER);
      edit.putString(PREF_STUN_SERVER_PORT, DEFAULT_STUN_SERVER_PORT);
      edit.commit();
      reload();
    }

    if (!settings.contains(PREF_MWI_ENABLED)) {
      CheckBoxPreference cb =
          (CheckBoxPreference) getPreferenceScreen().findPreference(PREF_MWI_ENABLED);
      cb.setChecked(true);
    }
    if (!settings.contains(PREF_REGISTRATION)) {
      CheckBoxPreference cb =
          (CheckBoxPreference) getPreferenceScreen().findPreference(PREF_REGISTRATION);
      cb.setChecked(true);
    }
    if (Sipdroid.market) {
      CheckBoxPreference cb = (CheckBoxPreference) getPreferenceScreen().findPreference(PREF_3G);
      cb.setChecked(false);
      CheckBoxPreference cb2 = (CheckBoxPreference) getPreferenceScreen().findPreference(PREF_EDGE);
      cb2.setChecked(false);
      getPreferenceScreen().findPreference(PREF_3G).setEnabled(false);
      getPreferenceScreen().findPreference(PREF_EDGE).setEnabled(false);
    }

    settings.registerOnSharedPreferenceChangeListener(this);

    updateSummaries();
  }
Ejemplo n.º 10
0
 private void saveFavourite() {
   SharedPreferences shared =
       ((Activity) mContext).getSharedPreferences("favourite_filter", Activity.MODE_PRIVATE);
   Editor editor = shared.edit();
   editor.remove("favourite_filter_list");
   editor.commit();
   String str = "";
   for (int i = 0; i < favouriteFilterInfos.size(); i++) {
     str += favouriteFilterInfos.get(i).getFilterType() + ",";
   }
   editor.putString("favourite_filter_list", str);
   editor.commit();
 }
Ejemplo n.º 11
0
 @Override
 protected void onPause() {
   // TODO Auto-generated method stub
   super.onPause();
   position = pagefactory.getPosition();
   Editor editor = sp.edit();
   editor.putInt(id + "begin", position[0]);
   editor.putInt(id + "end", position[1]);
   editor.commit();
   int fontSize = pagefactory.getTextFont();
   Editor editor2 = sp.edit();
   editor2.putInt("fontsize", fontSize);
   editor2.commit();
 }
Ejemplo n.º 12
0
        @Override
        public void onClick(View v) {
          // TODO Auto-generated method stub
          switch (v.getId()) {
            case R.id.iv_setting_leftarrow:
              finish();
              break;
            case R.id.rl_setting_version:
              progressDialog.show();
              new Thread(r_CheckNewVersion).start();
              break;
            case R.id.rl_setting_storage:
              File file = new File(Environment.getExternalStorageDirectory() + "/CourtPocket");
              if (file.exists()) {
                File flist[] = file.listFiles();
                for (int i = 0; i < flist.length; i++) {
                  flist[i].delete();
                }
                tv_storage.setText("0KB");
              }
              break;
            case R.id.rl_setting_notification:
              SharedPreferences prefs =
                  PreferenceManager.getDefaultSharedPreferences(SettingActivity.this);
              Boolean isNotificationOpen = prefs.getBoolean("isNotificationOpen", true);
              if (isNotificationOpen) {
                tv_notification.setText("关闭");
                Editor pEdit = prefs.edit();
                pEdit.putBoolean("isNotificationOpen", false);
                pEdit.commit();
              } else {
                tv_notification.setText("打开");
                Editor pEdit = prefs.edit();
                pEdit.putBoolean("isNotificationOpen", true);
                pEdit.commit();
              }
              break;
            case R.id.btn_setting_quitlogin:
              Data.ISLOGIN = false;

              // 帐号反注册信鸽推送
              XGPushManager.registerPush(SettingActivity.this, "*");

              setResult(RESULT_OK, SettingActivity.this.getIntent());
              finish();
              break;
          }
        }
 void saveVolume() {
   if (restored) {
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putInt("volume" + speakermode, am.getStreamVolume(stream()));
     edit.commit();
   }
 }
Ejemplo n.º 14
0
 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();
 }
  /**
   * 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();
  }
Ejemplo n.º 16
0
  /** Create login session */
  public void createLocationsSession(String locations) {

    editor.putBoolean(IS_LOADED, true);
    editor.putString(KEY_LOCATIONS, locations);
    // commit changes
    editor.commit();
  }
Ejemplo n.º 17
0
 /**
  * 保存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();
 }
Ejemplo n.º 18
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();
                  }
                });
      }
    }
  }
 // 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();
 }
 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();
 }
Ejemplo n.º 21
0
 /**
  * 写入整型数据
  *
  * @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();
 }
  @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);
  }
Ejemplo n.º 23
0
  /**
   * Internal Method to create new File in internal memory for each provider and save accessGrant
   *
   * @param auth AuthProvider
   */
  private void writeToken(AuthProvider auth) {

    AccessGrant accessGrant = auth.getAccessGrant();
    String key = accessGrant.getKey();
    String secret = accessGrant.getSecret();

    String providerid = accessGrant.getProviderId();

    Map<String, Object> attributes = accessGrant.getAttributes();

    Editor edit = PreferenceManager.getDefaultSharedPreferences(getContext()).edit();

    edit.putString(mProviderName.toString() + " key", key);
    edit.putString(mProviderName.toString() + " secret", secret);
    edit.putString(mProviderName.toString() + " providerid", providerid);

    if (attributes != null) {
      for (Map.Entry entry : attributes.entrySet()) {
        System.out.println(entry.getKey() + ", " + entry.getValue());
      }

      for (String s : attributes.keySet()) {
        edit.putString(
            mProviderName.toString() + "attribute " + s, String.valueOf(attributes.get(s)));
      }
    }

    edit.commit();
  }
Ejemplo n.º 24
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();
 }
Ejemplo n.º 25
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();
 }
 void saveSettings() {
   if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
       .getBoolean(
           org.sipdroid.sipua.ui.Settings.PREF_OLDVALID,
           org.sipdroid.sipua.ui.Settings.DEFAULT_OLDVALID)) {
     int oldvibrate = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
     int oldvibrate2 = am.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION);
     if (!PreferenceManager.getDefaultSharedPreferences(Receiver.mContext)
         .contains(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2))
       oldvibrate2 = AudioManager.VIBRATE_SETTING_ON;
     int oldpolicy =
         android.provider.Settings.System.getInt(
             cr,
             android.provider.Settings.System.WIFI_SLEEP_POLICY,
             Settings.System.WIFI_SLEEP_POLICY_DEFAULT);
     Editor edit = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).edit();
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE, oldvibrate);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDVIBRATE2, oldvibrate2);
     edit.putInt(org.sipdroid.sipua.ui.Settings.PREF_OLDPOLICY, oldpolicy);
     edit.putInt(
         org.sipdroid.sipua.ui.Settings.PREF_OLDRING,
         am.getStreamVolume(AudioManager.STREAM_RING));
     edit.putBoolean(org.sipdroid.sipua.ui.Settings.PREF_OLDVALID, true);
     edit.commit();
   }
 }
Ejemplo n.º 27
0
 @Override
 protected void onPostExecute(String result) {
   // TODO Auto-generated method stub
   super.onPostExecute(result);
   if (pd != null && pd.isShowing()) pd.dismiss();
   if (result != null && result.equals("1")) {
     Log.d("check", result + "_");
     // if(upload!=null)
     uploadList = db.retriveUpload();
     for (Upload up : uploadList) {
       db.deleteUpload(up);
     }
     Editor edit = preference.edit();
     edit.putInt("upload", 2);
     edit.putInt("playMode", 2);
     edit.putString("activity", null);
     edit.clear();
     edit.commit();
     finish();
   } else {
     try {
       alert.showAlertDialog(home.this, "Error", "Unable to process server", true);
     } catch (Exception e) {
       // TODO: handle exception
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 28
0
  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();
    }
  }
  @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);
  }
Ejemplo n.º 30
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();
  }