Showing
8 changed files
with
134 additions
and
26 deletions
... | ... | @@ -57,6 +57,12 @@ |
57 | 57 | <meta-data |
58 | 58 | android:name="ScopedStorage" |
59 | 59 | android:value="true" /> |
60 | + <meta-data | |
61 | + android:name="com.rokid.uxr.application.mode" | |
62 | + android:value="3d" /> | |
63 | + <meta-data | |
64 | + android:name="com.rokid.uxr.sdk.version" | |
65 | + android:value="10900" /> | |
60 | 66 | |
61 | 67 | <!-- 适配 Android 7.0 文件意图 --> |
62 | 68 | <provider | ... | ... |
1 | 1 | package com.studymachine.www.app; |
2 | 2 | |
3 | +import android.app.Activity; | |
4 | +import android.app.AppOpsManager; | |
3 | 5 | import android.content.Context; |
4 | 6 | import android.content.Intent; |
5 | 7 | import android.hardware.display.DisplayManager; |
6 | 8 | import android.hardware.usb.UsbDevice; |
9 | +import android.net.Uri; | |
10 | +import android.os.Binder; | |
7 | 11 | import android.os.Build; |
8 | 12 | import android.os.Bundle; |
13 | +import android.provider.Settings; | |
9 | 14 | import android.view.Display; |
10 | 15 | import android.view.View; |
11 | 16 | import android.view.WindowManager; |
... | ... | @@ -40,6 +45,9 @@ import com.studymachine.www.ui.presentation.WebPresentation; |
40 | 45 | |
41 | 46 | import org.greenrobot.eventbus.EventBus; |
42 | 47 | |
48 | +import java.lang.reflect.Field; | |
49 | +import java.lang.reflect.Method; | |
50 | + | |
43 | 51 | import okhttp3.Call; |
44 | 52 | |
45 | 53 | /** |
... | ... | @@ -71,7 +79,8 @@ public abstract class AppActivity extends BaseActivity |
71 | 79 | */ |
72 | 80 | private int mDialogCount; |
73 | 81 | |
74 | - public GlassInfo deviceInfo = RKGlassDevice.getInstance().getGlassInfo();; | |
82 | + public GlassInfo deviceInfo = RKGlassDevice.getInstance().getGlassInfo(); | |
83 | + ; | |
75 | 84 | |
76 | 85 | MutableLiveData<Boolean> connectStatus = new MutableLiveData(); |
77 | 86 | |
... | ... | @@ -131,30 +140,69 @@ public abstract class AppActivity extends BaseActivity |
131 | 140 | mDialog.dismiss(); |
132 | 141 | } |
133 | 142 | |
143 | + //判断是否开启悬浮窗权限 context可以用你的Activity.或者tiis | |
144 | + public static boolean checkFloatPermission(Context context) { | |
145 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) | |
146 | + return true; | |
147 | + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | |
148 | + try { | |
149 | + Class cls = Class.forName("android.content.Context"); | |
150 | + Field declaredField = cls.getDeclaredField("APP_OPS_SERVICE"); | |
151 | + declaredField.setAccessible(true); | |
152 | + Object obj = declaredField.get(cls); | |
153 | + if (!(obj instanceof String)) { | |
154 | + return false; | |
155 | + } | |
156 | + String str2 = (String) obj; | |
157 | + obj = cls.getMethod("getSystemService", String.class).invoke(context, str2); | |
158 | + cls = Class.forName("android.app.AppOpsManager"); | |
159 | + Field declaredField2 = cls.getDeclaredField("MODE_ALLOWED"); | |
160 | + declaredField2.setAccessible(true); | |
161 | + Method checkOp = cls.getMethod("checkOp", Integer.TYPE, Integer.TYPE, String.class); | |
162 | + int result = (Integer) checkOp.invoke(obj, 24, Binder.getCallingUid(), context.getPackageName()); | |
163 | + return result == declaredField2.getInt(cls); | |
164 | + } catch (Exception e) { | |
165 | + return false; | |
166 | + } | |
167 | + } else { | |
168 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
169 | + AppOpsManager appOpsMgr = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); | |
170 | + if (appOpsMgr == null) | |
171 | + return false; | |
172 | + int mode = appOpsMgr.checkOpNoThrow("android:system_alert_window", android.os.Process.myUid(), context | |
173 | + .getPackageName()); | |
174 | + return mode == AppOpsManager.MODE_ALLOWED || mode == AppOpsManager.MODE_IGNORED; | |
175 | + } else { | |
176 | + return Settings.canDrawOverlays(context); | |
177 | + } | |
178 | + } | |
179 | + } | |
180 | + | |
181 | + private void requestSettingCanDrawOverlays() { | |
182 | + int sdkInt = Build.VERSION.SDK_INT; | |
183 | + if (sdkInt >= Build.VERSION_CODES.O) {//8.0以上 | |
184 | + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); | |
185 | + startActivity(intent); | |
186 | + } else if (sdkInt >= Build.VERSION_CODES.M) {//6.0-8.0 | |
187 | + Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); | |
188 | + intent.setData(Uri.parse("package:" + getPackageName())); | |
189 | + startActivity(intent); | |
190 | + } else {//4.4-6.0以下 | |
191 | + //无需处理了 | |
192 | + } | |
193 | + } | |
194 | + | |
134 | 195 | @Override |
135 | 196 | protected void initLayout() { |
136 | - if(!RKGlassDevice.getInstance().requestUSBDevicePermission()){ | |
197 | + if (!checkFloatPermission(this)) { | |
198 | + //权限请求方法 | |
199 | + requestSettingCanDrawOverlays(); | |
200 | + } | |
201 | + if (!RKGlassDevice.getInstance().requestUSBDevicePermission()) { | |
137 | 202 | toast("请到系统设置添加悬浮框权限"); |
138 | 203 | finish(); |
139 | 204 | } |
140 | - RKGlassDevice.getInstance().init(new OnGlassDeviceConnectListener() { | |
141 | - @Override | |
142 | - public void onGlassDeviceConnected(UsbDevice usbDevice) { | |
143 | -// //Glass 设备连接成功 | |
144 | -// addControllerView(); | |
145 | - connectStatus.setValue(true); | |
146 | - openAppPresentation(); | |
147 | - } | |
148 | - | |
149 | - @Override | |
150 | - public void onGlassDeviceDisconnected() { | |
151 | - connectStatus.setValue(false); | |
152 | - ActivityManager.getInstance().finishAllActivities(); | |
153 | -// mControllerBid.setVisibility(View.GONE); | |
154 | - } | |
155 | - }); | |
156 | 205 | |
157 | - deviceInfo = RKGlassDevice.getInstance().getGlassInfo(); | |
158 | 206 | super.initLayout(); |
159 | 207 | if (getTitleBar() != null) { |
160 | 208 | getTitleBar().setOnTitleBarListener(this); |
... | ... | @@ -172,6 +220,30 @@ public abstract class AppActivity extends BaseActivity |
172 | 220 | //保持常亮 |
173 | 221 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
174 | 222 | EventBusManager.register(this); |
223 | + RKGlassDevice.getInstance().init(new OnGlassDeviceConnectListener() { | |
224 | + @Override | |
225 | + public void onGlassDeviceConnected(UsbDevice usbDevice) { | |
226 | +// //Glass 设备连接成功 | |
227 | +// addControllerView(); | |
228 | + if (isDestroyed()){ | |
229 | + return; | |
230 | + } | |
231 | + connectStatus.setValue(true); | |
232 | + openAppPresentation(); | |
233 | + } | |
234 | + | |
235 | + @Override | |
236 | + public void onGlassDeviceDisconnected() { | |
237 | + if (isDestroyed()){ | |
238 | + return; | |
239 | + } | |
240 | + | |
241 | + connectStatus.setValue(false); | |
242 | + ActivityManager.getInstance().finishAllActivities(); | |
243 | +// mControllerBid.setVisibility(View.GONE); | |
244 | + } | |
245 | + }); | |
246 | + deviceInfo = RKGlassDevice.getInstance().getGlassInfo(); | |
175 | 247 | } |
176 | 248 | |
177 | 249 | /** |
... | ... | @@ -289,6 +361,12 @@ public abstract class AppActivity extends BaseActivity |
289 | 361 | } |
290 | 362 | |
291 | 363 | @Override |
364 | + protected void onResume() { | |
365 | + RKGlassDevice.getInstance().setDisplayMode(RKGlassDevice.GlassDisplayMode.MODE_2D); | |
366 | + super.onResume(); | |
367 | + } | |
368 | + | |
369 | + @Override | |
292 | 370 | protected void onDestroy() { |
293 | 371 | super.onDestroy(); |
294 | 372 | if (isShowDialog()) { | ... | ... |
... | ... | @@ -154,13 +154,13 @@ public final class AppApplication extends Application { |
154 | 154 | @Override |
155 | 155 | public void onGlassDeviceConnected(UsbDevice usbDevice) { |
156 | 156 | //Glass 设备连接成功 |
157 | - MutableLiveData<Boolean> connectStatus = new MutableLiveData(); | |
158 | - connectStatus.setValue(true); | |
157 | +// MutableLiveData<Boolean> connectStatus = new MutableLiveData(); | |
158 | +// connectStatus.setValue(true); | |
159 | 159 | } |
160 | 160 | |
161 | 161 | @Override |
162 | 162 | public void onGlassDeviceDisconnected() { |
163 | - ActivityManager.getInstance().finishAllActivities(); | |
163 | +// ActivityManager.getInstance().finishAllActivities(); | |
164 | 164 | //Glass 设备断开连接 |
165 | 165 | } |
166 | 166 | }); | ... | ... |
... | ... | @@ -2,9 +2,14 @@ package com.studymachine.www.js; |
2 | 2 | |
3 | 3 | |
4 | 4 | import android.app.Activity; |
5 | +import android.content.Context; | |
5 | 6 | import android.graphics.drawable.Drawable; |
7 | +import android.hardware.display.DisplayManager; | |
8 | +import android.os.Build; | |
6 | 9 | import android.os.Handler; |
7 | 10 | import android.os.Looper; |
11 | +import android.view.Display; | |
12 | +import android.view.WindowManager; | |
8 | 13 | import android.webkit.JavascriptInterface; |
9 | 14 | |
10 | 15 | |
... | ... | @@ -25,6 +30,7 @@ import com.studymachine.www.app.AppPresentation; |
25 | 30 | import com.studymachine.www.app.ModeHandler; |
26 | 31 | import com.studymachine.www.event.SwfEvent; |
27 | 32 | import com.studymachine.www.http.glide.GlideApp; |
33 | +import com.studymachine.www.manager.ActivityManager; | |
28 | 34 | import com.studymachine.www.manager.GlobalParameterManager; |
29 | 35 | import com.studymachine.www.manager.UserManager; |
30 | 36 | import com.studymachine.www.other.AppConfig; |
... | ... | @@ -35,6 +41,7 @@ import com.studymachine.www.ui.activity.AiListActivity; |
35 | 41 | import com.studymachine.www.ui.activity.BrowserActivity; |
36 | 42 | import com.studymachine.www.ui.activity.SwfActivity; |
37 | 43 | import com.studymachine.www.ui.dialog.WaitDialog; |
44 | +import com.studymachine.www.ui.presentation.BrowserPresentation; | |
38 | 45 | import com.studymachine.www.widget.X5WebView; |
39 | 46 | |
40 | 47 | import org.greenrobot.eventbus.EventBus; |
... | ... | @@ -246,8 +253,10 @@ public class MainJavaScriptInterface { |
246 | 253 | } |
247 | 254 | |
248 | 255 | Tool.startOtherApp(mContext, packageName); |
256 | + ActivityManager.getInstance().finishAllActivities(); | |
249 | 257 | if (presentation != null) { |
250 | 258 | presentation.dismiss(); |
259 | + presentation = null; | |
251 | 260 | } |
252 | 261 | } |
253 | 262 | ... | ... |
... | ... | @@ -8,6 +8,8 @@ import androidx.annotation.NonNull; |
8 | 8 | import androidx.annotation.Nullable; |
9 | 9 | import androidx.collection.ArrayMap; |
10 | 10 | |
11 | +import com.rokid.axr.phone.glassdevice.RKGlassDevice; | |
12 | + | |
11 | 13 | import java.util.ArrayList; |
12 | 14 | |
13 | 15 | import timber.log.Timber; |
... | ... | @@ -122,6 +124,7 @@ public final class ActivityManager implements Application.ActivityLifecycleCallb |
122 | 124 | */ |
123 | 125 | public void finishAllActivities() { |
124 | 126 | finishAllActivities((Class<? extends Activity>) null); |
127 | + RKGlassDevice.getInstance().deInit(); | |
125 | 128 | } |
126 | 129 | |
127 | 130 | /** | ... | ... |
... | ... | @@ -109,10 +109,13 @@ public final class BrowserActivity extends AppActivity |
109 | 109 | |
110 | 110 | @Override |
111 | 111 | protected void initData() { |
112 | - if (deviceInfo != null && deviceInfo.getSn() != null) { | |
112 | + if (deviceInfo != null && deviceInfo.getSn() != null && deviceInfo.isvSyncStatus()) { | |
113 | 113 | mControlBack = findViewById(R.id.control_back); |
114 | 114 | mControlChange = findViewById(R.id.control_change); |
115 | 115 | mControlMode = findViewById(R.id.control_mode); |
116 | + if (mControlBack == null){ | |
117 | + return; | |
118 | + } | |
116 | 119 | mControlBack.setVisibility(View.VISIBLE); |
117 | 120 | mControlChange.setVisibility(View.VISIBLE); |
118 | 121 | mControlMode.setVisibility(View.GONE); |
... | ... | @@ -211,10 +214,17 @@ public final class BrowserActivity extends AppActivity |
211 | 214 | } else { |
212 | 215 | presentation.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY); |
213 | 216 | } |
217 | + } else { | |
218 | + return; | |
214 | 219 | } |
215 | 220 | } |
216 | 221 | presentation.setOwnerActivity(this); |
217 | - presentation.show(); | |
222 | + try { | |
223 | + presentation.show(); | |
224 | + } catch (Exception e) { | |
225 | + presentation.dismiss(); | |
226 | + presentation.show(); | |
227 | + } | |
218 | 228 | presentation.setMode(0); |
219 | 229 | } |
220 | 230 | ... | ... |
... | ... | @@ -41,10 +41,10 @@ public final class RestartActivity extends AppActivity { |
41 | 41 | Intent intent; |
42 | 42 | if (UserManager.getInstance().getToken()==null) { |
43 | 43 | // 如果是未登录的情况下跳转到闪屏页 |
44 | - intent = new Intent(context, LoginActivity.class); | |
44 | + intent = new Intent(context, SplashActivity.class); | |
45 | 45 | } else { |
46 | 46 | // 如果是已登录的情况下跳转到首页 |
47 | - intent = new Intent(context, HomeActivity.class); | |
47 | + intent = new Intent(context, SplashActivity.class); | |
48 | 48 | } |
49 | 49 | if (!(context instanceof Activity)) { |
50 | 50 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ... | ... |
... | ... | @@ -2,9 +2,11 @@ package com.studymachine.www.ui.presentation; |
2 | 2 | |
3 | 3 | import static com.hjq.http.EasyUtils.post; |
4 | 4 | |
5 | +import android.app.Activity; | |
5 | 6 | import android.content.Context; |
6 | 7 | import android.graphics.Bitmap; |
7 | 8 | import android.graphics.drawable.BitmapDrawable; |
9 | +import android.os.Build; | |
8 | 10 | import android.os.Message; |
9 | 11 | import android.view.Display; |
10 | 12 | import android.view.View; | ... | ... |