Commit b0c8089a by gao.chao

call配置为依赖

parent 9cc36a03
......@@ -50,6 +50,7 @@ dependencies {
api 'com.android.support.constraint:constraint-layout:1.1.3'
api "com.tencent.bugly:crashreport_upgrade:1.3.4"
api 'com.tencent.bugly:nativecrashreport:3.6.0.1'
// api(name:'fastDevelop-release', ext:'aar')
api project(':fastDevelop')
api project(':web')
......
......@@ -106,11 +106,11 @@ public class FunctionActivity extends BaseActivity {
findViewById(R.id.b8).setOnClickListener(new OnMultiClickListener() {
@Override
public void onMultiClick(View v) {
CallParticipationBean bean = new CallParticipationBean();
CallParticipationBean bean = new CallParticipationBean("map_location");
bean.setTag("map_location");
bean.setContext(FunctionActivity.this);
bean.setLooper(CallConstant.LOOPER_NO_MAIN);
bean.setListener(new CallReturnListener() {
bean.setCallReturnListener(new CallReturnListener() {
@Override
public void onReturn(CallReturnBean bean) {
showToast(JSON.toJSONString(bean));
......
......@@ -20,8 +20,7 @@ public class MyApplication extends BaseApplication {
CallManage.getInstance().addTarget(new GoMapLocationCallTarget());
CallManage.getInstance().addTarget(new GoWebCallTarget());
CallManage.getInstance().addTarget(new InitWebCallTarget());
CallParticipationBean bean = new CallParticipationBean();
bean.setTag("web_initWeb");
CallParticipationBean bean = new CallParticipationBean("web_initWeb");
CallManage.getInstance().handleTarget(bean);
initBugly("cb8018da1b", true);
Configure.APP_LOGO = R.mipmap.ic_launcher;
......
......@@ -38,8 +38,7 @@ public class PageActivity extends BaseActivity {
findViewById(R.id.b1).setOnClickListener(new OnMultiClickListener() {
@Override
public void onMultiClick(View v) {
CallParticipationBean bean = new CallParticipationBean();
bean.setTag("web_goWeb");
CallParticipationBean bean = new CallParticipationBean("web_goWeb");
bean.setContext(PageActivity.this);
bean.addParameter("url", "https://customer.kujiatech.com/#/?token=8427db8972dd09105a00d62d8bc7cfd5&username=18001874470&v=" + System.currentTimeMillis());
CallManage.getInstance().handleTarget(bean);
......@@ -48,8 +47,7 @@ public class PageActivity extends BaseActivity {
findViewById(R.id.b2).setOnClickListener(new OnMultiClickListener() {
@Override
public void onMultiClick(View v) {
CallParticipationBean bean = new CallParticipationBean();
bean.setTag("web_goWeb");
CallParticipationBean bean = new CallParticipationBean("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" +
......@@ -84,8 +82,7 @@ public class PageActivity extends BaseActivity {
findViewById(R.id.b7).setOnClickListener(new OnMultiClickListener() {
@Override
public void onMultiClick(View v) {
CallParticipationBean bean = new CallParticipationBean();
bean.setTag("map_goMapLocation");
CallParticipationBean bean = new CallParticipationBean("map_goMapLocation");
bean.setContext(PageActivity.this);
CallManage.getInstance().handleTarget(bean);
}
......
......@@ -19,6 +19,9 @@ allprojects {
repositories {
google()
jcenter()
maven {
url"https://raw.githubusercontent.com/GCkinbg/repos/master"
}
}
}
......
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);
}
//处理call
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);
}
} else {
if (callTarget instanceof CallImmediatelyHandlerTarget) {
onImmediatelyHandler(bean, (CallImmediatelyHandlerTarget) callTarget);
} else if (callTarget instanceof CallTimeHandTarget) {
onTimeHandHandler(bean, (CallTimeHandTarget) callTarget);
}
}
}
//处理耗时不能立刻返回的call
private void onTimeHandHandler(final CallParticipationBean bean, final CallTimeHandTarget target) {
handler.post(new Runnable() {
@Override
public void run() {
if (bean.getLooper() == CallConstant.LOOPER_MAIN) {
target.delayProcessing(bean, new CallTimeHandlerListener() {
@Override
public void timeHandler(CallReturnBean c) {
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) {
target.delayProcessing(bean, new CallTimeHandlerListener() {
@Override
public void timeHandler(CallReturnBean c) {
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) {
target.delayProcessing(bean, new CallTimeHandlerListener() {
@Override
public void timeHandler(final CallReturnBean c) {
handler.post(new Runnable() {
@Override
public void run() {
if (bean.getListener() != null) {
bean.getListener().onReturn(c);
}
}
});
}
});
return null;
}
};
asyncTask.execute();
}
}
});
}
//处理不耗时能立刻返回的call
private void onImmediatelyHandler(final CallParticipationBean bean,
final CallImmediatelyHandlerTarget target) {
handler.post(new Runnable() {
@Override
public void run() {
if (bean.getLooper() == CallConstant.LOOPER_MAIN) {
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();
}
}
});
}
}
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
......@@ -38,5 +38,7 @@ dependencies {
api 'com.android.support:recyclerview-v7:28.0.0'
api 'com.android.support:appcompat-v7:28.0.0'
api files('libs/zixing-core-3.2.0.jar')
api project(':call')
// api project(':call')
api 'com.gc:call:1.0.0'
}
include ':app', ':fastDevelop', ':web', ':map', ':call'
include ':app', ':fastDevelop', ':web', ':map'
\ No newline at end of file
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