Commit eedcab35b6f563030ce8414b25c1f37b317f79ca

Authored by YangShuai
1 parent aedde39e

1 新增全局通知(这个不用,已经移动到主项目中)

app/src/main/java/com/cnlive/strike/xiaojiaspeaker/MainActivity.java
... ... @@ -2,11 +2,17 @@ package com.cnlive.strike.xiaojiaspeaker;
2 2  
3 3  
4 4 import android.content.Intent;
  5 +import android.databinding.DataBindingUtil;
5 6 import android.os.Bundle;
  7 +import android.os.Handler;
  8 +import android.support.design.widget.Snackbar;
6 9 import android.support.v7.app.AppCompatActivity;
  10 +import android.view.LayoutInflater;
  11 +import android.view.View;
7 12  
8 13 import com.alibaba.android.arouter.launcher.ARouter;
9 14 import com.cnlive.strike.xiaojiaspeaker.commonInfo.XiaoJIaCommInfo;
  15 +import com.cnlive.strike.xiaojiaspeaker.databinding.ActivitySpeakerMainBinding;
10 16 import com.cnlive.strike.xiaojiaspeaker.ui.activity.AllDeviceActivity;
11 17 import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity;
12 18 import com.cnlive.strike.xiaojiaspeaker.ui.activity.BluetoothConnActivity;
... ... @@ -22,11 +28,12 @@ import com.cnlive.strike.xiaojiaspeaker.ui.activity.SpeakerMainActivity;
22 28  
23 29 public class MainActivity extends AppCompatActivity {
24 30 private static final String TAG = "MainActivity";
  31 + private ActivitySpeakerMainBinding binding;
25 32  
26 33 @Override
27 34 protected void onCreate(Bundle savedInstanceState) {
28 35 super.onCreate(savedInstanceState);
29   - setContentView(R.layout.activity_speaker_main);
  36 + binding = DataBindingUtil.setContentView(this, R.layout.activity_speaker_main);
30 37 XiaoJIaCommInfo.setUserId(this, "10514333".trim());
31 38 XiaoJIaCommInfo.setUserPhone(this, "18301489586".trim());
32 39  
... ... @@ -54,7 +61,18 @@ public class MainActivity extends AppCompatActivity {
54 61 // .withString("currentSelectFamilyId", "")
55 62 // .navigation(this);
56 63  
  64 +
57 65 finish();
  66 +
  67 +// View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_snaker, null);
  68 +// new Handler().postDelayed(new Runnable() {
  69 +// @Override
  70 +// public void run() {
  71 +// Snackbar.make(getWindow().getDecorView(), "这是一个snackbar", Snackbar.LENGTH_LONG).show();
  72 +// MyApp.instance().createAndStart();
  73 +// }
  74 +// },5000);
  75 +
58 76 }
59 77  
60 78 }
... ...
app/src/main/java/com/cnlive/strike/xiaojiaspeaker/MyApp.java
1 1 package com.cnlive.strike.xiaojiaspeaker;
2 2  
  3 +import android.animation.Animator;
  4 +import android.animation.AnimatorListenerAdapter;
  5 +import android.animation.AnimatorSet;
  6 +import android.animation.ObjectAnimator;
  7 +import android.app.Activity;
3 8 import android.app.Application;
  9 +import android.os.Bundle;
  10 +import android.os.Handler;
  11 +import android.util.Log;
  12 +import android.view.LayoutInflater;
  13 +import android.view.View;
  14 +import android.view.ViewGroup;
  15 +import android.widget.LinearLayout;
4 16  
5 17 import com.alibaba.android.arouter.launcher.ARouter;
6 18 import com.cnlive.libs.base.application.AppConfig;
7 19 import com.cnlive.strike.speaker.BuildConfig;
  20 +import com.cnlive.strike.xiaojiaspeaker.util.utilcode.util.ScreenUtils;
8 21  
  22 +import static com.cnlive.strike.xiaojiaspeaker.util.utilcode.util.ConvertUtils.dp2px;
  23 +
  24 +
  25 +public class MyApp extends Application implements Application.ActivityLifecycleCallbacks {
  26 + /*当前对象的静态实例*/
  27 + private static MyApp instance;
  28 + /*当前显示的Activity*/
  29 + private Activity activity;
9 30  
10   -public class MyApp extends Application {
11 31 @Override
12 32 public void onCreate() {
13 33 super.onCreate();
  34 + MyApp.instance = this;
  35 + this.registerActivityLifecycleCallbacks(this);
  36 +
14 37 initARouter();
15 38 String userId = "";
16 39 AppConfig.init(this, BuildConfig.APP_ID, BuildConfig.APP_KEY,
17 40 BuildConfig.APP_SCERET, BuildConfig.SPECIAL_GROUP_MEMBER_LIMIT,
18   - BuildConfig.VERSION_AS_DEBUG, "","",
  41 + BuildConfig.VERSION_AS_DEBUG, "", "",
19 42 "10514333", "",
20   - "","", "",
21   - "", "","",
  43 + "", "", "",
  44 + "", "", "",
22 45 BuildConfig.BAIDU_MAP_APP_KEY, "");
23 46 }
24 47  
... ... @@ -35,4 +58,144 @@ public class MyApp extends Application {
35 58 ARouter.init(this); // 尽可能早,推荐在Application中初始化
36 59 }
37 60  
  61 + /**
  62 + * 获取Application对象
  63 + *
  64 + * @return 返回一个App对象实例
  65 + * @see MyApp
  66 + */
  67 + public static MyApp instance() {
  68 + return MyApp.instance;
  69 + }
  70 +
  71 + /**
  72 + * 显示View
  73 + *
  74 + * @param view 需要显示到Activity的视图
  75 + */
  76 + public void showView(View view) {
  77 + /*Activity不为空并且没有被释放掉*/
  78 + if (this.activity != null && !this.activity.isFinishing()) {
  79 + /*获取Activity顶层视图,并添加自定义View*/
  80 + ((ViewGroup) this.activity.getWindow().getDecorView()).addView(view);
  81 + }
  82 + }
  83 +
  84 + /**
  85 + * 隐藏View
  86 + *
  87 + * @param view 需要从Activity中移除的视图
  88 + */
  89 + public void hideView(View view) {
  90 + /*Activity不为空并且没有被释放掉*/
  91 + if (this.activity != null && !this.activity.isFinishing() && null != view) {
  92 + /*获取Activity顶层视图*/
  93 + ViewGroup root = ((ViewGroup) this.activity.getWindow().getDecorView());
  94 + if (null == root) {
  95 + return;
  96 + }
  97 + removeView(view, root);
  98 + }
  99 + }
  100 +
  101 + private void removeView(View view, ViewGroup root) {
  102 + ObjectAnimator bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getScreenHeight() - dp2px(80), ScreenUtils.getScreenHeight()).setDuration(500);
  103 + /*初始化动画组合器*/
  104 + AnimatorSet animator = new AnimatorSet();
  105 + animator.play(bottomToTop);
  106 + /*添加动画结束回调*/
  107 + animator.addListener(new AnimatorListenerAdapter() {
  108 + @Override
  109 + public void onAnimationEnd(Animator animation) {
  110 + super.onAnimationEnd(animation);
  111 + /*如果Activity中存在View对象则删除*/
  112 + if (root.indexOfChild(view) != -1) {
  113 + /*从顶层视图中删除*/
  114 + root.removeView(view);
  115 + }
  116 + }
  117 + });
  118 + /*启动动画*/
  119 + animator.start();
  120 + }
  121 +
  122 + @Override
  123 + public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
  124 +
  125 + }
  126 +
  127 + @Override
  128 + public void onActivityStarted(Activity activity) {
  129 +
  130 + }
  131 +
  132 + @Override
  133 + public void onActivityResumed(Activity activity) {
  134 + /*获取当前显示的Activity*/
  135 + this.activity = activity;
  136 + }
  137 +
  138 + @Override
  139 + public void onActivityPaused(Activity activity) {
  140 +
  141 + }
  142 +
  143 + @Override
  144 + public void onActivityStopped(Activity activity) {
  145 +
  146 + }
  147 +
  148 + @Override
  149 + public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
  150 +
  151 + }
  152 +
  153 + @Override
  154 + public void onActivityDestroyed(Activity activity) {
  155 +
  156 + }
  157 +
  158 +
  159 + public void createAndStart() {
  160 + /*创建提示消息View*/
  161 + View view = LayoutInflater.from(this).inflate(R.layout.view_top_msg, null);
  162 + if (null == view) {
  163 + return;
  164 + }
  165 + LinearLayout ll_ignore = view.findViewById(R.id.ll_ignore);
  166 + LinearLayout ll_lookUp = view.findViewById(R.id.ll_lookUp);
  167 + ll_ignore.setOnClickListener(new View.OnClickListener() {
  168 + @Override
  169 + public void onClick(View v) {
  170 + if (null != view) {
  171 + instance().hideView(view);
  172 + }
  173 + }
  174 + });
  175 + /*创建属性动画,从下到上*/
  176 + ObjectAnimator bottomToTop = ObjectAnimator.ofFloat(view, "translationY", ScreenUtils.getScreenHeight(), ScreenUtils.getScreenHeight() - dp2px(80)).setDuration(500);
  177 + /*初始化动画组合器*/
  178 + AnimatorSet animator = new AnimatorSet();
  179 + /*组合动画*/
  180 + animator.play(bottomToTop);
  181 + /*添加动画结束回调*/
  182 + animator.addListener(new AnimatorListenerAdapter() {
  183 + @Override
  184 + public void onAnimationEnd(Animator animation) {
  185 + super.onAnimationEnd(animation);
  186 + new Handler().postDelayed(new Runnable() {
  187 + @Override
  188 + public void run() {
  189 + /*删除View*/
  190 + instance().hideView(view);
  191 + }
  192 + }, 5000);
  193 + }
  194 + });
  195 + /*添加View到当前显示的Activity*/
  196 + instance().showView(view);
  197 + /*启动动画*/
  198 + animator.start();
  199 + }
  200 +
