190 lines
6.5 KiB
Java
190 lines
6.5 KiB
Java
package com.gh.base;
|
||
|
||
import android.os.Bundle;
|
||
import android.support.annotation.NonNull;
|
||
import android.view.View;
|
||
import android.view.View.OnClickListener;
|
||
import android.widget.TextView;
|
||
import android.widget.Toast;
|
||
|
||
import com.gh.common.util.DataUtils;
|
||
import com.gh.common.util.DialogUtils;
|
||
import com.gh.common.util.PackageUtils;
|
||
import com.gh.common.util.RunningUtils;
|
||
import com.gh.common.util.ShareUtils;
|
||
import com.gh.common.util.StringUtils;
|
||
import com.gh.gamecenter.LoginActivity;
|
||
import com.gh.gamecenter.R;
|
||
import com.gh.gamecenter.eventbus.EBShowDialog;
|
||
import com.lightgame.download.FileUtils;
|
||
import com.lightgame.utils.AppManager;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
import org.greenrobot.eventbus.Subscribe;
|
||
import org.greenrobot.eventbus.ThreadMode;
|
||
import org.json.JSONException;
|
||
import org.json.JSONObject;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
import butterknife.ButterKnife;
|
||
import pub.devrel.easypermissions.EasyPermissions;
|
||
|
||
import static com.gh.common.util.EntranceUtils.KEY_DATA;
|
||
import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE;
|
||
|
||
public abstract class BaseActivity extends BaseAppCompatToolBarActivity implements EasyPermissions.PermissionCallbacks{
|
||
|
||
protected String mEntrance;
|
||
private boolean mIsPause;
|
||
|
||
@Override
|
||
protected void onCreate(Bundle savedInstanceState) {
|
||
super.onCreate(savedInstanceState);
|
||
init(mContentView);
|
||
AppManager.getInstance().addActivity(this);
|
||
EventBus.getDefault().register(this);
|
||
mEntrance = getIntent().getStringExtra(KEY_ENTRANCE);
|
||
if (getIntent().getBundleExtra(KEY_DATA) != null) {
|
||
mEntrance = getIntent().getBundleExtra(KEY_DATA).getString(KEY_ENTRANCE);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
protected boolean onNavigationIconClicked() {
|
||
return false;
|
||
}
|
||
|
||
private void init(View contentView) {
|
||
setContentView(contentView);
|
||
|
||
ButterKnife.bind(this);
|
||
|
||
View back = findViewById(R.id.actionbar_rl_back);
|
||
if (back != null)
|
||
back.setOnClickListener(new OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
finish();
|
||
}
|
||
});
|
||
}
|
||
|
||
protected void initTitle(String title) {
|
||
TextView actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title);
|
||
actionbar_tv_title.setText(title);
|
||
// setNavigationTitle(title);
|
||
}
|
||
|
||
public void toast(String msg) {
|
||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||
}
|
||
|
||
public void toast(int msg) {
|
||
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
|
||
}
|
||
|
||
//如果是游戏分享,newsTitle默认为空
|
||
public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList<String> tag, boolean isToolsBox) {
|
||
|
||
//判断是否是官方版
|
||
boolean isPlugin = false;
|
||
if (tag != null) {
|
||
for (String s : tag) {
|
||
if (!"官方版".equals(s)) {
|
||
isPlugin = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
ShareUtils.getInstance(this).showShareWindows(getWindow().getDecorView(), url, gameName, icon, newsTitle, isPlugin, true, isToolsBox);
|
||
|
||
if (newsTitle == null) {
|
||
DataUtils.onEvent(this, "内容分享", gameName);
|
||
} else {
|
||
DataUtils.onEvent(this, "内容分享", newsTitle);
|
||
}
|
||
}
|
||
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void onEventMainThread(final EBShowDialog showDialog) {
|
||
//TODO 改为缓存到UI可见时才调用,参考beier-assist
|
||
if (!mIsPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) {
|
||
if ("hijack".equals(showDialog.getType())) {
|
||
DialogUtils.showQqSessionDialog(this, "2586716223");// 建议用户联系客服
|
||
} else if ("plugin".equals(showDialog.getType())) {
|
||
DialogUtils.showPluginDialog(this, new DialogUtils.ConfirmListener() {
|
||
@Override
|
||
public void onConfirm() {
|
||
if (FileUtils.isEmptyFile(showDialog.getPath())) {
|
||
Toast.makeText(BaseActivity.this, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show();
|
||
} else {
|
||
startActivity(PackageUtils.getUninstallIntent(BaseActivity.this, showDialog.getPath()));
|
||
}
|
||
}
|
||
});
|
||
} else if ("loginException".equals(showDialog.getType())) {
|
||
try {
|
||
JSONObject object = new JSONObject(showDialog.getPath());
|
||
JSONObject device = object.getJSONObject("device");
|
||
String manufacturer = device.getString("manufacturer");
|
||
String model = device.getString("model");
|
||
DialogUtils.showAlertDialog(this, "你的账号已在另外一台设备登录"
|
||
, StringUtils.buildString("(", manufacturer, "-", model, ")")
|
||
, "知道了", "重新登录"
|
||
, null, new DialogUtils.CancelListener() {
|
||
@Override
|
||
public void onCancel() {
|
||
startActivity(LoginActivity.getIntent(BaseActivity.this, false));
|
||
}
|
||
});
|
||
} catch (JSONException e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
@Override
|
||
protected void onDestroy() {
|
||
super.onDestroy();
|
||
EventBus.getDefault().unregister(this);
|
||
AppManager.getInstance().finishActivity(this);
|
||
}
|
||
|
||
@Override
|
||
protected void onPause() {
|
||
super.onPause();
|
||
// DataUtils.onPause(this);
|
||
mIsPause = true;
|
||
}
|
||
|
||
@Override
|
||
protected void onResume() {
|
||
super.onResume();
|
||
// DataUtils.onResume(this);
|
||
mIsPause = false;
|
||
// DownloadManager.getInstance(this).initGameMap();
|
||
}
|
||
|
||
@Override
|
||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
|
||
}
|
||
|
||
@Override
|
||
public void onPermissionsDenied(int requestCode, List<String> perms) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onPermissionsGranted(int requestCode, List<String> perms) {
|
||
|
||
}
|
||
}
|