Nav drawer android design support library and more

This commit is contained in:
Karim Abou Zeid 2015-05-30 01:13:41 +02:00
commit b233b3b718
25 changed files with 303 additions and 405 deletions

View file

@ -1,6 +1,5 @@
package com.kabouzeid.gramophone.adapter;
import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.annotation.Nullable;
@ -151,9 +150,9 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
view.setOnLongClickListener(this);
// fixes the ripple starts at the right position
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setOnTouchListener(new View.OnTouchListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
((FrameLayout) view.findViewById(R.id.content)).getForeground().setHotspot(motionEvent.getX(), motionEvent.getY());

View file

@ -1,7 +1,6 @@
package com.kabouzeid.gramophone.ui.activities;
import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -111,7 +110,6 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
}
};
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -119,7 +117,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
App.bus.register(this);
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
if (PreferenceUtils.getInstance(this).coloredNavigationBarAlbumEnabled())
setNavigationBarColor(DialogUtils.resolveColor(this, R.attr.default_bar_color));
@ -140,7 +138,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
setUpToolBar();
setUpViews();
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getEnterTransition().addListener(new SmallTransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
@ -164,21 +162,6 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
}
}
@Override
protected boolean shouldColorStatusBar() {
return false;
}
@Override
protected boolean shouldColorNavBar() {
return false;
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
}
@Override
public String getTag() {
return TAG;
@ -222,20 +205,22 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
.resetViewBeforeLoading(true)
.build(),
new SimpleImageLoadingListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
applyPalette(null);
albumArtBackground.setImageBitmap(new StackBlurManager(BitmapFactory.decodeResource(getResources(), R.drawable.default_album_art)).process(10));
if (Util.isAtLeastLollipop()) startPostponedEnterTransition();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
startPostponedEnterTransition();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
applyPalette(loadedImage);
albumArtBackground.setImageBitmap(new StackBlurManager(loadedImage).process(10));
if (Util.isAtLeastLollipop()) startPostponedEnterTransition();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
startPostponedEnterTransition();
}
}
);
@ -245,7 +230,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
if (bitmap != null) {
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
@ -266,7 +251,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void resetColors() {
int titleTextColor = DialogUtils.resolveColor(this, R.attr.title_text_color);
int defaultBarColor = DialogUtils.resolveColor(this, R.attr.default_bar_color);
@ -291,7 +276,7 @@ public class AlbumDetailActivity extends AbsFabActivity implements PaletteColorH
return toolbarColor;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setNavigationBarColored(boolean colored) {
if (colored) {
setNavigationBarColor(toolbarColor);

View file

@ -1,7 +1,6 @@
package com.kabouzeid.gramophone.ui.activities;
import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -125,7 +124,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
};
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -133,7 +132,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
App.bus.register(this);
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
if (PreferenceUtils.getInstance(this).coloredNavigationBarArtistEnabled())
setNavigationBarColor(DialogUtils.resolveColor(this, R.attr.default_bar_color));
@ -148,12 +147,12 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
getSupportActionBar().setTitle(null);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
fixLollipopTransitionImageWrongSize();
startPostponedEnterTransition();
}
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getEnterTransition().addListener(new SmallTransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
@ -177,21 +176,6 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
}
}
@Override
protected boolean shouldColorStatusBar() {
return false;
}
@Override
protected boolean shouldColorNavBar() {
return false;
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
}
private void initViews() {
artistImage = (ImageView) findViewById(R.id.artist_image);
artistImageBackground = (ImageView) findViewById(R.id.artist_image_background);
@ -235,7 +219,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
loadBiography();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setNavigationBarColored(boolean colored) {
if (colored) {
setNavigationBarColor(toolbarColor);
@ -327,7 +311,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
if (bitmap != null) {
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
@ -365,7 +349,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
return toolbarColor;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void resetColors() {
int titleTextColor = DialogUtils.resolveColor(this, R.attr.title_text_color);
int defaultBarColor = DialogUtils.resolveColor(this, R.attr.default_bar_color);
@ -443,7 +427,7 @@ public class ArtistDetailActivity extends AbsFabActivity implements PaletteColor
toolbar.setEnabled(false);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void fixLollipopTransitionImageWrongSize() {
getWindow().getSharedElementEnterTransition().addListener(new Transition.TransitionListener() {
@Override

View file

@ -1,12 +1,15 @@
package com.kabouzeid.gramophone.ui.activities;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.util.Pair;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
@ -16,15 +19,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 android.widget.ImageView;
import android.widget.TextView;
import com.afollestad.materialcab.MaterialCab;
import com.afollestad.materialdialogs.ThemeSingleton;
@ -43,7 +45,6 @@ import com.kabouzeid.gramophone.model.MusicRemoteEvent;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.model.UIPreferenceChangedEvent;
import com.kabouzeid.gramophone.ui.activities.base.AbsFabActivity;
import com.kabouzeid.gramophone.ui.fragments.NavigationDrawerFragment;
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AbsMainActivityFragment;
import com.kabouzeid.gramophone.ui.fragments.mainactivityfragments.AlbumViewFragment;
import com.kabouzeid.gramophone.util.MusicUtil;
@ -60,20 +61,20 @@ import java.util.List;
import java.util.Set;
public class MainActivity extends AbsFabActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks, KabViewsDisableAble, CabHolder {
implements KabViewsDisableAble, CabHolder, View.OnClickListener {
public static final String TAG = MainActivity.class.getSimpleName();
private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;
private NavigationDrawerFragment navigationDrawerFragment;
private Toolbar toolbar;
private PagerAdapter pagerAdapter;
private ViewPager viewPager;
private PagerSlidingTabStrip slidingTabLayout;
private int currentPage = -1;
private MaterialCab cab;
private View statusBar;
private NavigationView navigationView;
private View navigationDrawerHeader;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -81,31 +82,16 @@ public class MainActivity extends AbsFabActivity
setContentView(R.layout.activity_main);
initViews();
navigationDrawerFragment.setUp(
drawerLayout
);
setUpDrawerLayout();
setUpToolBar();
setUpViewPager();
if (PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled())
setNavigationBarThemeColor();
handlePlaybackIntent(getIntent());
}
@Override
protected boolean shouldColorStatusBar() {
return false;
}
@Override
protected boolean shouldColorNavBar() {
return PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled();
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
}
private void setUpViewPager() {
pagerAdapter = new PagerAdapter(this, getSupportFragmentManager());
final PagerAdapter.MusicFragments[] fragments = PagerAdapter.MusicFragments.values();
@ -121,7 +107,7 @@ public class MainActivity extends AbsFabActivity
currentPage = startPosition;
viewPager.setCurrentItem(startPosition);
navigationDrawerFragment.setItemChecked(startPosition);
navigationView.getMenu().getItem(startPosition).setChecked(true);
slidingTabLayout.setIndicatorColor(ThemeSingleton.get().positiveColor);
slidingTabLayout.setViewPager(viewPager);
@ -134,7 +120,7 @@ public class MainActivity extends AbsFabActivity
@Override
public void onPageSelected(final int position) {
navigationDrawerFragment.setItemChecked(position);
navigationView.getMenu().getItem(position).setChecked(true);
currentPage = position;
}
@ -148,9 +134,7 @@ public class MainActivity extends AbsFabActivity
viewPager = (ViewPager) findViewById(R.id.pager);
slidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.tabs);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
statusBar = findViewById(R.id.status_bar);
navigationView = (NavigationView) findViewById(R.id.nav_view);
}
private void setUpToolBar() {
@ -166,7 +150,75 @@ public class MainActivity extends AbsFabActivity
final int colorPrimary = PreferenceUtils.getInstance(this).getThemeColorPrimary();
ViewUtil.setBackgroundAlpha(toolbar, alpha, colorPrimary);
ViewUtil.setBackgroundAlpha(slidingTabLayout, alpha, colorPrimary);
ViewUtil.setBackgroundAlpha(statusBar, alpha, colorPrimary);
}
private void setUpNavigationView() {
final int colorAccent = ThemeSingleton.get().positiveColor;
navigationView.setItemTextColor(new ColorStateList(
new int[][]{
//{-android.R.attr.state_enabled}, // disabled
{android.R.attr.state_checked}, // checked
{} // default
},
new int[]{
// 0,
colorAccent,
Color.argb(222, 0, 0, 0)
}
));
navigationView.setItemIconTintList(new ColorStateList(
new int[][]{
//{-android.R.attr.state_enabled}, // disabled
{android.R.attr.state_checked}, // checked
{} // default
},
new int[]{
// 0,
colorAccent,
Color.argb(138, 0, 0, 0)
}
));
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
drawerLayout.closeDrawers();
switch (menuItem.getItemId()) {
case R.id.nav_songs:
menuItem.setChecked(true);
viewPager.setCurrentItem(PagerAdapter.MusicFragments.SONG.ordinal(), true);
break;
case R.id.nav_albums:
menuItem.setChecked(true);
viewPager.setCurrentItem(PagerAdapter.MusicFragments.ALBUM.ordinal(), true);
break;
case R.id.nav_artists:
menuItem.setChecked(true);
viewPager.setCurrentItem(PagerAdapter.MusicFragments.ARTIST.ordinal(), true);
break;
case R.id.nav_playlists:
menuItem.setChecked(true);
viewPager.setCurrentItem(PagerAdapter.MusicFragments.PLAYLIST.ordinal(), true);
break;
case R.id.nav_settings:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
}
}, 200);
break;
case R.id.nav_about:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new AboutDialog().show(getSupportFragmentManager(), "ABOUT_DIALOG");
}
}, 200);
break;
}
return true;
}
});
}
private void setUpDrawerToggle() {
@ -186,16 +238,8 @@ public class MainActivity extends AbsFabActivity
}
private void setUpDrawerLayout() {
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.setStatusBarBackgroundColor(PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker());
setUpNavigationView();
}
@Override
@ -210,21 +254,26 @@ public class MainActivity extends AbsFabActivity
}
private void updateNavigationDrawerHeader() {
if (navigationDrawerFragment != null) {
Song song = MusicPlayerRemote.getCurrentSong();
if (song.id != -1) {
navigationDrawerFragment.getSongTitle().setText(song.title);
navigationDrawerFragment.getSongArtist().setText(song.artistName);
ImageLoader.getInstance().displayImage(
MusicUtil.getAlbumArtUri(song.albumId).toString(),
navigationDrawerFragment.getAlbumArtImageView(),
new DisplayImageOptions.Builder()
.cacheInMemory(true)
.showImageOnFail(R.drawable.default_album_art)
.resetViewBeforeLoading(true)
.build()
);
Song song = MusicPlayerRemote.getCurrentSong();
if (song.id != -1) {
if (navigationDrawerHeader == null) {
navigationDrawerHeader = navigationView.inflateHeaderView(R.layout.navigation_drawer_header);
navigationDrawerHeader.setOnClickListener(this);
}
((TextView) navigationDrawerHeader.findViewById(R.id.song_title)).setText(song.title);
((TextView) navigationDrawerHeader.findViewById(R.id.song_artist)).setText(song.artistName);
ImageLoader.getInstance().displayImage(
MusicUtil.getAlbumArtUri(song.albumId).toString(),
((ImageView) navigationDrawerHeader.findViewById(R.id.album_art)),
new DisplayImageOptions.Builder()
.cacheInMemory(true)
.showImageOnFail(R.drawable.default_album_art)
.resetViewBeforeLoading(true)
.build()
);
} else {
navigationView.removeHeaderView(navigationDrawerHeader);
navigationDrawerHeader = null;
}
}
@ -257,37 +306,6 @@ public class MainActivity extends AbsFabActivity
}
}
@Override
public void onNavigationDrawerItemSelected(int position) {
if (position == NavigationDrawerFragment.NAVIGATION_DRAWER_HEADER) {
NavigationUtil.openCurrentPlayingIfPossible(this, getSharedViewsWithFab(new Pair[]{
Pair.create(navigationDrawerFragment.getAlbumArtImageView(),
getResources().getString(R.string.transition_album_cover)
)
}));
} else if (position == NavigationDrawerFragment.ABOUT_INDEX) {
drawerLayout.closeDrawers();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
new AboutDialog().show(getSupportFragmentManager(), "ABOUT_DIALOG");
}
}, 200);
} else if (position == NavigationDrawerFragment.SETTINGS_INDEX) {
drawerLayout.closeDrawers();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
}
}, 200);
} else {
if (viewPager != null) {
viewPager.setCurrentItem(position, true);
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (isAlbumPage()) {
@ -355,13 +373,16 @@ public class MainActivity extends AbsFabActivity
setToolBarTransparent((boolean) event.getValue());
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
setShouldColorNavBar((boolean) event.getValue());
if ((boolean) event.getValue()) setNavigationBarThemeColor();
else resetNavigationBarColor();
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_CHANGED:
try {
setShouldColorNavBar(((Set) event.getValue()).contains(PreferenceUtils.COLORED_NAVIGATION_BAR_OTHER_SCREENS));
if (((Set) event.getValue()).contains(PreferenceUtils.COLORED_NAVIGATION_BAR_OTHER_SCREENS))
setNavigationBarThemeColor();
else resetNavigationBarColor();
} catch (NullPointerException ignored) {
setShouldColorNavBar(false);
resetNavigationBarColor();
}
break;
}
@ -369,7 +390,7 @@ public class MainActivity extends AbsFabActivity
@Override
public void onBackPressed() {
if (navigationDrawerFragment.isDrawerOpen()) drawerLayout.closeDrawers();
if (drawerLayout.isDrawerOpen(navigationView)) drawerLayout.closeDrawers();
else if (cab != null && cab.isActive()) cab.finish();
else super.onBackPressed();
}
@ -569,4 +590,15 @@ public class MainActivity extends AbsFabActivity
.start(callback);
return cab;
}
@Override
public void onClick(View v) {
if (v == navigationDrawerHeader) {
NavigationUtil.openCurrentPlayingIfPossible(this, getSharedViewsWithFab(new Pair[]{
Pair.create(((ImageView) navigationDrawerHeader.findViewById(R.id.album_art)),
getResources().getString(R.string.transition_album_cover)
)
}));
}
}
}

