package com.gh.base; import android.annotation.TargetApi; import android.app.Activity; 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.view.Window; import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.gh.common.constant.Config; 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.common.util.Utils; import com.gh.download.DownloadManager; import com.gh.gamecenter.R; import com.gh.gamecenter.eventbus.EBShowDialog; import com.gh.gamecenter.listener.OnCallBackListener; import com.gh.gamecenter.manager.SystemBarTintManager; import com.gh.gamecenter.manager.SystemBarTintManager.SystemBarConfig; import java.util.ArrayList; import butterknife.ButterKnife; import de.greenrobot.event.EventBus; public class BaseActivity extends Activity implements OnCallBackListener { private SystemBarTintManager tintManager; protected String entrance; private boolean isPause; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Utils.log(this.getClass().getSimpleName()); AppController.getInstance().addActivity(this); EventBus.getDefault().register(this); entrance = getIntent().getStringExtra("entrance"); if (getIntent().getBundleExtra("data") != null) { entrance = getIntent().getBundleExtra("data").getString("entrance"); } } protected void init(View contentView, String title) { init(contentView); TextView actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title); actionbar_tv_title.setText(title); } protected void init(View contentView) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTheme(R.style.AppTheme); setTranslucentStatus(true); tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.theme); SystemBarConfig config = tintManager.getConfig(); contentView.setPadding(0, config.getPixelInsetTop(false), 0, config.getPixelInsetBottom()); } setContentView(contentView); ButterKnife.bind(this); int actionbar_height = getSharedPreferences(Config.PREFERENCE, Context.MODE_PRIVATE).getInt("actionbar_height", DisplayUtils.dip2px(getApplicationContext(), 48)); RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar); 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 SystemBarTintManager getTintManager() { return tintManager; } @Override public void finish() { super.finish(); AppController.getInstance().removeActivity(this); } 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(); } @TargetApi(19) protected void setTranslucentStatus(boolean status) { Window window = getWindow(); WindowManager.LayoutParams winParams = window.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if (status) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } window.setAttributes(winParams); } //如果是游戏分享,newsTitle默认为空 public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList tag) { //判断是否是官方版 boolean isPlugin = false; if (tag != null){ for (String s : tag) { if (!"官方版".equals(s)){ isPlugin = true; } } } ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin, true); if (newsTitle == null) { DataUtils.onEvent(this, "内容分享", gameName); } else { DataUtils.onEvent(this, "内容分享", newsTitle); } } public void onEventMainThread(final EBShowDialog showDialog) { if (!isPause && 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.ConfiremListener(){ @Override public void onConfirem() { 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); } @Override protected void onPause() { super.onPause(); DataUtils.onPause(this); isPause = true; } @Override protected void onResume() { super.onResume(); DataUtils.onResume(this); isPause = false; DownloadManager.getInstance(this).initGameMap(); } @Override public void loadDone() { } @Override public void loadDone(Object obj) { } @Override public void loadError() { } @Override public void loadEmpty() { } }