@Override protected void onResume() { super.onResume(); renren.init(this); if (renren.isSessionKeyValid()) { // 已经登录 startLoginedMainActivity(); // startTutorialsActivity(); } }
/** * 使用Widget窗口发状态 * * @param apiID 应用的api ID * @param activity 显示此widget的activity * @param listener 监听结果的listener * @throws RenrenException */ public void startStatusPubWidget( String appID, Activity activity, final AbstractRequestListener<StatusSetResponseBean> listener) throws RenrenException { if (!renren.isSessionKeyValid()) { String errorMsg = "Session key is not valid."; throw new RenrenException(RenrenError.ERROR_CODE_TOKEN_ERROR, errorMsg, errorMsg); } final Bundle params = new Bundle(); params.putString("app_id", appID); renren.widgetDialog( activity, params, new RenrenWidgetListener() { @Override public void onError(Bundle retParams) { if (listener != null) { listener.onRenrenError( new RenrenError( retParams.getString("error") + retParams.getString("error_description"))); } } @Override public void onComplete(Bundle retParams) { if (listener != null) { if (retParams.getString("flag").equals("success")) { listener.onComplete(new StatusSetResponseBean(1)); } else { listener.onComplete(null); } } } @Override public void onCancel(Bundle retParams) { String errorMsg = "Operation cancelled."; if (listener != null) { listener.onRenrenError( new RenrenError(RenrenError.ERROR_CODE_OPERATION_CANCELLED, errorMsg, errorMsg)); } } }, "status"); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (renren != null) { renren.authorizeCallback(requestCode, resultCode, data); } }
/** * 发布一条状态到人人网 * * @param status 要发布的状态对象 * @return 若状态为空或者发送失败,会抛出异常,否则返回成功 {@link FeedPublishResponseBean}对象 * @throws RenrenException * @throws Throwable */ public StatusSetResponseBean publish(StatusSetRequestParam status) throws RenrenException, Throwable { if (!renren.isSessionKeyValid()) { String errorMsg = "Session key is not valid."; throw new RenrenException(RenrenError.ERROR_CODE_TOKEN_ERROR, errorMsg, errorMsg); } // 参数不能为空 if (status == null) { String errorMsg = "The parameter is null."; throw new RenrenException(RenrenError.ERROR_CODE_NULL_PARAMETER, errorMsg, errorMsg); } // 发布状态 String response; try { Bundle params = status.getParams(); response = renren.requestJSON(params); } catch (RenrenException rre) { Util.logger(rre.getMessage()); throw rre; } catch (RuntimeException re) { Util.logger(re.getMessage()); throw new Throwable(re); } RenrenError rrError = Util.parseRenrenError(response, Renren.RESPONSE_FORMAT_JSON); if (rrError != null) { throw new RenrenException(rrError); } else { try { JSONObject json = new JSONObject(response); if (json.optInt("result") == 1) { return new StatusSetResponseBean(response); } else { String errorMsg = "Cannot parse the response."; throw new RenrenException( RenrenError.ERROR_CODE_UNABLE_PARSE_RESPONSE, errorMsg, errorMsg); } } catch (JSONException je) { Util.logger(je.getMessage()); throw new RenrenException( RenrenError.ERROR_CODE_UNABLE_PARSE_RESPONSE, je.getMessage(), je.getMessage()); } } } // end of public Status publish(Activity activity, Status status,
/** * 显示发送/编辑状态的窗口 * * @param activity 显示窗口的Activity,不能为null * @param stat 要发送/编辑的状态,若为null,则显示的窗口为新建状态窗口 * <p>注意:需要在AndroidManifest.xml中添加Activity描述行 * <p><activity android:name= * "com.renren.api.connect.android.AuthorizationHelper$BlockActivity" * android:theme="@android:style/Theme.Dialog" ></activity> * <p>同时需要在AndroidManifest.xml中添加Activity行 * <p><activity android:name= "com.renren.api.connect.android.activity.StatusPubActivity" * ></activity> */ public void startStatusPubActivity(final Activity activity, final StatusSetRequestParam stat) { Intent intent = new Intent(activity, StatusPubActivity.class); Bundle bundle = new Bundle(); if (stat != null) { bundle.putParcelable(StatusSetRequestParam.STATUS_LABEL, stat); } intent.putExtras(bundle); renren.startRenrenRequestActivity(activity, intent); }
@SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { /*待登录界面不应播放BGM,因为这里没有游戏设置的入口,无法关闭音乐会让用户觉得无法控制*/ SoundPlayer.stopMusic(); super.onCreate(savedInstanceState); setContentView(R.layout.main); getOverflowMenu(); getActionBar().setTitle("连接人人"); renren = new Renren(API_KEY, SECRET_KEY, APP_ID, this); helper = ActivityHelper.getInstance(); helper.addActivity(this); helper.setRenren(renren); handler = new Handler(); storer = ValueStorer.getInstance(); initButtons(); if (renren.isSessionKeyValid()) { // 已经登录 loadFriends(); loadMyImages(); Log.i("MainActivity", "logined"); startLoginedMainActivity(); } }