Exemple #1
0
    @Override
    public void onLocationChanged(Location loc) {
      // save to application context
      MyAppContext mContext = ((MyAppContext) getApplicationContext());
      mContext.mCurrLocation.setLatitude(loc.getLatitude());
      mContext.mCurrLocation.setLongitude(loc.getLongitude());
      mContext.mCurrLocation.setAltitude(loc.getAccuracy());

      // save to persistance storage
      SharedPreferences settings =
          getSharedPreferences(Main.PREFS_NAME, Context.MODE_WORLD_WRITEABLE);
      Editor ed = settings.edit();
      ed.putString("MyLat", String.valueOf(loc.getLatitude()));
      ed.putString("MyLong", String.valueOf(loc.getLongitude()));
      ed.putString("MyAtt", String.valueOf(loc.getAltitude()));
      ed.commit();

      drawText();

      String Text =
          "My current location is:"
              + "\nLatitude = "
              + loc.getLatitude()
              + "\nLongitude = "
              + loc.getLongitude();
      Toast.makeText(getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
      // unregister
      mLocManager.removeUpdates(mLocListener);
    }
  /**
   * 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();
  }
  private void cacheUserToken(MobileServiceUser user) {
    SharedPreferences prefs = getSharedPreferences(SHAREDPREFFILE, Context.MODE_PRIVATE);
    Editor editor = prefs.edit();
    editor.putString(USERIDPREF, user.getUserId());
    editor.putString(TOKENPREF, user.getAuthenticationToken());
    editor.commit();

    ListenableFuture<JsonElement> result =
        mClient.invokeApi("getuserinfo", "GET", new ArrayList<Pair<String, String>>());

    Futures.addCallback(
        result,
        new FutureCallback<JsonElement>() {
          @Override
          public void onSuccess(JsonElement result) {
            SharedPreferences prefs = getSharedPreferences(SHAREDPREFFILE, Context.MODE_PRIVATE);
            Editor editor = prefs.edit();
            editor.putString(
                USERNAME,
                result.getAsJsonObject().get("userPrincipalName").toString().replace("\"", ""));
            editor.putString(
                USERIDACTIVEDIRECTORY, result.getAsJsonObject().get("objectId").toString());
            editor.commit();
          }

          @Override
          public void onFailure(Throwable t) {}
        });
  }
 @Override
 public void createLoginSession(User user) {
   editor.putBoolean(IS_LOGGED_IN, true);
   editor.putString(KEY_NAME, user.getName());
   editor.putString(USER_NAME, user.getUserName());
   editor.commit();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fun_app_with_twitter);

    mSharedPreferences = getSharedPreferences(Const.PREFERENCE_NAME, MODE_PRIVATE);
    getTweetButton = (Button) findViewById(R.id.getTweet);
    getTweetButton.setOnClickListener(this);
    buttonLogin = (Button) findViewById(R.id.twitterLogin);
    buttonLogin.setOnClickListener(this);
    keyword = (EditText) findViewById(R.id.keyword);

    if (!isConnected()) {
      buttonLogin.setText(R.string.label_connect);
    } else {
      buttonLogin.setText(R.string.label_disconnect);
    }

    /** Handle OAuth Callback */
    Uri uri = getIntent().getData();
    if (uri != null && uri.toString().startsWith(Const.CALLBACK_URL)) {
      String verifier = uri.getQueryParameter(Const.IEXTRA_OAUTH_VERIFIER);
      try {
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
        Editor e = mSharedPreferences.edit();
        e.putString(Const.PREF_KEY_TOKEN, accessToken.getToken());
        e.putString(Const.PREF_KEY_SECRET, accessToken.getTokenSecret());
        e.commit();
      } catch (Exception e) {
        // System.out.println(e.toString());
        Log.e(TAG, e.getMessage());
        Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
      }
    }
  }
  /** Perform Opera Link synchronisation */
  private void syncItems() {
    ProgressDialog dialog =
        ProgressDialog.show(this, "", "Synchronizing notes with server. Please wait...", false);

    boolean synced;
    synced = uploadNewNotes();
    synced = synced && updateNotes();
    synced = synced && deleteNotes();
    synced = synced && getServerNotes();
    dialog.cancel();

    fillData();

    if (!isConnected) {
      showToast("Authorization expired, you need to authorize the application again");
      Editor prefEditor = pref.edit();
      prefEditor.putString(REQUEST_TOKEN_PREF_KEY, null);
      prefEditor.putString(ACCESS_TOKEN_PREF_KEY, null);
      prefEditor.putString(TOKEN_SECRET_PREF_KEY, null);
      prefEditor.commit();
    }
    if (!synced) {
      showToast("There were some problems, not all changes submitted. Try again later");
    }
    isSynchronized = synced;
  }
 public void storeAccessToken(AccessToken accessToken, String username, String loginname) {
   editor.putString(TWEET_AUTH_KEY, accessToken.getToken());
   editor.putString(TWEET_AUTH_SECRET_KEY, accessToken.getTokenSecret());
   editor.putString(TWEET_USER_NAME, username);
   editor.putString(TWEET_LOGIN_NAME, loginname);
   editor.commit();
 }
  /**
   * 点击按钮
   *
   * @param view
   */
  public void gxlogin(View view) {
    // System.out.println("点击按钮了,存储数据啦!");
    String qq = etQQ.getText().toString().trim();
    String pwd = etPwd.getText().toString().trim();
    if (TextUtils.isEmpty(qq) || TextUtils.isEmpty(pwd)) {
      Toast.makeText(this, "QQ号或者密码不能为空!!!", 0).show();
      return;
    }

    // 用户是否勾选,记住密码
    boolean isChecked = cbRem.isChecked();
    if (isChecked) {
      // 存储数据

      // 2. 获取编辑器Editor
      Editor edit = mSp.edit();
      // 3. 用编辑器存储数据
      edit.putString("qq", qq);
      edit.putString("mm", pwd);
      // 4. 重要,记住提交数据
      edit.commit();

      Toast.makeText(this, "数据存储成功!", 0).show();
    } else {
      System.out.println("不存储数据");
    }
  }
 public void storeToken(String username, String userId, String token) {
   Log.d(TAG, "Storing token - user="******", userId=" + userId + " , token=" + token);
   editor.putString(TOKEN, token);
   editor.putString(USERNAME, username);
   editor.putString(USERID, userId);
   editor.commit();
 }
