|
@@ -19,7 +19,6 @@ import com.miekir.mvp.widget.LoadingDialog;
|
|
|
public abstract class BaseActivity extends AppCompatActivity {
|
|
public abstract class BaseActivity extends AppCompatActivity {
|
|
|
private LoadingDialog mLoadingDialog;
|
|
private LoadingDialog mLoadingDialog;
|
|
|
private View rootView;
|
|
private View rootView;
|
|
|
- //private Unbinder mBinder;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -27,9 +26,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
// getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
// getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
|
|
//}
|
|
//}
|
|
|
- // 重新create之后,activity对象不一样
|
|
|
|
|
- //Log.d(getClass().getName(), "obj is : " + this.toString());
|
|
|
|
|
-
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
rootView = LayoutInflater.from(this).inflate(getLayoutId(), null);
|
|
rootView = LayoutInflater.from(this).inflate(getLayoutId(), null);
|
|
|
setContentView(rootView);
|
|
setContentView(rootView);
|
|
@@ -52,14 +48,20 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
mLoadingDialog.setCancelListener(new LoadingDialog.OnLoadingCancelListener() {
|
|
mLoadingDialog.setCancelListener(new LoadingDialog.OnLoadingCancelListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onLoadingCancel() {
|
|
public void onLoadingCancel() {
|
|
|
- // todo 这个方法不执行
|
|
|
|
|
- onTaskCancel();
|
|
|
|
|
|
|
+ mLoadingTime = 0;
|
|
|
|
|
+ onProgressTaskCancel();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public abstract void onTaskCancel();
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 可见任务被取消
|
|
|
|
|
+ */
|
|
|
|
|
+ public abstract void onProgressTaskCancel();
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 隐藏输入法
|
|
|
|
|
+ */
|
|
|
protected void hideInputMethod() {
|
|
protected void hideInputMethod() {
|
|
|
if (rootView != null) {
|
|
if (rootView != null) {
|
|
|
rootView.requestFocus();
|
|
rootView.requestFocus();
|
|
@@ -86,7 +88,6 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
- dismissLoading();
|
|
|
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -110,7 +111,30 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
showLoading(msg, true);
|
|
showLoading(msg, true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private volatile int mLoadingTime = 0;
|
|
|
|
|
+ private synchronized void onLoadTimeChange(boolean isShow) {
|
|
|
|
|
+ if (isShow) {
|
|
|
|
|
+ mLoadingTime++;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ mLoadingTime--;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (mLoadingTime <= 0 && mLoadingDialog != null) {
|
|
|
|
|
+ mLoadingTime = 0;
|
|
|
|
|
+ if (isMainThread()) {
|
|
|
|
|
+ mLoadingDialog.close();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ mLoadingDialog.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
public void showLoading(final String msg, final boolean cancelable) {
|
|
public void showLoading(final String msg, final boolean cancelable) {
|
|
|
|
|
+ onLoadTimeChange(true);
|
|
|
if (mLoadingDialog == null) {
|
|
if (mLoadingDialog == null) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -127,18 +151,7 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void dismissLoading() {
|
|
|
|
|
- if (mLoadingDialog != null) {
|
|
|
|
|
- if (isMainThread()) {
|
|
|
|
|
- mLoadingDialog.close();
|
|
|
|
|
- } else {
|
|
|
|
|
- runOnUiThread(new Runnable() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void run() {
|
|
|
|
|
- mLoadingDialog.close();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void hideLoading() {
|
|
|
|
|
+ onLoadTimeChange(false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|