Skip to content

Commit

Permalink
Merge pull request #12 from HuanTanSheng/dev
Browse files Browse the repository at this point in the history
预览页面的状态栏字体颜色智能适配实现
  • Loading branch information
HuanTanSheng authored Jan 20, 2018
2 parents 035edc8 + 9a34827 commit cb4fa99
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
122 changes: 65 additions & 57 deletions easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,74 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<RelativeLayout
android:id="@+id/m_top_bar"
style="?metaButtonBarStyle"
<FrameLayout
android:id="@+id/m_top_bar_layout"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_gravity="top"
android:background="@color/easy_photos_bar_primary"
android:clickable="true"
android:fitsSystemWindows="true"
android:focusable="true">

<ImageView
android:id="@+id/iv_back"
android:layout_width="42dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="onClick"
android:padding="10dp"
app:srcCompat="@drawable/ic_arrow_back_easy_photos" />

<View
android:id="@+id/m_back_line"
android:layout_width="1dp"
android:layout_height="22dp"
android:layout_alignEnd="@id/iv_back"
android:layout_alignRight="@id/iv_back"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:background="@color/easy_photos_bar_primary_dark" />

<com.huantansheng.easyphotos.ui.widget.PressedTextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toEndOf="@id/m_back_line"
android:layout_toRightOf="@id/m_back_line"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/easy_photos_fg_primary" />
android:layout_height="wrap_content"
style="?metaButtonBarStyle"
android:background="@color/colorPrimaryDark">

<com.huantansheng.easyphotos.ui.widget.PressedTextView
android:id="@+id/tv_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/bg_menu_done_easy_photos"
android:gravity="center"
android:maxWidth="200dp"
android:padding="6dp"
android:textColor="@color/white_easy_photos"
android:textSize="12sp"
android:textStyle="bold" />
<RelativeLayout
android:id="@+id/m_top_bar"
android:layout_width="match_parent"
android:layout_height="42dp"
android:layout_gravity="top"
android:background="@color/easy_photos_bar_primary"
android:clickable="true"
android:fitsSystemWindows="true"
android:focusable="true">

<ImageView
android:id="@+id/iv_back"
android:layout_width="42dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="onClick"
android:padding="10dp"
app:srcCompat="@drawable/ic_arrow_back_easy_photos" />

<View
android:id="@+id/m_back_line"
android:layout_width="1dp"
android:layout_height="22dp"
android:layout_alignEnd="@id/iv_back"
android:layout_alignRight="@id/iv_back"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:background="@color/easy_photos_bar_primary_dark" />

<com.huantansheng.easyphotos.ui.widget.PressedTextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toEndOf="@id/m_back_line"
android:layout_toRightOf="@id/m_back_line"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/easy_photos_fg_primary" />

<com.huantansheng.easyphotos.ui.widget.PressedTextView
android:id="@+id/tv_done"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/bg_menu_done_easy_photos"
android:gravity="center"
android:maxWidth="200dp"
android:padding="6dp"
android:textColor="@color/white_easy_photos"
android:textSize="12sp"
android:textStyle="bold" />

</RelativeLayout>
</FrameLayout>

</RelativeLayout>

<RelativeLayout
android:id="@+id/m_bottom_bar"
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#393a3f</color>
<color name="colorPrimaryDark">#303135</color>
<color name="colorPrimaryDark">#303135</color>//303135
<color name="colorAccent">#FF4081</color>

<color name="black_overlay">#66000000</color>
Expand Down

0 comments on commit cb4fa99

Please sign in to comment.