mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
migrating SlidingMenu to DrawerLayout
This commit is contained in:
parent
0bf7f466a5
commit
218357daf9
@ -158,7 +158,6 @@ public interface TwidereConstants extends SharedPreferenceConstants, IntentConst
|
||||
int REQUEST_PICK_ACTIVITY = 18;
|
||||
int REQUEST_SETTINGS = 19;
|
||||
int REQUEST_OPEN_DOCUMENT = 20;
|
||||
int REQUEST_SWIPEBACK_ACTIVITY = 101;
|
||||
|
||||
int TABLE_ID_ACCOUNTS = 1;
|
||||
int TABLE_ID_STATUSES = 12;
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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 android.support.v4.widget;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/7/18.
|
||||
*/
|
||||
public class DrawerLayoutTrojan {
|
||||
|
||||
public static View findDrawerWithGravity(DrawerLayout layout, int gravity) {
|
||||
return layout.findDrawerWithGravity(gravity);
|
||||
}
|
||||
|
||||
}
|
@ -44,6 +44,7 @@ import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v4.widget.DrawerLayoutTrojan;
|
||||
import android.support.v7.app.ThemedAppCompatDelegateFactory;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Gravity;
|
||||
@ -152,7 +153,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
private View mActionsButton;
|
||||
private View mActionBarWithOverlay;
|
||||
private FrameLayout mLeftDrawerContainer;
|
||||
private TintedStatusFrameLayout mColorStatusFrameLayout;
|
||||
private TintedStatusFrameLayout mHomeContent;
|
||||
|
||||
private UpdateUnreadCountTask mUpdateUnreadCountTask;
|
||||
|
||||
@ -169,8 +170,8 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
private View mActionBarContainer;
|
||||
|
||||
public void closeAccountsDrawer() {
|
||||
// if (mSlidingMenu == null) return;
|
||||
// mSlidingMenu.showContent();
|
||||
if (mDrawerLayout == null) return;
|
||||
mDrawerLayout.closeDrawers();
|
||||
}
|
||||
|
||||
public long[] getActivatedAccountIds() {
|
||||
@ -222,14 +223,13 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
case android.R.id.home: {
|
||||
final FragmentManager fm = getSupportFragmentManager();
|
||||
final int count = fm.getBackStackEntryCount();
|
||||
|
||||
// if (mSlidingMenu.isMenuShowing()) {
|
||||
// mSlidingMenu.showContent();
|
||||
// return true;
|
||||
// } else if (count == 0) {
|
||||
// mSlidingMenu.showMenu();
|
||||
// return true;
|
||||
// }
|
||||
if (mDrawerLayout.isDrawerOpen(GravityCompat.START) || mDrawerLayout.isDrawerOpen(GravityCompat.END)) {
|
||||
mDrawerLayout.closeDrawers();
|
||||
return true;
|
||||
} else if (count == 0) {
|
||||
mDrawerLayout.openDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case R.id.search: {
|
||||
@ -251,12 +251,12 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
if (action != null) {
|
||||
switch (action) {
|
||||
case ACTION_HOME_ACCOUNTS_DASHBOARD: {
|
||||
// if (mSlidingMenu.isMenuShowing()) {
|
||||
// mSlidingMenu.showContent(true);
|
||||
// } else {
|
||||
// mSlidingMenu.showMenu(true);
|
||||
// setControlBarVisibleAnimate(true);
|
||||
// }
|
||||
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
mDrawerLayout.closeDrawers();
|
||||
} else {
|
||||
mDrawerLayout.openDrawer(GravityCompat.START);
|
||||
setControlBarVisibleAnimate(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -265,33 +265,31 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
if (action != null) {
|
||||
switch (action) {
|
||||
case ACTION_NAVIGATION_PREVIOUS_TAB: {
|
||||
// final int previous = mViewPager.getCurrentItem() - 1;
|
||||
// final int mode = mSlidingMenu.getMode();
|
||||
// if (previous < 0 && (mode == SlidingMenu.LEFT || mode == SlidingMenu.LEFT_RIGHT)) {
|
||||
// mSlidingMenu.showMenu(true);
|
||||
// setControlBarVisibleAnimate(true);
|
||||
// } else if (previous < mPagerAdapter.getCount()) {
|
||||
// if (mSlidingMenu.isSecondaryMenuShowing()) {
|
||||
// mSlidingMenu.showContent(true);
|
||||
// } else {
|
||||
// mViewPager.setCurrentItem(previous, true);
|
||||
// }
|
||||
// }
|
||||
final int previous = mViewPager.getCurrentItem() - 1;
|
||||
if (previous < 0 && DrawerLayoutTrojan.findDrawerWithGravity(mDrawerLayout, Gravity.START) != null) {
|
||||
mDrawerLayout.openDrawer(GravityCompat.START);
|
||||
setControlBarVisibleAnimate(true);
|
||||
} else if (previous < mPagerAdapter.getCount()) {
|
||||
if (mDrawerLayout.isDrawerOpen(GravityCompat.END)) {
|
||||
mDrawerLayout.closeDrawers();
|
||||
} else {
|
||||
mViewPager.setCurrentItem(previous, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case ACTION_NAVIGATION_NEXT_TAB: {
|
||||
// final int next = mViewPager.getCurrentItem() + 1;
|
||||
// final int mode = mSlidingMenu.getMode();
|
||||
// if (next >= mPagerAdapter.getCount() && (mode == SlidingMenu.RIGHT || mode == SlidingMenu.LEFT_RIGHT)) {
|
||||
// mSlidingMenu.showSecondaryMenu(true);
|
||||
// setControlBarVisibleAnimate(true);
|
||||
// } else if (next >= 0) {
|
||||
// if (mSlidingMenu.isMenuShowing()) {
|
||||
// mSlidingMenu.showContent(true);
|
||||
// } else {
|
||||
// mViewPager.setCurrentItem(next, true);
|
||||
// }
|
||||
// }
|
||||
final int next = mViewPager.getCurrentItem() + 1;
|
||||
if (next >= mPagerAdapter.getCount() && DrawerLayoutTrojan.findDrawerWithGravity(mDrawerLayout, Gravity.END) != null) {
|
||||
mDrawerLayout.openDrawer(GravityCompat.END);
|
||||
setControlBarVisibleAnimate(true);
|
||||
} else if (next >= 0) {
|
||||
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
mDrawerLayout.closeDrawers();
|
||||
} else {
|
||||
mViewPager.setCurrentItem(next, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -361,7 +359,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
|
||||
mTabColumns = getResources().getInteger(R.integer.default_tab_columns);
|
||||
|
||||
mColorStatusFrameLayout.setOnFitSystemWindowsListener(this);
|
||||
mHomeContent.setOnFitSystemWindowsListener(this);
|
||||
mPagerAdapter = new SupportTabsAdapter(this, getSupportFragmentManager(), mTabIndicator, mTabColumns);
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
// mViewPager.setOffscreenPageLimit(3);
|
||||
@ -403,10 +401,14 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
// Steal MENU key event
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_MENU: {
|
||||
// if (mSlidingMenu != null) {
|
||||
// mSlidingMenu.toggle(true);
|
||||
// return true;
|
||||
// }
|
||||
if (mDrawerLayout != null) {
|
||||
if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
|
||||
mDrawerLayout.closeDrawers();
|
||||
} else {
|
||||
mDrawerLayout.openDrawer(GravityCompat.START);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -552,16 +554,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
setControlBarVisibleAnimate(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(final boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
// if (mSlidingMenu != null && mSlidingMenu.isMenuShowing()) {
|
||||
// updateDrawerPercentOpen(1, false);
|
||||
// } else {
|
||||
// updateDrawerPercentOpen(0, false);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSearchRequested() {
|
||||
startActivity(new Intent(this, QuickSearchBarActivity.class));
|
||||
@ -580,7 +572,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
if (fragment instanceof AccountsDashboardFragment) {
|
||||
((AccountsDashboardFragment) fragment).requestFitSystemWindows();
|
||||
}
|
||||
mColorStatusFrameLayout.setStatusBarHeight(insets.top);
|
||||
mHomeContent.setStatusBarHeight(insets.top);
|
||||
}
|
||||
|
||||
public void updateUnreadCount() {
|
||||
@ -592,17 +584,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
mTabIndicator.setDisplayBadge(mPreferences.getBoolean(KEY_UNREAD_COUNT, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_SWIPEBACK_ACTIVITY: {
|
||||
// closeAccountsDrawer();
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(final Intent intent) {
|
||||
final int tabPosition = handleIntent(intent, false);
|
||||
@ -660,7 +641,7 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
mActionsButton = findViewById(R.id.actions_button);
|
||||
mActionBarWithOverlay = findViewById(R.id.twidere_action_bar_with_overlay);
|
||||
mTabIndicator = (TabPagerIndicator) findViewById(R.id.main_tabs);
|
||||
mColorStatusFrameLayout = (TintedStatusFrameLayout) findViewById(R.id.home_content);
|
||||
mHomeContent = (TintedStatusFrameLayout) findViewById(R.id.home_content);
|
||||
}
|
||||
|
||||
private Fragment getKeyboardShortcutRecipient() {
|
||||
@ -817,11 +798,11 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
mTabIndicator.setLabelColor(contrastColor);
|
||||
ActivitySupport.setTaskDescription(this, new TaskDescriptionCompat(null, null, themeColor));
|
||||
}
|
||||
mColorStatusFrameLayout.setDrawColor(true);
|
||||
mColorStatusFrameLayout.setDrawShadow(false);
|
||||
mColorStatusFrameLayout.setColor(actionBarColor, actionBarAlpha);
|
||||
mHomeContent.setDrawColor(true);
|
||||
mHomeContent.setDrawShadow(false);
|
||||
mHomeContent.setColor(actionBarColor, actionBarAlpha);
|
||||
StatusBarProxy.setStatusBarDarkIcon(getWindow(), TwidereColorUtils.getYIQLuminance(actionBarColor) > ThemeUtils.ACCENT_COLOR_THRESHOLD);
|
||||
mColorStatusFrameLayout.setFactor(1);
|
||||
mHomeContent.setFactor(1);
|
||||
mActionBarWithOverlay.setAlpha(actionBarAlpha / 255f);
|
||||
mActionsButton.setAlpha(actionBarAlpha / 255f);
|
||||
}
|
||||
@ -836,35 +817,11 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
||||
}
|
||||
|
||||
private void setupSlidingMenu() {
|
||||
// if (mSlidingMenu == null) return;
|
||||
// final Resources res = getResources();
|
||||
// final int marginThreshold = res.getDimensionPixelSize(R.dimen.default_sliding_menu_margin_threshold);
|
||||
// final boolean relativeBehindWidth = res.getBoolean(R.bool.relative_behind_width);
|
||||
// mSlidingMenu.setMode(SlidingMenu.LEFT);
|
||||
// mSlidingMenu.setShadowWidthRes(R.dimen.default_sliding_menu_shadow_width);
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, GravityCompat.START);
|
||||
// mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right);
|
||||
// if (relativeBehindWidth) {
|
||||
// mSlidingMenu.setBehindOffsetRes(R.dimen.drawer_offset_home);
|
||||
// } else {
|
||||
// mSlidingMenu.setBehindWidthRes(R.dimen.drawer_width_home);
|
||||
// }
|
||||
// mSlidingMenu.setTouchmodeMarginThreshold(marginThreshold);
|
||||
// mSlidingMenu.setFadeDegree(0.5f);
|
||||
// mSlidingMenu.setMenu(R.layout.drawer_home_accounts);
|
||||
// mSlidingMenu.setOnOpenedListener(this);
|
||||
// mSlidingMenu.setOnClosedListener(this);
|
||||
// mLeftDrawerContainer = (LeftDrawerFrameLayout) mSlidingMenu.getMenu().findViewById(R.id.left_drawer_container);
|
||||
// final boolean isTransparentBackground = ThemeUtils.isTransparentBackground(getCurrentThemeBackgroundOption());
|
||||
// mLeftDrawerContainer.setClipEnabled(isTransparentBackground);
|
||||
// mLeftDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
|
||||
// mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this));
|
||||
// final Window window = getWindow();
|
||||
// ThemeUtils.applyWindowBackground(this, mSlidingMenu.getContent(), getCurrentThemeResourceId(),
|
||||
// getThemeBackgroundOption(), getCurrentThemeBackgroundAlpha());
|
||||
// window.setBackgroundDrawable(new EmptyDrawable());
|
||||
//
|
||||
// mSlidingMenu.addIgnoredView(mActionBarContainer);
|
||||
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_start, GravityCompat.START);
|
||||
final Window window = getWindow();
|
||||
ThemeUtils.applyWindowBackground(this, mHomeContent, getCurrentThemeResourceId(),
|
||||
getThemeBackgroundOption(), getCurrentThemeBackgroundAlpha());
|
||||
window.setBackgroundDrawable(new EmptyDrawable());
|
||||
}
|
||||
|
||||
private void showDataProfilingRequest() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user