From 568aeacf2ac1f95d76f49512f71a8936325f9abd Mon Sep 17 00:00:00 2001 From: Lukas Date: Thu, 13 Apr 2017 23:39:49 -0700 Subject: [PATCH] - minor ui adjustments --- .../koller/cameraroll/ui/AlbumActivity.java | 25 ++++++++---------- .../cameraroll/ui/ExifEditorActivity.java | 3 +-- .../cameraroll/ui/FileExplorerActivity.java | 4 +++ .../us/koller/cameraroll/ui/MainActivity.java | 26 ++++++++----------- .../cameraroll/ui/SettingsActivity.java | 3 +-- .../cameraroll/ui/ThemeableActivity.java | 14 +++++----- 6 files changed, 34 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java index 8bee2fa2..f5b8c09d 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/AlbumActivity.java @@ -28,21 +28,18 @@ import android.transition.Fade; import android.transition.Slide; import android.transition.TransitionSet; -import android.util.Log; import android.view.Gravity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; -import android.view.Window; import android.view.WindowInsets; import android.view.animation.AccelerateDecelerateInterpolator; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Set; import us.koller.cameraroll.R; import us.koller.cameraroll.adapter.album.RecyclerViewAdapter; @@ -225,7 +222,7 @@ public void onClick(View view) { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - private int statusBarColor = getColorPrimaryDark(); + private int statusBarColor = getStatusBarColor(); @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { @@ -243,7 +240,8 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { } toolbar.setTranslationY(translationY); - if (THEME == LIGHT) { + //animate statusBar color + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { float animatedValue = (-translationY) / toolbar.getPaddingTop(); if (animatedValue > 1.0f) { animatedValue = 1.0f; @@ -254,16 +252,15 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int animatedColor = Color.argb(alpha, Color.red(statusBarColor), Color.green(statusBarColor), Color.blue(statusBarColor)); - Window window = getWindow(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - window.setStatusBarColor(animatedColor); - } + getWindow().setStatusBarColor(animatedColor); - animatedValue = (-translationY) / toolbar.getHeight(); - if (animatedValue > 0.9f) { - Util.setLightStatusBarIcons(findViewById(R.id.root_view)); - } else { - Util.setDarkStatusBarIcons(findViewById(R.id.root_view)); + if (THEME == LIGHT) { + animatedValue = (-translationY) / toolbar.getHeight(); + if (animatedValue > 0.9f) { + Util.setLightStatusBarIcons(findViewById(R.id.root_view)); + } else { + Util.setDarkStatusBarIcons(findViewById(R.id.root_view)); + } } } } diff --git a/app/src/main/java/us/koller/cameraroll/ui/ExifEditorActivity.java b/app/src/main/java/us/koller/cameraroll/ui/ExifEditorActivity.java index 3560db00..68b8ed15 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/ExifEditorActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/ExifEditorActivity.java @@ -261,8 +261,7 @@ public void onThemeApplied(int theme) { toolbar.setTitleTextColor(ContextCompat.getColor(this, text_color_res)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - int statusBarColorRes = theme == DARK ? R.color.black : R.color.grey_300; - getWindow().setStatusBarColor(ContextCompat.getColor(this, statusBarColorRes)); + getWindow().setStatusBarColor(getStatusBarColor()); } if (theme == LIGHT) { diff --git a/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java b/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java index 4af3f059..00fe2a5c 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/FileExplorerActivity.java @@ -967,6 +967,10 @@ public void onThemeApplied(int theme) { fab.setBackgroundTintList(ColorStateList .valueOf(ContextCompat.getColor(this, accent_color_res))); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + getWindow().setStatusBarColor(getStatusBarColor()); + } + if (theme == ThemeableActivity.LIGHT) { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setActivated(true); diff --git a/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java b/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java index 864d198a..a0992075 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/MainActivity.java @@ -1,6 +1,5 @@ package us.koller.cameraroll.ui; -import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; @@ -28,18 +27,15 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.Set; import us.koller.cameraroll.R; import us.koller.cameraroll.adapter.main.RecyclerViewAdapter; import us.koller.cameraroll.data.Album; import us.koller.cameraroll.data.Provider.MediaProvider; import us.koller.cameraroll.data.Settings; -import us.koller.cameraroll.ui.widget.GridMarginDecoration; import us.koller.cameraroll.ui.widget.ParallaxImageView; import us.koller.cameraroll.util.SortUtil; import us.koller.cameraroll.util.Util; -import us.koller.cameraroll.util.animators.ColorFade; public class MainActivity extends ThemeableActivity { @@ -133,7 +129,7 @@ public void onClick(View view) { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - private int statusBarColor = getColorPrimaryDark(); + private int statusBarColor = getStatusBarColor(); @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { @@ -152,7 +148,8 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { toolbar.setTranslationY(translationY); - if (THEME == LIGHT) { + //animate statusBar color + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { float animatedValue = (-translationY) / toolbar.getPaddingTop(); if (animatedValue > 1.0f) { animatedValue = 1.0f; @@ -163,16 +160,15 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { int animatedColor = Color.argb(alpha, Color.red(statusBarColor), Color.green(statusBarColor), Color.blue(statusBarColor)); - Window window = getWindow(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - window.setStatusBarColor(animatedColor); - } + getWindow().setStatusBarColor(animatedColor); - animatedValue = (-translationY) / toolbar.getHeight(); - if (animatedValue > 0.9f) { - Util.setLightStatusBarIcons(findViewById(R.id.root_view)); - } else { - Util.setDarkStatusBarIcons(findViewById(R.id.root_view)); + if (THEME == LIGHT) { + animatedValue = (-translationY) / toolbar.getHeight(); + if (animatedValue > 0.9f) { + Util.setLightStatusBarIcons(findViewById(R.id.root_view)); + } else { + Util.setDarkStatusBarIcons(findViewById(R.id.root_view)); + } } } } diff --git a/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java b/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java index bf09d6d2..7d556050 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/SettingsActivity.java @@ -156,8 +156,7 @@ public void onThemeApplied(int theme) { toolbar.setTitleTextColor(ContextCompat.getColor(this, text_color_res)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - int statusBarColorRes = theme == DARK ? R.color.black : R.color.grey_300; - getWindow().setStatusBarColor(ContextCompat.getColor(this, statusBarColorRes)); + getWindow().setStatusBarColor(getStatusBarColor()); } if (theme == LIGHT) { diff --git a/app/src/main/java/us/koller/cameraroll/ui/ThemeableActivity.java b/app/src/main/java/us/koller/cameraroll/ui/ThemeableActivity.java index 48e111a7..a6655a18 100644 --- a/app/src/main/java/us/koller/cameraroll/ui/ThemeableActivity.java +++ b/app/src/main/java/us/koller/cameraroll/ui/ThemeableActivity.java @@ -5,6 +5,7 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; @@ -160,14 +161,11 @@ private void setupTaskDescription() { overviewIcon.recycle(); } - public int getColorPrimaryDark() { - int[] attrs = new int[]{R.attr.colorPrimaryDark}; - TypedArray ta = obtainStyledAttributes(attrs); - int defColor = ContextCompat.getColor(this, R.color.colorPrimaryDark); - int colorPrimaryDark = ta.getColor(0, defColor); - ta.recycle(); - - return colorPrimaryDark; + public int getStatusBarColor() { + if (THEME == LIGHT) { + return Color.argb(20, 0, 0, 0); + } + return Color.argb(30, 0, 0, 0); } }