| | |
| | | package com.weikou.beibeivideo.ui; |
| | | |
| | | import android.app.Dialog; |
| | | import android.content.res.Configuration; |
| | | import android.content.res.Resources; |
| | | import android.graphics.Color; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.support.v4.app.FragmentActivity; |
| | | import android.view.Window; |
| | | import android.view.WindowManager; |
| | | |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.weikou.beibeivideo.ui.dialog.LoadingDialogUtil; |
| | | import com.weikou.beibeivideo.util.ui.TopStatusSettings; |
| | | |
| | | import java.lang.reflect.Field; |
| | | //import com.umeng.message.PushAgent; |
| | | |
| | | public class BaseActivity extends FragmentActivity { |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle arg0) { |
| | | super.onCreate(arg0); |
| | | protected Dialog loadingDialog; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle arg0) { |
| | | super.onCreate(arg0); |
| | | loadingDialog = LoadingDialogUtil.getLoadingDialog(this, ""); |
| | | // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 锁定竖屏 |
| | | // PushAgent.getInstance(this).onAppStart(); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| | | Window window = getWindow(); |
| | | window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, |
| | | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
| | | } |
| | | } |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| | | // Window window = getWindow(); |
| | | // window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, |
| | | // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
| | | // } |
| | | |
| | | public void onResume() { |
| | | super.onResume(); |
| | | MobclickAgent.onResume(this); |
| | | } |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| | | try { |
| | | Class decorViewClazz = Class.forName("com.android.internal.policy.DecorView"); |
| | | Field field = decorViewClazz.getDeclaredField("mSemiTransparentStatusBarColor"); |
| | | field.setAccessible(true); |
| | | field.setInt(getWindow().getDecorView(), Color.TRANSPARENT); //改为透明 |
| | | } catch (Exception e) { |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void onPause() { |
| | | super.onPause(); |
| | | MobclickAgent.onPause(this); |
| | | } |
| | | protected void initStatusBar() { |
| | | // /* |
| | | // * 计算状态栏高度并设置 |
| | | // */ |
| | | // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| | | // int result = 0; |
| | | // int resourceId = getResources().getIdentifier("status_bar_height", |
| | | // "dimen", "android"); |
| | | // if (resourceId > 0) { |
| | | // result = getResources().getDimensionPixelSize(resourceId); |
| | | // } |
| | | // LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, |
| | | // result); |
| | | // findViewById(R.id.v_status_bar).setLayoutParams(params); |
| | | // findViewById(R.id.v_status_bar).setVisibility(View.VISIBLE); |
| | | // } else { |
| | | // findViewById(R.id.v_status_bar).setVisibility(View.GONE); |
| | | // } |
| | | |
| | | TopStatusSettings.setStatusViewAndDeepColor(this); |
| | | } |
| | | |
| | | @Override |
| | | public void onConfigurationChanged(Configuration newConfig) { |
| | | if (newConfig.fontScale != 1)//非默认值 |
| | | getResources(); |
| | | super.onConfigurationChanged(newConfig); |
| | | } |
| | | |
| | | @Override |
| | | public Resources getResources() { |
| | | Resources res = super.getResources(); |
| | | Configuration newConfig = new Configuration(); |
| | | newConfig.setToDefaults();//设置默认 |
| | | |
| | | try { |
| | | if (Build.BRAND.toLowerCase().equalsIgnoreCase("xiaomi")) { |
| | | if (res.getConfiguration().fontScale != 1.1) { |
| | | newConfig.fontScale = 1.1f; |
| | | res.updateConfiguration(newConfig, res.getDisplayMetrics()); |
| | | } |
| | | } else { |
| | | if (res.getConfiguration().fontScale != 1) { |
| | | newConfig.fontScale = 1.0f; |
| | | res.updateConfiguration(newConfig, res.getDisplayMetrics()); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | res.updateConfiguration(newConfig, res.getDisplayMetrics()); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | public void onResume() { |
| | | super.onResume(); |
| | | MobclickAgent.onResume(this); |
| | | } |
| | | |
| | | public void onPause() { |
| | | super.onPause(); |
| | | MobclickAgent.onPause(this); |
| | | } |
| | | |
| | | } |