backup with notch problem
This commit is contained in:
parent
f31831ea7f
commit
62b12da2ad
70 changed files with 1131 additions and 990 deletions
|
@ -3,6 +3,7 @@ package code.name.monkey.retromusic.cast;
|
|||
import android.net.Uri;
|
||||
|
||||
import com.google.android.gms.cast.MediaInfo;
|
||||
import com.google.android.gms.cast.MediaLoadOptions;
|
||||
import com.google.android.gms.cast.MediaMetadata;
|
||||
import com.google.android.gms.cast.framework.CastSession;
|
||||
import com.google.android.gms.cast.framework.media.RemoteMediaClient;
|
||||
|
@ -22,7 +23,7 @@ public class CastHelper {
|
|||
String ipAddress = RetroUtil.getIPAddress(true);
|
||||
URL baseUrl;
|
||||
try {
|
||||
baseUrl = new URL("http", ipAddress, Constants.CAST_SERVER_PORT, "");
|
||||
baseUrl = new URL("https", ipAddress, Constants.CAST_SERVER_PORT, "");
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
|
@ -48,7 +49,9 @@ public class CastHelper {
|
|||
.setStreamDuration(song.duration)
|
||||
.build();
|
||||
RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();
|
||||
remoteMediaClient.load(mediaInfo, true, 0);
|
||||
remoteMediaClient.load(mediaInfo, new MediaLoadOptions.Builder()
|
||||
.build());
|
||||
//remoteMediaClient.load(mediaInfo, true, 0);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -455,10 +455,6 @@ public class MusicPlayerRemote {
|
|||
return musicService != null;
|
||||
}
|
||||
|
||||
public static void setZeroVolume() {
|
||||
|
||||
}
|
||||
|
||||
@interface PlaybackLocation {
|
||||
int REMOTE = 0;
|
||||
int LOCAL = 1;
|
||||
|
|
|
@ -305,6 +305,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
|
||||
registerHeadsetEvents();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private AudioManager getAudioManager() {
|
||||
|
@ -1209,6 +1210,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
playerHandler.sendEmptyMessage(TRACK_ENDED);
|
||||
}
|
||||
|
||||
|
||||
private static final class QueueSaveHandler extends Handler {
|
||||
@NonNull
|
||||
private final WeakReference<MusicService> mService;
|
||||
|
|
|
@ -186,7 +186,7 @@ public class AlbumDetailsActivity extends AbsSlidingMusicPanelActivity implement
|
|||
|
||||
if (toolbar != null && !PreferenceUtil.getInstance().getFullScreenMode()) {
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||
params.topMargin = RetroUtil.getStatusBarHeight(this);
|
||||
params.topMargin = RetroUtil.getStatusBarHeight( );
|
||||
toolbar.setLayoutParams(params);
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ public class ArtistDetailActivity extends AbsSlidingMusicPanelActivity implement
|
|||
|
||||
if (toolbar != null && !PreferenceUtil.getInstance().getFullScreenMode()) {
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
|
||||
params.topMargin = RetroUtil.getStatusBarHeight(this);
|
||||
params.topMargin = RetroUtil.getStatusBarHeight( );
|
||||
toolbar.setLayoutParams(params);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ public class LyricsActivity extends AbsMusicServiceActivity implements
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setDrawUnderStatusBar();
|
||||
setDrawUnderNavigationBar();
|
||||
//setDrawUnderNavigationBar();
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_lyrics);
|
||||
|
|
|
@ -97,8 +97,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity implements Shared
|
|||
|
||||
getBottomNavigationView().setOnNavigationItemSelectedListener(this);
|
||||
|
||||
drawerLayout.setOnApplyWindowInsetsListener((view, windowInsets) -> windowInsets.replaceSystemWindowInsets(0, 0, 0, 0));
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
selectedFragment(PreferenceUtil.getInstance().getLastPage());
|
||||
//setCurrentFragment(new LibraryFragment(), false, LibraryFragment.TAG);
|
||||
|
@ -277,11 +275,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity implements Shared
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals(PreferenceUtil.GENERAL_THEME) ||
|
||||
|
@ -325,11 +318,11 @@ public class MainActivity extends AbsSlidingMusicPanelActivity implements Shared
|
|||
.show();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
PreferenceUtil.getInstance().setLastPage(menuItem.getItemId());
|
||||
selectedFragment(menuItem.getItemId());
|
||||
applyInsets();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@ package code.name.monkey.retromusic.ui.activities.base;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.google.android.gms.cast.framework.CastButtonFactory;
|
||||
import com.google.android.gms.cast.framework.CastContext;
|
||||
import com.google.android.gms.cast.framework.CastSession;
|
||||
import com.google.android.gms.cast.framework.SessionManagerListener;
|
||||
|
@ -11,6 +13,7 @@ import com.google.android.gms.common.GoogleApiAvailability;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.cast.WebServer;
|
||||
|
||||
public abstract class AbsCastActivity extends AbsBaseActivity {
|
||||
|
|
|
@ -1,73 +1,99 @@
|
|||
package code.name.monkey.retromusic.ui.activities.base;
|
||||
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.PathInterpolator;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.google.android.gms.cast.framework.CastSession;
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
|
||||
import com.sothree.slidinguppanel.SlidingUpPanelLayout.PanelState;
|
||||
|
||||
import androidx.annotation.FloatRange;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil;
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil;
|
||||
import code.name.monkey.appthemehelper.util.NavigationViewUtil;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.cast.CastHelper;
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
|
||||
import code.name.monkey.retromusic.ui.fragments.MiniPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.NowPlayingScreen;
|
||||
import code.name.monkey.retromusic.ui.fragments.base.AbsPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.adaptive.AdaptiveFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.blur.BlurPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.card.CardFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.cardblur.CardBlurFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.color.ColorFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.fit.FitFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.flat.FlatPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.full.FullPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.hmm.HmmPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.material.MaterialFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.normal.PlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.plain.PlainPlayerFragment;
|
||||
import code.name.monkey.retromusic.ui.fragments.player.simple.SimplePlayerFragment;
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||
import code.name.monkey.retromusic.util.RetroUtil;
|
||||
import code.name.monkey.retromusic.util.ViewUtil;
|
||||
import code.name.monkey.retromusic.views.BottomNavigationBarTinted;
|
||||
import code.name.monkey.retromusic.views.FitSystemWindowsLayout;
|
||||
|
||||
public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity {
|
||||
public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivity implements
|
||||
SlidingUpPanelLayout.PanelSlideListener, PlayerFragment.Callbacks {
|
||||
|
||||
public static final String TAG = AbsSlidingMusicPanelActivity.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.sliding_layout)
|
||||
SlidingUpPanelLayout slidingUpPanelLayout;
|
||||
|
||||
@BindView(R.id.bottom_navigation)
|
||||
BottomNavigationBarTinted bottomNavigationView;
|
||||
|
||||
@BindView(R.id.parentPanel)
|
||||
ViewGroup parentPanel;
|
||||
|
||||
@BindView(R.id.mini_player_container)
|
||||
ViewGroup miniPlayerContainer;
|
||||
@BindView(R.id.main_content)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
|
||||
private MiniPlayerFragment miniPlayerFragment;
|
||||
private AbsPlayerFragment playerFragment;
|
||||
private NowPlayingScreen currentNowPlayingScreen;
|
||||
|
||||
private int navigationbarColor;
|
||||
private int taskColor;
|
||||
private boolean lightStatusbar;
|
||||
private boolean lightNavigationBar;
|
||||
private ValueAnimator navigationBarColorAnimator;
|
||||
private ArgbEvaluator argbEvaluator = new ArgbEvaluator();
|
||||
|
||||
protected AbsSlidingMusicPanelActivity() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
setDrawUnderNavigationBar();
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(createContentView());
|
||||
ButterKnife.bind(this);
|
||||
setLightStatusbar(true);
|
||||
setLightNavigationBar(true);
|
||||
//setupBottomView();
|
||||
miniPlayerFragment = (MiniPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.mini_player_fragment);
|
||||
}
|
||||
|
||||
private void setupBottomView() {
|
||||
bottomNavigationView.setBackgroundColor(ThemeStore.primaryColor(this));
|
||||
bottomNavigationView.setSelectedItemId(PreferenceUtil.getInstance().getLastPage());
|
||||
|
||||
int iconColor = ATHUtil.resolveColor(this, R.attr.iconColor);
|
||||
int accentColor = ThemeStore.accentColor(this);
|
||||
NavigationViewUtil.setItemIconColors(bottomNavigationView, ColorUtil.withAlpha(iconColor, 0.5f), accentColor);
|
||||
NavigationViewUtil.setItemTextColors(bottomNavigationView, ColorUtil.withAlpha(iconColor, 0.5f), accentColor);
|
||||
|
||||
bottomNavigationView.setLabelVisibilityMode(PreferenceUtil.getInstance().getTabTitleMode());
|
||||
//bottomNavigationView.getMenu().removeItem(R.id.action_playlist);
|
||||
checkDisplayCutout();
|
||||
choosFragmentForTheme();
|
||||
setupSlidingUpPanel();
|
||||
}
|
||||
|
||||
public void setBottomBarVisibility(int gone) {
|
||||
if (bottomNavigationView != null) {
|
||||
bottomNavigationView.setVisibility(gone);
|
||||
hideBottomBar(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,14 +102,15 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
@Override
|
||||
public void onServiceConnected() {
|
||||
super.onServiceConnected();
|
||||
if (!MusicPlayerRemote.getPlayingQueue().isEmpty())
|
||||
parentPanel.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
|
||||
slidingUpPanelLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
parentPanel.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
hideBottomBar(false);
|
||||
}
|
||||
});
|
||||
} // don't call hideBottomBar(true) here as it causes a bug with the SlidingUpPanelLayout
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +120,28 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
}
|
||||
|
||||
public void hideBottomBar(final boolean hide) {
|
||||
miniPlayerContainer.setVisibility(hide ? View.GONE : View.VISIBLE);
|
||||
//int heightOfBarWithTabs = getResources().getDimensionPixelSize(R.dimen.mini_player_height_expanded) + RetroUtil.getNavigationBarHeight(getResources());
|
||||
int height = RetroUtil.checkNavigationBarHeight() ? getResources().getDimensionPixelSize(R.dimen.mini_player_height) : getResources().getDimensionPixelSize(R.dimen.mini_player_height);
|
||||
int heightOfBar = getResources().getDimensionPixelSize(R.dimen.mini_player_height) + RetroUtil.getNavigationBarHeight(this);
|
||||
int heightOfBarWithTabs =
|
||||
getResources().getDimensionPixelSize(R.dimen.mini_player_height_expanded) +
|
||||
RetroUtil.getNavigationBarHeight(this);
|
||||
if (hide) {
|
||||
slidingUpPanelLayout.setPanelHeight(0);
|
||||
collapsePanel();
|
||||
} else {
|
||||
if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
|
||||
slidingUpPanelLayout.setPanelHeight(bottomNavigationView.getVisibility() == View.VISIBLE ? heightOfBarWithTabs : heightOfBar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDisplayCutout() {
|
||||
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
attrs.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected View wrapSlidingMusicPanel(@LayoutRes int resId) {
|
||||
|
@ -106,13 +154,18 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (handleBackPress()) {
|
||||
if (!handleBackPress())
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean handleBackPress() {
|
||||
return true;
|
||||
if (slidingUpPanelLayout.getPanelHeight() != 0 && playerFragment.onBackPressed())
|
||||
return true;
|
||||
if (getPanelState() == SlidingUpPanelLayout.PanelState.EXPANDED) {
|
||||
collapsePanel();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,7 +181,7 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
@Override
|
||||
public void showCastMiniController() {
|
||||
super.showCastMiniController();
|
||||
MusicPlayerRemote.setZeroVolume();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -138,8 +191,8 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
if (castSession == null) {
|
||||
return;
|
||||
}
|
||||
//MusicPlayerRemote.pauseSong();
|
||||
CastHelper.startCasting(castSession, MusicPlayerRemote.getCurrentSong());
|
||||
//MusicPlayerRemote.setZeroVolume();
|
||||
//CastHelper.startCasting(castSession, MusicPlayerRemote.getCurrentSong());
|
||||
}
|
||||
|
||||
public void toggleBottomNavigationView(boolean toggle) {
|
||||
|
@ -150,4 +203,311 @@ public abstract class AbsSlidingMusicPanelActivity extends AbsMusicServiceActivi
|
|||
return bottomNavigationView;
|
||||
}
|
||||
|
||||
public SlidingUpPanelLayout getSlidingUpPanelLayout() {
|
||||
return slidingUpPanelLayout;
|
||||
}
|
||||
|
||||
public AbsPlayerFragment getPlayerFragment() {
|
||||
return playerFragment;
|
||||
}
|
||||
|
||||
protected void setupSlidingUpPanel() {
|
||||
slidingUpPanelLayout.getViewTreeObserver()
|
||||
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
slidingUpPanelLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
|
||||
if (getPanelState() == PanelState.EXPANDED) {
|
||||
onPanelSlide(slidingUpPanelLayout, 1);
|
||||
onPanelExpanded(slidingUpPanelLayout);
|
||||
} else if (getPanelState() == PanelState.COLLAPSED) {
|
||||
onPanelCollapsed(slidingUpPanelLayout);
|
||||
} else {
|
||||
playerFragment.onHide();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
slidingUpPanelLayout.addPanelSlideListener(this);
|
||||
|
||||
applyInsets();
|
||||
}
|
||||
|
||||
protected void applyInsets() {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(coordinatorLayout, (v, insets) -> {
|
||||
//Bottom navigation view
|
||||
ViewGroup.MarginLayoutParams bParams = (ViewGroup.MarginLayoutParams) bottomNavigationView.getLayoutParams();
|
||||
if (!PreferenceUtil.getInstance().getFullScreenMode())
|
||||
bParams.bottomMargin = insets.getSystemWindowInsetBottom();
|
||||
bParams.rightMargin = insets.getSystemWindowInsetRight();
|
||||
bParams.leftMargin = insets.getSystemWindowInsetLeft();
|
||||
|
||||
|
||||
//For now playing screen
|
||||
FrameLayout layout = findViewById(R.id.safeArea);
|
||||
if (layout != null) {
|
||||
ViewGroup.MarginLayoutParams fParams = (ViewGroup.MarginLayoutParams) layout.getLayoutParams();
|
||||
if (!PreferenceUtil.getInstance().getFullScreenMode()) {
|
||||
fParams.topMargin = insets.getSystemWindowInsetTop();
|
||||
fParams.bottomMargin = insets.getSystemWindowInsetBottom();
|
||||
}
|
||||
fParams.leftMargin = insets.getSystemWindowInsetLeft();
|
||||
fParams.rightMargin = insets.getSystemWindowInsetRight();
|
||||
}
|
||||
|
||||
//Mini player
|
||||
FitSystemWindowsLayout miniPlayer = (FitSystemWindowsLayout) miniPlayerFragment.getView();
|
||||
if (miniPlayer != null) {
|
||||
ViewGroup.MarginLayoutParams mParams = (ViewGroup.MarginLayoutParams) miniPlayer.getLayoutParams();
|
||||
mParams.bottomMargin = insets.getSystemWindowInsetBottom();//RetroUtil.checkNavigationBarHeight() ? 0 : getResources().getDimensionPixelSize(R.dimen.mini_player_height);
|
||||
mParams.leftMargin = insets.getSystemWindowInsetLeft();
|
||||
mParams.rightMargin = insets.getSystemWindowInsetRight();
|
||||
}
|
||||
|
||||
//For Library, Folder, Home etc
|
||||
ViewGroup viewGroup = findViewById(R.id.content_container);
|
||||
if (viewGroup != null) {
|
||||
ViewGroup.MarginLayoutParams mParams = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
|
||||
mParams.leftMargin = insets.getSystemWindowInsetLeft();
|
||||
mParams.rightMargin = insets.getSystemWindowInsetRight();
|
||||
mParams.bottomMargin = insets.getSystemWindowInsetBottom();
|
||||
}
|
||||
|
||||
FrameLayout frameLayout = findViewById(R.id.sliding_panel);
|
||||
if (frameLayout != null) {
|
||||
ViewGroup.MarginLayoutParams mParams = (ViewGroup.MarginLayoutParams) frameLayout.getLayoutParams();
|
||||
mParams.leftMargin = insets.getSystemWindowInsetLeft();
|
||||
mParams.rightMargin = insets.getSystemWindowInsetRight();
|
||||
if (!PreferenceUtil.getInstance().getFullScreenMode()) {
|
||||
mParams.bottomMargin = insets.getSystemWindowInsetBottom();
|
||||
}
|
||||
}
|
||||
|
||||
coordinatorLayout.setOnApplyWindowInsetsListener(null);
|
||||
return insets.consumeSystemWindowInsets();
|
||||
});
|
||||
}
|
||||
|
||||
public SlidingUpPanelLayout.PanelState getPanelState() {
|
||||
return slidingUpPanelLayout == null ? null : slidingUpPanelLayout.getPanelState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPanelSlide(View panel, float slideOffset) {
|
||||
bottomNavigationView.setTranslationY(slideOffset * 400);
|
||||
setMiniPlayerAlphaProgress(slideOffset);
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator.cancel();
|
||||
super.setNavigationbarColor((int) argbEvaluator.evaluate(slideOffset, navigationbarColor, Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPanelStateChanged(View panel, PanelState previousState, PanelState newState) {
|
||||
switch (newState) {
|
||||
case COLLAPSED:
|
||||
onPanelCollapsed(panel);
|
||||
break;
|
||||
case EXPANDED:
|
||||
onPanelExpanded(panel);
|
||||
break;
|
||||
case ANCHORED:
|
||||
collapsePanel(); // this fixes a bug where the panel would get stuck for some reason
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onPanelCollapsed(View panel) {
|
||||
// restore values
|
||||
super.setLightStatusbar(lightStatusbar);
|
||||
super.setTaskDescriptionColor(taskColor);
|
||||
super.setNavigationbarColor(ThemeStore.primaryColor(this));
|
||||
super.setLightNavigationBar(lightNavigationBar);
|
||||
|
||||
playerFragment.setMenuVisibility(false);
|
||||
playerFragment.setUserVisibleHint(false);
|
||||
playerFragment.onHide();
|
||||
}
|
||||
|
||||
public void onPanelExpanded(View panel) {
|
||||
int playerFragmentColor = playerFragment.getPaletteColor();
|
||||
|
||||
super.setTaskDescriptionColor(playerFragmentColor);
|
||||
if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
|
||||
super.setNavigationbarColor(playerFragmentColor);
|
||||
} else {
|
||||
super.setNavigationbarColor(Color.TRANSPARENT);
|
||||
}
|
||||
|
||||
onPaletteColorChanged();
|
||||
playerFragment.setMenuVisibility(true);
|
||||
playerFragment.setUserVisibleHint(true);
|
||||
playerFragment.onShow();
|
||||
|
||||
}
|
||||
|
||||
private void setMiniPlayerAlphaProgress(@FloatRange(from = 0, to = 1) float progress) {
|
||||
if (miniPlayerFragment.getView() == null) return;
|
||||
float alpha = 1 - progress;
|
||||
miniPlayerFragment.getView().setAlpha(alpha);
|
||||
// necessary to make the views below clickable
|
||||
miniPlayerFragment.getView().setVisibility(alpha == 0 ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
private void choosFragmentForTheme() {
|
||||
currentNowPlayingScreen = PreferenceUtil.getInstance().getNowPlayingScreen();
|
||||
|
||||
Fragment fragment; // must implement AbsPlayerFragment
|
||||
switch (currentNowPlayingScreen) {
|
||||
case MATERIAL:
|
||||
fragment = new MaterialFragment();
|
||||
break;
|
||||
case BLUR:
|
||||
fragment = new BlurPlayerFragment();
|
||||
break;
|
||||
case FLAT:
|
||||
fragment = new FlatPlayerFragment();
|
||||
break;
|
||||
case PLAIN:
|
||||
fragment = new PlainPlayerFragment();
|
||||
break;
|
||||
case FULL:
|
||||
fragment = new FullPlayerFragment();
|
||||
break;
|
||||
case COLOR:
|
||||
fragment = new ColorFragment();
|
||||
break;
|
||||
case CARD:
|
||||
fragment = new CardFragment();
|
||||
break;
|
||||
case SIMPLE:
|
||||
fragment = new SimplePlayerFragment();
|
||||
break;
|
||||
case TINY:
|
||||
fragment = new HmmPlayerFragment();
|
||||
break;
|
||||
case BLUR_CARD:
|
||||
fragment = new CardBlurFragment();
|
||||
break;
|
||||
case ADAPTIVE:
|
||||
fragment = new AdaptiveFragment();
|
||||
break;
|
||||
case FIT:
|
||||
fragment = new FitFragment();
|
||||
break;
|
||||
case NORMAL:
|
||||
default:
|
||||
fragment = new PlayerFragment();
|
||||
break;
|
||||
}
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.player_fragment_container, fragment).commit();
|
||||
getSupportFragmentManager().executePendingTransactions();
|
||||
|
||||
playerFragment = (AbsPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.player_fragment_container);
|
||||
miniPlayerFragment = (MiniPlayerFragment) getSupportFragmentManager().findFragmentById(R.id.mini_player_fragment);
|
||||
|
||||
//noinspection ConstantConditions
|
||||
miniPlayerFragment.getView().setOnClickListener(v -> expandPanel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (currentNowPlayingScreen != PreferenceUtil.getInstance().getNowPlayingScreen()) {
|
||||
postRecreate();
|
||||
}
|
||||
}
|
||||
|
||||
public void setAntiDragView(View antiDragView) {
|
||||
//slidingUpPanelLayout.setAntiDragView(antiDragView);
|
||||
}
|
||||
|
||||
public void collapsePanel() {
|
||||
slidingUpPanelLayout.setPanelState(PanelState.COLLAPSED);
|
||||
}
|
||||
|
||||
public void expandPanel() {
|
||||
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaletteColorChanged() {
|
||||
if (getPanelState() == PanelState.EXPANDED) {
|
||||
int paletteColor = playerFragment.getPaletteColor();
|
||||
boolean isColorLight = ColorUtil.isColorLight(paletteColor);
|
||||
super.setTaskDescriptionColor(paletteColor);
|
||||
if ((currentNowPlayingScreen == NowPlayingScreen.FLAT || currentNowPlayingScreen == NowPlayingScreen.NORMAL) && PreferenceUtil.getInstance().getAdaptiveColor()) {
|
||||
super.setLightNavigationBar(true);
|
||||
super.setLightStatusbar(isColorLight);
|
||||
} else if (currentNowPlayingScreen == NowPlayingScreen.COLOR) {
|
||||
super.setLightStatusbar(isColorLight);
|
||||
super.setLightNavigationBar(isColorLight);
|
||||
} else if (currentNowPlayingScreen == NowPlayingScreen.BLUR || currentNowPlayingScreen == NowPlayingScreen.BLUR_CARD) {
|
||||
super.setLightStatusbar(false);
|
||||
} else if (currentNowPlayingScreen == NowPlayingScreen.CARD || currentNowPlayingScreen == NowPlayingScreen.FULL) {
|
||||
super.setNavigationbarColor(Color.TRANSPARENT);
|
||||
super.setLightStatusbar(false);
|
||||
} else if (currentNowPlayingScreen == NowPlayingScreen.FIT) {
|
||||
super.setNavigationbarColor(Color.TRANSPARENT);
|
||||
super.setLightStatusbar(false);
|
||||
} else {
|
||||
boolean isTheme = isOneOfTheseThemes() && ColorUtil.isColorLight(ThemeStore.primaryColor(this));
|
||||
super.setStatusbarColor(Color.TRANSPARENT);
|
||||
super.setLightStatusbar(isTheme);
|
||||
super.setLightNavigationBar(isTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOneOfTheseThemes() {
|
||||
return currentNowPlayingScreen == NowPlayingScreen.FLAT
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.PLAIN
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.SIMPLE
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.NORMAL
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.ADAPTIVE
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.TINY
|
||||
|| currentNowPlayingScreen == NowPlayingScreen.MATERIAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightStatusbar(boolean enabled) {
|
||||
lightStatusbar = enabled;
|
||||
if (getPanelState() == PanelState.COLLAPSED) {
|
||||
super.setLightStatusbar(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightNavigationBar(boolean enabled) {
|
||||
lightNavigationBar = enabled;
|
||||
if (getPanelState() == PanelState.COLLAPSED) {
|
||||
super.setLightNavigationBar(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNavigationbarColor(int color) {
|
||||
this.navigationbarColor = color;
|
||||
if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator.cancel();
|
||||
super.setNavigationbarColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
private void animateNavigationBarColor(int color) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator.cancel();
|
||||
navigationBarColorAnimator = ValueAnimator
|
||||
.ofArgb(getWindow().getNavigationBarColor(), color)
|
||||
.setDuration(ViewUtil.RETRO_MUSIC_ANIM_TIME);
|
||||
navigationBarColorAnimator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
|
||||
navigationBarColorAnimator.addUpdateListener(animation -> AbsSlidingMusicPanelActivity.super.setNavigationbarColor((Integer) animation.getAnimatedValue()));
|
||||
navigationBarColorAnimator.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator.cancel(); // just in case
|
||||
}
|
||||
}
|
|
@ -89,11 +89,7 @@ public abstract class AbsThemeActivity extends ATHActivity implements Runnable {
|
|||
}
|
||||
|
||||
public void setDrawUnderNavigationBar() {
|
||||
if (VersionUtils.hasLollipop()) {
|
||||
RetroUtil.setAllowDrawUnderNavigationBar(getWindow());
|
||||
} else if (VersionUtils.hasKitKat()) {
|
||||
RetroUtil.setStatusBarTranslucent(getWindow());
|
||||
}
|
||||
RetroUtil.setAllowDrawUnderNavigationBar(getWindow());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -174,7 +170,7 @@ public abstract class AbsThemeActivity extends ATHActivity implements Runnable {
|
|||
}
|
||||
|
||||
public void setImmersiveFullscreen() {
|
||||
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
|
|
|
@ -80,7 +80,7 @@ public class MiniPlayerFragment extends AbsMusicServiceFragment implements Music
|
|||
//noinspection ConstantConditions
|
||||
view.setBackgroundColor(ThemeStore.primaryColor(getContext()));
|
||||
view.setOnTouchListener(new FlingPlayBackController(getActivity()));
|
||||
view.setOnClickListener(v -> NavigationUtil.gotoNowPlayingActivity(getContext()));
|
||||
//view.setOnClickListener(v -> NavigationUtil.gotoNowPlayingActivity(getContext()));
|
||||
setUpMiniPlayer();
|
||||
|
||||
if (RetroUtil.isTablet()) {
|
||||
|
|
|
@ -2,24 +2,24 @@ package code.name.monkey.retromusic.ui.fragments;
|
|||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import code.name.monkey.retromusic.R;
|
||||
|
||||
|
||||
public enum NowPlayingScreen {
|
||||
NORMAL(R.string.normal, R.drawable.np_normal, 0),
|
||||
|
||||
ADAPTIVE(R.string.adaptive, R.drawable.np_adaptive, 10),
|
||||
BLUR(R.string.blur, R.drawable.np_blur, 4),
|
||||
CARD(R.string.card, R.drawable.np_card, 6),
|
||||
COLOR(R.string.color, R.drawable.np_color, 5),
|
||||
BLUR_CARD(R.string.blur_card, R.drawable.np_blur_card, 9),
|
||||
FIT(R.string.fit, R.drawable.np_adaptive, 12),
|
||||
FLAT(R.string.flat, R.drawable.np_flat, 1),
|
||||
FULL(R.string.full, R.drawable.np_full, 2),
|
||||
PLAIN(R.string.plain, R.drawable.np_plain, 3),
|
||||
BLUR(R.string.blur, R.drawable.np_blur, 4),
|
||||
COLOR(R.string.color, R.drawable.np_color, 5),
|
||||
CARD(R.string.card, R.drawable.np_card, 6),
|
||||
TINY(R.string.tiny, R.drawable.np_tiny, 7),
|
||||
SIMPLE(R.string.simple, R.drawable.np_simple, 8),
|
||||
BLUR_CARD(R.string.blur_card, R.drawable.np_blur_card, 9),
|
||||
ADAPTIVE(R.string.adaptive, R.drawable.np_adaptive, 10),
|
||||
MATERIAL(R.string.material, R.drawable.np_material, 11),
|
||||
FIT(R.string.fit, R.drawable.np_adaptive, 12);
|
||||
NORMAL(R.string.normal, R.drawable.np_normal, 0),
|
||||
PLAIN(R.string.plain, R.drawable.np_plain, 3),
|
||||
SIMPLE(R.string.simple, R.drawable.np_simple, 8);
|
||||
|
||||
@StringRes
|
||||
public final int titleRes;
|
||||
|
|
|
@ -34,6 +34,7 @@ import code.name.monkey.retromusic.util.MusicUtil;
|
|||
import code.name.monkey.retromusic.util.NavigationUtil;
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||
import code.name.monkey.retromusic.util.RetroUtil;
|
||||
import code.name.monkey.retromusic.util.SystemUtils;
|
||||
import code.name.monkey.retromusic.views.FitSystemWindowsLayout;
|
||||
|
||||
public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implements Toolbar.OnMenuItemClickListener, PaletteColorHolder {
|
||||
|
@ -55,8 +56,11 @@ public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implemen
|
|||
protected void addSafeArea(View view) {
|
||||
FitSystemWindowsLayout safeArea = view.findViewById(R.id.safeArea);
|
||||
if (safeArea != null) {
|
||||
if (PreferenceUtil.getInstance().getFullScreenMode()) safeArea.setFit(false);
|
||||
else safeArea.setFit(true);
|
||||
//ViewGroup.MarginLayoutParams params = ((ViewGroup.MarginLayoutParams) safeArea.getLayoutParams());
|
||||
//params.topMargin = RetroUtil.getStatusBarHeight();
|
||||
//params.bottomMargin = RetroUtil.getNavigationBarHeight();
|
||||
//if (PreferenceUtil.getInstance().getFullScreenMode()) safeArea.setFit(false);
|
||||
//else safeArea.setFit(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,4 +231,5 @@ public abstract class AbsPlayerFragment extends AbsMusicServiceFragment implemen
|
|||
|
||||
void onPaletteColorChanged();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
@BindView(R.id.fragment_container)
|
||||
View contentContainer;
|
||||
|
||||
|
||||
private Unbinder unBinder;
|
||||
private MaterialCab cab;
|
||||
private FragmentManager fragmentManager;
|
||||
|
@ -110,6 +111,7 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
setStatusbarColorAuto(view);
|
||||
setupToolbar();
|
||||
inflateFragment();
|
||||
|
||||
}
|
||||
|
||||
private void inflateFragment() {
|
||||
|
@ -142,13 +144,14 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
TintHelper.setTintAuto(contentContainer, primaryColor, true);
|
||||
|
||||
toolbar.setBackgroundColor(primaryColor);
|
||||
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
|
||||
appbar.setBackgroundColor(primaryColor);
|
||||
appbar.addOnOffsetChangedListener((appBarLayout, verticalOffset) ->
|
||||
getMainActivity().setLightStatusbar(!ATHUtil.isWindowBackgroundDark(getContext())));
|
||||
getMainActivity().setTitle(null);
|
||||
getMainActivity().setSupportActionBar(toolbar);
|
||||
toolbar.setNavigationOnClickListener(v -> showMainMenu());
|
||||
toolbar.setNavigationOnClickListener(v -> NavigationUtil.goToSearch(getMainActivity()));
|
||||
toolbar.setOnClickListener(v -> showMainMenu());
|
||||
toolbar.setNavigationIcon(RetroUtil.getTintedDrawable(getMainActivity(), R.drawable.ic_search_white_24dp, ThemeStore.textColorPrimary(getMainActivity())));
|
||||
}
|
||||
|
||||
private Fragment getCurrentFragment() {
|
||||
|
@ -363,9 +366,6 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde
|
|||
MusicPlayerRemote.openAndShuffleQueue(SongLoader.getAllSongs(getContext())
|
||||
.blockingFirst(), true);
|
||||
return true;
|
||||
case R.id.action_search:
|
||||
NavigationUtil.goToSearch(getMainActivity());
|
||||
break;
|
||||
case R.id.action_equalizer:
|
||||
NavigationUtil.openEqualizer(getActivity());
|
||||
return true;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package code.name.monkey.retromusic.ui.fragments.mainactivity.home;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
|
@ -11,12 +10,9 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -35,7 +31,6 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import butterknife.Unbinder;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil;
|
||||
import code.name.monkey.appthemehelper.util.TintHelper;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
|
||||
|
@ -75,9 +70,9 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@BindView(R.id.app_bar)
|
||||
/*@BindView(R.id.app_bar)
|
||||
AppBarLayout appbar;
|
||||
|
||||
*/
|
||||
@BindView(R.id.image)
|
||||
@Nullable
|
||||
ImageView imageView;
|
||||
|
@ -85,8 +80,8 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
@BindView(R.id.user_image)
|
||||
CircularImageView userImage;
|
||||
|
||||
@BindView(R.id.collapsing_toolbar)
|
||||
CollapsingToolbarLayout toolbarLayout;
|
||||
/* @BindView(R.id.collapsing_toolbar)
|
||||
CollapsingToolbarLayout toolbarLayout;*/
|
||||
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recentArtistRV;
|
||||
|
@ -121,18 +116,12 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
@BindView(R.id.container)
|
||||
View container;
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
|
||||
@BindView(R.id.suggestion_songs)
|
||||
RecyclerView suggestionsSongs;
|
||||
|
||||
@BindView(R.id.suggestion_container)
|
||||
LinearLayout suggestionsContainer;
|
||||
|
||||
@BindView(R.id.search_icon)
|
||||
ImageView searchIcon;
|
||||
|
||||
private Unbinder unbinder;
|
||||
private HomePresenter homePresenter;
|
||||
private CompositeDisposable disposable;
|
||||
|
@ -241,18 +230,13 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
private void setupToolbar() {
|
||||
int primaryColor = ThemeStore.primaryColor(getContext());
|
||||
TintHelper.setTintAuto(container, primaryColor, true);
|
||||
|
||||
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
|
||||
toolbar.setBackgroundColor(primaryColor);
|
||||
appbar.setBackgroundColor(primaryColor);
|
||||
appbar.addOnOffsetChangedListener((appBarLayout, verticalOffset) ->
|
||||
getMainActivity().setLightStatusbar(!ATHUtil.isWindowBackgroundDark(getContext())));
|
||||
userImage.setOnClickListener(v -> showMainMenu());
|
||||
|
||||
getActivity().setTitle(null);
|
||||
getMainActivity().setSupportActionBar(toolbar);
|
||||
toolbar.setNavigationIcon(RetroUtil.getTintedDrawable(getMainActivity(), R.drawable.ic_menu_white_24dp, ThemeStore.textColorPrimary(getMainActivity())));
|
||||
toolbar.setOnClickListener(v -> NavigationUtil.goToSearch(getMainActivity()));
|
||||
toolbar.setNavigationOnClickListener(v -> showMainMenu());
|
||||
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||
searchIcon.setImageTintList(ColorStateList.valueOf(ThemeStore.accentColor(getContext())));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -346,7 +330,6 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
Display display = getMainActivity().getWindowManager().getDefaultDisplay();
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
display.getMetrics(metrics);
|
||||
|
||||
return metrics;
|
||||
}
|
||||
|
||||
|
@ -360,7 +343,7 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
}
|
||||
|
||||
@OnClick({R.id.last_added, R.id.top_played, R.id.action_shuffle, R.id.history,
|
||||
R.id.user_image, R.id.search})
|
||||
R.id.user_image})
|
||||
void startUserInfo(View view) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
|
@ -380,12 +363,7 @@ public class BannerHomeFragment extends AbsMainActivityFragment implements MainA
|
|||
case R.id.user_image:
|
||||
NavigationUtil.goToUserInfo(getActivity());
|
||||
break;
|
||||
case R.id.search:
|
||||
NavigationUtil.goToSearch(activity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -107,11 +107,6 @@ public class AdaptiveFragment extends AbsPlayerFragment implements Callbacks {
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_adaptive_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColorAuto();
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -162,5 +157,4 @@ public class AdaptiveFragment extends AbsPlayerFragment implements Callbacks {
|
|||
updateIsFavorite();
|
||||
updateSong();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -140,11 +140,6 @@ public class BlurPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_blur, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColor(Color.TRANSPARENT);
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,12 +160,7 @@ public class CardFragment extends AbsPlayerFragment implements PlayerAlbumCoverF
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_card_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColor(Color.TRANSPARENT);
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -122,11 +122,6 @@ public class CardBlurFragment extends AbsPlayerFragment implements
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_card_blur_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColor(Color.TRANSPARENT);
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.animation.ValueAnimator;
|
|||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -136,10 +135,6 @@ public class ColorFragment extends AbsPlayerFragment {
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_color_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,11 +88,7 @@ public class FlatPlayerFragment extends AbsPlayerFragment implements
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_flat_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
//getPlayerActivity().setNavigationbarColorAuto();
|
||||
addSafeArea(view);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class FullPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
@BindView(R.id.player_toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
Unbinder unbinder;
|
||||
private Unbinder unbinder;
|
||||
|
||||
private int lastColor;
|
||||
private FullPlaybackControlsFragment fullPlaybackControlsFragment;
|
||||
|
@ -42,11 +42,7 @@ public class FullPlayerFragment extends AbsPlayerFragment implements PlayerAlbum
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_full, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColor(Color.TRANSPARENT);
|
||||
addSafeArea(view);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,11 +99,7 @@ public class HmmPlayerFragment extends AbsPlayerFragment implements
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_hmm_player, container, false);
|
||||
unBinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColor(Color.TRANSPARENT);
|
||||
addSafeArea(view);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -108,11 +108,6 @@ public class MaterialFragment extends AbsPlayerFragment implements PlayerAlbumCo
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_material, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColorAuto();
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil;
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil;
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote;
|
||||
|
@ -136,10 +135,7 @@ public class PlayerFragment extends AbsPlayerFragment implements PlayerAlbumCove
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
addSafeArea(view);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -75,11 +75,7 @@ public class PlainPlayerFragment extends AbsPlayerFragment implements
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_plain_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColorAuto();
|
||||
addSafeArea(view);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,11 +46,6 @@ public class SimplePlayerFragment extends AbsPlayerFragment implements
|
|||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_simple_player, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
if (getPlayerActivity() != null) {
|
||||
getPlayerActivity().setDrawUnderNavigationBar();
|
||||
getPlayerActivity().setNavigationbarColorAuto();
|
||||
addSafeArea(view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
|
@ -695,41 +695,6 @@ public final class PreferenceUtil {
|
|||
mPreferences.edit().putBoolean(CIRCULAR_ALBUM_ART, false).apply();
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getAlbumGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(mPreferences.getString(ALBUM_GRID_STYLE, "0"));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_card;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getHomeGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(mPreferences.getString(HOME_ARTIST_GRID_STYLE, "0"));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_home_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_artist;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
|
||||
public int getArtistGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(Objects.requireNonNull(mPreferences.getString(ARTIST_GRID_STYLE, "0")));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_card;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
public String getAlbumDetailsStyle() {
|
||||
return mPreferences.getString(ALBUM_DETAIL_STYLE, "0");
|
||||
|
@ -805,4 +770,41 @@ public final class PreferenceUtil {
|
|||
return LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED;
|
||||
}
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getHomeGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(mPreferences.getString(HOME_ARTIST_GRID_STYLE, "0"));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_home_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_artist;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getArtistGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(Objects.requireNonNull(mPreferences.getString(ARTIST_GRID_STYLE, "0")));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_card;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
public int getAlbumGridStyle(Context context) {
|
||||
int pos = Integer.parseInt(mPreferences.getString(ALBUM_GRID_STYLE, "0"));
|
||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_grid_style_layout);
|
||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||
typedArray.recycle();
|
||||
if (layoutRes == -1) {
|
||||
return R.layout.item_card;
|
||||
}
|
||||
return layoutRes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,10 @@ import android.provider.BaseColumns;
|
|||
import android.provider.MediaStore;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewConfiguration;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
|
@ -49,6 +51,7 @@ import code.name.monkey.retromusic.RetroApplication;
|
|||
public class RetroUtil {
|
||||
|
||||
private static final int[] TEMP_ARRAY = new int[1];
|
||||
private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";
|
||||
|
||||
public static int calculateNoOfColumns(Context context) {
|
||||
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
|
||||
|
@ -88,21 +91,18 @@ public class RetroUtil {
|
|||
return RetroApplication.getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
public static boolean isRTL(@NonNull Context context) {
|
||||
Configuration config = context.getResources().getConfiguration();
|
||||
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||
}
|
||||
|
||||
|
||||
@TargetApi(19)
|
||||
public static void setStatusBarTranslucent(@NonNull Window window) {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isMarshMellow() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
|
||||
}
|
||||
|
@ -131,7 +131,6 @@ public class RetroUtil {
|
|||
return px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
public static void openUrl(Activity context, String str) {
|
||||
Intent intent = new Intent("android.intent.action.VIEW");
|
||||
intent.setData(Uri.parse(str));
|
||||
|
@ -151,7 +150,6 @@ public class RetroUtil {
|
|||
return size;
|
||||
}
|
||||
|
||||
|
||||
public static void hideSoftKeyboard(@Nullable Activity activity) {
|
||||
if (activity != null) {
|
||||
View currentFocus = activity.getCurrentFocus();
|
||||
|
@ -179,7 +177,6 @@ public class RetroUtil {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static Drawable getVectorDrawable(@NonNull Resources res, @DrawableRes int resId,
|
||||
@Nullable Resources.Theme theme) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
|
@ -295,28 +292,18 @@ public class RetroUtil {
|
|||
}
|
||||
|
||||
public static void statusBarHeight(View statusBar) {
|
||||
statusBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(statusBar.getContext())));
|
||||
statusBar.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
|
||||
}
|
||||
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
public static int getStatusBarHeight() {
|
||||
int result = 0;
|
||||
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
int resourceId = RetroApplication.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = context.getResources().getDimensionPixelSize(resourceId);
|
||||
result = RetroApplication.getContext().getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int getNavigationBarHeight(Context context) {
|
||||
int result = 0;
|
||||
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = context.getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void setAllowDrawUnderNavigationBar(Window window) {
|
||||
window.setNavigationBarColor(Color.TRANSPARENT);
|
||||
window.getDecorView().setSystemUiVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ?
|
||||
|
@ -348,7 +335,59 @@ public class RetroUtil {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static boolean hasNavBar(Resources resources) {
|
||||
public static int getNavigationBarHeight(Activity activity) {
|
||||
/* int result = 0;
|
||||
int resourceId = RetroApplication.getContext().getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = RetroApplication.getContext().getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;*/
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
int usableHeight = metrics.heightPixels;
|
||||
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||
int realHeight = metrics.heightPixels;
|
||||
if (realHeight > usableHeight)
|
||||
if (PreferenceUtil.getInstance().getFullScreenMode()) {
|
||||
return 0;
|
||||
} else
|
||||
return realHeight - usableHeight;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getNavBarHeight(Context c) {
|
||||
int result = 0;
|
||||
boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();
|
||||
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
|
||||
|
||||
if (!hasMenuKey && !hasBackKey) {
|
||||
//The device has a navigation bar
|
||||
Resources resources = c.getResources();
|
||||
|
||||
int orientation = resources.getConfiguration().orientation;
|
||||
int resourceId;
|
||||
if (isTablet(c)) {
|
||||
resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
|
||||
} else {
|
||||
resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android");
|
||||
}
|
||||
|
||||
if (resourceId > 0) {
|
||||
return resources.getDimensionPixelSize(resourceId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isTablet(Context c) {
|
||||
return (c.getResources().getConfiguration().screenLayout
|
||||
& Configuration.SCREENLAYOUT_SIZE_MASK)
|
||||
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
|
||||
}
|
||||
|
||||
private static boolean hasNavBar(Resources resources) {
|
||||
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
|
||||
if (id > 0)
|
||||
return resources.getBoolean(id);
|
||||
|
@ -375,33 +414,17 @@ public class RetroUtil {
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static int getNavigationBarWidth(Resources resources) {
|
||||
if (!hasNavBar(resources))
|
||||
return 0;
|
||||
|
||||
public static boolean checkNavigationBarHeight() {
|
||||
Resources resources = RetroApplication.getContext().getResources();
|
||||
int orientation = resources.getConfiguration().orientation;
|
||||
|
||||
//Only phone between 0-599 has navigationbar can move
|
||||
boolean isSmartphone = resources.getConfiguration().smallestScreenWidthDp < 600;
|
||||
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE && isSmartphone) {
|
||||
int id = resources.getIdentifier("navigation_bar_width", "dimen", "android");
|
||||
if (id > 0)
|
||||
return resources.getDimensionPixelSize(id);
|
||||
if (!hasNavBar(resources)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static boolean isNavigationBarLeftSide() {
|
||||
Display display = ((WindowManager) RetroApplication.getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
int screenOrientation = display.getRotation();
|
||||
return screenOrientation == Surface.ROTATION_180;
|
||||
}
|
||||
|
||||
public static boolean isNavigationBarRightSide() {
|
||||
Display display = ((WindowManager) RetroApplication.getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
int screenOrientation = display.getRotation();
|
||||
return screenOrientation == Surface.ROTATION_90;
|
||||
boolean isSmartPhone = resources.getConfiguration().smallestScreenWidthDp < 600;
|
||||
if (isSmartPhone && Configuration.ORIENTATION_LANDSCAPE == orientation)
|
||||
return false;
|
||||
int id = resources
|
||||
.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");
|
||||
return id > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package code.name.monkey.retromusic.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import code.name.monkey.retromusic.RetroApplication;
|
||||
|
||||
public class SystemUtils {
|
||||
|
||||
private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height";
|
||||
private static final String NAV_BAR_HEIGHT_RES_NAME = "navigation_bar_height";
|
||||
private static final String NAV_BAR_HEIGHT_LANDSCAPE_RES_NAME = "navigation_bar_height_landscape";
|
||||
private static final String NAV_BAR_WIDTH_RES_NAME = "navigation_bar_width";
|
||||
private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";
|
||||
private final float mSmallestWidthDp;
|
||||
private final boolean mInPortrait;
|
||||
|
||||
private Activity activity;
|
||||
|
||||
public SystemUtils(Activity activity) {
|
||||
this.activity = activity;
|
||||
Resources resources = activity.getResources();
|
||||
mSmallestWidthDp = getSmallestWidthDp(activity);
|
||||
mInPortrait = (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
|
||||
}
|
||||
|
||||
private static boolean hasNavBar(Resources resources) {
|
||||
int id = resources.getIdentifier(SHOW_NAV_BAR_RES_NAME, "bool", "android");
|
||||
if (id > 0)
|
||||
return resources.getBoolean(id);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int getNavigationBarHeight() {
|
||||
int result = 0;
|
||||
int resourceId = RetroApplication.getContext().getResources().getIdentifier("navigation_bar_height", "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = RetroApplication.getContext().getResources().getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getComboHeight() {
|
||||
if (isNavigationAtBottom()) {
|
||||
return getNavigationBarWidth();
|
||||
} else {
|
||||
return getNavigationBarHeight();
|
||||
}
|
||||
}
|
||||
|
||||
public int getNavigationBarWidth() {
|
||||
Resources res = activity.getResources();
|
||||
int result = 0;
|
||||
if (hasNavBar(activity.getResources())) {
|
||||
if (!isNavigationAtBottom())
|
||||
return getInternalDimensionSize(res, NAV_BAR_WIDTH_RES_NAME);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addPadding(ViewGroup viewGroup) {
|
||||
Context context = viewGroup.getContext();
|
||||
Resources resources = context.getResources();
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams();
|
||||
if (isNavigationAtBottom()) {
|
||||
params.leftMargin = getNavigationBarWidth();
|
||||
params.rightMargin = getNavigationBarWidth();
|
||||
} else {
|
||||
params.bottomMargin = getNavigationBarHeight();
|
||||
}
|
||||
}
|
||||
|
||||
private int getInternalDimensionSize(Resources res, String key) {
|
||||
int result = 0;
|
||||
int resourceId = res.getIdentifier(key, "dimen", "android");
|
||||
if (resourceId > 0) {
|
||||
result = res.getDimensionPixelSize(resourceId);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private float getSmallestWidthDp(Activity activity) {
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
|
||||
float widthDp = metrics.widthPixels / metrics.density;
|
||||
float heightDp = metrics.heightPixels / metrics.density;
|
||||
return Math.min(widthDp, heightDp);
|
||||
}
|
||||
|
||||
boolean isNavigationAtBottom() {
|
||||
return (mSmallestWidthDp >= 600 || mInPortrait);
|
||||
}
|
||||
|
||||
}
|
|
@ -33,12 +33,7 @@ public class FitSystemWindowsLayout extends FrameLayout {
|
|||
}
|
||||
|
||||
mFit = fit;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
|
||||
requestApplyInsets();
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
requestFitSystemWindows();
|
||||
}
|
||||
requestApplyInsets();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
|
|
@ -92,7 +92,7 @@ public class MetalRecyclerViewPager extends RecyclerView {
|
|||
if (RetroUtil.isTablet()) {
|
||||
itemWidth = (metrics.widthPixels / 2) - itemMargin * 3;
|
||||
} else {
|
||||
itemWidth = metrics.widthPixels - itemMargin * 2;
|
||||
itemWidth = metrics.widthPixels - itemMargin ;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package code.name.monkey.retromusic.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.WindowInsets;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
public class StatusBarMarginFrameLayout extends FrameLayout {
|
||||
|
||||
|
||||
public StatusBarMarginFrameLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public StatusBarMarginFrameLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public StatusBarMarginFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
|
||||
lp.topMargin = insets.getSystemWindowInsetTop();
|
||||
setLayoutParams(lp);
|
||||
}
|
||||
return super.onApplyWindowInsets(insets);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Mantou Earth - Live your wallpaper with live earth
|
||||
* Copyright (C) 2015 XiNGRZ <xxx@oxo.ooo>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package code.name.monkey.retromusic.views;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
public class WindowInsetsFrameLayout extends FrameLayout {
|
||||
|
||||
private static final String TAG = "WindowInsetsFrameLayout";
|
||||
|
||||
public WindowInsetsFrameLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public WindowInsetsFrameLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public WindowInsetsFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this, (v, insets) ->
|
||||
applySystemWindowInsets21(insets) ? insets.consumeSystemWindowInsets() : insets);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected boolean fitSystemWindows(Rect insets) {
|
||||
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
|
||||
return applySystemWindowInsets19(insets);
|
||||
}
|
||||
|
||||
return super.fitSystemWindows(insets);
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
private boolean applySystemWindowInsets19(Rect insets) {
|
||||
boolean consumed = false;
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
|
||||
if (!child.getFitsSystemWindows()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Rect childInsets = new Rect(insets);
|
||||
|
||||
computeInsetsWithGravity(child, childInsets);
|
||||
|
||||
child.setPadding(childInsets.left, childInsets.top, childInsets.right, childInsets.bottom);
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
private boolean applySystemWindowInsets21(WindowInsetsCompat insets) {
|
||||
boolean consumed = false;
|
||||
|
||||
for (int i = 0; i < getChildCount(); i++) {
|
||||
View child = getChildAt(i);
|
||||
|
||||
if (!child.getFitsSystemWindows()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Rect childInsets = new Rect(
|
||||
insets.getSystemWindowInsetLeft(),
|
||||
insets.getSystemWindowInsetTop(),
|
||||
insets.getSystemWindowInsetRight(),
|
||||
insets.getSystemWindowInsetBottom());
|
||||
|
||||
computeInsetsWithGravity(child, childInsets);
|
||||
|
||||
ViewCompat.dispatchApplyWindowInsets(child, insets.replaceSystemWindowInsets(childInsets));
|
||||
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
private void computeInsetsWithGravity(View view, Rect insets) {
|
||||
LayoutParams lp = (LayoutParams) view.getLayoutParams();
|
||||
|
||||
int gravity = GravityCompat.getAbsoluteGravity(
|
||||
lp.gravity, ViewCompat.getLayoutDirection(view));
|
||||
|
||||
if (lp.width != LayoutParams.MATCH_PARENT) {
|
||||
if ((gravity & Gravity.LEFT) != Gravity.LEFT) {
|
||||
insets.left = 0;
|
||||
}
|
||||
|
||||
if ((gravity & Gravity.RIGHT) != Gravity.RIGHT) {
|
||||
insets.right = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (lp.height != LayoutParams.MATCH_PARENT) {
|
||||
if ((gravity & Gravity.TOP) != Gravity.TOP) {
|
||||
insets.top = 0;
|
||||
}
|
||||
|
||||
if ((gravity & Gravity.BOTTOM) != Gravity.BOTTOM) {
|
||||
insets.bottom = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue