Commit 4155c8d2c46c2805a3c50b71958949ee0a5f369c

Authored by wugian
1 parent e5cade54

screen control

... ... @@ -43,11 +43,11 @@
43 43 <activity
44 44 android:name=".activity.StartActivity"
45 45 android:theme="@style/AppStartTheme">
46   - <!-- <intent-filter>
  46 + <intent-filter>
47 47 <action android:name="android.intent.action.MAIN"/>
48 48
49 49 <category android:name="android.intent.category.LAUNCHER"/>
50   - </intent-filter>-->
  50 + </intent-filter>
51 51 </activity>
52 52 <activity android:name=".activity.SearchNewActivity"/>
53 53 <activity android:name=".activity.PlayListActivity"/>
... ... @@ -131,11 +131,11 @@
131 131
132 132 <activity android:name="com.xgimi.smartscreen.ConfigActivity"/>
133 133 <activity android:name="com.xgimi.smartscreen.MainActivity">
134   - <intent-filter>
  134 + <!-- <intent-filter>
135 135 <action android:name="android.intent.action.MAIN"/>
136 136
137 137 <category android:name="android.intent.category.LAUNCHER"/>
138   - </intent-filter>
  138 + </intent-filter>-->
139 139 </activity>
140 140 <service android:name="com.xgimi.smartscreen.service.ConfigService"/>
141 141 </application>
... ...
... ... @@ -10,8 +10,10 @@ import android.text.method.ScrollingMovementMethod;
10 10 import android.util.Log;
11 11 import android.view.View;
12 12 import android.widget.TextView;
13   -import android.widget.Toast;
  13 +import com.gimi.common.cinema.model.MessageEvent;
  14 +import com.gimi.common.cinema.utils.Utils;
14 15 import com.xgimi.gimicinema.R;
  16 +import org.greenrobot.eventbus.EventBus;
15 17 import org.json.JSONException;
16 18 import org.json.JSONObject;
17 19
... ... @@ -22,12 +24,15 @@ import java.io.PrintWriter;
22 24 import java.net.Socket;
23 25 import java.net.SocketTimeoutException;
24 26
  27 +import static com.xgimi.smartscreen.MainActivity.UPDATE_CURRENT_CTRL_SCREEN;
  28 +