View file

@ -1,7 +1,6 @@
package com.kabouzeid.gramophone.ui.activities;
import android.animation.Animator;
import android.annotation.TargetApi;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -79,7 +78,7 @@ public class MusicControllerActivity extends AbsFabActivity {
private boolean opaqueToolBar = PreferenceUtils.getInstance(this).opaqueToolbarNowPlaying();
private boolean forceSquareAlbumArt = PreferenceUtils.getInstance(this).forceAlbumArtSquared();
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -100,7 +99,7 @@ public class MusicControllerActivity extends AbsFabActivity {
getSupportActionBar().setTitle(null);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getEnterTransition().addListener(new SmallTransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
@ -130,20 +129,6 @@ public class MusicControllerActivity extends AbsFabActivity {
getFab().setOnLongClickListener(null);
}
@Override
protected boolean shouldColorStatusBar() {
return false; // let other code handle this below
}
@Override
protected boolean shouldColorNavBar() {
return false; // let other code handle this below
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
}
private void moveSeekBarIntoPlace() {
// RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) progressSlider.getLayoutParams();
@ -360,7 +345,7 @@ public class MusicControllerActivity extends AbsFabActivity {
notifyTaskColorChange(defaultBarColor);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void animateColorChange(final int newColor) {
if (lastFooterColor != -1 && lastFooterColor != newColor) {
ViewUtil.animateViewColor(footer, lastFooterColor, newColor, COLOR_TRANSITION_TIME);

View file

@ -1,7 +1,5 @@
package com.kabouzeid.gramophone.ui.activities;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -38,7 +36,7 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
private PlaylistSongAdapter adapter;
private ArrayList<PlaylistSong> songs;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -79,24 +77,12 @@ public class PlaylistDetailActivity extends AbsFabActivity implements CabHolder
getSupportActionBar().setTitle(playlist.name);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (PreferenceUtils.getInstance(this).coloredNavigationBarPlaylistEnabled())
setNavigationBarThemeColor();
App.bus.register(this);
}
@Override
protected boolean shouldColorStatusBar() {
return true;
}
@Override
protected boolean shouldColorNavBar() {
return PreferenceUtils.getInstance(this).coloredNavigationBarPlaylistEnabled();
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
}
private void getIntentExtras() {
Bundle intentExtras = getIntent().getExtras();
final int playlistId = intentExtras.getInt(AppKeys.E_PLAYLIST);

View file

@ -59,21 +59,9 @@ public class SearchActivity extends AbsBaseActivity {
setSupportActionBar(toolbar);
//noinspection ConstantConditions
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected boolean shouldColorStatusBar() {
return true;
}
@Override
protected boolean shouldColorNavBar() {
return true;
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
setNavigationBarThemeColor();
setStatusBarThemeColor();
}
@Override

View file

@ -40,21 +40,10 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
if (savedInstanceState == null)
getFragmentManager().beginTransaction().replace(R.id.content_frame, new SettingsFragment()).commit();
}
@Override
protected boolean shouldColorStatusBar() {
return true;
}
@Override
protected boolean shouldColorNavBar() {
return PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled();
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
if (PreferenceUtils.getInstance(this).coloredNavigationBarOtherScreensEnabled())
setNavigationBarThemeColor();
setStatusBarThemeColor();
}
@Override
@ -202,13 +191,16 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
super.onUIPreferenceChangedEvent(event);
switch (event.getAction()) {
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_OTHER_SCREENS_CHANGED:
setShouldColorNavBar((boolean) event.getValue());
if ((boolean) event.getValue()) setNavigationBarThemeColor();
else resetNavigationBarColor();
break;
case UIPreferenceChangedEvent.COLORED_NAVIGATION_BAR_CHANGED:
try {
setShouldColorNavBar(((Set) event.getValue()).contains(PreferenceUtils.COLORED_NAVIGATION_BAR_OTHER_SCREENS));
if (((Set) event.getValue()).contains(PreferenceUtils.COLORED_NAVIGATION_BAR_OTHER_SCREENS))
setNavigationBarThemeColor();
else resetNavigationBarColor();
} catch (NullPointerException ignored) {
setShouldColorNavBar(false);
resetNavigationBarColor();
}
break;
}

View file

@ -1,7 +1,5 @@
package com.kabouzeid.gramophone.ui.activities.base;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import com.crashlytics.android.Crashlytics;
@ -65,7 +63,7 @@ public abstract class AbsBaseActivity extends ThemeBaseActivity implements KabVi
return areViewsEnabled;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void onUIPreferenceChangedEvent(UIPreferenceChangedEvent event) {
switch (event.getAction()) {
case UIPreferenceChangedEvent.THEME_CHANGED:

View file

@ -1,6 +1,5 @@
package com.kabouzeid.gramophone.ui.activities.base;
import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.graphics.BitmapFactory;
import android.os.Build;
@ -9,39 +8,29 @@ import android.support.v7.app.AppCompatActivity;
import com.afollestad.materialdialogs.ThemeSingleton;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.ColorChooserDialog;
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
import com.kabouzeid.gramophone.util.PreferenceUtils;
import com.kabouzeid.gramophone.util.Util;
import com.readystatesoftware.systembartint.SystemBarTintManager;
/**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/
public abstract class ThemeBaseActivity extends AppCompatActivity implements KabViewsDisableAble {
private final boolean statusBarTranslucent = shouldSetStatusBarTranslucent();
@Override
protected void onCreate(Bundle savedInstanceState) {
setStatusBarTranslucent(statusBarTranslucent);
setTheme(PreferenceUtils.getInstance(this).getGeneralTheme());
super.onCreate(savedInstanceState);
setupTheme();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setupTheme() {
// Apply colors to system UI if necessary
setShouldColorNavBar(shouldColorNavBar());
setShouldColorStatusBar(shouldColorStatusBar());
// Accent colors in dialogs, and any dynamic views that pull from this singleton
private void setupTheme() {
ThemeSingleton.get().positiveColor = PreferenceUtils.getInstance(this).getThemeColorAccent();
ThemeSingleton.get().negativeColor = ThemeSingleton.get().positiveColor;
ThemeSingleton.get().neutralColor = ThemeSingleton.get().positiveColor;
ThemeSingleton.get().widgetColor = ThemeSingleton.get().positiveColor;
// Dark theme
ThemeSingleton.get().darkTheme = PreferenceUtils.getInstance(this).getGeneralTheme() == R.style.Theme_MaterialMusic;
if (!overridesTaskColor()) {
@ -60,61 +49,38 @@ public abstract class ThemeBaseActivity extends AppCompatActivity implements Kab
}
}
private void setStatusBarTranslucent(boolean statusBarTranslucent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
protected void setStatusBarTranslucent(boolean statusBarTranslucent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
Util.setStatusBarTranslucent(getWindow(), statusBarTranslucent);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected final void setNavigationBarColor(int color) {
if (Util.isAtLeastLollipop())
getWindow().setNavigationBarColor(ColorChooserDialog.shiftColorDown(color));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow().setNavigationBarColor(color);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected final void setStatusBarColor(int color) {
if (!statusBarTranslucent && Util.isAtLeastLollipop()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
getWindow().setStatusBarColor(color);
} else {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintColor(color);
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected final void setShouldColorNavBar(boolean shouldColorNavBar) {
if (Util.isAtLeastLollipop()) {
if (shouldColorNavBar) {
setNavigationBarColor(PreferenceUtils.getInstance(this).getThemeColorPrimary());
} else {
getWindow().setNavigationBarColor(Util.resolveColor(this, android.R.attr.navigationBarColor));
}
}
protected final void setNavigationBarThemeColor() {
setNavigationBarColor(PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker());
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected final void setShouldColorStatusBar(boolean shouldColorStatusBar) {
if (shouldColorStatusBar) {
final int primary = PreferenceUtils.getInstance(this).getThemeColorPrimary();
setStatusBarColor(primary);
} else {
if (Util.isAtLeastLollipop()) {
getWindow().setStatusBarColor(Util.resolveColor(this, android.R.attr.statusBarColor));
} else {
SystemBarTintManager tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(false);
}
}
protected final void setStatusBarThemeColor() {
setStatusBarColor(PreferenceUtils.getInstance(this).getThemeColorPrimaryDarker());
}
protected abstract boolean shouldColorStatusBar();
protected final void resetNavigationBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
setNavigationBarColor(Util.resolveColor(this, android.R.attr.navigationBarColor));
}
protected abstract boolean shouldColorNavBar();
protected abstract boolean shouldSetStatusBarTranslucent();
protected final void resetStatusBarColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
setStatusBarColor(Util.resolveColor(this, android.R.attr.statusBarColor));
}
protected boolean overridesTaskColor() {
return false;

View file

@ -1,6 +1,5 @@
package com.kabouzeid.gramophone.ui.activities.tageditor;
import android.annotation.TargetApi;
import android.app.SearchManager;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@ -113,21 +112,6 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
protected boolean shouldColorStatusBar() {
return false;
}
@Override
protected boolean shouldColorNavBar() {
return false;
}
@Override
protected boolean shouldSetStatusBarTranslucent() {
return true;
}
private void initViews() {
fab = (FloatingActionButton) findViewById(R.id.fab);
scrollView = (ObservableScrollView) findViewById(R.id.observableScrollView);
@ -213,7 +197,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
protected abstract void save();
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void resetColors() {
final int primaryColor = PreferenceUtils.getInstance(this).getThemeColorPrimary();
paletteColorPrimary = primaryColor;
@ -257,7 +241,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
return super.onOptionsItemSelected(item);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void setNoImageMode() {
isInNoImageMode = true;
image.setVisibility(View.GONE);
@ -306,7 +290,7 @@ public abstract class AbsTagEditorActivity extends AbsBaseActivity {
private void applyPalette(final Bitmap bitmap) {
Palette.from(bitmap)
.generate(new Palette.PaletteAsyncListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onGenerated(Palette palette) {
final Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();

View file

@ -12,7 +12,6 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
@ -36,7 +35,7 @@ public class NavigationDrawerFragment extends Fragment {
private DrawerLayout drawerLayout;
private RecyclerView drawerRecyclerView;
private Button headerButton;
private View headerButton;
private ImageView albumArt;
private TextView songTitle;
private TextView songArtist;
@ -98,7 +97,7 @@ public class NavigationDrawerFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
return inflater.inflate(R.layout.navigation_drawer_header, container, false);
}
@Override
@ -110,12 +109,12 @@ public class NavigationDrawerFragment extends Fragment {
}
private void initViews() {
drawerRecyclerView = (RecyclerView) fragmentRootView.findViewById(R.id.navigation_drawer_list);
final View drawerHeader = fragmentRootView.findViewById(R.id.header);
headerButton = (Button) drawerHeader.findViewById(R.id.header_clickable);
albumArt = (ImageView) drawerHeader.findViewById(R.id.album_art);
songTitle = (TextView) drawerHeader.findViewById(R.id.song_title);
songArtist = (TextView) drawerHeader.findViewById(R.id.song_artist);
// drawerRecyclerView = (RecyclerView) fragmentRootView.findViewById(R.id.navigation_drawer_list);
// final View drawerHeader = fragmentRootView.findViewById(R.id.header);
// headerButton = (View) drawerHeader.findViewById(R.id.header_clickable);
// albumArt = (ImageView) drawerHeader.findViewById(R.id.album_art);
// songTitle = (TextView) drawerHeader.findViewById(R.id.song_title);
// songArtist = (TextView) drawerHeader.findViewById(R.id.song_artist);
}
private void setUpViews() {

View file

@ -16,7 +16,6 @@ public abstract class AbsMainActivityFragment extends Fragment implements KabVie
protected int getTopPadding() {
return Util.getActionBarSize(getActivity()) +
Util.getStatusBarHeight(getActivity()) +
getResources().getDimensionPixelSize(R.dimen.tab_height) +
getResources().getDimensionPixelSize(R.dimen.list_padding_vertical);
}