menu button to open sliding menu should work
improved user profile editor
This commit is contained in:
parent
85aa0299ab
commit
42bca8487c
|
@ -23,23 +23,18 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.v4.view.LayoutInflaterCompat;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Window;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.activity.iface.IThemedActivity;
|
||||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.ThemedLayoutInflaterFactory;
|
||||
import org.mariotaku.twidere.util.support.ViewSupport;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/4/22.
|
||||
*/
|
||||
public class ThemedAppCompatDelegate implements Constants {
|
||||
public class ThemedAppCompatDelegateFactory implements Constants {
|
||||
|
||||
|
||||
/**
|
||||
|
@ -47,46 +42,24 @@ public class ThemedAppCompatDelegate implements Constants {
|
|||
*
|
||||
* @param callback An optional callback for AppCompat specific events
|
||||
*/
|
||||
public static AppCompatDelegate create(IThemedActivity themed, AppCompatCallback callback) {
|
||||
public static ThemedAppCompatDelegate create(IThemedActivity themed, AppCompatCallback callback) {
|
||||
final Activity activity = (Activity) themed;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
return new ThemedAppCompatDelegateImplV11(themed, activity, activity.getWindow(), callback);
|
||||
return new ThemedAppCompatDelegate(themed, activity, activity.getWindow(), callback);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static class ThemedAppCompatDelegateImplV11 extends AppCompatDelegateImplV11 {
|
||||
public static final class ThemedAppCompatDelegate extends AppCompatDelegateImplV11 {
|
||||
|
||||
private final IThemedActivity themed;
|
||||
private KeyListener keyListener;
|
||||
|
||||
private ThemedAppCompatDelegateImplV11(final IThemedActivity themed, final Context context,
|
||||
Window window, AppCompatCallback callback) {
|
||||
private ThemedAppCompatDelegate(final IThemedActivity themed, final Context context,
|
||||
Window window, AppCompatCallback callback) {
|
||||
super(context, window, callback);
|
||||
this.themed = themed;
|
||||
// try {
|
||||
// final Field field = AppCompatDelegateImplV7.class.getDeclaredField("mInvalidatePanelMenuRunnable");
|
||||
// field.setAccessible(true);
|
||||
// final Runnable old = (Runnable) field.get(this);
|
||||
// field.set(this, new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// if (old != null) {
|
||||
// old.run();
|
||||
// }
|
||||
// final int themeColor = themed.getCurrentThemeColor();
|
||||
// final int themeId = themed.getCurrentThemeResourceId();
|
||||
// final int itemColor = ThemeUtils.getContrastActionBarItemColor(context, themeId, themeColor);
|
||||
// final Toolbar toolbar = ThemeUtils.getToolbarFromActivity((Activity) themed);
|
||||
// if (toolbar != null) {
|
||||
// ThemeUtils.setActionBarOverflowColor(toolbar, itemColor);
|
||||
// ThemeUtils.wrapToolbarMenuIcon(ViewSupport.findViewByType(toolbar, ActionMenuView.class), itemColor, itemColor);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// } catch (Exception ignore) {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -96,6 +69,28 @@ public class ThemedAppCompatDelegate implements Constants {
|
|||
LayoutInflaterCompat.setFactory(inflater, new ThemedLayoutInflaterFactory(themed, this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyListener != null && keyListener.onKeyDown(keyCode, event)) return true;
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
if (keyListener != null && keyListener.onKeyUp(keyCode, event)) return true;
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
public void setKeyListener(KeyListener listener) {
|
||||
keyListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface KeyListener {
|
||||
|
||||
boolean onKeyDown(int keyCode, KeyEvent event);
|
||||
|
||||
boolean onKeyUp(int keyCode, KeyEvent event);
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.view.ViewPager.OnPageChangeListener;
|
||||
import android.support.v7.app.ThemedAppCompatDelegateFactory;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -96,11 +97,11 @@ import org.mariotaku.twidere.util.ReadStateManager;
|
|||
import org.mariotaku.twidere.util.ThemeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereColorUtils;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.support.ActivitySupport;
|
||||
import org.mariotaku.twidere.util.support.ViewSupport;
|
||||
import org.mariotaku.twidere.util.support.ActivitySupport.TaskDescriptionCompat;
|
||||
import org.mariotaku.twidere.util.message.TaskStateChangedEvent;
|
||||
import org.mariotaku.twidere.util.message.UnreadCountUpdatedEvent;
|
||||
import org.mariotaku.twidere.util.support.ActivitySupport;
|
||||
import org.mariotaku.twidere.util.support.ActivitySupport.TaskDescriptionCompat;
|
||||
import org.mariotaku.twidere.util.support.ViewSupport;
|
||||
import org.mariotaku.twidere.view.ExtendedViewPager;
|
||||
import org.mariotaku.twidere.view.HomeSlidingMenu;
|
||||
import org.mariotaku.twidere.view.LeftDrawerFrameLayout;
|
||||
|
@ -217,20 +218,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
mControlBarShowHideHelper.setControlBarVisibleAnimate(visible);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(final int keyCode, @NonNull final KeyEvent event) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_MENU: {
|
||||
if (mSlidingMenu != null) {
|
||||
mSlidingMenu.toggle(true);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -400,6 +387,27 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
initUnreadCount();
|
||||
updateActionsButton();
|
||||
updateSlidingMenuTouchMode();
|
||||
getDelegate().setKeyListener(new ThemedAppCompatDelegateFactory.KeyListener() {
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
// Steal MENU key event
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_MENU: {
|
||||
if (mSlidingMenu != null) {
|
||||
mSlidingMenu.toggle(true);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
if (refreshOnStart) {
|
||||
|
@ -646,17 +654,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
|
|||
return 1 + mTabsContainer.getTranslationY() / totalHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (mSlidingMenu != null) {
|
||||
mSlidingMenu.toggle(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContentChanged() {
|
||||
super.onContentChanged();
|
||||
|
|
|
@ -75,12 +75,15 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
|
|||
private final View.OnLayoutChangeListener mLayoutChangeListener = new View.OnLayoutChangeListener() {
|
||||
|
||||
private final Rect tempInsets = new Rect();
|
||||
private boolean compatCalled;
|
||||
|
||||
@Override
|
||||
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
|
||||
if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
|
||||
if (compatCalled) return;
|
||||
if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom && !ViewSupport.isInLayout(v)) {
|
||||
mMainContent.getSystemWindowsInsets(tempInsets);
|
||||
onFitSystemWindows(tempInsets);
|
||||
compatCalled = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -122,10 +125,15 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
|
|||
final View actionBarContainer = findViewById(R.id.twidere_action_bar_container);
|
||||
if (actionBarContainer != null) {
|
||||
final ViewGroup.LayoutParams toolBarParams = actionBarContainer.getLayoutParams();
|
||||
boolean changed = false;
|
||||
if (toolBarParams instanceof ViewGroup.MarginLayoutParams) {
|
||||
final int topMargin = ((ViewGroup.MarginLayoutParams) toolBarParams).topMargin;
|
||||
changed = topMargin != insets.top;
|
||||
((ViewGroup.MarginLayoutParams) toolBarParams).topMargin = insets.top;
|
||||
}
|
||||
actionBarContainer.setLayoutParams(toolBarParams);
|
||||
if (changed) {
|
||||
actionBarContainer.setLayoutParams(toolBarParams);
|
||||
}
|
||||
}
|
||||
insets.top += ThemeUtils.getActionBarHeight(this);
|
||||
super.onFitSystemWindows(insets);
|
||||
|
@ -522,6 +530,10 @@ public class LinkHandlerActivity extends BaseAppCompatActivity implements System
|
|||
setTitle(R.string.view_map);
|
||||
break;
|
||||
}
|
||||
case LINK_ID_PROFILE_EDITOR: {
|
||||
setTitle(R.string.edit_profile);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
setTitle(getString(R.string.app_name));
|
||||
break;
|
||||
|
|
|
@ -24,8 +24,7 @@ import android.os.Bundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.app.ThemedAppCompatDelegate;
|
||||
import android.support.v7.app.ThemedAppCompatDelegateFactory;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
|
||||
|
@ -44,7 +43,7 @@ public abstract class ThemedAppCompatActivity extends AppCompatActivity implemen
|
|||
private String mCurrentThemeBackgroundOption;
|
||||
private String mCurrentThemeFontFamily;
|
||||
|
||||
private AppCompatDelegate mDelegate;
|
||||
private ThemedAppCompatDelegateFactory.ThemedAppCompatDelegate mDelegate;
|
||||
private Toolbar mToolbar;
|
||||
|
||||
@Override
|
||||
|
@ -115,9 +114,9 @@ public abstract class ThemedAppCompatActivity extends AppCompatActivity implemen
|
|||
}
|
||||
|
||||
@Override
|
||||
public AppCompatDelegate getDelegate() {
|
||||
public ThemedAppCompatDelegateFactory.ThemedAppCompatDelegate getDelegate() {
|
||||
if (mDelegate != null) return mDelegate;
|
||||
return mDelegate = ThemedAppCompatDelegate.create(this, this);
|
||||
return mDelegate = ThemedAppCompatDelegateFactory.create(this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -57,6 +57,7 @@ import org.mariotaku.twidere.util.AsyncTaskManager;
|
|||
import org.mariotaku.twidere.util.AsyncTaskUtils;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper.UpdateProfileBannerImageTask;
|
||||
import org.mariotaku.twidere.util.AsyncTwitterWrapper.UpdateProfileImageTask;
|
||||
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.ParseUtils;
|
||||
import org.mariotaku.twidere.util.TwitterWrapper;
|
||||
|
@ -72,7 +73,8 @@ import static android.text.TextUtils.isEmpty;
|
|||
import static org.mariotaku.twidere.util.Utils.getTwitterInstance;
|
||||
|
||||
public class UserProfileEditorFragment extends BaseSupportFragment implements OnSizeChangedListener, TextWatcher,
|
||||
OnClickListener, LoaderCallbacks<SingleResponse<ParcelableUser>> {
|
||||
OnClickListener, LoaderCallbacks<SingleResponse<ParcelableUser>>,
|
||||
KeyboardShortcutsHandler.TakeAllKeyboardShortcut {
|
||||
|
||||
private static final int LOADER_ID_USER = 1;
|
||||
|
||||
|
@ -478,6 +480,7 @@ public class UserProfileEditorFragment extends BaseSupportFragment implements On
|
|||
if (f instanceof DialogFragment) {
|
||||
((DialogFragment) f).dismissAllowingStateLoss();
|
||||
}
|
||||
mFragment.getActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue