Correct colored status bar implementation for Lollipop, updated status bar colors in some activities to be darker than toolbar color (e.g. tag editor), added elevation to some views, etc. Getting KitKat support again for this colored UI will also come back soon with SystemBarTInt.
This commit is contained in:
parent
0f60a54d50
commit
3028b96634
22 changed files with 323 additions and 193 deletions
|
|
@ -56,15 +56,15 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
private Album album;
|
||||
|
||||
private ObservableRecyclerView recyclerView;
|
||||
private View statusBar;
|
||||
private ImageView albumArtImageView;
|
||||
private View songsBackgroundView;
|
||||
private TextView albumTitleView;
|
||||
private Toolbar toolbar;
|
||||
private int headerOffset;
|
||||
private int titleViewHeight;
|
||||
private int albumArtViewHeight;
|
||||
private int toolbarColor;
|
||||
public Toolbar toolbar;
|
||||
|
||||
private final SmallObservableScrollViewCallbacks observableScrollViewCallbacks = new SmallObservableScrollViewCallbacks() {
|
||||
@Override
|
||||
public void onScrollChanged(int scrollY, boolean b, boolean b2) {
|
||||
|
|
@ -81,7 +81,6 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
// Change alpha of overlay
|
||||
float alpha = Math.max(0, Math.min(1, (float) scrollY / flexibleRange));
|
||||
ViewUtil.setBackgroundAlpha(toolbar, alpha, toolbarColor);
|
||||
ViewUtil.setBackgroundAlpha(statusBar, alpha, toolbarColor);
|
||||
|
||||
// Translate name text
|
||||
int maxTitleTranslationY = albumArtViewHeight;
|
||||
|
|
@ -121,8 +120,11 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
|
||||
initViews();
|
||||
setUpObservableListViewParams();
|
||||
setUpToolBar();
|
||||
setUpViews();
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setTitle(null);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -141,12 +143,11 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
}
|
||||
|
||||
private void initViews() {
|
||||
albumArtImageView = (ImageView) findViewById(R.id.album_art);
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
albumArtImageView = (ImageView) findViewById(R.id.album_art);
|
||||
recyclerView = (ObservableRecyclerView) findViewById(R.id.list);
|
||||
albumTitleView = (TextView) findViewById(R.id.album_title);
|
||||
songsBackgroundView = findViewById(R.id.list_background);
|
||||
statusBar = findViewById(R.id.statusBar);
|
||||
}
|
||||
|
||||
private void setUpObservableListViewParams() {
|
||||
|
|
@ -155,7 +156,8 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
int toolbarHeight = Util.getActionBarSize(this);
|
||||
titleViewHeight = getResources().getDimensionPixelSize(R.dimen.title_view_height);
|
||||
headerOffset = toolbarHeight;
|
||||
headerOffset += getResources().getDimensionPixelSize(R.dimen.statusMargin);
|
||||
if (Util.hasKitKatSDK() && !Util.hasLollipopSDK())
|
||||
headerOffset += getResources().getDimensionPixelSize(R.dimen.statusMargin);
|
||||
}
|
||||
|
||||
private void setUpViews() {
|
||||
|
|
@ -239,12 +241,6 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
|
|||
});
|
||||
}
|
||||
|
||||
private void setUpToolBar() {
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setTitle(null);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
private void setUpSongsAdapter() {
|
||||
final ArrayList<Song> songs = AlbumSongLoader.getAlbumSongList(this, album.id, new SongTrackNumberComparator());
|
||||
final AlbumSongAdapter albumSongAdapter = new AlbumSongAdapter(this, songs);
|
||||
|
|
|
|||
|
|
@ -65,15 +65,14 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
private Artist artist;
|
||||
|
||||
private ObservableListView songListView;
|
||||
private View statusBar;
|
||||
private ImageView artistImage;
|
||||
private View songsBackgroundView;
|
||||
private TextView artistNameTv;
|
||||
private Toolbar toolbar;
|
||||
private int headerOffset;
|
||||
private int titleViewHeight;
|
||||
private int artistImageViewHeight;
|
||||
private int toolbarColor;
|
||||
public Toolbar toolbar;
|
||||
|
||||
private View songListHeader;
|
||||
private RecyclerView albumRecyclerView;
|
||||
|
|
@ -95,7 +94,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
// Change alpha of overlay
|
||||
float alpha = Math.max(0, Math.min(1, (float) scrollY / flexibleRange));
|
||||
ViewUtil.setBackgroundAlpha(toolbar, alpha, toolbarColor);
|
||||
ViewUtil.setBackgroundAlpha(statusBar, alpha, toolbarColor);
|
||||
|
||||
// Translate name text
|
||||
int maxTitleTranslationY = artistImageViewHeight;
|
||||
|
|
@ -110,7 +108,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -148,12 +145,11 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
}
|
||||
|
||||
private void initViews() {
|
||||
artistImage = (ImageView) findViewById(R.id.artist_image);
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
artistImage = (ImageView) findViewById(R.id.artist_image);
|
||||
songListView = (ObservableListView) findViewById(R.id.list);
|
||||
artistNameTv = (TextView) findViewById(R.id.artist_name);
|
||||
songsBackgroundView = findViewById(R.id.list_background);
|
||||
statusBar = findViewById(R.id.statusBar);
|
||||
|
||||
songListHeader = LayoutInflater.from(this).inflate(R.layout.artist_detail_header, songListView, false);
|
||||
albumRecyclerView = (RecyclerView) songListHeader.findViewById(R.id.recycler_view);
|
||||
|
|
@ -165,7 +161,8 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
|
|||
int toolbarHeight = Util.getActionBarSize(this);
|
||||
titleViewHeight = getResources().getDimensionPixelSize(R.dimen.title_view_height);
|
||||
headerOffset = toolbarHeight;
|
||||
headerOffset += getResources().getDimensionPixelSize(R.dimen.statusMargin);
|
||||
if (Util.hasKitKatSDK() && !Util.hasLollipopSDK())
|
||||
headerOffset += getResources().getDimensionPixelSize(R.dimen.statusMargin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,12 +17,14 @@ import android.support.v7.internal.view.menu.MenuPopupHelper;
|
|||
import android.support.v7.widget.ActionMenuPresenter;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
|
|
@ -62,11 +64,12 @@ public class MainActivity extends AbsFabActivity
|
|||
implements NavigationDrawerFragment.NavigationDrawerCallbacks, KabViewsDisableAble {
|
||||
|
||||
public static final String TAG = MainActivity.class.getSimpleName();
|
||||
private static final boolean DEBUG = true;
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
private NavigationDrawerFragment navigationDrawerFragment;
|
||||
private Toolbar toolbar;
|
||||
private View statusBar;
|
||||
private PagerAdapter pagerAdapter;
|
||||
private ViewPager viewPager;
|
||||
private PagerSlidingTabStrip slidingTabLayout;
|
||||
|
|
@ -149,7 +152,6 @@ public class MainActivity extends AbsFabActivity
|
|||
private void setUpToolBar() {
|
||||
setTitle(getResources().getString(R.string.app_name));
|
||||
toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
statusBar = findViewById(R.id.statusBar);
|
||||
setToolBarTransparent(PreferenceUtils.getInstance(this).transparentToolbar());
|
||||
setSupportActionBar(toolbar);
|
||||
setUpDrawerToggle();
|
||||
|
|
@ -159,7 +161,6 @@ public class MainActivity extends AbsFabActivity
|
|||
float alpha = transparent ? 0.97f : 1f;
|
||||
final int colorPrimary = PreferenceUtils.getInstance(this).getThemeColorPrimary();
|
||||
ViewUtil.setBackgroundAlpha(toolbar, alpha, colorPrimary);
|
||||
ViewUtil.setBackgroundAlpha(statusBar, alpha, colorPrimary);
|
||||
ViewUtil.setBackgroundAlpha(slidingTabLayout, alpha, colorPrimary);
|
||||
}
|
||||
|
||||
|
|
@ -170,6 +171,20 @@ public class MainActivity extends AbsFabActivity
|
|||
R.string.navigation_drawer_open,
|
||||
R.string.navigation_drawer_close
|
||||
);
|
||||
|
||||
drawerLayout.setStatusBarBackgroundColor(PreferenceUtils
|
||||
.getInstance(this).getThemeColorPrimaryDarker());
|
||||
FrameLayout navDrawerFrame = (FrameLayout) findViewById(R.id.nav_drawer_frame);
|
||||
int navDrawerMargin = getResources().getDimensionPixelSize(R.dimen.nav_drawer_margin);
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
int navDrawerWidthLimit = getResources().getDimensionPixelSize(R.dimen.nav_drawer_width_limit);
|
||||
int navDrawerWidth = displayMetrics.widthPixels - navDrawerMargin;
|
||||
if (navDrawerWidth > navDrawerWidthLimit) {
|
||||
navDrawerWidth = navDrawerWidthLimit;
|
||||
}
|
||||
navDrawerFrame.setLayoutParams(new DrawerLayout.LayoutParams(navDrawerWidth,
|
||||
DrawerLayout.LayoutParams.MATCH_PARENT, Gravity.START));
|
||||
|
||||
drawerLayout.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -537,4 +552,4 @@ public class MainActivity extends AbsFabActivity
|
|||
});
|
||||
return super.onMenuOpened(featureId, menu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,7 +76,10 @@ public abstract class ThemeBaseActivity extends ActionBarActivity implements Kab
|
|||
|
||||
protected void setUpTranslucence(boolean statusBarTranslucent, boolean navigationBarTranslucent) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
Util.setStatusBarTranslucent(getWindow(), statusBarTranslucent);
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
// Not needed on Lollipop
|
||||
Util.setStatusBarTranslucent(getWindow(), statusBarTranslucent);
|
||||
}
|
||||
if (Util.isInPortraitMode(this) || Util.isTablet(this)) {
|
||||
Util.setNavBarTranslucent(getWindow(), navigationBarTranslucent);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
|
|||
paletteColorPrimary = vibrantColor;
|
||||
observableScrollViewCallbacks.onScrollChanged(scrollView.getCurrentScrollY(), false, false);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setStatusBarColor(vibrantColor);
|
||||
getWindow().setStatusBarColor(ColorChooserDialog.shiftColorDown(vibrantColor));
|
||||
getWindow().setNavigationBarColor(vibrantColor);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,15 @@ public abstract class AbsMainActivityFragment extends Fragment implements KabVie
|
|||
private boolean areViewsEnabled;
|
||||
|
||||
protected int getTopPadding() {
|
||||
if (Util.hasKitKatSDK()) {
|
||||
final int norm = Util.getActionBarSize(getActivity()) +
|
||||
getResources().getDimensionPixelSize(R.dimen.tab_height) +
|
||||
getResources().getDimensionPixelSize(R.dimen.list_padding_vertical);
|
||||
if (Util.hasKitKatSDK() && !Util.hasLollipopSDK()) {
|
||||
if (Util.isInPortraitMode(getActivity()) || Util.isTablet(getActivity())) {
|
||||
return Util.getActionBarSize(getActivity()) + getResources().getDimensionPixelSize(R.dimen.tab_height) + Util.getStatusBarHeight(getActivity());
|
||||
return norm + Util.getStatusBarHeight(getActivity());
|
||||
}
|
||||
return Util.getActionBarSize(getActivity()) + getResources().getDimensionPixelSize(R.dimen.tab_height) + Util.getStatusBarHeight(getActivity());
|
||||
}
|
||||
return Util.getActionBarSize(getActivity()) + getResources().getDimensionPixelSize(R.dimen.tab_height);
|
||||
return norm;
|
||||
}
|
||||
|
||||
protected int getBottomPadding() {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import android.graphics.PorterDuff;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
|
@ -18,6 +19,9 @@ import android.view.inputmethod.InputMethodManager;
|
|||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
|
|
@ -201,4 +205,23 @@ public class Util {
|
|||
}
|
||||
return drawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of {@param set}. Used only for debugging purposes.
|
||||
*/
|
||||
@NonNull
|
||||
public static String setToString(@NonNull Set<String> set) {
|
||||
Iterator<String> i = set.iterator();
|
||||
if (!i.hasNext()) {
|
||||
return "[]";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder().append('[');
|
||||
while (true) {
|
||||
sb.append(i.next());
|
||||
if (!i.hasNext()) {
|
||||
return sb.append(']').toString();
|
||||
}
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
package com.kabouzeid.gramophone.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
||||
/**
|
||||
* A layout that draws something in the insets passed to {@link #fitSystemWindows(Rect)}, i.e. the area above UI chrome
|
||||
* (status and navigation bars, overlay action bars).
|
||||
*/
|
||||
public class ScrimInsetsFrameLayout extends FrameLayout {
|
||||
private Drawable mInsetForeground;
|
||||
|
||||
private Rect mInsets;
|
||||
private Rect mTempRect = new Rect();
|
||||
private OnInsetsCallback mOnInsetsCallback;
|
||||
|
||||
public ScrimInsetsFrameLayout(Context context) {
|
||||
super(context);
|
||||
init(context, null, 0);
|
||||
}
|
||||
|
||||
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyle) {
|
||||
final TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
R.styleable.ScrimInsetsView, defStyle, 0);
|
||||
if (a == null) {
|
||||
return;
|
||||
}
|
||||
mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsView_insetForeground);
|
||||
a.recycle();
|
||||
|
||||
setWillNotDraw(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean fitSystemWindows(Rect insets) {
|
||||
mInsets = new Rect(insets);
|
||||
setWillNotDraw(mInsetForeground == null);
|
||||
ViewCompat.postInvalidateOnAnimation(this);
|
||||
if (mOnInsetsCallback != null) {
|
||||
mOnInsetsCallback.onInsetsChanged(insets);
|
||||
}
|
||||
return true; // consume insets
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
if (mInsets != null && mInsetForeground != null) {
|
||||
int sc = canvas.save();
|
||||
canvas.translate(getScrollX(), getScrollY());
|
||||
|
||||
// Top
|
||||
mTempRect.set(0, 0, width, mInsets.top);
|
||||
mInsetForeground.setBounds(mTempRect);
|
||||
mInsetForeground.draw(canvas);
|
||||
|
||||
// Bottom
|
||||
mTempRect.set(0, height - mInsets.bottom, width, height);
|
||||
mInsetForeground.setBounds(mTempRect);
|
||||
mInsetForeground.draw(canvas);
|
||||
|
||||
// Left
|
||||
mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom);
|
||||
mInsetForeground.setBounds(mTempRect);
|
||||
mInsetForeground.draw(canvas);
|
||||
|
||||
// Right
|
||||
mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom);
|
||||
mInsetForeground.setBounds(mTempRect);
|
||||
mInsetForeground.draw(canvas);
|
||||
|
||||
canvas.restoreToCount(sc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
if (mInsetForeground != null) {
|
||||
mInsetForeground.setCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
if (mInsetForeground != null) {
|
||||
mInsetForeground.setCallback(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the calling container to specify a callback for custom processing when insets change (i.e. when
|
||||
* {@link #fitSystemWindows(Rect)} is called. This is useful for setting padding on UI elements based on
|
||||
* UI chrome insets (e.g. a Google Map or a ListView). When using with ListView or GridView, remember to set
|
||||
* clipToPadding to false.
|
||||
*/
|
||||
public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) {
|
||||
mOnInsetsCallback = onInsetsCallback;
|
||||
}
|
||||
|
||||
public static interface OnInsetsCallback {
|
||||
public void onInsetsChanged(Rect insets);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue