Commit 9cc36a03 by gao.chao

组件化工具-延时回调

parent 3d9d83f3
...@@ -5,10 +5,14 @@ import android.support.annotation.Nullable; ...@@ -5,10 +5,14 @@ import android.support.annotation.Nullable;
import android.view.View; import android.view.View;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gc.call.CallConstant;
import com.gc.call.CallManage;
import com.gc.call.CallParticipationBean;
import com.gc.call.CallReturnBean;
import com.gc.call.CallReturnListener;
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.bean.LocationBean;
import com.mayi.fastdevelop.bean.UserInfo; 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;
...@@ -102,17 +106,17 @@ public class FunctionActivity extends BaseActivity { ...@@ -102,17 +106,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() { CallParticipationBean bean = new CallParticipationBean();
// @Override bean.setTag("map_location");
// public void onFail(String msg) { bean.setContext(FunctionActivity.this);
// showToast(msg); bean.setLooper(CallConstant.LOOPER_NO_MAIN);
// } bean.setListener(new CallReturnListener() {
// @Override
// @Override public void onReturn(CallReturnBean bean) {
// public void onSuccess(LocationBean bean) { showToast(JSON.toJSONString(bean));
// showToast(JSON.toJSONString(bean)); }
// } });
// }); CallManage.getInstance().handleTarget(bean);
} }
}); });
} }
......
...@@ -28,6 +28,7 @@ public class CallManage { ...@@ -28,6 +28,7 @@ public class CallManage {
map.put(callTarget.getTag(), callTarget); map.put(callTarget.getTag(), callTarget);
} }
//处理call
public void handleTarget(final CallParticipationBean bean) { public void handleTarget(final CallParticipationBean bean) {
Log.i(TAG, "handleTarget:" + bean.getTag()); Log.i(TAG, "handleTarget:" + bean.getTag());
CallTarget callTarget = map.get(bean.getTag()); CallTarget callTarget = map.get(bean.getTag());
...@@ -37,31 +38,86 @@ public class CallManage { ...@@ -37,31 +38,86 @@ public class CallManage {
callReturn.setMsg("没有找到对应的CallTarget"); callReturn.setMsg("没有找到对应的CallTarget");
callReturn.setCode(CallConstant.CODE_NO_TARGET); callReturn.setCode(CallConstant.CODE_NO_TARGET);
bean.getListener().onReturn(callReturn); bean.getListener().onReturn(callReturn);
bean.getListener().onReturn(callReturn);
} }
} else { } else {
if (callTarget instanceof CallImmediatelyHandlerTarget) { if (callTarget instanceof CallImmediatelyHandlerTarget) {
onImmediatelyHandler(bean, (CallImmediatelyHandlerTarget) callTarget); onImmediatelyHandler(bean, (CallImmediatelyHandlerTarget) callTarget);
} else if (callTarget instanceof CallTimeHandTarget) { } else if (callTarget instanceof CallTimeHandTarget) {
onTimeHandHandler(bean, (CallTimeHandTarget) callTarget);
} }
} }
} }
private void onImmediatelyHandler(final CallParticipationBean bean, final CallImmediatelyHandlerTarget target) { //处理耗时不能立刻返回的call
private void onTimeHandHandler(final CallParticipationBean bean, final CallTimeHandTarget target) {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
if (bean.getLooper() == CallConstant.LOOPER_MAIN) { 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() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
CallReturnBean c = target.onHandle(bean);
if (bean.getListener() != null) { if (bean.getListener() != null) {
bean.getListener().onReturn(c); 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) { } else if (bean.getLooper() == CallConstant.LOOPER_NO_MAIN) {
AsyncTask asyncTask = new AsyncTask() { AsyncTask asyncTask = new AsyncTask() {
@Override @Override
...@@ -96,20 +152,5 @@ public class CallManage { ...@@ -96,20 +152,5 @@ public class CallManage {
}); });
} }
// 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;
// }
} }
...@@ -20,7 +20,7 @@ public class LocationUtils { ...@@ -20,7 +20,7 @@ public class LocationUtils {
public void onLocationChanged(AMapLocation amapLocation) { public void onLocationChanged(AMapLocation amapLocation) {
if (amapLocation != null) { if (amapLocation != null) {
if (amapLocation.getErrorCode() == 0) { if (amapLocation.getErrorCode() == 0) {
LogUtils.e("amapLocation" + amapLocation); LogUtils.i("amapLocation" + amapLocation);
if (callback != null) { if (callback != null) {
LocationBean bean = new LocationBean(); LocationBean bean = new LocationBean();
bean.setAddress(amapLocation.getAddress()); bean.setAddress(amapLocation.getAddress());
......
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