38 201 }
... ...
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/frame/view/AllDeviceFragmentView.java
... ... @@ -11,11 +11,13 @@ import com.cnlive.strike.xiaojiaspeaker.commonInfo.XiaoJIaCommInfo;
11 11 import com.cnlive.strike.xiaojiaspeaker.netWork.bean.FamilyListBean;
12 12 import com.cnlive.strike.xiaojiaspeaker.ui.activity.BlueToothStep1Activity;
13 13 import com.cnlive.strike.xiaojiaspeaker.ui.activity.DeviceDetailActivity;
  14 +import com.cnlive.strike.xiaojiaspeaker.ui.activity.RemoteControlActivity;
14 15 import com.cnlive.strike.xiaojiaspeaker.ui.adapter.AllDeviceAdapter;
15 16 import com.cnlive.strike.xiaojiaspeaker.ui.fragment.AllDeviceFragment;
16 17 import com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu.PopMenu;
17 18 import com.cnlive.strike.xiaojiaspeaker.ui.widget.popmenu.PopMenuInfo;
18 19 import com.hannesdorfmann.mosby3.mvp.MvpView;
  20 +import com.qmuiteam.qmui.alpha.QMUIAlphaImageButton;
19 21  
20 22 import java.util.ArrayList;
21 23 import java.util.List;
... ... @@ -28,6 +30,7 @@ public class AllDeviceFragmentView implements MvpView {
28 30 // private PopMenu mPopMenu;
29 31 private String TAG = "AllDeviceFragmentView";
30 32 private FamilyListBean familyListBean;
  33 + private QMUIAlphaImageButton remoteButton;//远程控制按钮
31 34  
32 35 public AllDeviceFragmentView(AllDeviceFragment fragment) {
33 36 this.fragment = fragment;
... ... @@ -38,11 +41,20 @@ public class AllDeviceFragmentView implements MvpView {
38 41 }
39 42  
40 43 public void initView() {
41   -// initPopView();
  44 + if (null == remoteButton) {
  45 + remoteButton = fragment.binding.topbar.addRightImageButton(R.drawable.icon_xiaojia_menu, R.id.right_menu);
  46 + remoteButton.setOnClickListener(new View.OnClickListener() {
  47 + @Override
  48 + public void onClick(View v) {
  49 + //远程控制
  50 + RemoteControlActivity.startActivity(getContext());
  51 + }
  52 + });
  53 + }
  54 + remoteButton.setVisibility(View.GONE);
42 55 }
43 56  
44 57 public void initAllDeviceList(FamilyListBean familyListBean) {
45   -
46 58 this.familyListBean = familyListBean;
47 59 this.allDeviceInfoList = new ArrayList<>();
48 60 if (null != familyListBean && null != familyListBean.getUsers()) {
... ... @@ -50,7 +62,7 @@ public class AllDeviceFragmentView implements MvpView {
50 62 for (FamilyListBean.UsersBeanX usersBean : familyListBean.getUsers()) {
51 63  
52 64 //存储自己为主人的家庭
53   - if (FamilyListBean.THE_HOST==usersBean.getIsMaster()) {
  65 + if (FamilyListBean.THE_HOST == usersBean.getIsMaster()) {
54 66 Log.e(TAG, "getId: " + usersBean.getUserId());
55 67 Log.e(TAG, "getToken: " + usersBean.getToken());
56 68 //存储家庭id
... ... @@ -73,8 +85,10 @@ public class AllDeviceFragmentView implements MvpView {
73 85 }
74 86 if (null == allDeviceInfoList || allDeviceInfoList.size() == 0) {
75 87 XiaoJIaCommInfo.setUserIsBind(getContext(), false);
  88 + initTopBarBtn(false);
76 89 } else {
77 90 XiaoJIaCommInfo.setUserIsBind(getContext(), true);
  91 + initTopBarBtn(true);
78 92 }
79 93 adapter = new AllDeviceAdapter(getContext(), allDeviceInfoList);
80 94 fragment.binding.rvAllDevice.setLayoutManager(new LinearLayoutManager(getContext()));
... ... @@ -194,4 +208,12 @@ public class AllDeviceFragmentView implements MvpView {
194 208 }
195 209 fragment.binding.emptyLayout.show(false, titleText, detailText, getContext().getString(R.string.retry), R.drawable.wufalianjie, listener);
196 210 }
  211 +
  212 + public void initTopBarBtn(boolean isShowRemote) {
  213 +
  214 + if (isShowRemote) {
  215 + //控制
  216 + remoteButton.setVisibility(View.VISIBLE);
  217 + }
  218 + }
197 219 }
... ...
module_xiaojiaSoundBox/src/main/java/com/cnlive/strike/xiaojiaspeaker/ui/fragment/AllDeviceFragment.java
... ... @@ -86,29 +86,17 @@ public class AllDeviceFragment extends MvpBindingFragment&lt;AllDeviceFragmentView,
86 86 getActivity().finish();
87 87 }
88 88 });
89   -
90   -
91 89 //添加设备按钮
92 90 addButton = binding.topbar.addRightImageButton(R.drawable.icon_xiaojia_item_add, R.id.right_add);
93 91 addButton.setOnClickListener(new View.OnClickListener() {
94 92 @Override
95 93 public void onClick(View view) {
96   - if (null != getMvpView()) {
97   -// getMvpView().showPop(addButton);
  94 + if (null != getContext()) {
98 95 BlueToothStep1Activity.startActivity(getActivity());
99 96  
100 97 }
101 98 }
102 99 });
103   - //控制
104   - binding.topbar.addRightImageButton(R.drawable.icon_xiaojia_menu, R.id.right_menu).setOnClickListener(new View.OnClickListener() {
105   - @Override
106   - public void onClick(View v) {
107   - //远程控制
108   - RemoteControlActivity.startActivity(getActivity());
109   - }
110   - });
111   -
112 100 }
113 101 }
114 102  
... ...
module_xiaojiaSoundBox/src/main/res/drawable/shape_xiaojia_black_tip.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<shape xmlns:android="http://schemas.android.com/apk/res/android">
  3 + <corners android:radius="10dp" />
  4 + <solid android:color="#BF000000" />
  5 +</shape>
0 6 \ No newline at end of file
... ...
module_xiaojiaSoundBox/src/main/res/layout/layout_snaker.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + xmlns:app="http://schemas.android.com/apk/res-auto"
  4 + xmlns:tools="http://schemas.android.com/tools"
  5 + android:layout_width="match_parent"
  6 + android:layout_height="match_parent">
  7 +
  8 + <android.support.design.widget.CoordinatorLayout
  9 + android:id="@+id/snackbar_container"
  10 + android:layout_width="match_parent"
  11 + android:layout_height="match_parent">
  12 +
  13 + <TextView
  14 + android:layout_width="wrap_content"
  15 + android:layout_height="wrap_content"
  16 + android:text="asfvsadfvas" />
  17 +
  18 + </android.support.design.widget.CoordinatorLayout>
  19 +
  20 +</android.support.constraint.ConstraintLayout>
0 21 \ No newline at end of file
... ...
module_xiaojiaSoundBox/src/main/res/layout/view_top_msg.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:id="@+id/view_top_msg_parent"
  4 + android:layout_width="match_parent"
  5 + android:layout_height="match_parent"
  6 + android:orientation="vertical">
  7 +
  8 + <LinearLayout
  9 + android:layout_width="match_parent"
  10 + android:layout_height="50dp"
  11 + android:layout_margin="10dp"
  12 + android:background="@drawable/shape_xiaojia_black_tip"
  13 + android:gravity="center_vertical">
  14 +
  15 + <TextView
  16 + android:layout_width="0dp"
  17 + android:layout_height="wrap_content"
  18 + android:layout_marginLeft="10dp"
  19 + android:layout_weight="1"
  20 + android:gravity="left"
  21 + android:text="您被好友绑定成为了亲情关系"
  22 + android:textColor="@color/white"
  23 + android:textSize="15sp" />
  24 +
  25 + <LinearLayout
  26 + android:layout_width="wrap_content"
  27 + android:layout_height="match_parent"
  28 + android:layout_gravity="right">
  29 +
  30 + <LinearLayout
  31 + android:layout_width="0dp"
  32 + android:layout_height="match_parent"
  33 + android:layout_weight="1"
  34 + android:id="@+id/ll_ignore"
  35 + android:gravity="center">
  36 +
  37 + <TextView
  38 + android:layout_width="wrap_content"
  39 + android:layout_height="wrap_content"
  40 + android:layout_marginLeft="5dp"
  41 + android:layout_marginRight="10dp"
  42 + android:text="忽略"
  43 + android:textColor="@color/white"
  44 + android:textSize="15sp" />
  45 + </LinearLayout>
  46 +
  47 + <View
  48 + android:layout_width="1dp"
  49 + android:layout_height="match_parent"
  50 + android:layout_marginTop="15dp"
  51 + android:layout_marginBottom="15dp"
  52 + android:background="@color/white" />
  53 +
  54 + <LinearLayout
  55 + android:layout_width="0dp"
  56 + android:layout_height="match_parent"
  57 + android:layout_marginRight="20dp"
  58 + android:layout_weight="1"
  59 + android:id="@+id/ll_lookUp"
  60 + android:gravity="center">
  61 +
  62 + <TextView
  63 + android:layout_width="wrap_content"
  64 + android:layout_height="wrap_content"
  65 + android:layout_marginLeft="10dp"
  66 + android:layout_marginRight="5dp"
  67 + android:text="查看"
  68 + android:textColor="@color/white"
  69 + android:textSize="15sp" />
  70 + </LinearLayout>
  71 + </LinearLayout>
  72 + </LinearLayout>
  73 +
  74 +</LinearLayout>
0 75 \ No newline at end of file
... ...