Search in sources :

Example 1 with SlidingUpPanelLayout

use of com.sothree.slidinguppanel.SlidingUpPanelLayout in project Shuttle by timusus.

the class MainActivity method onCreate.

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    if (!ShuttleUtils.isUpgraded() && !ShuttleUtils.isAmazonBuild()) {
        IabManager.getInstance();
    }
    ThemeUtils.setTheme(this);
    if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setFlags(FLAG_TRANSLUCENT_STATUS, FLAG_TRANSLUCENT_STATUS);
        mTintManager = new SystemBarTintManager(this);
    }
    if (ShuttleUtils.hasLollipop()) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    if (SettingsManager.getInstance().canTintNavBar()) {
        getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
    }
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    // Now call super to ensure the theme was properly set
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mIsSlidingEnabled = getResources().getBoolean(R.bool.isSlidingEnabled);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mDummyStatusBar = (FrameLayout) findViewById(R.id.dummyStatusBar);
    if (ShuttleUtils.hasKitKat()) {
        mDummyStatusBar.setVisibility(View.VISIBLE);
        mDummyStatusBar.setBackgroundColor(ColorUtils.getPrimaryColorDark(this));
        LinearLayout.LayoutParams statusBarParams = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, (int) ActionBarUtils.getStatusBarHeight(this));
        mDummyStatusBar.setLayoutParams(statusBarParams);
    }
    setSupportActionBar(mToolbar);
    ThemeUtils.themeStatusBar(this, mTintManager);
    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getString(R.string.library_title);
    mDrawerLayout = (CustomDrawerLayout) findViewById(R.id.drawer_layout);
    if (ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
        getWindow().setStatusBarColor(Color.TRANSPARENT);
    }
    mDrawerLayout.setStatusBarBackgroundColor(ShuttleUtils.hasLollipop() ? ColorUtils.getPrimaryColorDark(this) : ColorUtils.getPrimaryColor());
    mNavigationDrawerFragment.setup((DrawerLayout) findViewById(R.id.drawer_layout));
    if (mIsSlidingEnabled) {
        mSlidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.container);
        setDragView(null, false);
        //The second panel slide offset is mini player height + toolbar height + status bar height.
        //This gets our 'up next' sitting snugly underneath the toolbar
        int offset = (int) (ActionBarUtils.getActionBarHeight(this) + (ShuttleUtils.hasKitKat() ? ActionBarUtils.getStatusBarHeight(this) : 0) - getResources().getDimension(R.dimen.mini_player_height));
        mSlidingUpPanelLayout.setSlidePanelOffset(-offset);
        mSlidingUpPanelLayout.hidePanel();
        mSlidingUpPanelLayout.addPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {

            @Override
            public void onPanelSlide(View panel, float slideOffset) {
                setActionBarAlpha(slideOffset, false);
                boolean canChangeElevation = true;
                Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
                if (playingFragment != null) {
                    Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
                    if (childFragment != null && childFragment instanceof QueueFragment) {
                        canChangeElevation = false;
                    }
                }
                if (canChangeElevation) {
                    getSupportActionBar().setElevation(ResourceUtils.toPixels(4) * slideOffset);
                }
                mNavigationDrawerFragment.animateDrawerToggle(slideOffset);
            }

            @Override
            public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) {
                switch(newState) {
                    case COLLAPSED:
                        {
                            setDragView(null, false);
                            mTitle = getString(R.string.library_title);
                            supportInvalidateOptionsMenu();
                            toggleQueue(false);
                            mNavigationDrawerFragment.toggleDrawerLock(false);
                            break;
                        }
                    case EXPANDED:
                        {
                            Fragment playerFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
                            if (playerFragment != null && playerFragment instanceof PlayerFragment) {
                                setDragView(((PlayerFragment) playerFragment).getDragView(), true);
                                if (((PlayerFragment) playerFragment).isQueueShowing()) {
                                    toggleQueue(true);
                                }
                            }
                            mTitle = getString(R.string.nowplaying_title);
                            supportInvalidateOptionsMenu();
                            mNavigationDrawerFragment.toggleDrawerLock(true);
                            break;
                        }
                }
            }
        });
    }
    if (savedInstanceState != null && mIsSlidingEnabled) {
        if (savedInstanceState.getBoolean(ARG_EXPANDED, false)) {
            final ActionBar actionBar = getSupportActionBar();
            //If the sliding panel was previously expanded, expand it again.
            mSlidingUpPanelLayout.post(() -> {
                mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED, false);
                setActionBarAlpha(1f, false);
            });
            mTitle = getString(R.string.nowplaying_title);
            if (actionBar != null) {
                actionBar.setTitle(mTitle);
            }
            Fragment playingFragment = getSupportFragmentManager().findFragmentById(R.id.player_container);
            if (playingFragment != null) {
                Fragment childFragment = playingFragment.getChildFragmentManager().findFragmentById(R.id.queue_container);
                if (childFragment != null && childFragment instanceof QueueFragment) {
                    toggleQueue(true);
                }
            }
        }
    }
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.main_container, MainFragment.newInstance()).commit();
        getSupportFragmentManager().beginTransaction().add(R.id.mini_player_container, MiniPlayerFragment.newInstance()).commit();
        if (mIsSlidingEnabled) {
            getSupportFragmentManager().beginTransaction().add(R.id.player_container, PlayerFragment.newInstance()).commit();
        }
    }
    themeTaskDescription();
    handleIntent(getIntent());
}
Also used : SlidingUpPanelLayout(com.sothree.slidinguppanel.SlidingUpPanelLayout) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) View(android.view.View) FolderFragment(com.simplecity.amp_library.ui.fragments.FolderFragment) Fragment(android.support.v4.app.Fragment) QueuePagerFragment(com.simplecity.amp_library.ui.fragments.QueuePagerFragment) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) QueueFragment(com.simplecity.amp_library.ui.fragments.QueueFragment) AlbumArtistFragment(com.simplecity.amp_library.ui.fragments.AlbumArtistFragment) NavigationDrawerFragment(com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment) PlaylistFragment(com.simplecity.amp_library.ui.fragments.PlaylistFragment) GenreFragment(com.simplecity.amp_library.ui.fragments.GenreFragment) DetailFragment(com.simplecity.amp_library.ui.fragments.DetailFragment) SuggestedFragment(com.simplecity.amp_library.ui.fragments.SuggestedFragment) MainFragment(com.simplecity.amp_library.ui.fragments.MainFragment) AlbumFragment(com.simplecity.amp_library.ui.fragments.AlbumFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) SuppressLint(android.annotation.SuppressLint) LinearLayout(android.widget.LinearLayout) ActionBar(android.support.v7.app.ActionBar) PlayerFragment(com.simplecity.amp_library.ui.fragments.PlayerFragment) MiniPlayerFragment(com.simplecity.amp_library.ui.fragments.MiniPlayerFragment) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Fragment (android.support.v4.app.Fragment)1 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 LinearLayout (android.widget.LinearLayout)1 SystemBarTintManager (com.readystatesoftware.systembartint.SystemBarTintManager)1 AlbumArtistFragment (com.simplecity.amp_library.ui.fragments.AlbumArtistFragment)1 AlbumFragment (com.simplecity.amp_library.ui.fragments.AlbumFragment)1 DetailFragment (com.simplecity.amp_library.ui.fragments.DetailFragment)1 FolderFragment (com.simplecity.amp_library.ui.fragments.FolderFragment)1 GenreFragment (com.simplecity.amp_library.ui.fragments.GenreFragment)1 MainFragment (com.simplecity.amp_library.ui.fragments.MainFragment)1 MiniPlayerFragment (com.simplecity.amp_library.ui.fragments.MiniPlayerFragment)1 NavigationDrawerFragment (com.simplecity.amp_library.ui.fragments.NavigationDrawerFragment)1 PlayerFragment (com.simplecity.amp_library.ui.fragments.PlayerFragment)1 PlaylistFragment (com.simplecity.amp_library.ui.fragments.PlaylistFragment)1 QueueFragment (com.simplecity.amp_library.ui.fragments.QueueFragment)1 QueuePagerFragment (com.simplecity.amp_library.ui.fragments.QueuePagerFragment)1 SuggestedFragment (com.simplecity.amp_library.ui.fragments.SuggestedFragment)1 SlidingUpPanelLayout (com.sothree.slidinguppanel.SlidingUpPanelLayout)1