Exemple #10
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();
 }
Exemple #11
0
  private void delProfile(String profile) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String[] profileEntries = settings.getString("profileEntries", "").split("\\|");
    String[] profileValues = settings.getString("profileValues", "").split("\\|");

    Log.d(TAG, "Profile :" + profile);
    if (profileEntries.length > 2) {
      StringBuilder profileEntriesBuffer = new StringBuilder();
      StringBuilder profileValuesBuffer = new StringBuilder();

      String newProfileValue = "1";

      for (int i = 0; i < profileValues.length - 1; i++) {
        if (!profile.equals(profileValues[i])) {
          profileEntriesBuffer.append(profileEntries[i]).append("|");
          profileValuesBuffer.append(profileValues[i]).append("|");
          newProfileValue = profileValues[i];
        }
      }
      profileEntriesBuffer.append(getString(R.string.profile_new));
      profileValuesBuffer.append("0");

      Editor ed = settings.edit();
      ed.putString("profileEntries", profileEntriesBuffer.toString());
      ed.putString("profileValues", profileValuesBuffer.toString());
      ed.putString("profile", newProfileValue);
      ed.commit();

      loadProfileList();
    }
  }
    /**
     * Retrieve the oauth_verifier, and store the oauth and oauth_token_secret for future API calls.
     */
    @Override
    protected Void doInBackground(Uri... params) {
      final Uri uri = params[0];
      final String oauth_verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);

      try {
        provider.retrieveAccessToken(consumer, oauth_verifier);

        final Editor edit = prefs.edit();
        edit.putString(OAuth.OAUTH_TOKEN, consumer.getToken());
        edit.putString(OAuth.OAUTH_TOKEN_SECRET, consumer.getTokenSecret());
        edit.commit();

        String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
        String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

        consumer.setTokenWithSecret(token, secret);
        context.startActivity(new Intent(context, TwitterActivity.class));

        executeAfterAccessTokenRetrieval();

        Log.i(TAG, "OAuth - Access Token Retrieved");

      } catch (Exception e) {
        Log.e(TAG, "OAuth - Access Token Retrieval Error", e);
      }

      return null;
    }
 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();
 }
 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();
   }
 }
  /**
   * 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;
    }
  }
    @SuppressLint("SimpleDateFormat")
    @Override
    protected void onPostExecute(String result) {
      String refreshToken = null;
      String accessToken = null;
      int timeToExpireSecond = 3000;
      try {
        IdentityProxy identityProxy = IdentityProxy.getInstance();

        if (responseCode != null && responseCode.equals("200")) {
          JSONObject response = new JSONObject(result);

          try {
            accessToken = response.getString("access_token");
            refreshToken = response.getString("refresh_token");
            timeToExpireSecond = Integer.parseInt(response.getString("expires_in"));
            Token token = new Token();
            token.setDate();
            token.setRefreshToken(refreshToken);
            token.setAccessToken(accessToken);
            token.setExpired(false);

            SharedPreferences mainPref =
                IdentityProxy.getInstance()
                    .getContext()
                    .getSharedPreferences("com.mdm", Context.MODE_PRIVATE);
            Editor editor = mainPref.edit();
            editor.putString("access_token", accessToken);
            editor.putString("refresh_token", refreshToken);
            DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            Date date = new Date();
            long expiresIN = date.getTime() + (timeToExpireSecond * 1000);
            Date expireDate = new Date(expiresIN);
            String strDate = dateFormat.format(expireDate);
            token.setDate(strDate);
            editor.putString("date", strDate);
            editor.commit();

            identityProxy.receiveAccessToken(responseCode, "success", token);
          } catch (JSONException e) { // admin user

          }

        } else if (responseCode != null) {
          if ("500".equals(responseCode)) {
            identityProxy.receiveAccessToken(responseCode, result, null);
          } else {
            JSONObject mainObject = new JSONObject(result);
            String error = mainObject.getString("error");
            String errorDescription = mainObject.getString("error_description");
            Log.d(TAG, error);
            Log.d(TAG, errorDescription);
            identityProxy.receiveAccessToken(responseCode, errorDescription, null);
          }
        }
      } catch (JSONException e) {
        Log.d(TAG, e.toString());
      }
    }
 void storeKeys(String key, String secret) {
   // Save the access key for later
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
   Editor edit = prefs.edit();
   edit.putString("dbPrivKey", key);
   edit.putString("dbPrivSecret", secret);
   edit.commit();
 }
Exemple #18
0
 public void setLoggedInApiKey(String apiKey) {
   this.api_key = apiKey;
   Editor ed = this.settings.edit();
   ed.putString("email", this.getEmail());
   ed.putString("api_key", api_key);
   ed.commit();
   afterLogin();
 }
  public void resetAccessToken() {
    editor.putString(TWEET_AUTH_KEY, null);
    editor.putString(TWEET_AUTH_SECRET_KEY, null);
    editor.putString(TWEET_USER_NAME, null);
    editor.putString(TWEET_LOGIN_NAME, null);

    editor.commit();
  }
 public synchronized void saveContactInfo(ContactInfo info) {
   if (mSharePreference != null && info != null) {
     Editor editor = mSharePreference.edit();
     editor.putString(JsonKey.HomeKey.QQ, info.getmQQ());
     editor.putString(JsonKey.HomeKey.WEIXIN, info.getmWeixin());
     editor.commit();
   }
 }
 public synchronized void saveArea(Area area) {
   if (mSharePreference != null && area != null) {
     Editor editor = mSharePreference.edit();
     editor.putString(AREA_ID, area.getmId());
     editor.putString(AREA_NAME, area.getmName());
     editor.commit();
   }
 }
Exemple #22
0
 public static boolean save(FacebookModule fbmod, Context context) {
   Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
   editor.putString(TOKEN, fbmod.facebook.getAccessToken());
   editor.putLong(EXPIRES, fbmod.facebook.getAccessExpires());
   editor.putString(UID, fbmod.uid);
   editor.putString(APPID, fbmod.getAppid());
   return editor.commit();
 }
 public static void setString(String key, String value, boolean isPublic) {
   if (isPublic) {
     mEditor.putString(key, value);
   } else {
     mEditor.putString(userId() + key, value);
   }
   mEditor.commit();
 }
 /**
  * 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).
  */
 public void storeKeys(String key, String secret) {
   // Save the access key for later
   SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
   Editor edit = prefs.edit();
   edit.putString(ACCESS_KEY_NAME, key);
   edit.putString(ACCESS_SECRET_NAME, secret);
   edit.commit();
 }
  /** Create login session */
  public void createLoginSession(String nama_user, String alamat_email) {
    // Storing login value as TRUE
    editor.putBoolean(IS_LOGIN, true);

    editor.putString(KEY_NAME, nama_user);
    editor.putString(KEY_EMAIL, alamat_email);
    editor.commit();
  }
 private void saveAccessToken(AccessToken at) {
   String token = at.getToken();
   String secret = at.getTokenSecret();
   Editor editor = mPrefs.edit();
   editor.putString(Const.PREF_KEY_TOKEN, token);
   editor.putString(Const.PREF_KEY_SECRET, secret);
   editor.commit();
 }
