package com.gh.base; import android.content.Context; import android.os.Build; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.gh.common.constant.Config; import com.gh.common.util.AppManager; import com.gh.common.util.DataUtils; import com.gh.common.util.DialogUtils; import com.gh.common.util.DisplayUtils; import com.gh.common.util.FileUtils; import com.gh.common.util.PackageUtils; import com.gh.common.util.RunningUtils; import com.gh.common.util.ShareUtils; import com.gh.download.DownloadManager; import com.gh.gamecenter.R; import com.gh.gamecenter.eventbus.EBShowDialog; import com.gh.gamecenter.listener.OnCallBackListener; import com.readystatesoftware.systembartint.SystemBarTintManager.SystemBarConfig; import java.util.ArrayList; import butterknife.ButterKnife; import de.greenrobot.event.EventBus; 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 OnCallBackListener { 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) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { SystemBarConfig config = getTintManager().getConfig(); contentView.setPadding(0, config.getPixelInsetTop(false), 0, config.getPixelInsetBottom()); } setContentView(contentView); ButterKnife.bind(this); View reuse_actionbar = findViewById(R.id.reuse_actionbar); if (reuse_actionbar != null) { int actionbar_height = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE) .getInt("actionbar_height", DisplayUtils.dip2px(getApplicationContext(), 55)); LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, actionbar_height); reuse_actionbar.setLayoutParams(lparams); findViewById(R.id.actionbar_rl_back).setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { finish(); } }); } } protected void init(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 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); } } public void onEventMainThread(final EBShowDialog showDialog) { if (!mIsPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) { if ("hijack".equals(showDialog.getType())) { DialogUtils.showQqSessionDialog(this, null);// 建议用户联系客服 } 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())); } } }); } } } @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 loadDone() { } @Override public void loadDone(Object obj) { } @Override public void loadError() { } @Override public void loadEmpty() { } }