25 29
26 30 public class ControlDialog extends Dialog implements View.OnClickListener {
27 31 private static final String TAG = "ControlDialog";
28 32
29 33 private Context mContext;
30 34 private String mDeviceIp;
  35 + private int sn;
31 36
32 37 private TextView tvDeviceInfo;
33 38
... ... @@ -36,7 +41,6 @@ public class ControlDialog extends Dialog implements View.OnClickListener {
36 41
37 42 public ControlDialog(Context context, String DeviceIp) {
38 43 super(context);
39   -
40 44 this.mContext = context;
41 45 this.mDeviceIp = DeviceIp;
42 46 }
... ... @@ -59,6 +63,9 @@ public class ControlDialog extends Dialog implements View.OnClickListener {
59 63 TextView tvDown = (TextView) findViewById(R.id.tv_down);
60 64 tvDown.setOnClickListener(this);
61 65
  66 + TextView tvControl = (TextView) findViewById(R.id.tv_control);
  67 + tvControl.setOnClickListener(this);
  68 +
62 69
63 70 messageThread = new MessageThread();
64 71
... ... @@ -90,49 +97,25 @@ public class ControlDialog extends Dialog implements View.OnClickListener {
90 97 @Override
91 98 public void onClick(View v) {
92 99 switch (v.getId()) {
93   - case R.id.tv_up:/*
94   -
95   -
  100 + case R.id.tv_up:
96 101 MessageEvent msgEvent = new MessageEvent();
97   - msgEvent.setEventId(SmartScreenBean.UPACTION);
98   - msgEvent.setMessage("192.168.31.164");
99   - EventBus.getDefault().post(msgEvent);*/
100   - JSONObject dataUp = new JSONObject();
101   - getDeviceInfo();
102   - try {
103   - dataUp.put("cmd", 2);
104   - dataUp.put("action", 0);
105   - } catch (JSONException e) {
106   - e.printStackTrace();
107   - }
108   -
109   - Message msgUp = new Message();
110   - msgUp.what = 0x345;
111   - msgUp.obj = dataUp;
112   - messageThread.sendHandler.sendMessage(msgUp);
113   -
  102 + msgEvent.setEventId(SmartScreenBean.DOWNACTION);
  103 + msgEvent.setMessage(mDeviceIp);
  104 + EventBus.getDefault().post(msgEvent);
114 105 break;
115   -
116 106 case R.id.tv_down:
117   -
118   - /* MessageEvent msgEvent1 = new MessageEvent();
  107 + MessageEvent msgEvent1 = new MessageEvent();
119 108 msgEvent1.setEventId(SmartScreenBean.DOWNACTION);
120   - msgEvent1.setMessage("192.168.31.164");
121   - EventBus.getDefault().post(msgEvent1);*/
122   - JSONObject dataDown = new JSONObject();
123   -
124   - try {
125   - dataDown.put("cmd", 2);
126   - dataDown.put("action", 1);
127   - } catch (JSONException e) {
128   - e.printStackTrace();
129   - }
130   -
131   - Message msgDown = new Message();
132   - msgDown.what = 0x345;
133   - msgDown.obj = dataDown;
134   - messageThread.sendHandler.sendMessage(msgDown);
135   -
  109 + msgEvent1.setMessage(mDeviceIp);
  110 + EventBus.getDefault().post(msgEvent1);
  111 + break;
  112 + case R.id.tv_control:
  113 + Utils.saveInt(mContext, "screen-sn", sn);
  114 + Utils.saveString(mContext, "screen-ip", mDeviceIp);
  115 + MessageEvent msgEvent2 = new MessageEvent();
  116 + msgEvent2.setEventId(UPDATE_CURRENT_CTRL_SCREEN);
  117 + msgEvent2.setMessage("UPDATE_CURRENT_CTRL_SCREEN");
  118 + EventBus.getDefault().post(msgEvent2);
136 119 break;
137 120 }
138 121 }
... ... @@ -147,25 +130,14 @@ public class ControlDialog extends Dialog implements View.OnClickListener {
147 130
148 131 try {
149 132 JSONObject jsonObject = new JSONObject(data);
150   -
151 133 int cmd = jsonObject.getInt("cmd");
152   -
153 134 if (cmd == 1) {
154   - int sn = jsonObject.getInt("sn");
  135 + sn = jsonObject.getInt("sn");
155 136 String swver = jsonObject.getString("swver");
156 137 String hdver = jsonObject.getString("hdver");
157   -
158   - tvDeviceInfo.setText("序列号:" + sn + "\n\n软件版本:" + swver + "\n\n硬件版本:" + hdver);
159   -
160   - } else if (cmd == 2) {
161   - int result = jsonObject.getInt("result");
162   - if (result == 1) { //成功
163   - Toast.makeText(mContext, "操作成功", Toast.LENGTH_SHORT).show();
164   - } else if (result == 0) { //失败
165   - Toast.makeText(mContext, "操作失败", Toast.LENGTH_SHORT).show();
166   - }
  138 + String status = jsonObject.getString("status");
  139 + tvDeviceInfo.setText("序列号:" + sn + "\n\n软件版本:" + swver + "\n\n硬件版本:" + hdver + "\n\n幕布状态:" + status);
167 140 }
168   -
169 141 } catch (JSONException e) {
170 142 e.printStackTrace();
171 143 }
... ... @@ -223,8 +195,8 @@ public class ControlDialog extends Dialog implements View.OnClickListener {
223 195
224 196 if (msg.what == 0x345) {
225 197 Log.i(TAG, "写数据:" + (msg.obj).toString());
226   -// pw.write((msg.obj).toString());
227   - pw.write("{\"cmd\":2,\"action\":0}");
  198 + pw.write((msg.obj).toString());
  199 +// pw.write("{\"cmd\":2,\"action\":0}");
228 200 pw.flush();
229 201 }
230 202 }
... ... @@ -251,7 +223,6 @@ public class ControlDialog extends Dialog implements View.OnClickListener {
251 223 e.printStackTrace();
252 224 }
253 225 }
254   -
255 226 }
256 227 }
257 228 }
... ...
1 1 package com.xgimi.smartscreen;
2 2
3 3 import android.app.Activity;
  4 +import android.content.Intent;
4 5 import android.os.AsyncTask;
5 6 import android.os.Bundle;
  7 +import android.text.TextUtils;
6 8 import android.util.Log;
7 9 import android.view.View;
8 10 import android.view.Window;
9 11 import android.widget.AdapterView;
10 12 import android.widget.ArrayAdapter;
11 13 import android.widget.ListView;
  14 +import android.widget.TextView;
12 15 import android.widget.Toast;
  16 +import com.gimi.common.cinema.model.MessageEvent;
  17 +import com.gimi.common.cinema.utils.Utils;
13 18 import com.xgimi.gimicinema.R;
  19 +import com.xgimi.smartscreen.service.ConfigService;
  20 +import org.greenrobot.eventbus.EventBus;
  21 +import org.greenrobot.eventbus.Subscribe;
  22 +import org.greenrobot.eventbus.ThreadMode;
14 23
15 24 import java.io.IOException;
16 25 import java.net.DatagramPacket;
... ... @@ -23,8 +32,9 @@ import java.util.List;
23 32
24 33 public class MainActivity extends Activity {
25 34 private static final String TAG = "MainActivity";
26   -
  35 + public static final int UPDATE_CURRENT_CTRL_SCREEN = 0x998;
27 36 private ListView lvDevice;
  37 + private TextView txt_header_current;
28 38 List<String> listData;
29 39 ArrayAdapter<String> adapter;
30 40
... ... @@ -36,29 +46,11 @@ public class MainActivity extends Activity {
36 46 protected void onCreate(Bundle savedInstanceState) {
37 47 super.onCreate(savedInstanceState);
38 48 setContentView(R.layout.content_main);
39   -// Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
40   -// setSupportActionBar(toolbar);
41   -
42   -// FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
43   -// fab.setOnClickListener(new View.OnClickListener() {
44   -// @Override
45   -// public void onClick(View view) {
46   -// startActivity(new Intent(MainActivity.this, ConfigActivity.class));
47   -// }
48   -// });
49   -
50   -// swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
51   -//
52   -// swipeRefreshLayout.setColorSchemeResources(R.color.g);
53   -// swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
54   -//
55   -// swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
56   -// @Override
57   -// public void onRefresh() {
58   -// }
59   -// });
  49 + EventBus.getDefault().register(this);
  50 + startService(new Intent(this, ConfigService.class));
60 51
61 52 lvDevice = (ListView) findViewById(R.id.lv_device);
  53 + txt_header_current = (TextView) findViewById(R.id.txt_header_current);
62 54 lvDevice.setOnItemClickListener(new AdapterView.OnItemClickListener() {
63 55 @Override
64 56 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
... ... @@ -67,6 +59,11 @@ public class MainActivity extends Activity {
67 59 dialog.show();
68 60 }
69 61 });
  62 + String string = Utils.getString(this, "screen-ip", "");
  63 + int anInt = Utils.getInt(this, "screen-sn", 0);
  64 + if (!TextUtils.isEmpty(string)) {
  65 + txt_header_current.setText("当前控制幕布IP:" + string + ", sn:" + anInt);
  66 + }
70 67 new SearchAsyncTask().execute();
71 68
72 69 }
... ... @@ -80,6 +77,33 @@ public class MainActivity extends Activity {
80 77 // swipeRefreshLayout.setRefreshing(false);
81 78 }
82 79
  80 + @Override
  81 + protected void onResume() {
  82 + super.onResume();
  83 + }
  84 +
  85 + private void resetCurrent() {
  86 + String string = Utils.getString(this, "screen-ip", "");
  87 + int anInt = Utils.getInt(this, "screen-sn", 0);
  88 + if (!TextUtils.isEmpty(string)) {
  89 + txt_header_current.setText("当前控制幕布IP:" + string + ",sn:" + anInt);
  90 + }
  91 + }
  92 +
  93 + public void down(View view) {
  94 + MessageEvent msgEvent = new MessageEvent();
  95 + msgEvent.setEventId(SmartScreenBean.DOWNACTION);
  96 + msgEvent.setMessage(Utils.getString(this, "screen-ip", ""));
  97 + EventBus.getDefault().post(msgEvent);
  98 + }
  99 +
  100 + public void up(View view) {
  101 + MessageEvent msgEvent = new MessageEvent();
  102 + msgEvent.setEventId(SmartScreenBean.UPACTION);
  103 + msgEvent.setMessage(Utils.getString(this, "screen-ip", ""));
  104 + EventBus.getDefault().post(msgEvent);
  105 + }
  106 +
83 107 private class SearchAsyncTask extends AsyncTask<Void, Integer, String> {
84 108
85 109 InetAddress deviceAddress = null;
... ... @@ -193,4 +217,21 @@ public class MainActivity extends Activity {
193 217 }
194 218 }
195 219
  220 + @Override
  221 + protected void onDestroy() {
  222 + super.onDestroy();
  223 +
  224 + EventBus.getDefault().unregister(this);
  225 + }
  226 +
  227 +
  228 + @Subscribe(threadMode = ThreadMode.MAIN)
  229 + public void onMoonEvent(MessageEvent messageEvent) {
  230 + switch (messageEvent.getEventId()) {
  231 + case UPDATE_CURRENT_CTRL_SCREEN:
  232 + resetCurrent();
  233 + Log.d(TAG, messageEvent.getMessage());
  234 + break;
  235 + }
  236 + }
196 237 }
... ...
... ... @@ -70,8 +70,8 @@ public class ConfigService extends Service {
70 70 public void onCreate() {
71 71 super.onCreate();
72 72 Log.d(TAG, "onCreate");
  73 + Log.d("ConfigService", "onStartCommand register event bus");
73 74 EventBus.getDefault().register(this);
74   -
75 75 configStat = 0;
76 76 IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
77 77 registerReceiver(netStateChange, filter);
... ...
1 1 <?xml version="1.0" encoding="utf-8"?>
2   -<RelativeLayout 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   - android:paddingBottom="@dimen/activity_vertical_margin"
8   - android:paddingLeft="@dimen/activity_horizontal_margin"
9   - android:paddingRight="@dimen/activity_horizontal_margin"
10   - android:paddingTop="@dimen/activity_vertical_margin"
11   - tools:showIn="@layout/activity_main">
  2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3 + android:layout_width="match_parent"
  4 + android:layout_height="match_parent"
  5 + android:paddingBottom="@dimen/activity_vertical_margin"
  6 + android:paddingLeft="@dimen/activity_horizontal_margin"
  7 + android:paddingRight="@dimen/activity_horizontal_margin"
  8 + android:paddingTop="@dimen/activity_vertical_margin"
  9 + android:orientation="vertical">
  10 + <RelativeLayout
  11 + android:layout_width="match_parent"
  12 + android:layout_height="wrap_content">
  13 +
  14 + <ImageView
  15 + android:id="@+id/img_header_menu_left"
  16 + android:layout_width="wrap_content"
  17 + android:layout_height="wrap_content"
  18 + android:layout_alignParentStart="true"
  19 + android:layout_centerVertical="true"
  20 + android:layout_marginStart="10dp"
  21 + android:contentDescription="@null"/>
  22 +
  23 + <TextView
  24 + android:id="@+id/txt_header_title"
  25 + android:layout_width="wrap_content"
  26 + android:layout_height="wrap_content"
  27 + android:layout_alignWithParentIfMissing="false"
  28 + android:layout_centerHorizontal="true"
  29 + android:layout_centerInParent="true"
  30 + android:layout_centerVertical="true"
  31 + android:layout_marginEnd="30dp"
  32 + android:layout_marginStart="30dp"
  33 + android:gravity="center_vertical"
  34 + android:singleLine="true"
  35 + android:text="设置智能幕布"
  36 + android:textAlignment="center"
  37 + android:textColor="@android:color/white"
  38 + android:textSize="30sp"/>
  39 + </RelativeLayout>
  40 + <RelativeLayout
  41 + android:layout_width="match_parent"
  42 + android:layout_height="wrap_content">
12 43
  44 + <TextView
  45 + android:id="@+id/txt_header_current"
  46 + android:layout_width="wrap_content"
  47 + android:layout_height="wrap_content"
  48 + android:layout_alignWithParentIfMissing="false"
  49 + android:layout_centerHorizontal="true"
  50 + android:layout_centerInParent="true"
  51 + android:layout_centerVertical="true"
  52 + android:layout_marginEnd="30dp"
  53 + android:layout_marginStart="30dp"
  54 + android:gravity="center_vertical"
  55 + android:singleLine="true"
  56 + android:text="当前控制幕布未设置"
  57 + android:textAlignment="center"
  58 + android:textColor="@android:color/white"
  59 + android:textSize="22sp"/>
  60 + </RelativeLayout>
13 61
14 62 <ListView
15 63 android:id="@+id/lv_device"
16 64 android:layout_width="match_parent"
17   - android:layout_height="match_parent"/>
  65 + android:layout_weight="1"
  66 + android:layout_height="0dp"/>
  67 +
  68 + <LinearLayout android:layout_width="match_parent"
  69 + android:orientation="vertical"
  70 + android:layout_height="wrap_content">
  71 +
  72 + <Button
  73 + android:layout_width="match_parent"
  74 + android:layout_height="46dp"
  75 + android:layout_marginTop="15dp"
  76 + android:text="up"
  77 + android:onClick="up"
  78 + android:textColor="@android:color/black"
  79 + android:textSize="18sp"/>
  80 +
  81 + <Button
  82 + android:layout_width="match_parent"
  83 + android:layout_height="46dp"
  84 + android:layout_marginTop="15dp"
  85 + android:text="down"
  86 + android:onClick="down"
  87 + android:textColor="@android:color/black"
  88 + android:textSize="18sp"/>
  89 + </LinearLayout>
18 90
19   -</RelativeLayout>
  91 +</LinearLayout>
... ...
1 1 <?xml version="1.0" encoding="utf-8"?>
2 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3   - android:layout_width="400dp"
4   - android:layout_height="wrap_content"
5   - android:gravity="center_horizontal"
6   - android:orientation="vertical">
  3 + android:layout_width="400dp"
  4 + android:layout_height="wrap_content"
  5 + android:gravity="center_horizontal"
  6 + android:background="@color/white"
  7 + android:orientation="vertical">
7 8
8 9 <LinearLayout
9   - android:layout_width="match_parent"
10   - android:layout_height="32dp"
11   - android:background="@color/white"
12   - android:gravity="center"
13   - android:orientation="vertical">
  10 + android:layout_width="match_parent"
  11 + android:layout_height="32dp"
  12 + android:gravity="center"
  13 + android:orientation="vertical">
14 14
15 15 <TextView
16   - android:layout_width="wrap_content"
17   - android:layout_height="wrap_content"
18   - android:text="幕布控制"
19   - android:textColor="@color/black"
20   - android:textSize="16sp" />
  16 + android:layout_width="wrap_content"
  17 + android:layout_height="wrap_content"
  18 + android:text="幕布控制"
  19 + android:textColor="@color/black"
  20 + android:textSize="20sp"/>
21 21
22 22 <TextView
23   - android:id="@+id/tv_dialog_ip"
24   - android:layout_width="wrap_content"
25   - android:layout_height="wrap_content"
26   - android:textColor="@color/black"
27   - android:textSize="16sp" />
  23 + android:id="@+id/tv_dialog_ip"
  24 + android:layout_width="wrap_content"
  25 + android:layout_height="wrap_content"
  26 + android:textColor="@color/black"
  27 + android:textSize="16sp"/>
28 28
29 29 </LinearLayout>
30 30
31 31 <TextView
32   - android:layout_width="match_parent"
33   - android:layout_height="1dp"
34   - android:background="@color/gray" />
  32 + android:layout_width="match_parent"
  33 + android:layout_height="1dp"
  34 + android:background="@color/gray"/>
35 35
36 36 <LinearLayout
37   - android:layout_width="match_parent"
38   - android:layout_height="90dp">
  37 + android:layout_width="match_parent"
  38 + android:layout_height="120dp">
39 39
40 40 <TextView
41   - android:id="@+id/tv_device_info"
42   - android:layout_width="match_parent"
43   - android:layout_height="match_parent"
44   - android:padding="5dp"
45   - android:textColor="@color/black"
46   - android:textSize="14sp" />
  41 + android:id="@+id/tv_device_info"
  42 + android:layout_width="match_parent"
  43 + android:layout_height="match_parent"
  44 + android:padding="5dp"
  45 + android:textColor="@color/black"
  46 + android:textSize="14sp"/>
47 47
48 48 </LinearLayout>
49 49
50 50
51 51 <TextView
52   - android:layout_width="match_parent"
53   - android:layout_height="1dp"
54   - android:background="@color/gray" />
  52 + android:layout_width="match_parent"
  53 + android:layout_height="1dp"
  54 + android:background="@color/gray"/>
55 55
56 56
57 57 <LinearLayout
58   - android:layout_width="match_parent"
59   - android:layout_height="48sp">
  58 + android:layout_width="match_parent"
  59 + android:layout_height="48sp">
60 60
61 61 <Button
62   - android:id="@+id/tv_up"
63   - android:layout_width="0dp"
64   - android:layout_height="match_parent"
65   - android:layout_weight="1"
66   - android:gravity="center"
67   - android:text="上"
68   - android:textColor="@color/g"
69   - android:textSize="16sp" />
  62 + android:id="@+id/tv_up"
  63 + android:layout_width="0dp"
  64 + android:layout_height="match_parent"
  65 + android:layout_weight="1"
  66 + android:gravity="center"
  67 + android:text="上"
  68 + android:textColor="@color/g"
  69 + android:textSize="16sp"/>
70 70
71 71 <TextView
72   - android:layout_width="1dp"
73   - android:layout_height="match_parent"
74   - android:background="@color/gray" />
  72 + android:layout_width="1dp"
  73 + android:layout_height="match_parent"
  74 + android:background="@color/gray"/>
75 75
76 76 <Button
77   - android:id="@+id/tv_down"
78   - android:layout_width="0dp"
79   - android:layout_height="match_parent"
80   - android:layout_weight="1"
81   - android:gravity="center"
82   - android:text="下"
83   - android:textColor="@color/g"
84   - android:textSize="16sp" />
  77 + android:id="@+id/tv_down"
  78 + android:layout_width="0dp"
  79 + android:layout_height="match_parent"
  80 + android:layout_weight="1"
  81 + android:gravity="center"
  82 + android:text="下"
  83 + android:textColor="@color/g"
  84 + android:textSize="16sp"/>
  85 + <TextView
  86 + android:layout_width="1dp"
  87 + android:layout_height="match_parent"
  88 + android:background="@color/gray"/>
  89 +
  90 + <Button
  91 + android:id="@+id/tv_control"
  92 + android:layout_width="0dp"
  93 + android:layout_height="match_parent"
  94 + android:layout_weight="1"
  95 + android:gravity="center"
  96 + android:text="控制当前幕布"
  97 + android:textColor="@color/g"
  98 + android:textSize="16sp"/>
85 99
86 100 </LinearLayout>
87 101
... ...
Please register or login to post a comment