Ejemplo n.º 1
0
 /** 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 */
 public static void put(Context context, String key, Object object) {
   SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = sp.edit();
   if (object instanceof String) {
     editor.putString(key, (String) object);
   } else if (object instanceof Integer) {
     editor.putInt(key, (Integer) object);
   } else if (object instanceof Boolean) {
     editor.putBoolean(key, (Boolean) object);
   } else if (object instanceof Float) {
     editor.putFloat(key, (Float) object);
   } else if (object instanceof Long) {
     editor.putLong(key, (Long) object);
   } else if (object instanceof String[]) {
     StringBuilder datas = new StringBuilder();
     String[] data = (String[]) object;
     for (int i = 0; i < data.length; i++) {
       if (i != 0) {
         datas.append(":");
       }
       datas.append(data[i]);
     }
     editor.putString(key, datas.toString());
   } else {
     editor.putString(key, object.toString());
   }
   SharedPreferencesCompat.apply(editor);
 }
Ejemplo n.º 2
0
  @Override
  protected void onPause() {
    super.onPause();

    setSip1(ip1.getText().toString());
    setSip2(ip2.getText().toString());
    setSip3(ip3.getText().toString());
    setSip4(ip4.getText().toString());
    setSport(port.getText().toString());
    setIport(Integer.parseInt(port.getText().toString()));

    //        setIp(getSip1() + "." + getSip2() + "." + getSip3() + "." + getSip4());

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("ip1", getSip1());
    editor.putString("ip2", getSip2());
    editor.putString("ip3", getSip3());
    editor.putString("ip4", getSip4());
    editor.putString("port", getSport());
    //        editor.putString("ip",getIp());
    editor.putString("ip", getSip1() + "." + getSip2() + "." + getSip3() + "." + getSip4());

    editor.commit();
  }
  private void useTheme(final Context context) {
    SharedPreferences preferences =
        context.getSharedPreferences(Theme.PREFS_NAME_THEME_SETTING, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(Theme.PREFS_KEY_PACKAGE_NAME, entry.getPackageName());
    editor.putInt(Theme.PREFS_KEY_RESOURCE_TYPE, Theme.RESOURCES_FROM_APK);
    editor.putString(Theme.PREFS_KEY_THEME_NAME, entry.getName());
    editor.commit();

    Dialog dialog =
        new AlertDialog.Builder(context)
            .setTitle(R.string.title_dialog_alert)
            .setMessage("重启应用皮肤才能生效,确认要退出应用吗?")
            .setPositiveButton(
                R.string.btn_confirm,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    exitApp(context);
                  }
                })
            .setNegativeButton(
                R.string.btn_cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                })
            .create();
    dialog.show();
  }
  @Test
  public void testInitialValue() {

    // Set verse preference to "20"
    Context context = InstrumentationRegistry.getTargetContext();
    String defaultPreferencesName = context.getPackageName() + "_preferences";
    SharedPreferences prefs =
        context.getSharedPreferences(defaultPreferencesName, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(Settings.KEY_PREF_VERSE, "20");
    editor.putString(Settings.KEY_PREF_FILENAME, "en_ulb_gen_01-20_01");
    editor.commit();

    // Touch the "new_record" button (the big microphone)
    onView(withId(R.id.new_record)).perform(click());

    // TODO: What's the right way to wait for the UI to update the picker?
    try {
      Thread.sleep(2500);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // Confirm that chunk picker shows chunk 20
    onView(withId(R.id.numberPicker)).check(matches(hasNumberPickerDisplayedValue(is("20"))));
  }
Ejemplo n.º 5
0
 private void saveUserInfo() {
   SharedPreferences userData = getSharedPreferences(PREFS_NAME, 0);
   SharedPreferences.Editor editor = userData.edit();
   editor.putString("username", username.getText().toString());
   editor.putString("userType", userType.toString());
   editor.commit();
 }
Ejemplo n.º 6
0
 // @TODO this is a sample to get through the database
 public void buildDummy(SQLiteDatabase db) {
   // set query to execute
   String query = "SELECT * FROM Users;";
   // set a cursor to run the query
   Cursor c = db.rawQuery(query, null);
   // move to the first row
   c.moveToFirst();
   // clear the shared preferences
   editor.clear();
   // set both the shared prefernces and the user elements...
   editor.putString("name", name = c.getString(1));
   editor.putFloat("weight", weight = c.getFloat(2));
   editor.putFloat("height", height = c.getFloat(3));
   editor.putFloat("BMI", BMI = c.getFloat(4));
   editor.putFloat("BMR", BMR = c.getFloat(5));
   editor.putFloat("Starting_Weight", start_weight = c.getFloat(6));
   editor.putInt("Start_LVL", start_lvl = c.getInt(7));
   editor.putFloat("Cal_Needs", cal_needs = c.getFloat(8));
   editor.putFloat("Current_Weight", cur_weight = c.getFloat(9));
   editor.putInt("Cur_Lvl", cur_lvl = c.getInt(10));
   editor.putString("Email", email = c.getString(11));
   editor.putString("Phone", phone = c.getString(12));
   // commit changes to shared preferences
   editor.commit();
 }
Ejemplo n.º 7
0
  public void startService(String aURL, String aAUTH, String aKEYS, String aSYSTEMURL) {
    InsiderrService.BASEURL = aURL;
    InsiderrService.AUTH = aAUTH;
    InsiderrService.KEYS = aKEYS;
    InsiderrService.SYSTEMURL = aSYSTEMURL;
    Log.d("Python", String.format("BASEURL: %s", InsiderrService.BASEURL));
    // Log.d( "Python", String.format("AUTH: %s",  InsiderrService.AUTH));
    Log.d("Python", String.format("KEYS: %s", InsiderrService.KEYS));
    Log.d("Python", String.format("SYSTEMURL: %s", InsiderrService.SYSTEMURL));

    SharedPreferences settings =
        getSharedPreferences(InsiderrService.PREFS_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString("BASEURL", aURL);
    editor.putString("AUTH", aAUTH);
    editor.putString("KEYS", aKEYS);
    editor.putString("SYSTEMURL", aSYSTEMURL);
    editor.putString("HASH", null);
    editor.commit();

    if (intentService == null) {
      Log.d("Python", "New service intent");
      intentService = new Intent(this, InsiderrService.class);
    } else {
      Log.d("Python", "Old service intent");
      stopService(intentService);
    }

    // now it should read the new values
    startService(intentService);
    // bindService(intentService, mConnection, Context.BIND_AUTO_CREATE);
  }
  public void savefNordSettings(View view) {
    switch (view.getId()) {
      case R.id.fNordSettingsSaveButton:
        if (username.getText().length() == 0 | password.getText().length() == 0) {
          Toast.makeText(this, "Please enter Username and Password", Toast.LENGTH_LONG).show();
          return;
        }
        SharedPreferences settings = getSharedPreferences(fNordSettingsFilename, 0);
        SharedPreferences.Editor editor = settings.edit();

        try {
          editor.putString(
              "username", SimpleCrypto.encrypt(fNordCryptoKey, username.getText().toString()));
          editor.putString(
              "password", SimpleCrypto.encrypt(fNordCryptoKey, password.getText().toString()));
          editor.commit();
        } catch (Exception e) {
          Log.v("Exception e", "Oh noes!");
        }

        Toast.makeText(this, "Settings saved.", Toast.LENGTH_LONG).show();

        setResult(1, new Intent());
        finish();
    }
  }
Ejemplo n.º 9
0
 public void save(String key, String value) {
   SharedPreferences sp = mContext.getSharedPreferences("mysp", Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = sp.edit();
   editor.putString("key", key);
   editor.putString("value", value);
   editor.commit();
 }
Ejemplo n.º 10
0
  @Override
  protected void onStop() {
    super.onStop();

    if (cursor != null) {
      cursor.close();
      cursor = null;
    }

    if (dbCon != null) {
      dbCon.close();
      dbCon = null;
    }

    if (db != null) {
      db.close();
      db = null;
    }

    // store for later re-use
    SharedPreferences settings = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = settings.edit();
    prefEditor.putLong(PREF_DATE_RANGE_ID, dateRange.id);
    prefEditor.putString(PREF_TYPE_SELECTOR, typeSelector);
    prefEditor.putString(PREF_CATEGORY_SELECTOR, categorySelector);
    prefEditor.putString(PREF_DESCRIPTION_SELECTOR, descriptionSelector);
    prefEditor.putString(PREF_DATE_SELECTOR, Util.formatDateForDB(dateSelector));
    prefEditor.commit();
  }
Ejemplo n.º 11
0
  /** send this when walk completed */
  private void walkCompleted() {
    if (!AndyUtils.isNetworkAvailable(mapActivity)) {
      AndyUtils.showToast(getResources().getString(R.string.toast_no_internet), mapActivity);
      return;
    }
    ClientRequestFragment.flag = 0;

    SharedPreferences sharedPreferences =
        getActivity().getSharedPreferences(AndyConstants.PREF_NAME_ITEM, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor;
    editor = sharedPreferences.edit();
    editor.putString("Customername", "");
    editor.putString("amount", "");
    editor.putString("phoneno.", "");
    editor.putString("address", "");
    editor.putString("locality", "");

    editor.commit();

    AndyUtils.showCustomProgressDialog(
        mapActivity, "", getResources().getString(R.string.progress_send_request), false);

    HashMap<String, String> map = new HashMap<String, String>();
    map.put(AndyConstants.URL, AndyConstants.ServiceType.WALK_COMPLETED);
    map.put(AndyConstants.Params.ID, preferenceHelper.getUserId());
    map.put(AndyConstants.Params.REQUEST_ID, String.valueOf(preferenceHelper.getRequestId()));
    map.put(AndyConstants.Params.TOKEN, preferenceHelper.getSessionToken());
    map.put(AndyConstants.Params.LATITUDE, preferenceHelper.getWalkerLatitude());
    map.put(AndyConstants.Params.LONGITUDE, preferenceHelper.getWalkerLongitude());
    map.put(AndyConstants.Params.DISTANCE, preferenceHelper.getDistance() + "");
    map.put(AndyConstants.Params.TIME, time);
    new HttpRequester(mapActivity, map, AndyConstants.ServiceCode.WALK_COMPLETED, this);
  }
  private void loginApiSuccess(Object obj) {

    if (obj instanceof User) {

      final User user = (User) obj;

      if (user.getCode() == 200) {
        if (DemoContext.getInstance() != null && user.getResult() != null) {
          SharedPreferences.Editor edit = DemoContext.getInstance().getSharedPreferences().edit();
          edit.putString("DEMO_USER_ID", user.getResult().getId());
          edit.putString("DEMO_USER_NAME", user.getResult().getUsername());
          edit.putString("DEMO_USER_PORTRAIT", user.getResult().getPortrait());
          edit.apply();
          Log.e(TAG, "-------login success------");

          httpLoginSuccess(user);
        }
      } else if (user.getCode() == 103) {

        if (mDialog != null) mDialog.dismiss();

        WinToast.toast(LoginActivity.this, "密码错误");
      } else if (user.getCode() == 104) {

        if (mDialog != null) mDialog.dismiss();

        WinToast.toast(LoginActivity.this, "账号错误");
      }
    }
  }
Ejemplo n.º 13
0
 /** Configure account. */
 private void configureAccount() {
   final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
   final SharedPreferences.Editor edit = settings.edit();
   edit.putString(MainApplication.ACCOUNT_USERNAME_KEY, accountJID.getText().toString());
   edit.putString(MainApplication.ACCOUNT_PASSWORD_KEY, accountPassword.getText().toString());
   edit.commit();
 }
  private void setSyncAccount(String account) {
    if (!getSyncAccountName(this).equals(account)) {
      SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = settings.edit();
      if (account != null) {
        editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
      } else {
        editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
      }
      editor.commit();

      // clean up last sync time
      setLastSyncTime(this, 0);

      // clean up local gtask related info
      new Thread(
              new Runnable() {
                public void run() {
                  ContentValues values = new ContentValues();
                  values.put(NoteColumns.GTASK_ID, "");
                  values.put(NoteColumns.SYNC_ID, 0);
                  getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
                }
              })
          .start();

      Toast.makeText(
              NotesPreferenceActivity.this,
              getString(R.string.preferences_toast_success_set_accout, account),
              Toast.LENGTH_SHORT)
          .show();
    }
  }
  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);
    }
  }
Ejemplo n.º 16
0
  /** Used to track the settings upon completion of the network change. */
  private void handleSetSelectNetwork(AsyncResult ar) {
    // look for our wrapper within the asyncresult, skip the rest if it
    // is null.
    if (!(ar.userObj instanceof NetworkSelectMessage)) {
      if (LOCAL_DEBUG) Log.d(LOG_TAG, "unexpected result from user object.");
      return;
    }

    NetworkSelectMessage nsm = (NetworkSelectMessage) ar.userObj;

    // found the object, now we send off the message we had originally
    // attached to the request.
    if (nsm.message != null) {
      if (LOCAL_DEBUG) Log.d(LOG_TAG, "sending original message to recipient");
      AsyncResult.forMessage(nsm.message, ar.result, ar.exception);
      nsm.message.sendToTarget();
    }

    // open the shared preferences editor, and write the value.
    // nsm.operatorNumeric is "" if we're in automatic.selection.
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
    SharedPreferences.Editor editor = sp.edit();
    editor.putString(NETWORK_SELECTION_KEY, nsm.operatorNumeric);
    editor.putString(NETWORK_SELECTION_NAME_KEY, nsm.operatorAlphaLong);

    // commit and log the result.
    if (!editor.commit()) {
      Log.e(LOG_TAG, "failed to commit network selection preference");
    }
  }
Ejemplo n.º 17
0
  private void saveSetting() {
    for (int i = 0; i < achievements.size(); i++) {
      data.achieveValue.set(i, achievements.get(i).getValue());
    }

    SharedPreferences sharedPreferences =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean("isLogin", isLogin);
    editor.putString("Username", data.getUser());
    editor.commit();

    SharedPreferences.Editor sPEditor = getPreferences(Context.MODE_PRIVATE).edit();
    String dataJasonString = convertingDataKeeperToJSONString(data);
    sPEditor.putString("DATAs" + data.getUser(), dataJasonString);
    Log.e("JasonStringSaved", dataJasonString);
    sPEditor.putString("FOODLIST", foodListJson);
    sPEditor.putString("ACTIVITYLIST", activityListJson);
    Calendar calendar = Calendar.getInstance();
    sPEditor.putInt("DAY", calendar.get(Calendar.DAY_OF_MONTH));
    sPEditor.putInt("lvl", data.getlvl());
    sPEditor.putInt("lvlexp", data.getLvlexp());
    sPEditor.commit();

    isLoad = false;
  }
Ejemplo n.º 18
0
 public static void setDropboxAccessTokenPair(Context context, AccessTokenPair accessTokenPair) {
   SharedPreferences settings = context.getSharedPreferences(DROPBOX_PREFS, Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = settings.edit();
   editor.putString(DROPBOX_KEY, accessTokenPair.key);
   editor.putString(DROPBOX_SECRET, accessTokenPair.secret);
   editor.commit();
 }
Ejemplo n.º 19
0
  private void updateSummaries() {
    int t = PREFS_DEFAULT_LOCATION_TIMEOUT;
    try {
      t =
          Integer.parseInt(
              prefs.getString(PREFS_KEY_LOCATION_TIMEOUT, "" + PREFS_DEFAULT_LOCATION_TIMEOUT));
      if (t < 1) {
        t = PREFS_DEFAULT_LOCATION_TIMEOUT;
        final SharedPreferences.Editor edit = prefs.edit();
        edit.putString(PREFS_KEY_LOCATION_TIMEOUT, "" + t);
        edit.commit();
      }
    } catch (final Exception e) {
      t = PREFS_DEFAULT_LOCATION_TIMEOUT;
      final SharedPreferences.Editor edit = prefs.edit();
      edit.putString(PREFS_KEY_LOCATION_TIMEOUT, "" + t);
      edit.commit();
    }
    final EditTextPreference timeout =
        (EditTextPreference) prefFrag.findPreference(PREFS_KEY_LOCATION_TIMEOUT);
    String summary = getResources().getString(R.string.pref_geolocation_timeout_summary);
    summary += "\nTimeout: '" + t + "'";
    timeout.setSummary(summary);

    final Preference povider = prefFrag.findPreference(PREFS_KEY_OPENCELLID_PROVIDER);
    final Preference gps = prefFrag.findPreference(PREFS_KEY_GPS);
    final boolean en = prefs.getBoolean(PREFS_KEY_LOCATE, PREFS_DEFAULT_LOCATE);
    povider.setEnabled(en);
    timeout.setEnabled(en);
    gps.setEnabled(en);
  }
Ejemplo n.º 20
0
 // 将用户的ID和密码存入sharedpreferences
 public void rememberMe(String user, String pwd) {
   SharedPreferences sp = getSharedPreferences(SP_INFOS, MODE_PRIVATE);
   SharedPreferences.Editor editor = sp.edit();
   editor.putString(Userid, user);
   editor.putString(Password, pwd);
   editor.commit();
 }
Ejemplo n.º 21
0
 private void initPrefs() {
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   SharedPreferences.Editor edit = prefs.edit();
   boolean changes = false;
   if (!prefs.contains(PREFS_VIBRATE_KEY)) {
     changes = true;
     edit.putString(PREFS_VIBRATE_KEY, PREFS_VIBRATE_DEFAULT);
   }
   if (!prefs.contains(PREFS_SERVER_HOST_KEY)) {
     changes = true;
     edit.putString(PREFS_SERVER_HOST_KEY, PREFS_SERVER_HOST_DEFAULT);
   }
   if (!prefs.contains(PREFS_SERVER_PORT_KEY)) {
     changes = true;
     edit.putString(PREFS_SERVER_PORT_KEY, PREFS_SERVER_PORT_DEFAULT);
   }
   if (!prefs.contains(PREFS_LAYOUT_KEY)) {
     changes = true;
     edit.putString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   }
   try {
     layoutManager.getLayoutResource(prefs.getString(PREFS_LAYOUT_KEY, ""));
   } catch (NoSuchElementException e) {
     changes = true;
     edit.putString(PREFS_LAYOUT_KEY, PREFS_LAYOUT_DEFAULT);
   }
   if (changes) {
     edit.commit();
   }
 }
Ejemplo n.º 22
0
  @Override
  public void onClick(DialogInterface dialog, int which) {
    switch (which) {
      case DialogInterface.BUTTON_POSITIVE:
        Editable text = mPunctuationCharacters.getText();
        String characters = null;
        int level;
        if (text != null) {
          characters = text.toString();
        }

        if (mNone.isChecked()) {
          level = SpeechSynthesis.PUNCT_NONE;
        } else if (characters == null || characters.isEmpty()) {
          level = mAll.isChecked() ? SpeechSynthesis.PUNCT_ALL : SpeechSynthesis.PUNCT_NONE;
        } else {
          level = mAll.isChecked() ? SpeechSynthesis.PUNCT_ALL : SpeechSynthesis.PUNCT_SOME;
        }

        onDataChanged(level, characters);

        if (shouldCommit()) {
          SharedPreferences.Editor editor = getEditor();
          if (editor != null) {
            editor.putString(VoiceSettings.PREF_PUNCTUATION_CHARACTERS, characters);
            editor.putString(VoiceSettings.PREF_PUNCTUATION_LEVEL, Integer.toString(level));
            editor.commit();
          }
        }
        break;
    }
    super.onClick(dialog, which);
  }
Ejemplo n.º 23
0
  /**
   * Configure PlayHaven
   *
   * @param context of the application
   * @param token configured in the PlayHaven Dashboard
   * @param secret configured in the PlayHaven Dashboard
   * @param projectId for push notification, optionally configured in PlayHaven Dashboard
   * @throws PlayHavenException if a problem occurs
   * @see <a href="https://dashboard.playhaven.com/">https://dashboard.playhaven.com/</a>
   */
  public static void configure(Context context, String token, String secret, String projectId)
      throws PlayHavenException {
    // Minimal validation
    validateToken(token);
    validateSecret(secret);

    // Setup default configuration values
    SharedPreferences.Editor editor = defaultConfiguration(context);

    // Setup PlayHaven values
    editor.putString(Config.Token.toString(), token);
    editor.putString(Config.Secret.toString(), secret);
    editor.putString(Config.PushProjectId.toString(), projectId);

    // And commit it
    editor.commit();

    /**
     * This will generate a log that looks like this:
     *
     * <pre>D/PlayHaven(  754): PlayHaven initialized: 2.0.0-SNAPSHOT-fe5c52f** 2012-11-21 08:45
     * </pre>
     *
     * Which can then be used to find the actual commit the version was against: <code>
     * git log -n 1 fe5c52f</code>
     */
    i("PlayHaven initialized: %s", Version.BANNER);
    debugConfig(context);
  }
Ejemplo n.º 24
0
 /** TODO: 一定是x5吗!! */
 public boolean rebuildUrl(String url) {
   String fixedLoginUrl = "";
   String toolbarUrl = "";
   if (!url.startsWith("http")) {
     url = "http://" + url;
   }
   int idx = url.indexOf("/directLogin.w");
   if (idx == -1) {
     if (url.endsWith("/")) {
       url = url.substring(0, url.length() - 1);
     }
     fixedLoginUrl = url + "/mobileUI/portal/directLogin.w";
     toolbarUrl = url + "/mobileUI/portal/mainToolbar.w?time=" + System.currentTimeMillis();
     int respCode = getRespStatus(toolbarUrl);
     if (respCode != 200) {
       toolbarUrl = url + "/x5/mobileUI/portal/mainToolbar.w?time=" + System.currentTimeMillis();
       int code = getRespStatus(toolbarUrl);
       if (code == 200) {
         fixedLoginUrl = url + "/x5/mobileUI/portal/directLogin.w";
         sharedEditor.putString(F_FIXEDLOGINURL, fixedLoginUrl);
         sharedEditor.commit();
       } else {
         loadSuccess = false;
         return false;
       }
     } else {
       fixedLoginUrl = url + "/mobileUI/portal/directLogin.w";
       sharedEditor.putString(F_FIXEDLOGINURL, fixedLoginUrl);
       sharedEditor.commit();
     }
   }
   return true;
 }
Ejemplo n.º 25
0
 public static void initialize(Context context) {
   if (DNUtils.getRootDir() != null) {
     STORE = context.getSharedPreferences(STORE_NAME, Context.MODE_PRIVATE);
     final String rootPath =
         Environment.getExternalStorageDirectory() + "/" + DNUtils.getRootDir();
     final String imagesPath = rootPath + "/images";
     final String jsonsPath = rootPath + "/texts";
     if (!STORE.contains(KEY_DIR_IMAGES)
         || !STORE.contains(KEY_DIR_IMAGES)
         || !STORE.contains(KEY_DIR_JSONS)) {
       final SharedPreferences.Editor editor = STORE.edit();
       editor.putString(KEY_DIR_ROOT, rootPath);
       editor.putString(KEY_DIR_IMAGES, imagesPath);
       editor.putString(KEY_DIR_JSONS, jsonsPath);
       editor.putLong(KEY_SIZE, 0);
       editor.commit();
     }
     File file = new File(rootPath);
     if (!file.exists()) file.mkdir();
     file = new File(imagesPath);
     if (!file.exists()) file.mkdir();
     file = new File(jsonsPath);
     if (!file.exists()) file.mkdir();
   }
 }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.account_add_btn_bar:
        {
          weibo = WeiboContext.getInstance(); // 单例,保证整个应用只有一个weibo对象
          weibo.getRequestToken();
          Intent intent = new Intent(AccountActivity.this, AuthorizeActivity.class);
          Bundle bundle = new Bundle();
          bundle.putString("url", weibo.getAuthorizeUrl());
          intent.putExtras(bundle);
          startActivity(intent); // 跳转到腾讯的微博授权页面,使用webview来显示
        }
        break;
      case R.id.user_default_headicon:
        {
          SharedPreferences preferences =
              getSharedPreferences("default_user", Activity.MODE_PRIVATE);
          SharedPreferences.Editor editor = preferences.edit();
          editor.putString("user_default_nick", currentUser.getUserName());
          editor.putString("user_default_name", currentUser.getUserId());
          editor.commit();
          Intent intent = new Intent(AccountActivity.this, MainActivity.class);
          startActivity(intent);
        }
        break;

      default:
        break;
    }
  }
Ejemplo n.º 27
0
  public void prevactivity_skipping(View view) {

    if (skip_pressed == true) {
      SharedPreferences.Editor editor = sharedpreferences.edit();
      editor.putString("Radiobuttonteaming1", "NA");
      editor.putString("Radiobuttonteaming2", "NA");
      editor.putString("Teamingskipped", "skipped");
      editor.commit();
      Intent intent = new Intent(this, RecordSkipping.class);
      intent.putExtra("activity", "prevskipping");
      intent.putExtra("TesterName", user_name);
      startActivity(intent);
    } else {
      rgrp1 = (RadioGroup) findViewById(R.id.rgrp1);
      radioButtonID1 = rgrp1.getCheckedRadioButtonId();

      rgrp2 = (RadioGroup) findViewById(R.id.rgrp2);
      radioButtonID2 = rgrp2.getCheckedRadioButtonId();
      //            if (radioButtonID1 == -1 || radioButtonID2 == -1)
      //                Toast.makeText(getBaseContext(), "Please select one option from each type
      // !", Toast.LENGTH_LONG).show();
      //            else {
      SharedPreferences.Editor editor = sharedpreferences.edit();
      editor.putInt("teamingidround1", radioButtonID1);
      editor.putInt("teamingidround2", radioButtonID2);
      editor.putString("Teamingskipped", "notskipped");
      editor.commit();
      Intent intent = new Intent(this, RecordSkipping.class);
      intent.putExtra("activity", "prevskipping");
      intent.putExtra("TesterName", user_name);
      startActivity(intent);
      // }
    }
  }
Ejemplo n.º 28
0
 /**
  * �����û���¼��Ϣ
  *
  * @param name
  * @param passwd
  */
 public void saveUserSession(String name, String passwd, String cookie) {
   SharedPreferences.Editor editor = mPerferences.edit();
   editor.putString(KEY_LOGIN_NAME, name);
   editor.putString(KEY_LOGIN_PASSWD, passwd);
   editor.putString(KEY_COOKIE, cookie);
   editor.commit();
 }
Ejemplo n.º 29
0
  public static void check() {
    HashMap<String, String> old = new HashMap<String, String>(codecs.size());

    for (Codec c : codecs) {
      c.update();
      old.put(c.name(), c.getValue());
      if (!c.isLoaded()) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
        SharedPreferences.Editor e = sp.edit();

        e.putString(c.key(), "never");
        e.commit();
      }
    }

    for (Codec c : codecs)
      if (!old.get(c.name()).equals("never")) {
        c.init();
        if (c.isLoaded()) {
          SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
          SharedPreferences.Editor e = sp.edit();

          e.putString(c.key(), old.get(c.name()));
          e.commit();
          c.init();
        } else c.fail();
      }
  }
    protected void onPostExecute(AccessToken accessToken) {

      try {
        // Shared Preferences
        SharedPreferences.Editor e = sharedPrefs.edit();

        Log.v("logging_in", "this is what the token should be: " + accessToken.getToken());

        if (sharedPrefs.getInt("current_account", 1) == 1) {
          e.putString("authentication_token_1", accessToken.getToken());
          e.putString("authentication_token_secret_1", accessToken.getTokenSecret());
          e.putBoolean("is_logged_in_1", true);
        } else {
          e.putString("authentication_token_2", accessToken.getToken());
          e.putString("authentication_token_secret_2", accessToken.getTokenSecret());
          e.putBoolean("is_logged_in_2", true);
        }

        e.commit(); // save changes

        // Hide login_activity button
        btnLoginTwitter.setText(getResources().getString(R.string.initial_sync));
        btnLoginTwitter.setEnabled(true);
        title.setText(getResources().getString(R.string.second_welcome));
        summary.setText(getResources().getString(R.string.second_info));

        hideHideWebView();

      } catch (Exception e) {
        restartLogin();
      }
    }