Optimized AbsThemeActivity recreate. Fixed wrong divider and overflow button colors on 4.1 devices. Replaced actionbar drawer toggle with a non moving menu drawable.
This commit is contained in:
parent
b093ede6d9
commit
52c405120c
16 changed files with 96 additions and 65 deletions
|
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
|
|||
import android.content.ComponentName;
|
||||
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.Build;
|
||||
|
|
@ -22,8 +21,6 @@ import android.support.design.widget.TabLayout;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
|
@ -88,7 +85,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
@Bind(R.id.drawer_layout)
|
||||
DrawerLayout drawerLayout;
|
||||
|
||||
private ActionBarDrawerToggle drawerToggle;
|
||||
private PagerAdapter pagerAdapter;
|
||||
private MaterialCab cab;
|
||||
@Nullable
|
||||
|
|
@ -179,10 +175,10 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
}
|
||||
|
||||
private void setUpToolbar() {
|
||||
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
|
||||
setTitle(getResources().getString(R.string.app_name));
|
||||
setAppBarColor();
|
||||
setSupportActionBar(toolbar);
|
||||
setUpDrawerToggle();
|
||||
}
|
||||
|
||||
private void setAppBarColor() {
|
||||
|
|
@ -258,22 +254,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
});
|
||||
}
|
||||
|
||||
private void setUpDrawerToggle() {
|
||||
drawerToggle = new ActionBarDrawerToggle(
|
||||
this,
|
||||
drawerLayout,
|
||||
R.string.navigation_drawer_open,
|
||||
R.string.navigation_drawer_close
|
||||
);
|
||||
drawerLayout.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawerToggle.syncState();
|
||||
}
|
||||
});
|
||||
drawerLayout.setDrawerListener(drawerToggle);
|
||||
}
|
||||
|
||||
private void setUpDrawerLayout() {
|
||||
setUpNavigationView();
|
||||
}
|
||||
|
|
@ -344,14 +324,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
handlePlaybackIntent(getIntent());
|
||||
}
|
||||
|
||||
public void restoreActionBar() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
//noinspection ConstantConditions
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
|
|
@ -364,7 +336,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
} else {
|
||||
menu.removeItem(R.id.action_view_as);
|
||||
}
|
||||
restoreActionBar();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -376,7 +347,12 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
if (drawerToggle.onOptionsItemSelected(item)) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
if (drawerLayout.isDrawerOpen(navigationView)) {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
} else {
|
||||
drawerLayout.openDrawer(navigationView);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -448,12 +424,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
drawerToggle.onConfigurationChanged(newConfig);
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (drawerLayout.isDrawerOpen(navigationView)) drawerLayout.closeDrawers();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.kabouzeid.gramophone.ui.activities.base;
|
|||
|
||||
import android.animation.Animator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
|
@ -32,7 +33,6 @@ import android.widget.LinearLayout;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.afollestad.materialdialogs.util.DialogUtils;
|
||||
|
|
@ -62,11 +62,11 @@ import butterknife.ButterKnife;
|
|||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
* <p/>
|
||||
* <p>
|
||||
* Do not use {@link #setContentView(int)} but wrap your layout with
|
||||
* {@link #wrapSlidingMusicPanelAndFab(int)} first and then return it in {@link #createContentView()}
|
||||
*/
|
||||
public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements SlidingUpPanelLayout.PanelSlideListener {
|
||||
public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements SlidingUpPanelLayout.PanelSlideListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public static final String TAG = AbsSlidingMusicPanelActivity.class.getSimpleName();
|
||||
|
||||
private static final int FAB_CIRCULAR_REVEAL_ANIMATION_TIME = 1000;
|
||||
|
|
@ -151,6 +151,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
setUpSlidingPanel();
|
||||
|
||||
initAppearanceVarsFromSharedPrefs();
|
||||
PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this);
|
||||
initProgressSliderDependentViews();
|
||||
|
||||
moveSeekBarIntoPlace();
|
||||
|
|
@ -176,6 +177,12 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
|
||||
protected abstract View createContentView();
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
PreferenceUtil.getInstance(this).unregisterOnSharedPreferenceChangedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -206,6 +213,48 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
updateShuffleState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
switch (key) {
|
||||
case PreferenceUtil.OPAQUE_STATUSBAR_NOW_PLAYING:
|
||||
opaqueStatusBar = PreferenceUtil.getInstance(this).opaqueStatusbarNowPlaying();
|
||||
// do not break here
|
||||
case PreferenceUtil.OPAQUE_TOOLBAR_NOW_PLAYING:
|
||||
opaqueToolBar = opaqueStatusBar && PreferenceUtil.getInstance(this).opaqueToolbarNowPlaying();
|
||||
if (lastFooterColor != -1) {
|
||||
animateColorChange(lastFooterColor);
|
||||
}
|
||||
if (opaqueStatusBar) {
|
||||
if (opaqueToolBar) {
|
||||
alignAlbumArtToToolbar();
|
||||
} else {
|
||||
alignAlbumArtToStatusBar();
|
||||
}
|
||||
} else {
|
||||
alignAlbumArtToTop();
|
||||
}
|
||||
break;
|
||||
case PreferenceUtil.FORCE_SQUARE_ALBUM_ART:
|
||||
forceSquareAlbumArt = PreferenceUtil.getInstance(this).forceAlbumArtSquared();
|
||||
albumArt.forceSquare(forceSquareAlbumArt);
|
||||
break;
|
||||
case PreferenceUtil.LARGER_TITLE_BOX_NOW_PLAYING:
|
||||
largerTitleBox = PreferenceUtil.getInstance(this).largerTitleBoxNowPlaying();
|
||||
adjustTitleBoxSize();
|
||||
break;
|
||||
case PreferenceUtil.ALTERNATIVE_PROGRESS_SLIDER_NOW_PLAYING:
|
||||
alternativeProgressSlider = PreferenceUtil.getInstance(this).alternativeProgressSliderNowPlaying();
|
||||
initProgressSliderDependentViews();
|
||||
moveSeekBarIntoPlace();
|
||||
setTint(seekBar, getThemeColorAccent());
|
||||
break;
|
||||
case PreferenceUtil.PLAYBACK_CONTROLLER_CARD_NOW_PLAYING:
|
||||
showPlaybackControllerCard = PreferenceUtil.getInstance(this).playbackControllerCardNowPlaying();
|
||||
setUpPlaybackControllerCard();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpPlayPauseButton() {
|
||||
updateFabState(false);
|
||||
|
||||
|
|
@ -233,8 +282,6 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
} else {
|
||||
MusicPlayerRemote.resumePlaying();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(AbsSlidingMusicPanelActivity.this, getResources().getString(R.string.playing_queue_empty), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -299,13 +346,13 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
|
||||
@Override
|
||||
public void onPanelSlide(View view, float slideOffset) {
|
||||
miniPlayer.setAlpha(1 - slideOffset);
|
||||
|
||||
float xTranslation = (dummyFab.getX() + mediaControllerContainer.getX() + footerFrame.getX() - playPauseFab.getLeft()) * slideOffset;
|
||||
float yTranslation = (dummyFab.getY() + mediaControllerContainer.getY() + footerFrame.getY() - playPauseFab.getTop()) * slideOffset;
|
||||
|
||||
playPauseFab.setTranslationX(xTranslation);
|
||||
playPauseFab.setTranslationY(yTranslation);
|
||||
|
||||
miniPlayer.setAlpha(1 - slideOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -324,7 +371,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
int cy = (dummyFab.getTop() + dummyFab.getBottom()) / 2;
|
||||
int finalRadius = Math.max(mediaControllerContainer.getWidth(), mediaControllerContainer.getHeight());
|
||||
|
||||
Animator animator = ViewAnimationUtils.createCircularReveal(mediaControllerContainer, cx, cy, dummyFab.getWidth() / 2, finalRadius);
|
||||
final Animator animator = ViewAnimationUtils.createCircularReveal(mediaControllerContainer, cx, cy, dummyFab.getWidth() / 2, finalRadius);
|
||||
animator.setInterpolator(new DecelerateInterpolator());
|
||||
animator.setDuration(FAB_CIRCULAR_REVEAL_ANIMATION_TIME);
|
||||
animator.start();
|
||||
|
|
@ -352,10 +399,6 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
}
|
||||
}
|
||||
|
||||
public FloatingActionButton getPlayPauseFab() {
|
||||
return playPauseFab;
|
||||
}
|
||||
|
||||
public SlidingUpPanelLayout getSlidingUpPanelLayout() {
|
||||
return slidingUpPanelLayout;
|
||||
}
|
||||
|
|
@ -425,6 +468,10 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
songTotalTime = (TextView) findViewById(R.id.player_alternative_song_total_time);
|
||||
seekBar = (SeekBar) findViewById(R.id.player_alternative_progress_slider);
|
||||
} else {
|
||||
findViewById(R.id.player_default_progress_container).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.player_default_progress_slider).setVisibility(View.VISIBLE);
|
||||
findViewById(R.id.player_alternative_progress_container).setVisibility(View.GONE);
|
||||
|
||||
songCurrentProgress = (TextView) findViewById(R.id.player_default_song_current_progress);
|
||||
songTotalTime = (TextView) findViewById(R.id.player_default_song_total_time);
|
||||
seekBar = (SeekBar) findViewById(R.id.player_default_progress_slider);
|
||||
|
|
@ -742,9 +789,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
}
|
||||
|
||||
private void startUpdatingProgressViews() {
|
||||
if (!progressViewsUpdateHandler.hasMessages(CMD_REFRESH_PROGRESS_VIEWS)) {
|
||||
queueNextRefresh(0);
|
||||
}
|
||||
queueNextRefresh(1);
|
||||
}
|
||||
|
||||
private void stopUpdatingProgressViews() {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.content.res.ColorStateList;
|
|||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
|
@ -41,7 +42,13 @@ public abstract class AbsThemeActivity extends AppCompatActivity implements KabV
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
recreateIfThemeChanged();
|
||||
// the handler is necessary to avoid "java.lang.RuntimeException: Performing pause of activity that is not resumed"
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
recreateIfThemeChanged();
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
|
||||
private void setupTheme() {
|
||||
|
|
|
|||
BIN
app/src/main/res/drawable-hdpi/ic_menu_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_menu_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 116 B |
BIN
app/src/main/res/drawable-mdpi/ic_menu_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_menu_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 B |
BIN
app/src/main/res/drawable-xhdpi/ic_menu_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_menu_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 135 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_menu_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_menu_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 183 B |
BIN
app/src/main/res/drawable-xxxhdpi/ic_menu_white_24dp.png
Normal file
BIN
app/src/main/res/drawable-xxxhdpi/ic_menu_white_24dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 235 B |
|
|
@ -13,7 +13,8 @@
|
|||
android:id="@+id/artist_image_background"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<com.kabouzeid.gramophone.views.SquareIfPlaceImageView
|
||||
android:id="@+id/image"
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@
|
|||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="-8dp"
|
||||
android:background="?dividerHorizontal" />
|
||||
android:background="?divider_color" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -86,7 +86,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?dividerHorizontal"
|
||||
android:background="?divider_color"
|
||||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
|
|
@ -96,6 +96,6 @@
|
|||
android:layout_gravity="bottom"
|
||||
android:layout_marginLeft="72dp"
|
||||
android:layout_marginStart="72dp"
|
||||
android:background="?dividerHorizontal" />
|
||||
android:background="?divider_color" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
@ -72,7 +72,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?dividerHorizontal"
|
||||
android:background="?divider_color"
|
||||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
|
|
@ -82,6 +82,6 @@
|
|||
android:layout_gravity="bottom"
|
||||
android:layout_marginLeft="72dp"
|
||||
android:layout_marginStart="72dp"
|
||||
android:background="?dividerHorizontal" />
|
||||
android:background="?divider_color" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
@ -10,4 +10,7 @@
|
|||
|
||||
<attr name="toolbarPopupTheme" format="reference" />
|
||||
|
||||
<attr name="icon_color" format="color" />
|
||||
<attr name="divider_color" format="color" />
|
||||
|
||||
</resources>
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
<resources>
|
||||
|
||||
<!--light theme-->
|
||||
<color name="music_controller_container_color">@android:color/white</color>
|
||||
<color name="music_controller_container_color">@color/cardview_light_background</color>
|
||||
<color name="default_bar_color">@color/grey_700</color>
|
||||
|
||||
<!--dark theme-->
|
||||
<color name="music_controller_container_color_dark">@color/grey_800</color>
|
||||
<color name="music_controller_container_color_dark">@color/cardview_dark_background</color>
|
||||
<color name="default_bar_color_dark">@color/grey_900</color>
|
||||
|
||||
</resources>
|
||||
|
|
@ -34,7 +34,6 @@
|
|||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">?attr/actionBarSize</item>
|
||||
<item name="android:theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
|
||||
<item name="android:minHeight">@dimen/abc_action_bar_default_height_material</item>
|
||||
<item name="popupTheme">?toolbarPopupTheme</item>
|
||||
<item name="android:elevation" tools:ignore="NewApi">@dimen/toolbar_elevation</item>
|
||||
<item name="android:transitionName" tools:ignore="NewApi">toolbar</item>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
<item name="default_bar_color">@color/default_bar_color_dark</item>
|
||||
|
||||
<item name="divider_color">@color/md_divider_white</item>
|
||||
<item name="icon_color">@color/secondary_text_default_material_dark</item>
|
||||
|
||||
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>
|
||||
|
||||
<!-- FOR EVERYWHERE WE CANT OVERRIDE THE ACCENT COLOR-->
|
||||
|
|
@ -40,6 +43,9 @@
|
|||
|
||||
<item name="default_bar_color">@color/default_bar_color</item>
|
||||
|
||||
<item name="divider_color">@color/md_divider_black</item>
|
||||
<item name="icon_color">@color/secondary_text_default_material_light</item>
|
||||
|
||||
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
|
||||
|
||||
<!-- FOR EVERYWHERE WE CANT OVERRIDE THE ACCENT COLOR-->
|
||||
|
|
@ -67,12 +73,12 @@
|
|||
</style>
|
||||
|
||||
<style name="OverFlowButtonParent">
|
||||
<item name="android:tint">?android:textColorSecondary</item>
|
||||
<item name="android:tint">?icon_color</item>
|
||||
<item name="android:src">@drawable/abc_ic_menu_moreoverflow_mtrl_alpha</item>
|
||||
<item name="android:padding">12dp</item>
|
||||
<item name="android:layout_width">48dp</item>
|
||||
<item name="android:layout_height">48dp</item>
|
||||
<item name="android:scaleType">fitXY</item>
|
||||
<!--<item name="android:scaleType">fitXY</item>-->
|
||||
<item name="android:background">?round_selector</item>
|
||||
<item name="android:layout_centerVertical">true</item>
|
||||
<item name="android:focusableInTouchMode">false</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue