PageRenderTime 62ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/dateLoveInternational/src/main/java/com/datelove/online/International/activity/MainActivity.java

https://bitbucket.org/juzhiwiscom/datelove
Java | 1470 lines | 1065 code | 155 blank | 250 comment | 186 complexity | 3c53a39898477ba2d50b624da276de22 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. package com.datelove.online.International.activity;
  2. import android.Manifest;
  3. import android.content.BroadcastReceiver;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.IntentFilter;
  7. import android.content.pm.PackageManager;
  8. import android.location.Location;
  9. import android.location.LocationListener;
  10. import android.location.LocationManager;
  11. import android.os.Build;
  12. import android.os.Bundle;
  13. import android.os.Handler;
  14. import android.os.Message;
  15. import android.os.PersistableBundle;
  16. import android.os.Vibrator;
  17. import android.support.annotation.NonNull;
  18. import android.support.annotation.Nullable;
  19. import android.support.v4.app.ActivityCompat;
  20. import android.support.v4.app.Fragment;
  21. import android.support.v4.app.FragmentManager;
  22. import android.support.v4.app.FragmentPagerAdapter;
  23. import android.support.v4.content.ContextCompat;
  24. import android.support.v4.view.ViewPager;
  25. import android.text.TextUtils;
  26. import android.util.Log;
  27. import android.view.KeyEvent;
  28. import android.view.View;
  29. import android.view.WindowManager;
  30. import android.view.animation.Animation;
  31. import android.view.animation.AnimationSet;
  32. import android.view.animation.AnimationUtils;
  33. import android.view.animation.TranslateAnimation;
  34. import android.widget.FrameLayout;
  35. import android.widget.ImageView;
  36. import android.widget.LinearLayout;
  37. import android.widget.RelativeLayout;
  38. import android.widget.TextView;
  39. import android.widget.Toast;
  40. import com.alibaba.fastjson.JSON;
  41. import com.alibaba.fastjson.JSONArray;
  42. import com.alibaba.fastjson.JSONObject;
  43. import com.datelove.online.International.R;
  44. import com.datelove.online.International.base.BaseFragmentActivity;
  45. import com.datelove.online.International.bean.BaseModel;
  46. import com.datelove.online.International.bean.FateUser;
  47. import com.datelove.online.International.bean.HeadMsgNotice;
  48. import com.datelove.online.International.bean.Image;
  49. import com.datelove.online.International.bean.LocationInfo;
  50. import com.datelove.online.International.bean.MsgBox;
  51. import com.datelove.online.International.bean.NewHeadMsgNotice;
  52. import com.datelove.online.International.bean.RecommendUser;
  53. import com.datelove.online.International.bean.User;
  54. import com.datelove.online.International.bean.UserBase;
  55. import com.datelove.online.International.constant.IUrlConstant;
  56. import com.datelove.online.International.event.BaseOpenMailFragmentEvent;
  57. import com.datelove.online.International.event.CloseMainActivityEvent;
  58. import com.datelove.online.International.event.HeadMsgEvent;
  59. import com.datelove.online.International.event.MatchInfoChangeEvent;
  60. import com.datelove.online.International.event.MessageChangedEvent;
  61. import com.datelove.online.International.event.NoSeeMeEvent;
  62. import com.datelove.online.International.event.OpenMailFragmentEvent;
  63. import com.datelove.online.International.event.RegistEvent;
  64. import com.datelove.online.International.event.UpdateMessageCountEvent;
  65. import com.datelove.online.International.event.UpdateUserProvince;
  66. import com.datelove.online.International.fragment.FateCardFragment;
  67. import com.datelove.online.International.fragment.MeFragment;
  68. import com.datelove.online.International.fragment.MessageFragment;
  69. import com.datelove.online.International.fragment.SearchFragment;
  70. import com.datelove.online.International.utils.CommonRequestUtil;
  71. import com.datelove.online.International.utils.Utils;
  72. import com.datelove.online.International.xml.PlatformInfoXml;
  73. import com.datelove.online.International.xml.UserInfoXml;
  74. import com.library.imageloader.ImageLoader;
  75. import com.library.imageloader.ImageLoaderUtil;
  76. import com.library.utils.HeightUtils;
  77. import com.library.utils.LogUtil;
  78. import com.library.utils.SharedPreferenceUtil;
  79. import com.library.utils.Util;
  80. import com.library.widgets.CircleImageView;
  81. import com.library.widgets.ScrollControlViewPager;
  82. import com.zhy.http.okhttp.OkHttpUtils;
  83. import com.zhy.http.okhttp.callback.Callback;
  84. import com.zhy.http.okhttp.callback.StringCallback;
  85. import org.greenrobot.eventbus.EventBus;
  86. import org.greenrobot.eventbus.Subscribe;
  87. import java.lang.ref.WeakReference;
  88. import java.util.ArrayList;
  89. import java.util.HashMap;
  90. import java.util.List;
  91. import java.util.Map;
  92. import butterknife.BindView;
  93. import butterknife.OnClick;
  94. import okhttp3.Call;
  95. import okhttp3.Response;
  96. import static com.datelove.online.International.utils.GoogleUtil.getGoogleProviceL1Key;
  97. //import com.datelove.online.International.fragment.NearbyFragment;
  98. /**
  99. * modified by zhangdroid on 2017-02-28
  100. */
  101. public class MainActivity extends BaseFragmentActivity {
  102. @BindView(R.id.viewPager)
  103. ScrollControlViewPager mViewPager;
  104. // 页眉
  105. @BindView(R.id.head_msg_container)
  106. RelativeLayout mRlHeadMsgContainer;
  107. @BindView(R.id.head_msg_content)
  108. TextView mTvHeadMsgContent;
  109. @BindView(R.id.head_msg_clear)
  110. ImageView mIvHeadMsgClear;
  111. // 新页眉
  112. @BindView(R.id.headMsg_container)
  113. FrameLayout mFlHeadMsgNew;
  114. @BindView(R.id.headMsg_unread)
  115. RelativeLayout mRlHeadMsgUnread;
  116. @BindView(R.id.headMsg_avatar)
  117. CircleImageView mIvHeadMsgAvatar;
  118. @BindView(R.id.headMsg_nickname)
  119. TextView mTvNickname;
  120. @BindView(R.id.headMsg_age)
  121. TextView mTvAge;
  122. @BindView(R.id.headMsg_height)
  123. TextView mTvHeight;
  124. @BindView(R.id.headMsg_content)
  125. TextView mTvMsgContent;
  126. @BindView(R.id.headMsg_check)
  127. TextView mTvMsgCheck;
  128. // 访客
  129. @BindView(R.id.headMsg_visitor)
  130. RelativeLayout mRlHeadMsgVisitor;
  131. @BindView(R.id.visitor_avatar)
  132. CircleImageView mIvVisitorAvatar;
  133. @BindView(R.id.visitor_content)
  134. TextView mTvVisitorContent;
  135. @BindView(R.id.visitor_ignore)
  136. TextView mTvVisitorIgnore;
  137. @BindView(R.id.visitor_look)
  138. TextView mTvVisitorLook;
  139. // 推荐用户
  140. @BindView(R.id.recommend_user_container)
  141. LinearLayout mLlRecommendUser;
  142. @BindView(R.id.recommend_user_avatar)
  143. CircleImageView mIvRecommendAvatar;
  144. @BindView(R.id.recommend_user_content)
  145. TextView mTvRecommendContent;
  146. @BindView(R.id.recommend_user_ignore)
  147. TextView mTvRecommendIgnore;
  148. @BindView(R.id.recommend_user_look)
  149. TextView mTvRecommendLook;
  150. // tab页
  151. @BindView(R.id.main_tab_fate)
  152. TextView mTvTabFate;
  153. @BindView(R.id.main_tab_search)
  154. TextView mTvTabSearch;
  155. @BindView(R.id.main_tab_mail)
  156. TextView mTvTabMail;
  157. @BindView(R.id.unread_msg_count)
  158. TextView mTvUnreadMsgCount;// 未读消息数
  159. @BindView(R.id.main_tab_nearby)
  160. TextView mTvTabNearby;
  161. @BindView(R.id.main_tab_me)
  162. TextView mTvTabMe;
  163. private static final int TAB_INDEX_FATE = 0;
  164. private static final int TAB_INDEX_SEARCH = 1;
  165. private static final int TAB_INDEX_MAIL = 2;
  166. private static final int TAB_INDEX_NEARBY = 4;
  167. private static final int TAB_INDEX_ME = 3;
  168. private static final int HEAD_MSG_REFRESH_PERIOD = 20 * 1000;
  169. private static final int MSG_TYPE_LOAD_DATA = 1;
  170. private static final int MSG_TYPE_HEAD_MSG = 2;
  171. private static final int MSG_TYPE_HEAD_MSG_NEW = 3;
  172. private static final int MSG_TYPE_RECOMMEND_USER = 4;
  173. private static final int MSG_TYPE_SHOW_UNREAD_MSG = 5;
  174. private static final int MSG_TYPE_DISMISS_UNREAD_MSG = 6;
  175. private static final int MSG_TYPE_DISMISS_VISITOR = 7;
  176. private static final int MSG_TYPE_HIDE_RECOMMEND_USER = 8;
  177. private static final int PERMISSION_CODE_ACCESS_FINE_LOCATION = 0;
  178. private boolean mReceiverTag = false; //广播接受者标识
  179. @BindView(R.id.iv_loading_heart)
  180. ImageView ivLoadingHeart;
  181. @BindView(R.id.fl_loading)
  182. FrameLayout flLoading;
  183. @BindView(R.id.tv_loading)
  184. TextView tvLoading;
  185. private LocationManager mLocationManager;
  186. /**
  187. * 页眉对象缓存
  188. */
  189. private HeadMsgNotice mHeadMsgNotice;
  190. /**
  191. * 新页眉对象缓存
  192. */
  193. private NewHeadMsgNotice mNewHeadMsgNotice;
  194. /**
  195. * 推荐用户对象缓存
  196. */
  197. private RecommendUser mRecommendUser;
  198. /**
  199. * 新页眉最后一条未读消息毫秒数
  200. */
  201. private long mLastMsgTime;
  202. /**
  203. * 推荐用户轮询周期(秒)
  204. */
  205. private int cycle;
  206. /**
  207. * 新页眉中当前正在显示的未读消息索引
  208. */
  209. private int mCurrDisplayItem;
  210. private TimerHandler mTimerHandler;
  211. private Context mContext;
  212. private Vibrator vibrator;
  213. private boolean isShake = true;
  214. private MainAdapter mainAdapter;
  215. private int currentUnreadMsgCount;
  216. private boolean isNewHeadMsg;
  217. private boolean getProvince = false;
  218. private int firstIntoSearch=0;
  219. private String getLatitude;
  220. private String getLongitude;
  221. private boolean againGetLocation=false;
  222. private String getProvinceFromSplash;
  223. private boolean isPause=false;
  224. private boolean isStartAnim;
  225. private AnimationSet animationSet;
  226. // private boolean stopRecommend=false;
  227. // private boolean stopMsg=false;
  228. @Override
  229. protected int getLayoutResId() {
  230. return R.layout.activity_main;
  231. }
  232. @Override
  233. protected void initViewsAndVariables() {
  234. // 设置状态栏
  235. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {// 5.0及以上
  236. View decorView = getWindow().getDecorView();
  237. decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
  238. // 设置状态栏背景
  239. getWindow().setStatusBarColor(getResources().getColor(R.color.main_color));
  240. } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {// 4.4
  241. getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  242. }
  243. mainAdapter = new MainAdapter(getSupportFragmentManager());
  244. mViewPager.setAdapter(mainAdapter);
  245. mViewPager.setCanScroll(false);
  246. mViewPager.setOffscreenPageLimit(4);
  247. /**显示加载动画**/
  248. flLoading.setVisibility(View.VISIBLE);
  249. tvLoading.setVisibility(View.VISIBLE);
  250. Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_show_loading);
  251. ivLoadingHeart.startAnimation(hyperspaceJumpAnimation);
  252. SharedPreferenceUtil.setBooleanValue(Utils.getContext(), "INTERCEPT_DIALOG", "INTERCEPT", false);
  253. new Handler().postDelayed(new Runnable() {
  254. @Override
  255. public void run() {
  256. flLoading.setVisibility(View.GONE);
  257. tvLoading.setVisibility(View.GONE);
  258. }
  259. }, 2000);
  260. mViewPager.setCurrentItem(TAB_INDEX_FATE);
  261. mTvTabFate.setSelected(true);
  262. /**对viewPage的界面改变进行监听,当刷新聊天列表的界面开始刷新,刷出聊天列表界面停止刷新**/
  263. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  264. @Override
  265. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  266. }
  267. @Override
  268. public void onPageSelected(int position) {
  269. MessageFragment item = (MessageFragment) mainAdapter.getItem(2);
  270. if (position != 2) {
  271. item.stopRefish();
  272. } else {
  273. item.startFirstRefish();
  274. }
  275. }
  276. @Override
  277. public void onPageScrollStateChanged(int state) {
  278. }
  279. });
  280. // 获取位置信息并上传
  281. requestLocation();
  282. // 延时加载数据
  283. mTimerHandler = new TimerHandler(this);
  284. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_LOAD_DATA, 1000 * 20);
  285. //注册广播
  286. // registerReceiver(mHomeKeyEventReceiver, new IntentFilter(
  287. // Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
  288. if (!mReceiverTag){ //在注册广播接受者的时候 判断是否已被注册,避免重复多次注册广播
  289. IntentFilter mFileter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
  290. mReceiverTag = true; //标识值 赋值为 true 表示广播已被注册
  291. this.registerReceiver(mHomeKeyEventReceiver, mFileter);
  292. }
  293. }
  294. /**
  295. * 加载页眉和推荐用户
  296. */
  297. private void loadData() {
  298. // 获取页眉
  299. // if (UserInfoXml.isShowHeadMsg()) {
  300. // getHeadMsg();
  301. //// mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG, HEAD_MSG_REFRESH_PERIOD);
  302. // }
  303. // 获取新页眉
  304. if (UserInfoXml.isShowHeadMsgNew()) {
  305. getNewHeadMsg();
  306. }
  307. // 获取推荐用户
  308. if (UserInfoXml.isShowRecommendUser()) {
  309. getRecommendUsr();
  310. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, HEAD_MSG_REFRESH_PERIOD);
  311. }
  312. }
  313. /**
  314. * 获取页眉
  315. */
  316. private void getHeadMsg() {
  317. // CommonRequestUtil.getHeadMsg(new CommonRequestUtil.OnGetHeadMsgListener() {
  318. // @Override
  319. // public void onSuccess(HeadMsgNotice headMsgNotice) {
  320. // if (headMsgNotice != null) {
  321. // mHeadMsgNotice = headMsgNotice;
  322. // String message = headMsgNotice.getMessage();
  323. // if (mViewPager.getCurrentItem() != TAB_INDEX_MAIL && !TextUtils.isEmpty(message)) {
  324. // mRlHeadMsgContainer.setVisibility(View.VISIBLE);
  325. // mTvHeadMsgContent.setText(message);
  326. // } else {
  327. // mRlHeadMsgContainer.setVisibility(View.GONE);
  328. // }
  329. // String noticeType = headMsgNotice.getNoticeType();
  330. // if (!TextUtils.isEmpty(noticeType) && "1".equals(noticeType)) {
  331. // // 有未读消息时刷新消息列表
  332. // EventBus.getDefault().post(new MessageChangedEvent());
  333. // }
  334. // }
  335. // }
  336. //
  337. // @Override
  338. // public void onFail() {
  339. //
  340. // }
  341. // });
  342. }
  343. /**
  344. * 获取新页眉
  345. */
  346. private void getNewHeadMsg() {
  347. String lastMsgTime = new SharedPreferenceUtil(MainActivity.this).takeLastTime();
  348. if (!TextUtils.isEmpty(lastMsgTime)) {
  349. mLastMsgTime = Long.parseLong(lastMsgTime);
  350. }
  351. CommonRequestUtil.getNewHeadMsg(mLastMsgTime, new CommonRequestUtil.OnGetNewHeadMsgListener() {
  352. @Override
  353. public void onSuccess(NewHeadMsgNotice newHeadMsgNotice) {
  354. if (newHeadMsgNotice != null) {
  355. mNewHeadMsgNotice = newHeadMsgNotice;
  356. mLastMsgTime = newHeadMsgNotice.getLastMsgTime();
  357. //将时间戳保存下来
  358. new SharedPreferenceUtil(MainActivity.this).saveLastTime(mLastMsgTime);
  359. mCurrDisplayItem = 0;
  360. String noticeType = newHeadMsgNotice.getNoticeType();
  361. if (!TextUtils.isEmpty(noticeType)) {
  362. switch (noticeType) {
  363. case "0":// 没有页眉,继续轮询
  364. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  365. break;
  366. case "1":// 未读消息
  367. // isNewHeadMsg=true;
  368. // 刷新聊天列表
  369. EventBus.getDefault().post(new MessageChangedEvent());
  370. setNewHeadMsg();
  371. break;
  372. case "2":// 访客
  373. FateUser fateUser = newHeadMsgNotice.getRemoteYuanfenUserBase();
  374. if (fateUser != null) {
  375. UserBase userBase = fateUser.getUserBaseEnglish();
  376. if (userBase != null) {
  377. if(mIvVisitorAvatar!=null && mIvVisitorAvatar.getVisibility()!=View.GONE){
  378. ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  379. .url(userBase.getImage().getThumbnailUrl()).imageView(mIvVisitorAvatar).build());
  380. mTvVisitorContent.setText(getString(R.string.visitor_tip, userBase.getNickName()));
  381. }
  382. }
  383. }
  384. if(mRlHeadMsgUnread!=null && mRlHeadMsgVisitor!=null){
  385. mRlHeadMsgUnread.setVisibility(View.GONE);
  386. mRlHeadMsgVisitor.setVisibility(View.VISIBLE);
  387. }
  388. showWithAnim(mFlHeadMsgNew);
  389. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_DISMISS_VISITOR, newHeadMsgNotice.getDisplaySecond() * 1000);
  390. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_DISMISS_VISITOR, 3 * 1000);
  391. break;
  392. }
  393. }
  394. }
  395. }
  396. @Override
  397. public void onFail() {
  398. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  399. }
  400. });
  401. }
  402. /**
  403. * 按照未读消息列表顺序显示未读信
  404. */
  405. private void setNewHeadMsg() {
  406. if (mNewHeadMsgNotice != null) {
  407. List<MsgBox> msgBoxList = mNewHeadMsgNotice.getUnreadMsgBoxList();
  408. if (!Util.isListEmpty(msgBoxList) && mCurrDisplayItem < msgBoxList.size()) {
  409. MsgBox msgBox = msgBoxList.get(mCurrDisplayItem);
  410. if (msgBox != null) {
  411. UserBase userBase = msgBox.getUserBaseEnglish();
  412. if (userBase != null) {
  413. Image image = userBase.getImage();
  414. if (image != null) {
  415. if(ImageLoaderUtil.getInstance()!=null){
  416. }
  417. ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  418. .url(image.getThumbnailUrl()).imageView(mIvHeadMsgAvatar).build());
  419. }
  420. mTvNickname.setText(userBase.getNickName());
  421. mTvAge.setText(TextUtils.concat(String.valueOf(userBase.getAge())));
  422. mTvAge.setSelected(userBase.getSex() == 0);
  423. if (userBase.getSex() == 0) {
  424. mTvAge.setBackgroundResource(R.drawable.shape_round_rectangle_blue_bg);
  425. } else {
  426. mTvAge.setBackgroundResource(R.drawable.shape_notification_age_women);
  427. }
  428. mTvHeight.setText(HeightUtils.getInchCmByCm(userBase.getHeightCm()));
  429. }
  430. String msgContent = msgBox.getMsg();
  431. if (!TextUtils.isEmpty(msgContent)) {
  432. // mTvMsgContent.setText(msgContent);
  433. mTvMsgContent.setText(getString(R.string.get_msg));
  434. }
  435. mRlHeadMsgUnread.setVisibility(View.VISIBLE);
  436. mRlHeadMsgVisitor.setVisibility(View.GONE);
  437. showWithAnim(mFlHeadMsgNew);
  438. }
  439. // 一段时间后显示下一条未读消息
  440. // mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_SHOW_UNREAD_MSG, mNewHeadMsgNotice.getDisplaySecond() * 1000);
  441. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_SHOW_UNREAD_MSG, 5 * 1000);
  442. }
  443. }
  444. }
  445. private void showWithAnim(View view) {
  446. if (isShake) {
  447. view.setVisibility(View.VISIBLE);
  448. vibrator = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
  449. vibrator.vibrate(200);
  450. view.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_in));
  451. }
  452. // view.startAnimation(AnimationUtils.loadAnimation(MainActivity.this, R.anim.push_bottom_in));
  453. }
  454. private void dismissWithAnim(final View view, final View view2) {
  455. // Animation outAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.push_bottom_out);
  456. if(view!=null && view2!=null){
  457. Animation outAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_out);
  458. view.startAnimation(outAnimation);
  459. outAnimation.setAnimationListener(new Animation.AnimationListener() {
  460. @Override
  461. public void onAnimationStart(Animation animation) {
  462. }
  463. @Override
  464. public void onAnimationEnd(Animation animation) {
  465. view.setVisibility(View.GONE);
  466. view2.setVisibility(View.GONE);
  467. }
  468. @Override
  469. public void onAnimationRepeat(Animation animation) {
  470. }
  471. });
  472. }
  473. }
  474. /**
  475. * 获取推荐用户
  476. */
  477. private void getRecommendUsr() {
  478. CommonRequestUtil.getRecommendUser(cycle, new CommonRequestUtil.OnGetRecommendUserListener() {
  479. @Override
  480. public void onSuccess(RecommendUser recommendUser) {
  481. if (recommendUser != null) {
  482. mRecommendUser = recommendUser;
  483. cycle = recommendUser.getCycle();
  484. User user = recommendUser.getUser();
  485. if (user != null) {
  486. UserBase userBase = user.getUserBaseEnglish();
  487. if (userBase != null) {
  488. // 显示推荐用户
  489. if(mLlRecommendUser!=null && mTvRecommendContent!=null){
  490. mLlRecommendUser.setVisibility(View.VISIBLE);
  491. mTvRecommendContent.setText(TextUtils.concat(userBase.getNickName(), " ", recommendUser.getSentence()));
  492. }
  493. if(mIvRecommendAvatar!=null){
  494. ImageLoaderUtil.getInstance().loadImage(MainActivity.this, new ImageLoader.Builder()
  495. .url(userBase.getImage().getThumbnailUrl()).imageView(mIvRecommendAvatar).build());
  496. }
  497. showWithAnim(mLlRecommendUser);
  498. }
  499. }
  500. }
  501. // 一段时间后隐藏推荐用户
  502. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HIDE_RECOMMEND_USER, 5 * 1000);
  503. }
  504. @Override
  505. public void onFail() {
  506. // 一段时间后隐藏推荐用户
  507. mTimerHandler.sendEmptyMessageDelayed(MSG_TYPE_HIDE_RECOMMEND_USER, 5 * 1000);
  508. }
  509. });
  510. }
  511. @Override
  512. protected void addListeners() {
  513. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  514. @Override
  515. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  516. }
  517. @Override
  518. public void onPageSelected(int position) {
  519. switch (position) {
  520. case TAB_INDEX_FATE:
  521. mTvTabFate.setSelected(true);
  522. mTvTabSearch.setSelected(false);
  523. mTvTabMail.setSelected(false);
  524. mTvTabNearby.setSelected(false);
  525. mTvTabMe.setSelected(false);
  526. break;
  527. case TAB_INDEX_SEARCH:
  528. mTvTabFate.setSelected(false);
  529. mTvTabSearch.setSelected(true);
  530. mTvTabMail.setSelected(false);
  531. mTvTabNearby.setSelected(false);
  532. mTvTabMe.setSelected(false);
  533. firstIntoSearch++;
  534. if(firstIntoSearch==1){
  535. flLoading.setVisibility(View.VISIBLE);
  536. tvLoading.setVisibility(View.VISIBLE);
  537. Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.anim_show_loading);
  538. ivLoadingHeart.startAnimation(hyperspaceJumpAnimation);
  539. new Handler().postDelayed(new Runnable() {
  540. @Override
  541. public void run() {
  542. flLoading.setVisibility(View.GONE);
  543. tvLoading.setVisibility(View.GONE);
  544. }
  545. }, 2000);
  546. }
  547. break;
  548. case TAB_INDEX_MAIL:
  549. mTvTabFate.setSelected(false);
  550. mTvTabSearch.setSelected(false);
  551. mTvTabMail.setSelected(true);
  552. mTvTabNearby.setSelected(false);
  553. mTvTabMe.setSelected(false);
  554. // 信箱tab页不显示页眉
  555. if (mRlHeadMsgContainer.isShown()) {
  556. mRlHeadMsgContainer.setVisibility(View.GONE);
  557. }
  558. // // 隐藏新页眉
  559. // if (mFlHeadMsgNew.isShown()) {
  560. // mFlHeadMsgNew.setVisibility(View.GONE);
  561. // if (mTimerHandler != null) {
  562. // mTimerHandler.removeMessages(MSG_TYPE_SHOW_UNREAD_MSG);
  563. // }
  564. // }
  565. break;
  566. case TAB_INDEX_NEARBY:
  567. mTvTabFate.setSelected(false);
  568. mTvTabSearch.setSelected(false);
  569. mTvTabMail.setSelected(false);
  570. mTvTabNearby.setSelected(true);
  571. mTvTabMe.setSelected(true);
  572. break;
  573. case TAB_INDEX_ME:
  574. mTvTabFate.setSelected(false);
  575. mTvTabSearch.setSelected(false);
  576. mTvTabMail.setSelected(false);
  577. mTvTabNearby.setSelected(true);
  578. mTvTabMe.setSelected(true);
  579. break;
  580. }
  581. }
  582. @Override
  583. public void onPageScrollStateChanged(int state) {
  584. }
  585. });
  586. // 查看页眉消息
  587. mRlHeadMsgContainer.setOnClickListener(new View.OnClickListener() {
  588. @Override
  589. public void onClick(View v) {
  590. if (mHeadMsgNotice != null) {
  591. mRlHeadMsgContainer.setVisibility(View.GONE);
  592. String noticeType = mHeadMsgNotice.getNoticeType();
  593. if (!TextUtils.isEmpty(noticeType)) {
  594. switch (noticeType) {
  595. case "1": // 未读消息
  596. if (mViewPager.getCurrentItem() != TAB_INDEX_MAIL) {
  597. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  598. }
  599. break;
  600. case "2":// 正在看我
  601. UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, mHeadMsgNotice.getRemoteUserId(), null, UserInfoDetailActivity.SOURCE_HEAD_MSG);
  602. break;
  603. }
  604. }
  605. }
  606. }
  607. });
  608. mIvHeadMsgClear.setOnClickListener(new View.OnClickListener() {
  609. @Override
  610. public void onClick(View v) {
  611. mRlHeadMsgContainer.setVisibility(View.GONE);
  612. }
  613. });
  614. // 新页眉
  615. mRlHeadMsgUnread.setOnClickListener(new View.OnClickListener() {
  616. @Override
  617. public void onClick(View v) {
  618. // 查看未读消息,进入聊天页面
  619. mFlHeadMsgNew.setVisibility(View.GONE);
  620. if (mNewHeadMsgNotice != null && mCurrDisplayItem < mNewHeadMsgNotice.getUnreadMsgBoxList().size()) {
  621. List<MsgBox> msgBoxList = mNewHeadMsgNotice.getUnreadMsgBoxList();
  622. if (!Util.isListEmpty(msgBoxList)) {
  623. MsgBox msgBox = msgBoxList.get(mCurrDisplayItem);
  624. if (msgBox != null) {
  625. UserBase userBase = msgBox.getUserBaseEnglish();
  626. if (userBase != null) {
  627. ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(), userBase.getImage().getThumbnailUrl());
  628. }
  629. }
  630. }
  631. }
  632. }
  633. });
  634. mTvVisitorLook.setOnClickListener(new View.OnClickListener() {
  635. @Override
  636. public void onClick(View v) {
  637. // 隐藏新页眉
  638. mRlHeadMsgVisitor.setVisibility(View.GONE);
  639. mFlHeadMsgNew.setVisibility(View.GONE);
  640. // 查看用户详情
  641. if (mNewHeadMsgNotice != null) {
  642. FateUser fateUser = mNewHeadMsgNotice.getRemoteYuanfenUserBase();
  643. if (fateUser != null) {
  644. UserBase userBase = fateUser.getUserBaseEnglish();
  645. if (userBase != null) {
  646. UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, userBase.getId(), null, UserInfoDetailActivity.SOURCE_HEAD_MSG);
  647. }
  648. }
  649. }
  650. }
  651. });
  652. mTvVisitorIgnore.setOnClickListener(new View.OnClickListener() {
  653. @Override
  654. public void onClick(View v) {
  655. // 隐藏新页眉
  656. mRlHeadMsgVisitor.setVisibility(View.GONE);
  657. mFlHeadMsgNew.setVisibility(View.GONE);
  658. }
  659. });
  660. // 推荐用户
  661. mTvRecommendLook.setOnClickListener(new View.OnClickListener() {
  662. @Override
  663. public void onClick(View v) {
  664. if (mRecommendUser != null) {
  665. UserBase userBase = mRecommendUser.getUser().getUserBaseEnglish();
  666. if (userBase != null) {
  667. // 隐藏推荐用户
  668. mLlRecommendUser.setVisibility(View.GONE);
  669. Image image = userBase.getImage();
  670. if (UserInfoXml.isMale()) {
  671. if (UserInfoXml.isMonthly()) {// 已付费男用户进入聊天页
  672. ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(),
  673. image == null ? null : image.getThumbnailUrl());
  674. } else {// 未付费男用户,进入对方空间页
  675. UserInfoDetailActivity.toUserInfoDetailActivity(MainActivity.this, userBase.getId(), null, UserInfoDetailActivity.SOURCE_FROM_RECOMMEND_USER);
  676. }
  677. } else {// 女用户进入聊天页
  678. ChatActivity.toChatActivity(MainActivity.this, userBase.getId(), userBase.getNickName(),
  679. image == null ? null : image.getThumbnailUrl());
  680. }
  681. }
  682. }
  683. }
  684. });
  685. mTvRecommendIgnore.setOnClickListener(new View.OnClickListener() {
  686. @Override
  687. public void onClick(View v) {
  688. // 隐藏推荐用户
  689. mLlRecommendUser.setVisibility(View.GONE);
  690. }
  691. });
  692. }
  693. @OnClick({R.id.main_tab_fate, R.id.main_tab_search, R.id.main_tab_mail, R.id.main_tab_nearby, R.id.main_tab_me})
  694. public void onClick(View view) {
  695. switch (view.getId()) {
  696. case R.id.main_tab_fate:
  697. mViewPager.setCurrentItem(TAB_INDEX_FATE);
  698. break;
  699. case R.id.main_tab_search:
  700. mViewPager.setCurrentItem(TAB_INDEX_SEARCH);
  701. break;
  702. case R.id.main_tab_mail:
  703. mViewPager.setCurrentItem(TAB_INDEX_MAIL);
  704. break;
  705. case R.id.main_tab_nearby:
  706. mViewPager.setCurrentItem(TAB_INDEX_NEARBY);
  707. break;
  708. case R.id.main_tab_me:
  709. mViewPager.setCurrentItem(TAB_INDEX_ME);
  710. break;
  711. }
  712. }
  713. /**
  714. * 请求定位信息
  715. */
  716. private void requestLocation() {
  717. getLatitude = SharedPreferenceUtil.getStringValue(MainActivity.this, "LOCATION", "getLatitude", "");
  718. getLongitude = SharedPreferenceUtil.getStringValue(MainActivity.this, "LOCATION", "getLongitude", "");
  719. getProvinceFromSplash =SharedPreferenceUtil.getStringValue(MainActivity.this,"GET_PROVINCE","province","");
  720. String country = UserInfoXml.getCountry();
  721. if (TextUtils.isEmpty(getLatitude) || TextUtils.isEmpty(getLongitude) || TextUtils.isEmpty(country)) {
  722. // 经纬度为空,重新定位
  723. mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  724. if (ContextCompat.checkSelfPermission(MainActivity.this,
  725. Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
  726. // 请求android.permission.ACCESS_FINE_LOCATION
  727. ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_CODE_ACCESS_FINE_LOCATION);
  728. } else {
  729. if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {// Network定位
  730. mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 5, mLocationListener);
  731. } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {// GPS定位
  732. uploadLocation(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
  733. }
  734. }
  735. } else if(TextUtils.isEmpty(getProvinceFromSplash)){
  736. // 城市为空,重新请求谷歌获取城市的接口
  737. getAddress(getLatitude, getLongitude,"English", country);
  738. }else{
  739. // 都不为空,调用位置接口
  740. getLocation(getLatitude, getLongitude, getProvinceFromSplash);
  741. }
  742. }
  743. private LocationListener mLocationListener = new LocationListener() {
  744. @Override
  745. public void onLocationChanged(Location location) {
  746. uploadLocation(location);
  747. }
  748. @Override
  749. public void onStatusChanged(String provider, int status, Bundle extras) {
  750. }
  751. @Override
  752. public void onProviderEnabled(String provider) {
  753. }
  754. @Override
  755. public void onProviderDisabled(String provider) {
  756. }
  757. };
  758. @Override
  759. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  760. if (requestCode == PERMISSION_CODE_ACCESS_FINE_LOCATION) {
  761. if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {// 申请权限成功
  762. if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {// Network定位
  763. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  764. // TODO: Consider calling
  765. // ActivityCompat#requestPermissions
  766. // here to request the missing permissions, and then overriding
  767. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  768. // int[] grantResults)
  769. // to handle the case where the user grants the permission. See the documentation
  770. // for ActivityCompat#requestPermissions for more details.
  771. return;
  772. }
  773. mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 2000, 5, mLocationListener);
  774. } else if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {// GPS定位
  775. uploadLocation(mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
  776. }
  777. }
  778. }
  779. }
  780. /**
  781. * 上传位置信息
  782. *
  783. * @param location 定位成功后的信息
  784. */
  785. private void uploadLocation(Location location) {
  786. if (location != null) {
  787. String getLatitude = String.valueOf(location.getLatitude());
  788. String getLongitude = String.valueOf(location.getLongitude());
  789. String country = UserInfoXml.getCountry();
  790. againGetLocation=true;
  791. getAddress(getLatitude, getLongitude,"English", country);
  792. // Map<String, String> googleAddress = GoogleUtil.getGoogleAddress(getLatitude, getLongitude, "English", country);
  793. // if (googleAddress != null) {
  794. // String province = googleAddress.get("province");
  795. //// 英国城市为空。。。
  796. // if (!TextUtils.isEmpty(province) && !province.equals(UserInfoXml.getProvinceName())) {
  797. // UserInfoXml.setProvinceName(province);
  798. // getProvince = true;
  799. // }
  800. // getLocation(getLatitude, getLongitude, province);
  801. // }
  802. }
  803. }
  804. private void getLocation(String latitude, String longitude, String province) {
  805. LocationInfo locationInfo = new LocationInfo();
  806. locationInfo.setAddrStr("");
  807. locationInfo.setProvince(province);
  808. locationInfo.setCity("");
  809. locationInfo.setCityCode("");
  810. locationInfo.setDistrict("");
  811. locationInfo.setStreet("");
  812. locationInfo.setStreetNumber("");
  813. locationInfo.setLatitude(latitude);
  814. locationInfo.setLongitude(longitude);
  815. Map<String, LocationInfo> map = new HashMap<String, LocationInfo>();
  816. map.put("locationInfo", locationInfo);
  817. OkHttpUtils.post()
  818. .url(IUrlConstant.URL_UPLOAD_LOCATION)
  819. .addHeader("token", PlatformInfoXml.getToken())
  820. .addParams("platformInfo", PlatformInfoXml.getPlatformJsonString())
  821. .addParams("locationInfo", JSON.toJSONString(map))
  822. .build()
  823. .execute(new Callback<BaseModel>() {
  824. @Override
  825. public BaseModel parseNetworkResponse(Response response, int id) throws Exception {
  826. String resultJson = response.body().string();
  827. if (!TextUtils.isEmpty(resultJson)) {
  828. return JSON.parseObject(resultJson, BaseModel.class);
  829. }
  830. return null;
  831. }
  832. @Override
  833. public void onError(Call call, Exception e, int id) {
  834. }
  835. @Override
  836. public void onResponse(BaseModel response, int id) {
  837. if (response != null) {
  838. String isSucceed = response.getIsSucceed();
  839. if (!TextUtils.isEmpty(isSucceed) && "1".equals(isSucceed)) {// 上传成功
  840. LogUtil.i(LogUtil.TAG_ZL, "上传位置信息成功");
  841. // 发送事件,更新位置信息
  842. if (getProvince) {
  843. EventBus.getDefault().post(new UpdateUserProvince());
  844. EventBus.getDefault().post(new MatchInfoChangeEvent());
  845. }
  846. }
  847. }
  848. }
  849. });
  850. }
  851. @Override
  852. protected void doRegister() {
  853. super.doRegister();
  854. EventBus.getDefault().register(this);
  855. }
  856. @Override
  857. protected void unregister() {
  858. super.unregister();
  859. // 关闭MainActivity事件
  860. EventBus.getDefault().post(new CloseMainActivityEvent());
  861. EventBus.getDefault().unregister(this);
  862. }
  863. @Subscribe
  864. public void onEvent(NoSeeMeEvent event) {
  865. mViewPager.setCurrentItem(TAB_INDEX_FATE, false);
  866. }
  867. @Subscribe
  868. public void onEvent(OpenMailFragmentEvent event) {
  869. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  870. }
  871. @Subscribe
  872. public void onEvent(HeadMsgEvent event) {
  873. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  874. }
  875. @Subscribe
  876. public void onEvent(BaseOpenMailFragmentEvent event) {
  877. mViewPager.setCurrentItem(TAB_INDEX_MAIL, false);
  878. }
  879. @Subscribe
  880. public void onEvent(RegistEvent event) {
  881. finish();
  882. }
  883. @Subscribe
  884. public void onEvent(UpdateMessageCountEvent event) {
  885. int unreadMsgCount = event.getUnreadMsgCount();
  886. /**有未读消息进行刷新**/
  887. // if(unreadMsgCount>currentUnreadMsgCount){
  888. // MessageFragment item = (MessageFragment)mainAdapter.getItem(2);
  889. // item.startFirstRefish();
  890. // }
  891. /**改变气泡数量**/
  892. if (unreadMsgCount > 0) {
  893. mTvUnreadMsgCount.setVisibility(View.VISIBLE);
  894. mTvUnreadMsgCount.setText(String.valueOf(unreadMsgCount > 99 ? 99 : unreadMsgCount));
  895. currentUnreadMsgCount = unreadMsgCount;
  896. // 开始动画
  897. isStartAnim=true;
  898. setAnim();
  899. } else {
  900. mTvUnreadMsgCount.setVisibility(View.GONE);
  901. mTvUnreadMsgCount.clearAnimation();
  902. animationSet = null;
  903. }
  904. }
  905. private void setAnim() {
  906. animationSet = new AnimationSet(false);
  907. TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, -10);
  908. translateAnimation.setDuration(100);
  909. TranslateAnimation translateAnimation2 = new TranslateAnimation(0, 0, -10, 0);
  910. translateAnimation2.setDuration(200);
  911. TranslateAnimation translateAnimation3 = new TranslateAnimation(0, 0, 0, 20);
  912. translateAnimation3.setDuration(250);
  913. if(animationSet != null){
  914. animationSet.setRepeatCount(20);
  915. animationSet.setRepeatMode(Animation.INFINITE);
  916. animationSet.addAnimation(translateAnimation);
  917. animationSet.addAnimation(translateAnimation2);
  918. animationSet.addAnimation(translateAnimation3);
  919. mTvUnreadMsgCount.startAnimation(animationSet);
  920. animationSet.setAnimationListener(new Animation.AnimationListener() {
  921. @Override
  922. public void onAnimationStart(Animation animation) {
  923. }
  924. @Override
  925. public void onAnimationEnd(Animation animation) {
  926. if (animationSet != null) {
  927. mTvUnreadMsgCount.startAnimation(animationSet);
  928. }
  929. }
  930. @Override
  931. public void onAnimationRepeat(Animation animation) {
  932. }
  933. });
  934. }
  935. }
  936. @Subscribe
  937. public void onEvent(CloseMainActivityEvent event) {
  938. mTimerHandler.removeMessages(MSG_TYPE_HEAD_MSG);
  939. mTimerHandler.removeMessages(MSG_TYPE_HEAD_MSG_NEW);
  940. mTimerHandler.removeMessages(MSG_TYPE_RECOMMEND_USER);
  941. mTimerHandler.removeMessages(MSG_TYPE_HIDE_RECOMMEND_USER);
  942. finish();
  943. }
  944. private class TimerHandler extends Handler {
  945. private WeakReference<MainActivity> mWeakReference;
  946. public TimerHandler(MainActivity mainActivity) {
  947. this.mWeakReference = new WeakReference<MainActivity>(mainActivity);
  948. }
  949. @Override
  950. public void handleMessage(Message msg) {
  951. if (null == this) { //走到了onDestory,则不再进行后续消息处理
  952. return;
  953. }
  954. if (MainActivity.this.isFinishing()) { //Activity正在停止,则不再后续处理
  955. return;
  956. }
  957. final MainActivity mainActivity = mWeakReference.get();
  958. switch (msg.what) {
  959. case MSG_TYPE_LOAD_DATA:// 加载数据
  960. if (mainActivity != null) {
  961. mainActivity.loadData();
  962. }
  963. break;
  964. // case MSG_TYPE_HEAD_MSG:// 页眉刷新
  965. // if (mainActivity != null) {
  966. // mainActivity.getHeadMsg();
  967. // }
  968. //// sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG, HEAD_MSG_REFRESH_PERIOD);
  969. // break;
  970. case MSG_TYPE_HEAD_MSG_NEW:// 新页眉刷新
  971. Log.v("Main===","新页眉刷新");
  972. if (mainActivity != null) {
  973. Log.v("Main===","新页眉刷新mainActivity");
  974. mainActivity.getNewHeadMsg();
  975. }
  976. break;
  977. case MSG_TYPE_RECOMMEND_USER:// 推荐用户刷新
  978. int cycle = 0;
  979. if (mainActivity != null) {
  980. mainActivity.getRecommendUsr();
  981. cycle = mainActivity.cycle;
  982. }
  983. // sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, cycle < 20 ? HEAD_MSG_REFRESH_PERIOD : cycle * 1000);
  984. break;
  985. case MSG_TYPE_SHOW_UNREAD_MSG:// 显示未读消息页眉
  986. // 先隐藏上一条
  987. if (mainActivity != null) {
  988. mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgUnread);
  989. mainActivity.mFlHeadMsgNew.postDelayed(new Runnable() {
  990. @Override
  991. public void run() {
  992. // 如果存在下一条,则显示
  993. if (mainActivity.mNewHeadMsgNotice != null && mainActivity.mCurrDisplayItem < mainActivity.mNewHeadMsgNotice.getUnreadMsgBoxList().size() - 1) {
  994. mainActivity.mCurrDisplayItem++;
  995. mainActivity.setNewHeadMsg();
  996. } else {
  997. // 继续轮询
  998. sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  999. }
  1000. }
  1001. }, 500);
  1002. }
  1003. break;
  1004. case MSG_TYPE_HIDE_RECOMMEND_USER:// 隐藏推荐用户页眉
  1005. // 隐藏上一条
  1006. if (mainActivity != null) {
  1007. mainActivity.dismissWithAnim(mainActivity.mLlRecommendUser, mainActivity.mLlRecommendUser);
  1008. }
  1009. sendEmptyMessageDelayed(MSG_TYPE_RECOMMEND_USER, HEAD_MSG_REFRESH_PERIOD);
  1010. break;
  1011. case MSG_TYPE_DISMISS_UNREAD_MSG:// 隐藏未读消息页眉
  1012. if (mainActivity != null) {
  1013. mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgUnread);
  1014. }
  1015. break;
  1016. case MSG_TYPE_DISMISS_VISITOR:// 隐藏访客页眉
  1017. if (mainActivity != null) {
  1018. mainActivity.dismissWithAnim(mainActivity.mFlHeadMsgNew, mainActivity.mRlHeadMsgVisitor);
  1019. }
  1020. sendEmptyMessageDelayed(MSG_TYPE_HEAD_MSG_NEW, HEAD_MSG_REFRESH_PERIOD);
  1021. break;
  1022. }
  1023. }
  1024. }
  1025. private static class MainAdapter extends FragmentPagerAdapter {
  1026. private List<Fragment> fragments = new ArrayList<>();
  1027. public MainAdapter(FragmentManager fm) {
  1028. super(fm);
  1029. fragments.add(new FateCardFragment());
  1030. fragments.add(new SearchFragment());
  1031. fragments.add(new MessageFragment());
  1032. fragments.add(new MeFragment());
  1033. // fragments.add(new RecentVistorsActivity());
  1034. }
  1035. @Override
  1036. public Fragment getItem(int position) {
  1037. return fragments.get(position);
  1038. }
  1039. @Override
  1040. public int getCount() {
  1041. return fragments.size();
  1042. }
  1043. }
  1044. @Override
  1045. protected void onStart() {
  1046. super.onStart();
  1047. isShake = true;
  1048. System.out.println("111111111111111111111111" + "MainonStart");
  1049. }
  1050. @Override
  1051. public void onCreate(@Nullable Bundle savedInstanceState, @Nullable PersistableBundle persistentState) {
  1052. super.onCreate(savedInstanceState, persistentState);
  1053. System.out.println("111111111111111111111111" + "Mainoncreat");
  1054. }
  1055. @Override
  1056. protected void onPause() {
  1057. super.onPause();
  1058. isShake = f

Large files files are truncated, but you can click here to view the full file