Commit 3d9d83f3 by gao.chao

拆出map

组件化工具(延时回调未完成)
parent dd265c7f
...@@ -53,4 +53,5 @@ dependencies { ...@@ -53,4 +53,5 @@ dependencies {
// api(name:'fastDevelop-release', ext:'aar') // api(name:'fastDevelop-release', ext:'aar')
api project(':fastDevelop') api project(':fastDevelop')
api project(':web') api project(':web')
api project(':map')
} }
...@@ -13,7 +13,6 @@ import com.mayi.fastdevelop.bean.UserInfo; ...@@ -13,7 +13,6 @@ import com.mayi.fastdevelop.bean.UserInfo;
import com.mayi.fastdevelop.comnon.Constant; import com.mayi.fastdevelop.comnon.Constant;
import com.mayi.fastdevelop.okhttp.NetWorkBuilder; import com.mayi.fastdevelop.okhttp.NetWorkBuilder;
import com.mayi.fastdevelop.okhttp.ResultCallback; import com.mayi.fastdevelop.okhttp.ResultCallback;
import com.mayi.fastdevelop.util.LocationUtils;
import com.mayi.fastdevelop.view.OnMultiClickListener; import com.mayi.fastdevelop.view.OnMultiClickListener;
public class FunctionActivity extends BaseActivity { public class FunctionActivity extends BaseActivity {
...@@ -103,17 +102,17 @@ public class FunctionActivity extends BaseActivity { ...@@ -103,17 +102,17 @@ public class FunctionActivity extends BaseActivity {
findViewById(R.id.b8).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b8).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
LocationUtils.startLocation(v.getContext(), new LocationUtils.LocationCallback() { // LocationUtils.startLocation(v.getContext(), new LocationUtils.LocationCallback() {
@Override // @Override
public void onFail(String msg) { // public void onFail(String msg) {
showToast(msg); // showToast(msg);
} // }
//
@Override // @Override
public void onSuccess(LocationBean bean) { // public void onSuccess(LocationBean bean) {
showToast(JSON.toJSONString(bean)); // showToast(JSON.toJSONString(bean));
} // }
}); // });
} }
}); });
} }
......
...@@ -2,18 +2,29 @@ package com.mayi.demo; ...@@ -2,18 +2,29 @@ package com.mayi.demo;
import android.app.Application; import android.app.Application;
import com.gc.call.CallManage;
import com.gc.call.CallParticipationBean;
import com.mayi.fastdevelop.base.BaseApplication; import com.mayi.fastdevelop.base.BaseApplication;
import com.mayi.fastdevelop.comnon.Configure; import com.mayi.fastdevelop.comnon.Configure;
import com.mayi.fastdevelop.web.WebUtil; import com.mayi.fastdevelop.map.GoMapLocationCallTarget;
import com.mayi.fastdevelop.map.LocationCallTarget;
import com.mayi.fastdevelop.web.InitWebCallTarget;
import com.mayi.fastdevelop.web.GoWebCallTarget;
public class MyApplication extends BaseApplication{ public class MyApplication extends BaseApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
WebUtil.initX5Webview(); CallManage.getInstance().addTarget(new LocationCallTarget());
initBugly("cb8018da1b",true); CallManage.getInstance().addTarget(new GoMapLocationCallTarget());
Configure.APP_LOGO=R.mipmap.ic_launcher; CallManage.getInstance().addTarget(new GoWebCallTarget());
CallManage.getInstance().addTarget(new InitWebCallTarget());
CallParticipationBean bean = new CallParticipationBean();
bean.setTag("web_initWeb");
CallManage.getInstance().handleTarget(bean);
initBugly("cb8018da1b", true);
Configure.APP_LOGO = R.mipmap.ic_launcher;
} }
@Override @Override
......
...@@ -6,16 +6,17 @@ import android.os.Bundle; ...@@ -6,16 +6,17 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.View; import android.view.View;
import com.gc.call.CallConstant;
import com.gc.call.CallManage;
import com.gc.call.CallParticipationBean;
import com.mayi.fastdevelop.base.BaseAPI; import com.mayi.fastdevelop.base.BaseAPI;
import com.mayi.fastdevelop.base.BaseActivity; import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.base.BasePresenter; import com.mayi.fastdevelop.base.BasePresenter;
import com.mayi.fastdevelop.commonpage.amap.MapLocationActivity;
import com.mayi.fastdevelop.commonpage.login.LoginActivity; import com.mayi.fastdevelop.commonpage.login.LoginActivity;
import com.mayi.fastdevelop.comnon.Key; import com.mayi.fastdevelop.comnon.Key;
import com.mayi.fastdevelop.comnon.RequestCode; import com.mayi.fastdevelop.comnon.RequestCode;
import com.mayi.fastdevelop.util.ToolUtils; import com.mayi.fastdevelop.util.ToolUtils;
import com.mayi.fastdevelop.view.OnMultiClickListener; import com.mayi.fastdevelop.view.OnMultiClickListener;
//import com.mayi.fastdevelop.web.BaseWebActivity;
public class PageActivity extends BaseActivity { public class PageActivity extends BaseActivity {
...@@ -37,18 +38,23 @@ public class PageActivity extends BaseActivity { ...@@ -37,18 +38,23 @@ public class PageActivity extends BaseActivity {
findViewById(R.id.b1).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b1).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
Bundle bundle = new Bundle(); CallParticipationBean bean = new CallParticipationBean();
bundle.putString("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5&username=18001874470&v=" + System.currentTimeMillis()); bean.setTag("web_goWeb");
// gotoActivity(BaseWebActivity.class, bundle); bean.setContext(PageActivity.this);
bean.addParameter("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5&username=18001874470&v=" + System.currentTimeMillis());
CallManage.getInstance().handleTarget(bean);
} }
}); });
findViewById(R.id.b2).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b2).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
Bundle bundle = new Bundle(); CallParticipationBean bean = new CallParticipationBean();
bundle.putString("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5" + bean.setTag("web_goWeb");
bean.setContext(PageActivity.this);
bean.setLooper(CallConstant.LOOPER_NO_MAIN_HANDLER_AND_MIAN_RETURN);
bean.addParameter("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5" +
"&username=18001874470&v=" + System.currentTimeMillis() + "&isNeedBackButton=true&userAppTitle=潜客"); "&username=18001874470&v=" + System.currentTimeMillis() + "&isNeedBackButton=true&userAppTitle=潜客");
// gotoActivity(BaseWebActivity.class, bundle); CallManage.getInstance().handleTarget(bean);
} }
}); });
findViewById(R.id.b3).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b3).setOnClickListener(new OnMultiClickListener() {
...@@ -78,8 +84,10 @@ public class PageActivity extends BaseActivity { ...@@ -78,8 +84,10 @@ public class PageActivity extends BaseActivity {
findViewById(R.id.b7).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b7).setOnClickListener(new OnMultiClickListener() {
@Override @Override
public void onMultiClick(View v) { public void onMultiClick(View v) {
Intent intent = new Intent(PageActivity.this, MapLocationActivity.class); CallParticipationBean bean = new CallParticipationBean();
startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE); bean.setTag("map_goMapLocation");
bean.setContext(PageActivity.this);
CallManage.getInstance().handleTarget(bean);
} }
}); });
findViewById(R.id.b8).setOnClickListener(new OnMultiClickListener() { findViewById(R.id.b8).setOnClickListener(new OnMultiClickListener() {
......
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.gc.call;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.gc.call.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gc.call" />
package com.gc.call;
public class CallConstant {
public static int CODE_SUCCESS= 0x0001;; //返回成功
public static int CODE_NO_TARGET =0x0002;//返回没有找到目标
public static int LOOPER_MAIN=0x0101; //主线程处理
public static int LOOPER_NO_MAIN=0x0102; //不在主线程处理,
public static int LOOPER_NO_MAIN_HANDLER_AND_MIAN_RETURN=0x0103; //不在主线程处理,在主线程回调
}
package com.gc.call;
//接受请求有能立即处理的继承CallImmediatelyHandlerTarget
public abstract class CallImmediatelyHandlerTarget extends CallTarget {
//处理数据
public abstract CallReturnBean onHandle(CallParticipationBean bean);
}
package com.gc.call;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.util.HashMap;
import java.util.Map;
public class CallManage {
private String TAG = "CallManage";
private Map<String, CallTarget> map = new HashMap<>();
private Handler handler = new Handler(Looper.getMainLooper());
private static CallManage callManage;
public static CallManage getInstance() {
if (callManage == null) {
callManage = new CallManage();
}
return callManage;
}
public void addTarget(CallTarget callTarget) {
map.put(callTarget.getTag(), callTarget);
}
public void handleTarget(final CallParticipationBean bean) {
Log.i(TAG, "handleTarget:" + bean.getTag());
CallTarget callTarget = map.get(bean.getTag());
if (callTarget == null) {
if (bean.getListener() != null) {
CallReturnBean callReturn = new CallReturnBean();
callReturn.setMsg("没有找到对应的CallTarget");
callReturn.setCode(CallConstant.CODE_NO_TARGET);
bean.getListener().onReturn(callReturn);
bean.getListener().onReturn(callReturn);
}
} else {
if (callTarget instanceof CallImmediatelyHandlerTarget) {
onImmediatelyHandler(bean, (CallImmediatelyHandlerTarget) callTarget);
} else if (callTarget instanceof CallTimeHandTarget) {
}
}
}
private void onImmediatelyHandler(final CallParticipationBean bean, final CallImmediatelyHandlerTarget target) {
handler.post(new Runnable() {
@Override
public void run() {
if (bean.getLooper() == CallConstant.LOOPER_MAIN) {
handler.post(new Runnable() {
@Override
public void run() {
CallReturnBean c = target.onHandle(bean);
if (bean.getListener() != null) {
bean.getListener().onReturn(c);
}
}
});
} else if (bean.getLooper() == CallConstant.LOOPER_NO_MAIN) {
AsyncTask asyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object[] objects) {
CallReturnBean c = target.onHandle(bean);
if (bean.getListener() != null) {
bean.getListener().onReturn(c);
}
return null;
}
};
asyncTask.execute();
} else if (bean.getLooper() == CallConstant.LOOPER_NO_MAIN_HANDLER_AND_MIAN_RETURN) {
AsyncTask asyncTask = new AsyncTask() {
@Override
protected CallReturnBean doInBackground(Object[] objects) {
return target.onHandle(bean);
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
if (bean.getListener() != null) {
bean.getListener().onReturn((CallReturnBean) o);
}
}
};
asyncTask.execute();
}
}
});
}
// private CallReturnBean onImmediatelyHandle(CallParticipationBean bean) {
// CallTarget callTarget = map.get(bean.getTag());
// if (callTarget != null) {
// if (callTarget instanceof CallImmediatelyHandlerTarget) {
// return ((CallImmediatelyHandlerTarget) callTarget).onHandle(bean);
// }
// } else {
// CallReturnBean callReturn = new CallReturnBean();
// callReturn.setMsg("没有找到对应的CallTarget");
// callReturn.setCode(CallConstant.CODE_NO_TARGET);
// bean.getListener().onReturn(callReturn);
// return callReturn;
// }
// return null;
// }
}
package com.gc.call;
import android.content.Context;
import org.json.JSONException;
import org.json.JSONObject;
//call的入参
public class CallParticipationBean {
private Context context;
private String tag; //目标
private JSONObject parameter; //入参
private CallReturnListener listener; //回调
private int looper=CallConstant.LOOPER_MAIN;//是否在主线处理,为true在主线程处理
public int getLooper() {
return looper;
}
public void setLooper(int looper) {
this.looper = looper;
}
public Context getContext() {
return context;
}
public void setContext(Context context) {
this.context = context;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public CallReturnListener getListener() {
return listener;
}
public void setListener(CallReturnListener listener) {
this.listener = listener;
}
public JSONObject getParameter() {
return parameter;
}
public void setParameter(JSONObject parameter) {
this.parameter = parameter;
}
public void addParameter(String key,String value){
if (parameter==null){
parameter=new JSONObject();
}
try {
parameter.put(key,value);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
package com.gc.call;
public class CallReturnBean {
private String msg;
private String returnJson;
private int code = CallConstant.CODE_SUCCESS;//返回 1:表示成功,默认值,2:没有找到目标 其他表示失败,可自定义
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getReturnJson() {
return returnJson;
}
public void setReturnJson(String returnJson) {
this.returnJson = returnJson;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}
package com.gc.call;
public interface CallReturnListener {
public void onReturn(CallReturnBean bean);
}
package com.gc.call;
abstract class CallTarget {
/**
* 获取目标 为了防止重复建议命名规范: module名+事件名 例 web_goWebPage
* web是module名 goWebPage是跳转web页面,为事件名
*
* @return
*/
public abstract String getTag();
}
package com.gc.call;
public abstract class CallTimeHandTarget extends CallTarget {
// 耗时处理数据
public abstract void delayProcessing(CallParticipationBean bean, CallTimeHandlerListener listener);
}
package com.gc.call;
//接受请求有不能立即处理的,处理需要耗时的继承CallImmediatelyHandlerTarget
public interface CallTimeHandlerListener {
public void timeHandler(CallReturnBean bean);
}
<resources>
<string name="app_name">call</string>
</resources>
package com.gc.call;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
...@@ -26,11 +26,6 @@ android { ...@@ -26,11 +26,6 @@ android {
dependencies { dependencies {
api fileTree(include: ['*.jar'], dir: 'libs') api fileTree(include: ['*.jar'], dir: 'libs')
//高德地图
api 'com.amap.api:location:latest.integration'
api 'com.amap.api:search:latest.integration'
api 'com.amap.api:3dmap:latest.integration'
api 'com.yanzhenjie:permission:2.0.0-rc12'//权限申请 api 'com.yanzhenjie:permission:2.0.0-rc12'//权限申请
api 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'//下拉刷新,加载更多 api 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.3'//下拉刷新,加载更多
api 'com.youth.banner:banner:1.4.10' //图片轮播控件 api 'com.youth.banner:banner:1.4.10' //图片轮播控件
...@@ -43,4 +38,5 @@ dependencies { ...@@ -43,4 +38,5 @@ dependencies {
api 'com.android.support:recyclerview-v7:28.0.0' api 'com.android.support:recyclerview-v7:28.0.0'
api 'com.android.support:appcompat-v7:28.0.0' api 'com.android.support:appcompat-v7:28.0.0'
api files('libs/zixing-core-3.2.0.jar') api files('libs/zixing-core-3.2.0.jar')
api project(':call')
} }
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
<application> <application>
<activity android:name=".commonpage.amap.MapLocationActivity" />
<activity android:name=".commonpage.main.MainActivity" /> <activity android:name=".commonpage.main.MainActivity" />
<activity android:name=".commonpage.login.LoginActivity"/> <activity android:name=".commonpage.login.LoginActivity"/>
......
...@@ -6,6 +6,7 @@ import android.text.TextUtils; ...@@ -6,6 +6,7 @@ import android.text.TextUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mayi.fastdevelop.util.LogUtils; import com.mayi.fastdevelop.util.LogUtils;
import com.tencent.bugly.crashreport.CrashReport;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -135,6 +136,8 @@ public class NetWorkUtil { ...@@ -135,6 +136,8 @@ public class NetWorkUtil {
} }
}); });
} }
Throwable throwable=new Throwable("网络异常",e);
CrashReport.postCatchedException(throwable);
LogUtils.netWorkFail("NetWorkUtil", call.request().url().toString(), bodyToString(call.request()), e); LogUtils.netWorkFail("NetWorkUtil", call.request().url().toString(), bodyToString(call.request()), e);
} }
......
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api 'com.android.support:appcompat-v7:28.0.0'
api project(':fastDevelop')
//高德地图
api 'com.amap.api:location:latest.integration'
api 'com.amap.api:search:latest.integration'
api 'com.amap.api:3dmap:latest.integration'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.mayi.fastdevelop.map;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.mayi.fastdevelop.map.test", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mayi.fastdevelop.map">
<application>
<activity android:name=".MapLocationActivity" />
</application>
</manifest>
\ No newline at end of file
package com.mayi.fastdevelop.map;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.gc.call.CallImmediatelyHandlerTarget;
import com.gc.call.CallParticipationBean;
import com.gc.call.CallReturnBean;
import com.mayi.fastdevelop.comnon.RequestCode;
//跳转地图定位页
public class GoMapLocationCallTarget extends CallImmediatelyHandlerTarget {
@Override
public String getTag() {
return "map_goMapLocation";
}
@Override
public CallReturnBean onHandle(CallParticipationBean bean) {
Context context = bean.getContext();
if (context != null) {
Intent intent = new Intent(context, MapLocationActivity.class);
if (context instanceof Activity) {
((Activity) context).startActivityForResult(intent,
RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE);
}
}
return null;
}
}
package com.mayi.fastdevelop.map;
import com.alibaba.fastjson.JSON;
import com.gc.call.CallParticipationBean;
import com.gc.call.CallReturnBean;
import com.gc.call.CallTimeHandTarget;
import com.gc.call.CallTimeHandlerListener;
import com.mayi.fastdevelop.bean.LocationBean;
public class LocationCallTarget extends CallTimeHandTarget {
@Override
public String getTag() {
return "map_location";
}
@Override
public void delayProcessing(CallParticipationBean bean, final CallTimeHandlerListener listener) {
LocationUtils.startLocation(bean.getContext(), new LocationUtils.LocationCallback() {
@Override
public void onFail(String msg) {
CallReturnBean callReturnBean = new CallReturnBean();
callReturnBean.setMsg(msg);
callReturnBean.setCode(-3);
listener.timeHandler(callReturnBean);
}
@Override
public void onSuccess(LocationBean bean) {
CallReturnBean callReturnBean = new CallReturnBean();
callReturnBean.setReturnJson(JSON.toJSONString(bean));
listener.timeHandler(callReturnBean);
}
});
}
}
package com.mayi.fastdevelop.util; package com.mayi.fastdevelop.map;
import android.content.Context; import android.content.Context;
...@@ -7,6 +7,7 @@ import com.amap.api.location.AMapLocationClient; ...@@ -7,6 +7,7 @@ import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption; import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener; import com.amap.api.location.AMapLocationListener;
import com.mayi.fastdevelop.bean.LocationBean; import com.mayi.fastdevelop.bean.LocationBean;
import com.mayi.fastdevelop.util.LogUtils;
public class LocationUtils { public class LocationUtils {
...@@ -61,9 +62,9 @@ public class LocationUtils { ...@@ -61,9 +62,9 @@ public class LocationUtils {
public interface LocationCallback { public interface LocationCallback {
public abstract void onFail(String msg); public void onFail(String msg);
public abstract void onSuccess(LocationBean bean); public void onSuccess(LocationBean bean);
} }
......
package com.mayi.fastdevelop.commonpage.amap; package com.mayi.fastdevelop.map;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
...@@ -44,7 +44,6 @@ import com.amap.api.services.help.InputtipsQuery; ...@@ -44,7 +44,6 @@ import com.amap.api.services.help.InputtipsQuery;
import com.amap.api.services.help.Tip; import com.amap.api.services.help.Tip;
import com.amap.api.services.poisearch.PoiResult; import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch; import com.amap.api.services.poisearch.PoiSearch;
import com.mayi.fastdevelop.R;
import com.mayi.fastdevelop.base.BaseAPI; import com.mayi.fastdevelop.base.BaseAPI;
import com.mayi.fastdevelop.base.BaseActivity; import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.base.BasePresenter; import com.mayi.fastdevelop.base.BasePresenter;
......
package com.mayi.fastdevelop.commonpage.amap; package com.mayi.fastdevelop.map;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
...@@ -9,7 +9,6 @@ import android.widget.ImageView; ...@@ -9,7 +9,6 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.amap.api.services.core.PoiItem; import com.amap.api.services.core.PoiItem;
import com.mayi.fastdevelop.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
<resources>
<string name="app_name">map</string>
</resources>
package com.mayi.fastdevelop.map;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
include ':app', ':fastDevelop', ':web' include ':app', ':fastDevelop', ':web', ':map', ':call'
...@@ -21,6 +21,8 @@ import android.support.v4.content.FileProvider; ...@@ -21,6 +21,8 @@ import android.support.v4.content.FileProvider;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -28,12 +30,11 @@ import com.mayi.fastdevelop.base.BaseAPI; ...@@ -28,12 +30,11 @@ import com.mayi.fastdevelop.base.BaseAPI;
import com.mayi.fastdevelop.base.BaseActivity; import com.mayi.fastdevelop.base.BaseActivity;
import com.mayi.fastdevelop.base.BasePresenter; import com.mayi.fastdevelop.base.BasePresenter;
import com.mayi.fastdevelop.bean.LocationBean; import com.mayi.fastdevelop.bean.LocationBean;
import com.mayi.fastdevelop.commonpage.amap.MapLocationActivity;
import com.mayi.fastdevelop.comnon.Key; import com.mayi.fastdevelop.comnon.Key;
import com.mayi.fastdevelop.comnon.RequestCode; import com.mayi.fastdevelop.comnon.RequestCode;
import com.mayi.fastdevelop.util.BitmapUtil; import com.mayi.fastdevelop.util.BitmapUtil;
import com.mayi.fastdevelop.util.DialogUtils; import com.mayi.fastdevelop.util.DialogUtils;
import com.mayi.fastdevelop.util.LocationUtils; import com.mayi.fastdevelop.util.LogUtils;
import com.mayi.fastdevelop.util.SpUtil; import com.mayi.fastdevelop.util.SpUtil;
import com.mayi.fastdevelop.util.SystemUtil; import com.mayi.fastdevelop.util.SystemUtil;
import com.mayi.fastdevelop.view.CustomTitleBar; import com.mayi.fastdevelop.view.CustomTitleBar;
...@@ -134,6 +135,7 @@ public class BaseWebActivity extends BaseActivity { ...@@ -134,6 +135,7 @@ public class BaseWebActivity extends BaseActivity {
super.onReceivedError(view, errorCode, description, failingUrl); super.onReceivedError(view, errorCode, description, failingUrl);
Throwable thr = new Throwable("web加载错误: errorCode" + errorCode + " \ndescription=" + description + " \nfailingUrl=" + failingUrl); Throwable thr = new Throwable("web加载错误: errorCode" + errorCode + " \ndescription=" + description + " \nfailingUrl=" + failingUrl);
CrashReport.postCatchedException(thr); CrashReport.postCatchedException(thr);
LogUtils.i(thr.getMessage());
} }
@Override @Override
...@@ -141,6 +143,7 @@ public class BaseWebActivity extends BaseActivity { ...@@ -141,6 +143,7 @@ public class BaseWebActivity extends BaseActivity {
super.onReceivedError(view, request, error); super.onReceivedError(view, request, error);
Throwable thr = new Throwable("web加载错误: errorCode" + error.getErrorCode() + " \ndescription=" + error.getDescription() + " \nfailingUrl=" + request.getUrl()); Throwable thr = new Throwable("web加载错误: errorCode" + error.getErrorCode() + " \ndescription=" + error.getDescription() + " \nfailingUrl=" + request.getUrl());
CrashReport.postCatchedException(thr); CrashReport.postCatchedException(thr);
LogUtils.i(thr.getMessage());
} }
}); });
initView(); initView();
...@@ -265,8 +268,13 @@ public class BaseWebActivity extends BaseActivity { ...@@ -265,8 +268,13 @@ public class BaseWebActivity extends BaseActivity {
} }
//app调用web方法 //app调用web方法
public void appCallJs(String method, String data) { public void appCallJs(final String method, final String data) {
webView.loadUrl("javascript:appCallJs.invoking;(" + method + "," + data + ")"); handler.post(new Runnable() {
@Override
public void run() {
webView.loadUrl("javascript:appCallJs.invoking;(" + method + "," + data + ")");
}
});
} }
...@@ -294,17 +302,17 @@ public class BaseWebActivity extends BaseActivity { ...@@ -294,17 +302,17 @@ public class BaseWebActivity extends BaseActivity {
} else if (TextUtils.equals("sendSMS", method)) {//发送短信 } else if (TextUtils.equals("sendSMS", method)) {//发送短信
sendSMS(data); sendSMS(data);
} else if (TextUtils.equals("location", method)) {//定位 } else if (TextUtils.equals("location", method)) {//定位
LocationUtils.startLocation(BaseWebActivity.this, new LocationUtils.LocationCallback() { // LocationUtils.startLocation(BaseWebActivity.this, new LocationUtils.LocationCallback() {
@Override // @Override
public void onFail(String msg) { // public void onFail(String msg) {
appCallJs("LocationFail", msg); // appCallJs("LocationFail", msg);
} // }
//
@Override // @Override
public void onSuccess(LocationBean bean) { // public void onSuccess(LocationBean bean) {
appCallJs("LocationSuccess", JSON.toJSONString(bean)); // appCallJs("LocationSuccess", JSON.toJSONString(bean));
} // }
}); // });
} }
} }
}); });
...@@ -334,8 +342,8 @@ public class BaseWebActivity extends BaseActivity { ...@@ -334,8 +342,8 @@ public class BaseWebActivity extends BaseActivity {
e.printStackTrace(); e.printStackTrace();
} }
if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面 if (TextUtils.equals(pageName, "MapLocation")) {//地图定位页面
Intent intent = new Intent(this, MapLocationActivity.class); // Intent intent = new Intent(this, MapLocationActivity.class);
startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE); // startActivityForResult(intent, RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE);
} else { } else {
if (webListener != null) { if (webListener != null) {
webListener.goPageListener(pageName, parameter); webListener.goPageListener(pageName, parameter);
...@@ -399,7 +407,7 @@ public class BaseWebActivity extends BaseActivity { ...@@ -399,7 +407,7 @@ public class BaseWebActivity extends BaseActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RequestCode.MAP_LOCATION_ACTIVITY_RESULTCODE) { if (requestCode == 0x04) {//地图定位回调
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
showToast(data.getStringExtra(Key.AVTIVITY_RESULT)); showToast(data.getStringExtra(Key.AVTIVITY_RESULT));
} }
...@@ -458,6 +466,32 @@ public class BaseWebActivity extends BaseActivity { ...@@ -458,6 +466,32 @@ public class BaseWebActivity extends BaseActivity {
asyncTask.execute(); asyncTask.execute();
} }
@Override
protected void onPause() {
super.onPause();
webView.pauseTimers();
if (isFinishing()) {
webView.loadUrl("about:blank");
}
}
@Override
protected void onResume() {
super.onResume();
webView.resumeTimers();
}
@Override
protected void onDestroy() {
ViewParent parent = webView.getParent();
if (parent != null) {
((ViewGroup) parent).removeView(webView);
}
// 销毁webview
webView.removeAllViews();
webView.destroy();
webView = null;
super.onDestroy();
}
} }
package com.mayi.fastdevelop.web;
import android.content.Intent;
import com.gc.call.CallImmediatelyHandlerTarget;
import com.gc.call.CallParticipationBean;
import com.gc.call.CallReturnBean;
//跳转H5页面
public class GoWebCallTarget extends CallImmediatelyHandlerTarget {
@Override
public String getTag() {
return "web_goWeb";
}
@Override
public CallReturnBean onHandle(CallParticipationBean bean) {
Intent intent = new Intent(bean.getContext(), BaseWebActivity.class);
intent.putExtra("url", bean.getParameter().optString("url"));
bean.getContext().startActivity(intent);
return null;
}
}
package com.mayi.fastdevelop.web;
import com.gc.call.CallImmediatelyHandlerTarget;
import com.gc.call.CallParticipationBean;
import com.gc.call.CallReturnBean;
//初始化浏览器
public class InitWebCallTarget extends CallImmediatelyHandlerTarget {
@Override
public String getTag() {
return "web_initWeb";
}
@Override
public CallReturnBean onHandle(CallParticipationBean bean) {
WebUtil.initX5Webview();
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment