From 9a34827f5970b46368d2d33419339651c8035b95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=93=E4=B8=80=E6=96=87?= <35919502@qq.com> Date: Sat, 20 Jan 2018 21:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=A7=88=E9=A1=B5=E9=9D=A2=E7=9A=84?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E6=A0=8F=E5=AD=97=E4=BD=93=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E9=80=82=E9=85=8D=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easyphotos/ui/PreviewActivity.java | 23 +++- .../easyphotos/utils/system/SystemUtils.java | 27 ++-- .../layout/activity_preview_easy_photos.xml | 122 ++++++++++-------- sample/src/main/res/values/colors.xml | 2 +- 4 files changed, 102 insertions(+), 72 deletions(-) diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java index 5ec76fc7..826ecffd 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java @@ -13,6 +13,7 @@ import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.View; +import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.view.animation.ScaleAnimation; @@ -31,6 +32,7 @@ import com.huantansheng.easyphotos.setting.Setting; import com.huantansheng.easyphotos.ui.adapter.PreviewPhotosAdapter; import com.huantansheng.easyphotos.ui.widget.PressedTextView; +import com.huantansheng.easyphotos.utils.Color.ColorUtils; import com.huantansheng.easyphotos.utils.system.SystemUtils; import java.util.ArrayList; @@ -60,7 +62,8 @@ public void run() { SystemUtils.getInstance().systemUiHide(PreviewActivity.this, decorView); } }; - private RelativeLayout mBottomBar, mToolBar; + private RelativeLayout mBottomBar; + private FrameLayout mToolBar; private final Runnable mShowPart2Runnable = new Runnable() { @Override public void run() { @@ -85,14 +88,21 @@ public void run() { private boolean isSingle = Setting.count == 1; private boolean unable = Result.count() == Setting.count; - private FrameLayout flFragment,mRootView; + private FrameLayout flFragment, mRootView; private PreviewFragment previewFragment; + private int statusColor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); decorView = getWindow().getDecorView(); SystemUtils.getInstance().systemUiInit(this, decorView); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + statusColor = ContextCompat.getColor(this, R.color.colorPrimaryDark); + if (ColorUtils.isWhiteColor(statusColor)) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + } + } setContentView(R.layout.activity_preview_easy_photos); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { @@ -197,13 +207,16 @@ private void doBack() { private void initView() { mRootView = (FrameLayout) findViewById(R.id.m_root_view); - if (!SystemUtils.getInstance().hasNavigationBar(this,mRootView)) { + mToolBar = (FrameLayout) findViewById(R.id.m_top_bar_layout); + if (!SystemUtils.getInstance().hasNavigationBar(this)) { mRootView.setFitsSystemWindows(true); - findViewById(R.id.m_bar_root_view).setPadding(0, SystemUtils.getInstance().getStatusBarHeight(this), 0, 0); + mToolBar.setPadding(0, SystemUtils.getInstance().getStatusBarHeight(this), 0, 0); + if (ColorUtils.isWhiteColor(statusColor)) { + SystemUtils.getInstance().setStatusDark(this, true); + } } PressedTextView tvEdit = (PressedTextView) findViewById(R.id.tv_edit); mBottomBar = (RelativeLayout) findViewById(R.id.m_bottom_bar); - mToolBar = (RelativeLayout) findViewById(R.id.m_top_bar); TextView tvSelector = (TextView) findViewById(R.id.tv_selector); ivSelector = (ImageView) findViewById(R.id.iv_selector); tvNumber = (TextView) findViewById(R.id.tv_number); diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/utils/system/SystemUtils.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/utils/system/SystemUtils.java index 5785cb21..79887a49 100644 --- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/utils/system/SystemUtils.java +++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/utils/system/SystemUtils.java @@ -4,6 +4,8 @@ import android.content.Context; import android.os.Build; import android.text.TextUtils; +import android.util.DisplayMetrics; +import android.view.Display; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.View; @@ -53,12 +55,17 @@ public static SystemUtils getInstance() { * * @return 有或没有 */ - public boolean hasNavigationBar(Context context, View rootView) { + public boolean hasNavigationBar(Activity activity) { if (null == hasNavigation) { - int[] size = new int[2]; - rootView.getLocationOnScreen(size); - int height = context.getResources().getDisplayMetrics().heightPixels; - hasNavigation = height - size[1] > 10; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + int windowHeight = activity.getResources().getDisplayMetrics().heightPixels; + DisplayMetrics dm = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getRealMetrics(dm); + int screenHeight = dm.heightPixels; + hasNavigation = screenHeight - windowHeight > 0; + } else { + hasNavigation = true; + } } return hasNavigation; @@ -70,7 +77,7 @@ public boolean hasNavigationBar(Context context, View rootView) { * @param decorView getWindow().getDecorView(),不同view也可以 */ public void systemUiInit(Activity activity, View decorView) { - if (!hasNavigationBar(activity, decorView)) { + if (!hasNavigationBar(activity)) { activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); return; @@ -101,7 +108,7 @@ private void showStatusBar(Activity activity) { */ public void systemUiHide(Activity activity, View decorView) { - if (!hasNavigationBar(activity, decorView)) { + if (!hasNavigationBar(activity)) { hideStatusBar(activity); return; } @@ -132,7 +139,7 @@ public void systemUiHide(Activity activity, View decorView) { * @param decorView getWindow().getDecorView(),不同view也可以 */ public void systemUiShow(Activity activity, View decorView) { - if (!hasNavigationBar(activity,decorView)) { + if (!hasNavigationBar(activity)) { showStatusBar(activity); return; } @@ -149,10 +156,12 @@ public void systemUiShow(Activity activity, View decorView) { * @return 状态栏高度,单位PX */ public int getStatusBarHeight(Context cxt) { - int statusBarHeight = -1; + int statusBarHeight = 0; int resourceId = cxt.getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = cxt.getResources().getDimensionPixelSize(resourceId); + } else { + statusBarHeight = (int) (23 * (cxt.getResources().getDisplayMetrics().density) + 0.5f); } return statusBarHeight; } diff --git a/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml b/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml index fb828608..b25eda5a 100644 --- a/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml +++ b/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml @@ -16,66 +16,74 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - - - - - - - + android:layout_height="wrap_content" + style="?metaButtonBarStyle" + android:background="@color/colorPrimaryDark"> - + + + + + + + + + + + + - #393a3f - #303135 + #303135//303135 #FF4081 #66000000