Java tutorial
/* * The MIT License (MIT) * * Copyright (c) 2014-2015 Umeng, Inc * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package com.umeng.comm.ui.activities; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.app.Activity; import android.app.Application; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import com.umeng.comm.core.constants.Constants; import com.umeng.comm.core.db.AbsDBHelper; import com.umeng.comm.core.utils.ResFinder; import com.umeng.comm.ui.fragments.AllFeedsFragment; /** * ?, ????????????, ???. * ?Activity?????Activity * * @author mrsimple */ public class FeedsActivity extends BaseFragmentActivity implements OnClickListener { /** * Feedfragment? */ // BaseFeedsFragment mFeedsFragment = new MainFeedsFragment(); /** * ??Fragment */ Fragment mTopicFragment = null; @Override protected void onCreate(Bundle arg0) { super.onCreate(arg0); setContentView(ResFinder.getLayout("umeng_comm_feeds_activity")); // fragmentcontainer id int container = ResFinder.getId("umeng_comm_main_container"); initFragment(container); addLoginPlatforms(); } /** * * ??apk?</br> */ private void addLoginPlatforms() { boolean isFromGenerateApk = getApplication().getClass().getSuperclass().equals(Application.class); if (isFromGenerateApk) { try { Method method = getApplication().getClass().getMethod("addLoginPlatforms", Activity.class); method.invoke(null, this); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } } @Override public void onClick(View v) { if (v.getId() == ResFinder.getId("umeng_comm_back_btn")) {// this.finish(); } // else if (v.getId() == ResFinder.getId("umeng_comm_topic_select_btn")) {// ? // showTopicFragment(); // } else if (v.getId() == ResFinder.getId("umeng_comm_new_post_btn")) {// // showPostFeedPage(); // } else if (v.getId() == ResFinder.getId("umeng_comm_post_back_btn") // || v.getId() == ResFinder.getId("umeng_comm_post_ok_btn")) {// ????feed? // showFragment(mFeedsFragment); // } } // /** // * ??Fragment????</br> // */ // private void showTopicFragment() { // if (mTopicFragment == null) { // mTopicFragment = new TopicFragment(); // } // // CommonUtils.checkLoginAndFireCallback(FeedsActivity.this, // new SimpleFetchListener<LoginResponse>() { // // @Override // public void onComplete(LoginResponse response) { // if (response.errCode == Constants.NO_ERROR) { // showFragment(mTopicFragment); // } else { // ToastMsg.showShortMsgByResName(FeedsActivity.this, // "umeng_comm_login_failed"); // return; // } // } // }); // } // @Override // public boolean onCreateOptionsMenu(Menu menu) { //// menu.add(Menu.NONE, Menu.FIRST + 1, 1, ResFinder.getString("umeng_comm_setting")); //// super.onCreateOptionsMenu(menu); // return true; // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // if (item.getItemId() == Menu.FIRST + 1) { // gotoSettingActivity(); // } // return super.onOptionsItemSelected(item); // } // /** // * ????????</br> // */ // private void showPostFeedPage() { // CommonUtils.checkLoginAndFireCallback(FeedsActivity.this, new SimpleFetchListener<LoginResponse>() { // // @Override // public void onComplete(LoginResponse response) { // if (response.errCode == Constants.NO_ERROR) { // gotoPostFeedActivity(); // } else { // ToastMsg.showShortMsgByResName(FeedsActivity.this, // "umeng_comm_login_failed"); // } // } // }); // } /** * ?</br> */ // private void gotoSettingActivity() { // CommonUtils.checkLoginAndFireCallback(FeedsActivity.this, new SimpleFetchListener<LoginResponse>() { // // @Override // public void onComplete(LoginResponse response) { // if (response.errCode == Constants.NO_ERROR) { // Intent settingIntent = new Intent(FeedsActivity.this, SettingActivity.class); // startActivity(settingIntent); // } else { // ToastMsg.showShortMsgByResName(FeedsActivity.this, // "umeng_comm_login_failed"); // } // } // }); // // } // // /** // * ???</br> // */ // private void gotoPostFeedActivity() { // Intent postIntent = new Intent(FeedsActivity.this, PostFeedActivity.class); // startActivity(postIntent); // } // // /** // * Feed?Fragment // */ // public void showMainFeedFragment() { // showFragment(mFeedsFragment); // } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { // ?feed?feed? if (!(mCurrentFragment instanceof AllFeedsFragment)) { showFragment(mFeedsFragment); return true; } } return super.onKeyDown(keyCode, event); } /** * push service</br> */ private void bindPushService() { // Pushable push = PushSDKManager.getInstance().getCurrentSDK(); // // if (mSdkImpl.getConfig().isPushEnable(this)) { // // ??? // push.enable(this); // // ,? // if (CommonUtils.isLogin(this)) { // push.setUserAlias(CommonUtils.getLoginUser(this)); // } // } else { // push.disable(); // } } @Override protected void onResume() { super.onResume(); dealLogoutLoginc(); bindPushService(); } /** * * ??FeedsActivity</br> */ private void dealLogoutLoginc() { Bundle bundle = getIntent().getExtras(); if (bundle != null) { boolean fromLogout = bundle.getBoolean(Constants.FROM_COMMUNITY_LOGOUT); if (fromLogout) { mFeedsFragment.cleanAdapterData(); } } } @Override protected void onDestroy() { // ? AbsDBHelper.closeDBCollection(); if (mFeedsFragment != null) { mFeedsFragment.hideCommentLayoutAndInputMethod(); } super.onDestroy(); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); } }