Browse Source

提交查漏补缺

皇甫睿欣 7 years ago
parent
commit
883f264b20

+ 7 - 0
app/build.gradle

@@ -9,6 +9,11 @@ android {
9 9
         versionCode 2
10 10
         versionName "2.0"
11 11
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12
+        manifestPlaceholders = [
13
+                JPUSH_PKGNAME: applicationId,
14
+                JPUSH_APPKEY : "595369d477b409e0f9096f69",
15
+                JPUSH_CHANNEL: "developer-default",
16
+        ]
12 17
     }
13 18
     buildTypes {
14 19
         release {
@@ -25,4 +30,6 @@ dependencies {
25 30
     annotationProcessor project(':laraver-compiler')
26 31
     compile 'com.facebook.stetho:stetho:1.4.2'
27 32
     compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
33
+    compile 'cn.jiguang.sdk:jpush:3.0.1'
34
+    compile 'cn.jiguang.sdk:jcore:1.1.0'
28 35
 }

+ 117 - 0
app/src/main/AndroidManifest.xml

@@ -1,6 +1,17 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2 2
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
3 4
     package="com.kuxuan.fastbrowser">
5
+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6
+    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
7
+    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
8
+    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
9
+
10
+    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
11
+    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
12
+    <uses-permission android:name="android.permission.GET_TASKS" />
13
+    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
14
+    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
4 15
 
5 16
     <application
6 17
         android:allowBackup="true"
@@ -17,6 +28,112 @@
17 28
                 <category android:name="android.intent.category.LAUNCHER" />
18 29
             </intent-filter>
19 30
         </activity>
31
+        <!-- Required SDK 核心功能-->
32
+        <!-- 可配置android:process参数将PushService放在其他进程中 -->
33
+        <service
34
+            android:name="cn.jpush.android.service.PushService"
35
+            android:enabled="true"
36
+            android:exported="false">
37
+            <intent-filter>
38
+                <action android:name="cn.jpush.android.intent.REGISTER" />
39
+                <action android:name="cn.jpush.android.intent.REPORT" />
40
+                <action android:name="cn.jpush.android.intent.PushService" />
41
+                <action android:name="cn.jpush.android.intent.PUSH_TIME" />
42
+            </intent-filter>
43
+        </service>
44
+
45
+        <!-- since 1.8.0 option 可选项。用于同一设备中不同应用的JPush服务相互拉起的功能。 -->
46
+        <!-- 若不启用该功能可删除该组件,将不拉起其他应用也不能被其他应用拉起 -->
47
+        <service
48
+            android:name="cn.jpush.android.service.DaemonService"
49
+            android:enabled="true"
50
+            android:exported="true">
51
+            <intent-filter>
52
+                <action android:name="cn.jpush.android.intent.DaemonService" />
53
+                <category android:name="com.diabin.fastec.example" />
54
+            </intent-filter>
55
+        </service>
56
+
57
+        <!-- Required SDK核心功能-->
58
+        <receiver
59
+            android:name="cn.jpush.android.service.PushReceiver"
60
+            android:enabled="true">
61
+            <intent-filter android:priority="1000">
62
+                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
63
+                <category android:name="com.diabin.fastec.example" />
64
+            </intent-filter>
65
+            <intent-filter>
66
+                <action android:name="android.intent.action.USER_PRESENT" />
67
+                <action
68
+                    android:name="android.net.conn.CONNECTIVITY_CHANGE"
69
+                    tools:ignore="BatteryLife" />
70
+            </intent-filter>
71
+            <!-- Optional -->
72
+            <intent-filter>
73
+                <action android:name="android.intent.action.PACKAGE_ADDED" />
74
+                <action android:name="android.intent.action.PACKAGE_REMOVED" />
75
+
76
+                <data android:scheme="package" />
77
+            </intent-filter>
78
+        </receiver>
79
+
80
+        <!-- Required SDK核心功能-->
81
+        <activity
82
+            android:name="cn.jpush.android.ui.PushActivity"
83
+            android:configChanges="orientation|keyboardHidden"
84
+            android:exported="false"
85
+            android:theme="@android:style/Theme.NoTitleBar">
86
+            <intent-filter>
87
+                <action android:name="cn.jpush.android.ui.PushActivity" />
88
+
89
+                <category android:name="android.intent.category.DEFAULT" />
90
+                <category android:name="com.diabin.fastec.example" />
91
+            </intent-filter>
92
+        </activity>
93
+
94
+        <!-- Required SDK核心功能-->
95
+        <service
96
+            android:name="cn.jpush.android.service.DownloadService"
97
+            android:enabled="true"
98
+            android:exported="false" />
99
+
100
+        <!-- Required SDK核心功能-->
101
+        <receiver android:name="cn.jpush.android.service.AlarmReceiver" />
102
+
103
+        <!-- User defined. 用户自定义的广播接收器-->
104
+        <receiver
105
+            android:name=".push.PushReceiver"
106
+            android:enabled="true">
107
+            <intent-filter>
108
+                <!--Required 用户注册SDK的intent-->
109
+                <action android:name="cn.jpush.android.intent.REGISTRATION" />
110
+                <!--Required 用户接收SDK消息的intent-->
111
+                <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
112
+                <!--Required 用户接收SDK通知栏信息的intent-->
113
+                <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
114
+                <!--Required 用户打开自定义通知栏的intent-->
115
+                <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
116
+                <!-- 接收网络变化 连接/断开 since 1.6.3 -->
117
+                <action android:name="cn.jpush.android.intent.CONNECTION" />
118
+                <category android:name="com.diabin.fastec.example" />
119
+            </intent-filter>
120
+        </receiver>
121
+
122
+        <!-- Required. For publish channel feature -->
123
+        <!-- JPUSH_CHANNEL 是为了方便开发者统计APK分发渠道。-->
124
+        <!-- 例如: -->
125
+        <!-- 发到 Google Play 的APK可以设置为 google-play; -->
126
+        <!-- 发到其他市场的 APK 可以设置为 xxx-market。 -->
127
+        <!-- 目前这个渠道统计功能的报表还未开放。-->
128
+        <meta-data
129
+            android:name="JPUSH_CHANNEL"
130
+            android:value="developer-default" />
131
+        <!-- Required. AppKey copied from Portal -->
132
+        <meta-data
133
+            android:name="JPUSH_APPKEY"
134
+            android:value="595369d477b409e0f9096f69" />
135
+        <!--极光推送结束-->
136
+
20 137
     </application>
21 138
 
22 139
 </manifest>

+ 9 - 1
app/src/main/java/com/kuxuan/fastbrowser/App.java

@@ -9,8 +9,12 @@ import com.kuxuan.laraver.browser.database.DatabaseManager;
9 9
 import com.kuxuan.fastbrowser.event.TextEvent;
10 10
 import com.kuxuan.laraver.net.interceptors.ReleaseInterceptor;
11 11
 
12
+import cn.jpush.android.api.JPushInterface;
13
+
12 14
 /**
13
- * Created by huangfuruixin on 2017/12/5.
15
+ *
16
+ * @author huangfuruixin
17
+ * @date 2017/12/5
14 18
  */
15 19
 
16 20
 public class App extends Application {
@@ -28,6 +32,10 @@ public class App extends Application {
28 32
                 .withWebHost("https://wwww.baidu.com/")
29 33
                 .configure();
30 34
         DatabaseManager.getInstance().init(this);
35
+        //开启极光推送
36
+        JPushInterface.setDebugMode(true);
37
+        JPushInterface.init(this);
38
+
31 39
     }
32 40
 
33 41
     private void initStetho() {

+ 13 - 0
app/src/main/java/com/kuxuan/fastbrowser/MainActivity.java

@@ -8,6 +8,7 @@ import com.kuxuan.laraver.activities.ProxyActivity;
8 8
 import com.kuxuan.laraver.browser.main.EcBottomDelegate;
9 9
 import com.kuxuan.laraver.delegates.LaraverDelegate;
10 10
 
11
+import cn.jpush.android.api.JPushInterface;
11 12
 import qiu.niorgai.StatusBarCompat;
12 13
 
13 14
 
@@ -24,6 +25,18 @@ public class MainActivity extends ProxyActivity{
24 25
     }
25 26
 
26 27
     @Override
28
+    protected void onPause() {
29
+        super.onPause();
30
+        JPushInterface.onPause(this);
31
+    }
32
+
33
+    @Override
34
+    protected void onResume() {
35
+        super.onResume();
36
+        JPushInterface.onPause(this);
37
+    }
38
+
39
+    @Override
27 40
     public LaraverDelegate setRootDelegate() {
28 41
         return new EcBottomDelegate();
29 42
     }

+ 63 - 0
app/src/main/java/com/kuxuan/fastbrowser/push/PushReceiver.java

@@ -0,0 +1,63 @@
1
+package com.kuxuan.fastbrowser.push;
2
+
3
+import android.content.BroadcastReceiver;
4
+import android.content.Context;
5
+import android.content.Intent;
6
+import android.os.Bundle;
7
+import android.support.v4.content.ContextCompat;
8
+
9
+import com.alibaba.fastjson.JSONObject;
10
+import com.kuxuan.fastbrowser.MainActivity;
11
+import com.kuxuan.laraver.util.log.LaraverLogger;
12
+
13
+import java.util.Set;
14
+
15
+import cn.jpush.android.api.JPushInterface;
16
+
17
+/**
18
+ * Created by huangfuruixin on 2017/12/12.
19
+ */
20
+
21
+public class PushReceiver extends BroadcastReceiver {
22
+    @Override
23
+    public void onReceive(Context context, Intent intent) {
24
+        final Bundle bundle = intent.getExtras();
25
+        final Set<String> keys = bundle.keySet();
26
+        final JSONObject json = new JSONObject();
27
+        for (String key : keys) {
28
+            final Object val = bundle.get(key);
29
+            json.put(key, val);
30
+        }
31
+
32
+        LaraverLogger.json("PushReceiver", json.toJSONString());
33
+
34
+        final String pushAction = intent.getAction();
35
+        if (pushAction.equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)) {
36
+            //处理接收到的信息
37
+            onReceivedMessage(bundle);
38
+        } else if (pushAction.equals(JPushInterface.ACTION_NOTIFICATION_OPENED)) {
39
+            //打开相应的Notification
40
+            onOpenNotification(context, bundle);
41
+        }
42
+    }
43
+
44
+    private void onReceivedMessage(Bundle bundle) {
45
+        final String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
46
+        final String msgId = bundle.getString(JPushInterface.EXTRA_MSG_ID);
47
+        final int notificationId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
48
+        final String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
49
+        final String extra = bundle.getString(JPushInterface.EXTRA_EXTRA);
50
+        final String alert = bundle.getString(JPushInterface.EXTRA_ALERT);
51
+    }
52
+
53
+    private void onOpenNotification(Context context, Bundle bundle) {
54
+        final String extra = bundle.getString(JPushInterface.EXTRA_EXTRA);
55
+        final Bundle openActivityBundle = new Bundle();
56
+        final Intent intent = new Intent(context, MainActivity.class);
57
+        intent.putExtras(openActivityBundle);
58
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
59
+        ContextCompat.startActivity(context, intent, null);
60
+    }
61
+}
62
+
63
+

+ 17 - 6
laraver-core/src/main/java/com/kuxuan/laraver/delegates/PermissionCheckerDelegate.java

@@ -12,6 +12,7 @@ import android.widget.Toast;
12 12
 import com.kuxuan.laraver.ui.camera.CameraImageBean;
13 13
 import com.kuxuan.laraver.ui.camera.LaraverCamera;
14 14
 import com.kuxuan.laraver.ui.camera.RequestCodes;
15
+import com.kuxuan.laraver.ui.scanner.ScannerDelegate;
15 16
 import com.kuxuan.laraver.util.callback.CallbackManager;
16 17
 import com.kuxuan.laraver.util.callback.CallbackType;
17 18
 import com.kuxuan.laraver.util.callback.IGlobalCallback;
@@ -30,7 +31,7 @@ import permissions.dispatcher.RuntimePermissions;
30 31
  * @date 2017/12/5
31 32
  */
32 33
 @RuntimePermissions
33
-public abstract class PermissionCheckerDelegate extends BaseDelegate{
34
+public abstract class PermissionCheckerDelegate extends BaseDelegate {
34 35
 
35 36
     //不是直接调用方法
36 37
     @NeedsPermission(Manifest.permission.CAMERA)
@@ -43,10 +44,14 @@ public abstract class PermissionCheckerDelegate extends BaseDelegate{
43 44
         PermissionCheckerDelegatePermissionsDispatcher.startCameraWithCheck(this);
44 45
     }
45 46
 
46
-    @Override
47
-    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
48
-        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
49
-        PermissionCheckerDelegatePermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
47
+    //扫描二维码(不直接调用)
48
+    @NeedsPermission(Manifest.permission.CAMERA)
49
+    void startScan(BaseDelegate delegate) {
50
+        delegate.getSupportDelegate().startForResult(new ScannerDelegate(), RequestCodes.SCAN);
51
+    }
52
+
53
+    public void startScanWithCheck(BaseDelegate delegate) {
54
+        PermissionCheckerDelegatePermissionsDispatcher.startScanWithCheck(this, delegate);
50 55
     }
51 56
 
52 57
     @OnPermissionDenied(Manifest.permission.CAMERA)
@@ -63,6 +68,7 @@ public abstract class PermissionCheckerDelegate extends BaseDelegate{
63 68
     void onCameraRationale(PermissionRequest request) {
64 69
         showRationaleDialog(request);
65 70
     }
71
+
66 72
     private void showRationaleDialog(final PermissionRequest request) {
67 73
         new AlertDialog.Builder(getContext())
68 74
                 .setPositiveButton("同意使用", new DialogInterface.OnClickListener() {
@@ -83,6 +89,12 @@ public abstract class PermissionCheckerDelegate extends BaseDelegate{
83 89
     }
84 90
 
85 91
     @Override
92
+    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
93
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
94
+        PermissionCheckerDelegatePermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
95
+    }
96
+
97
+    @Override
86 98
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
87 99
         super.onActivityResult(requestCode, resultCode, data);
88 100
         if (resultCode == RESULT_OK) {
@@ -122,5 +134,4 @@ public abstract class PermissionCheckerDelegate extends BaseDelegate{
122 134
             }
123 135
         }
124 136
     }
125
-
126 137
 }

+ 24 - 0
laraver-core/src/main/java/com/kuxuan/laraver/ui/scanner/LaraverViewFindView.java

@@ -0,0 +1,24 @@
1
+package com.kuxuan.laraver.ui.scanner;
2
+
3
+import android.content.Context;
4
+import android.graphics.Color;
5
+import android.util.AttributeSet;
6
+
7
+import me.dm7.barcodescanner.core.ViewFinderView;
8
+
9
+/**
10
+ * @author huangfuruixin
11
+ */
12
+public class LaraverViewFindView extends ViewFinderView {
13
+
14
+    public LaraverViewFindView(Context context) {
15
+        this(context, null);
16
+    }
17
+
18
+    public LaraverViewFindView(Context context, AttributeSet attributeSet) {
19
+        super(context, attributeSet);
20
+        mSquareViewFinder = true;
21
+        mBorderPaint.setColor(Color.YELLOW);
22
+        mLaserPaint.setColor(Color.YELLOW);
23
+    }
24
+}

+ 23 - 0
laraver-core/src/main/java/com/kuxuan/laraver/ui/scanner/ScanView.java

@@ -0,0 +1,23 @@
1
+package com.kuxuan.laraver.ui.scanner;
2
+
3
+import android.content.Context;
4
+import android.util.AttributeSet;
5
+
6
+import me.dm7.barcodescanner.core.IViewFinder;
7
+import me.dm7.barcodescanner.zbar.ZBarScannerView;
8
+
9
+public class ScanView extends ZBarScannerView {
10
+
11
+    public ScanView(Context context) {
12
+        this(context, null);
13
+    }
14
+
15
+    public ScanView(Context context, AttributeSet attributeSet) {
16
+        super(context, attributeSet);
17
+    }
18
+
19
+    @Override
20
+    protected IViewFinder createViewFinderView(Context context) {
21
+        return new LaraverViewFindView(context);
22
+    }
23
+}

+ 67 - 0
laraver-core/src/main/java/com/kuxuan/laraver/ui/scanner/ScannerDelegate.java

@@ -0,0 +1,67 @@
1
+package com.kuxuan.laraver.ui.scanner;
2
+
3
+import android.os.Bundle;
4
+import android.support.annotation.NonNull;
5
+import android.support.annotation.Nullable;
6
+import android.view.View;
7
+
8
+import com.kuxuan.laraver.delegates.LaraverDelegate;
9
+import com.kuxuan.laraver.util.callback.CallbackManager;
10
+import com.kuxuan.laraver.util.callback.CallbackType;
11
+import com.kuxuan.laraver.util.callback.IGlobalCallback;
12
+
13
+import me.dm7.barcodescanner.zbar.Result;
14
+import me.dm7.barcodescanner.zbar.ZBarScannerView;
15
+
16
+public class ScannerDelegate extends LaraverDelegate implements ZBarScannerView.ResultHandler {
17
+
18
+    private ScanView mScanView = null;
19
+
20
+    @Override
21
+    public void onCreate(@Nullable Bundle savedInstanceState) {
22
+        super.onCreate(savedInstanceState);
23
+        if (mScanView == null) {
24
+            mScanView = new ScanView(getContext());
25
+        }
26
+        mScanView.setAutoFocus(true);
27
+        mScanView.setResultHandler(this);
28
+    }
29
+
30
+    @Override
31
+    public Object setLayout() {
32
+        return mScanView;
33
+    }
34
+
35
+    @Override
36
+    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
37
+    }
38
+
39
+    @Override
40
+    public void onResume() {
41
+        super.onResume();
42
+        if (mScanView != null) {
43
+            mScanView.startCamera();
44
+        }
45
+    }
46
+
47
+    @Override
48
+    public void onPause() {
49
+        super.onPause();
50
+        if (mScanView != null) {
51
+            mScanView.stopCameraPreview();
52
+            mScanView.stopCamera();
53
+        }
54
+    }
55
+
56
+    @Override
57
+    public void handleResult(Result result) {
58
+        @SuppressWarnings("unchecked")
59
+        final IGlobalCallback<String> callback = CallbackManager
60
+                .getInstance()
61
+                .getCallback(CallbackType.ON_SCAN);
62
+        if (callback != null) {
63
+            callback.executeCallback(result.getContents());
64
+        }
65
+        getSupportDelegate().pop();
66
+    }
67
+}