Browse Source

立即邀请开发完成

huyuguo 5 years ago
parent
commit
b0ac816a0c

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

150
            android:name=".wxapi.WXEntryActivity"
150
            android:name=".wxapi.WXEntryActivity"
151
            android:configChanges="keyboardHidden|orientation|screenSize"
151
            android:configChanges="keyboardHidden|orientation|screenSize"
152
            android:exported="true"
152
            android:exported="true"
153
            android:screenOrientation="portrait"
154
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
153
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />
155
        <activity
154
        <activity
156
            android:name=".wxapi.WXPayEntryActivity"
155
            android:name=".wxapi.WXPayEntryActivity"

+ 37 - 11
app/src/main/java/com/electric/chargingpile/activity/MyWebViewActivity.java

23
import androidx.annotation.NonNull;
23
import androidx.annotation.NonNull;
24
import androidx.core.content.FileProvider;
24
import androidx.core.content.FileProvider;
25
25
26
import android.text.TextUtils;
26
import android.util.Log;
27
import android.util.Log;
27
import android.view.KeyEvent;
28
import android.view.KeyEvent;
28
import android.view.View;
29
import android.view.View;
111
    private final static int FILE_CHOOSER_RESULT_CODE = 128;  // 图片
112
    private final static int FILE_CHOOSER_RESULT_CODE = 128;  // 图片
112
    private final static int FILE_CAMERA_RESULT_CODE = 129; // 拍照
113
    private final static int FILE_CAMERA_RESULT_CODE = 129; // 拍照
113
    private String cameraFilePath;  // 拍照图片路径
114
    private String cameraFilePath;  // 拍照图片路径
115
    private boolean loginToShare;
114
116
115
    @Override
117
    @Override
116
    protected void onCreate(Bundle savedInstanceState) {
118
    protected void onCreate(Bundle savedInstanceState) {
174
            } else {
176
            } else {
175
                mUrl = mUrl + "?version_code=" + BuildConfig.VERSION_CODE + "&from=cdz&system=android";
177
                mUrl = mUrl + "?version_code=" + BuildConfig.VERSION_CODE + "&from=cdz&system=android";
176
            }
178
            }
179
            if (MainApplication.isLogin()) {
180
                mUrl = mUrl + "&phone=" + MainApplication.userPhone;
181
            }
182
177
            webView.loadUrl(mUrl);
183
            webView.loadUrl(mUrl);
178
        }
184
        }
179
    }
185
    }
182
    @JavascriptInterface
188
    @JavascriptInterface
183
    public void showminiprogram(final String user_name, String path, int type) {
189
    public void showminiprogram(final String user_name, String path, int type) {
184
        if (Util.isWxAppInstalledAndSupported(MyWebViewActivity.this)) {
190
        if (Util.isWxAppInstalledAndSupported(MyWebViewActivity.this)) {
185
            IWXAPI api = WXAPIFactory.createWXAPI(MyWebViewActivity.this,getResources().getString(R.string.wx_app_key));
191
            IWXAPI api = WXAPIFactory.createWXAPI(MyWebViewActivity.this, getResources().getString(R.string.wx_app_key));
186
            WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
192
            WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
187
            req.userName = user_name;
193
            req.userName = user_name;
188
            req.path = path;
194
            req.path = path;
194
    }
200
    }
195
201
196
    @JavascriptInterface
202
    @JavascriptInterface
203
    public void welfareshare(final String shareUrl) {
204
        if (TextUtils.isEmpty(shareUrl)) {
205
            loginToShare = true;
206
            startActivity(new Intent(getApplicationContext(), LoginActivity.class));
207
            ToastUtil.showToast(getApplicationContext(), "请先登录", Toast.LENGTH_SHORT);
208
        } else {
209
            loginToShare = false;
210
            showSimpleBottomSheetGrid(shareUrl);
211
        }
212
    }
213
214
    @JavascriptInterface
197
    public void showsharebtn(final String show) {
215
    public void showsharebtn(final String show) {
198
        runOnUiThread(new Runnable() {
216
        runOnUiThread(new Runnable() {
199
            @Override
217
            @Override
322
    }
340
    }
323
341
324
    private void btnToShare() {
342
    private void btnToShare() {
325
        showSimpleBottomSheetGrid();
343
        showSimpleBottomSheetGrid(shareUrl);
326
    }
344
    }
327
345
328
    private void showSimpleBottomSheetGrid() {
346
    private void showSimpleBottomSheetGrid(final String shareUrl) {
329
        final int TAG_SHARE_WECHAT_FRIEND = 0;
347
        final int TAG_SHARE_WECHAT_FRIEND = 0;
330
        final int TAG_SHARE_WECHAT_MOMENT = 1;
348
        final int TAG_SHARE_WECHAT_MOMENT = 1;
331
        final int TAG_SHARE_QQ = 2;
349
        final int TAG_SHARE_QQ = 2;
340
                        int tag = (int) itemView.getTag();
358
                        int tag = (int) itemView.getTag();
341
                        switch (tag) {
359
                        switch (tag) {
342
                            case TAG_SHARE_WECHAT_FRIEND:
360
                            case TAG_SHARE_WECHAT_FRIEND:
343
                                share(Wechat.NAME);
361
                                share(Wechat.NAME, shareUrl);
344
                                break;
362
                                break;
345
                            case TAG_SHARE_WECHAT_MOMENT:
363
                            case TAG_SHARE_WECHAT_MOMENT:
346
                                share(WechatMoments.NAME);
364
                                share(WechatMoments.NAME, shareUrl);
347
                                break;
365
                                break;
348
                            case TAG_SHARE_QQ:
366
                            case TAG_SHARE_QQ:
349
                                share(QQ.NAME);
367
                                share(QQ.NAME, shareUrl);
350
                                break;
368
                                break;
351
                        }
369
                        }
352
                    }
370
                    }
383
        build.show();
401
        build.show();
384
    }
402
    }
385
403
386
    private void share(final String name) {
404
    private void share(final String name, final String shareUrl) {
387
        Platform.ShareParams paramsToShare = new Platform.ShareParams();
405
        Platform.ShareParams paramsToShare = new Platform.ShareParams();
388
        paramsToShare.setText(shareContext);
406
        paramsToShare.setText(shareContext);
389
        paramsToShare.setTitle(shareTitle);
407
        paramsToShare.setTitle(shareTitle);
441
459
442
    @JavascriptInterface
460
    @JavascriptInterface
443
    public void gotoshare() {
461
    public void gotoshare() {
444
        showSimpleBottomSheetGrid();
462
        showSimpleBottomSheetGrid(shareUrl);
445
    }
463
    }
446
464
447
465
913
                break;
931
                break;
914
            }
932
            }
915
        }
933
        }
934
935
        if (null != mUrl && !"".equals(mUrl) && loginToShare) {
936
            if (!mUrl.contains("&phone=")) {
937
                if (MainApplication.isLogin()) {
938
                    mUrl = mUrl + "&phone=" + MainApplication.userPhone;
939
                    webView.loadUrl(mUrl);
940
                }
941
            }
942
        }
916
    }
943
    }
917
944
918
    private void skipShopCenter() {
945
    private void skipShopCenter() {
1070
                //当用户登录成功后,需要重新请求一次服务端,带上currentUrl。
1097
                //当用户登录成功后,需要重新请求一次服务端,带上currentUrl。
1071
                //用该方法中的webview变量加载请求链接。
1098
                //用该方法中的webview变量加载请求链接。
1072
                //服务端收到请求后在生成免登录url时,将currentUrl放入redirect参数,通知客户端302跳转到新生成的免登录URL。
1099
                //服务端收到请求后在生成免登录url时,将currentUrl放入redirect参数,通知客户端302跳转到新生成的免登录URL。
1073
                new android.app.AlertDialog.Builder(webView.getContext())
1100
                new AlertDialog.Builder(webView.getContext())
1074
                        .setTitle("跳转登录")
1101
                        .setTitle("跳转登录")
1075
                        .setMessage("跳转到登录页面?")
1102
                        .setMessage("跳转到登录页面?")
1076
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
1103
                        .setPositiveButton("是", new DialogInterface.OnClickListener() {
1092
             */
1119
             */
1093
            public void onCopyCode(WebView webView, String code) {
1120
            public void onCopyCode(WebView webView, String code) {
1094
                //当未登录的用户点击去登录时,会调用此处代码。
1121
                //当未登录的用户点击去登录时,会调用此处代码。
1095
                new android.app.AlertDialog.Builder(webView.getContext())
1122
                new AlertDialog.Builder(webView.getContext())
1096
                        .setTitle("复制券码")
1123
                        .setTitle("复制券码")
1097
                        .setMessage("已复制,券码为:" + code)
1124
                        .setMessage("已复制,券码为:" + code)
1098
                        .setPositiveButton("是", null)
1125
                        .setPositiveButton("是", null)
1262
        public void onGeolocationPermissionsShowPrompt(String origin,
1289
        public void onGeolocationPermissionsShowPrompt(String origin,
1263
                                                       GeolocationPermissions.Callback callback) {
1290
                                                       GeolocationPermissions.Callback callback) {
1264
            callback.invoke(origin, true, false);
1291
            callback.invoke(origin, true, false);
1265
            // TODO Auto-generated method stub
1266
            super.onGeolocationPermissionsShowPrompt(origin, callback);
1292
            super.onGeolocationPermissionsShowPrompt(origin, callback);
1267
        }
1293
        }
1268
1294