/** * 当前用户 * * @param context context */ public static void start(Context context) { Intent intent = new Intent(context, UserDetailActivity.class); Oauth2AccessToken token = AccessTokenKeeper.readAccessToken(context); intent.putExtra(INTENT_UID, token.getUid()); intent.putExtra(INTENT_TOKEN, token.getToken()); context.startActivity(intent); }
/** * 保存 Token 对象到 SharedPreferences。 * * @param context 应用程序上下文环境 * @param token Token 对象 */ public static void writeAccessToken(Context context, Oauth2AccessToken token) { if (null == context || null == token) { return; } SharedPreferences pref = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_APPEND); Editor editor = pref.edit(); editor.putString(KEY_UID, token.getUid()); editor.putString(KEY_ACCESS_TOKEN, token.getToken()); editor.putLong(KEY_EXPIRES_IN, token.getExpiresTime()); editor.commit(); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.ibtn_refresh_activity_friend: users_list.clear(); mFriendshipsAPI.followers( Long.parseLong(mAccessToken.getUid()), 200, 0, false, new MyRequestListener()); break; case R.id.ibtn_return_activity_friend: finish(); break; } }
private void init() { imageLoader = ImageLoader.getInstance(); imageLoader.init(ImageLoader_Init_Util.initConfiguration(getApplicationContext())); circleOptions = ImageLoader_Init_Util.initCircleDisplayImageOption(getApplicationContext()); inflater = LayoutInflater.from(getApplicationContext()); mFriendsAdapter = new FriendsAdapter(inflater, users_list, imageLoader, circleOptions); mAccessToken = AccessTokenKeeper.readAccessToken(getApplicationContext()); mFriendshipsAPI = new FriendshipsAPI(getApplicationContext(), Constants.APP_KEY, mAccessToken); ibtn_refresh = (ImageButton) findViewById(R.id.ibtn_refresh_activity_friend); ibtn_return = (ImageButton) findViewById(R.id.ibtn_return_activity_friend); tv_title = (TextView) findViewById(R.id.tv_title_activity_friend); tv_title.setText("我的粉丝"); lv_followers = (ListView) findViewById(R.id.lv_friends_activity_friend); lv_followers.setAdapter(mFriendsAdapter); mFriendshipsAPI.followers( Long.parseLong(mAccessToken.getUid()), 200, 0, false, new MyRequestListener()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_welcom); Oauth2AccessToken oauth2AccessToken = AccessTokenKeeper.readAccessToken(this); if (oauth2AccessToken != null && !TextUtils.isEmpty(oauth2AccessToken.getUid()) && !TextUtils.isEmpty(oauth2AccessToken.getToken()) && !TextUtils.isEmpty(oauth2AccessToken.getRefreshToken())) { startActivity(new Intent(this, MainActivity.class)); this.finish(); } else { mAuthInfo = new AuthInfo(this, Constants.APP_KEY, Constants.REDIRECT_URL, Constants.SCOPE); mSsoHandler = new SsoHandler(WelcomActivity.this, mAuthInfo); mSsoHandler.authorize(new AuthListener()); } }