Exemple #27
0
  public void save() {
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.context);

    Editor editor = sharedPrefs.edit();
    editor.putString(ApplicationConstant.LATITUDE, latitude);
    editor.putString(ApplicationConstant.LONGITUDE, longitude);
    editor.commit();
  }
 private void save() {
   Resources res = getResources();
   SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
   Editor ed = prefs.edit();
   ed.putString(res.getString(R.string.pref_bt_name), btName);
   ed.putString(res.getString(R.string.pref_bt_address), btAddress);
   ed.putString(res.getString(R.string.pref_bt_provider), hrProvider.getProviderName());
   ed.commit();
 }
  // set sharedPreference
  public void setWifiSetting(String wifiSSID, String wifiBSSID) {
    SharedPreferences sharedPrefs = this.getSharedPreferences(KEY_WIFI_MODE, Context.MODE_PRIVATE);
    Editor editor = sharedPrefs.edit();

    editor.putString(KEY_WIFISSID, wifiSSID); // SSID
    editor.putString(KEY_WIFIBSSID, wifiBSSID); // BSSID

    editor.commit();
  }
 /**
  * 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 storeKeys(String key, String secret) {
   // Save the access key for later
   SharedPreferences prefs =
       parentActivity.getSharedPreferences(ACCOUNT_PREFS_NAME, Context.MODE_PRIVATE);
   Editor edit = prefs.edit();
   edit.putString(ACCESS_KEY_NAME, key);
   edit.putString(ACCESS_SECRET_NAME, secret);
   edit.commit();
 }