Menu button on devices that have it will open the overflow. Radio buttons in grid size menu are themed with the accent color, resolves #18.
This commit is contained in:
parent
e4385c8edc
commit
0f60a54d50
3 changed files with 114 additions and 13 deletions
|
|
@ -50,7 +50,7 @@ dependencies {
|
|||
compile('com.crashlytics.sdk.android:crashlytics:2.2.1@aar') {
|
||||
transitive = true;
|
||||
}
|
||||
compile 'com.afollestad:material-dialogs:0.7.2.2'
|
||||
compile 'com.afollestad:material-dialogs:0.7.2.3'
|
||||
compile 'com.android.support:appcompat-v7:22.0.0'
|
||||
compile 'com.android.support:recyclerview-v7:22.0.0'
|
||||
compile 'com.android.support:gridlayout-v7:22.0.0'
|
||||
|
|
|
|||
|
|
@ -7,13 +7,18 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.internal.view.menu.MenuPopupHelper;
|
||||
import android.support.v7.widget.ActionMenuPresenter;
|
||||
import android.support.v7.widget.ActionMenuView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
|
|
@ -48,6 +53,7 @@ import com.kabouzeid.gramophone.util.ViewUtil;
|
|||
import com.koushikdutta.async.future.FutureCallback;
|
||||
import com.koushikdutta.ion.Ion;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -490,4 +496,45 @@ public class MainActivity extends AbsFabActivity
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
if (toolbar != null)
|
||||
toolbar.showOverflowMenu();
|
||||
return true;
|
||||
}
|
||||
return super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuOpened(int featureId, Menu menu) {
|
||||
toolbar.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Field f1 = Toolbar.class.getDeclaredField("mMenuView");
|
||||
f1.setAccessible(true);
|
||||
ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar);
|
||||
|
||||
Field f2 = ActionMenuView.class.getDeclaredField("mPresenter");
|
||||
f2.setAccessible(true);
|
||||
ActionMenuPresenter presenter = (ActionMenuPresenter) f2.get(actionMenuView);
|
||||
|
||||
Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup");
|
||||
f3.setAccessible(true);
|
||||
MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter);
|
||||
ViewUtil.setCheckBoxTintForMenu(overflowMenuPopupHelper);
|
||||
|
||||
Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup");
|
||||
f4.setAccessible(true);
|
||||
MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter);
|
||||
ViewUtil.setCheckBoxTintForMenu(subMenuPopupHelper);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
return super.onMenuOpened(featureId, menu);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,21 @@ package com.kabouzeid.gramophone.util;
|
|||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.os.Build;
|
||||
import android.support.v7.internal.view.menu.ListMenuItemView;
|
||||
import android.support.v7.internal.view.menu.MenuPopupHelper;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.PathInterpolator;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import com.afollestad.materialdialogs.ThemeSingleton;
|
||||
import com.afollestad.materialdialogs.internal.MDTintHelper;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
|
|
@ -99,15 +106,62 @@ public class ViewUtil {
|
|||
});
|
||||
}
|
||||
|
||||
public static void animateTextViewMaxLines(TextView text, int maxLines) {
|
||||
try {
|
||||
ObjectAnimator animation = ObjectAnimator.ofInt(text, "maxLines", maxLines);
|
||||
animation.setInterpolator(new AccelerateInterpolator());
|
||||
animation.setDuration(200);
|
||||
animation.start();
|
||||
} catch (Exception e) {
|
||||
// Some devices crash at runtime when using the ObjectAnimator
|
||||
text.setMaxLines(maxLines);
|
||||
// public static void animateTextViewMaxLines(TextView text, int maxLines) {
|
||||
// try {
|
||||
// ObjectAnimator animation = ObjectAnimator.ofInt(text, "maxLines", maxLines);
|
||||
// animation.setInterpolator(new AccelerateInterpolator());
|
||||
// animation.setDuration(200);
|
||||
// animation.start();
|
||||
// } catch (Exception e) {
|
||||
// // Some devices crash at runtime when using the ObjectAnimator
|
||||
// text.setMaxLines(maxLines);
|
||||
// }
|
||||
// }
|
||||
|
||||
public static void setCheckBoxTintForMenu(MenuPopupHelper menuPopupHelper) {
|
||||
if (menuPopupHelper != null) {
|
||||
final ListView listView = menuPopupHelper.getPopup().getListView();
|
||||
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
try {
|
||||
Field checkboxField = ListMenuItemView.class.getDeclaredField("mCheckBox");
|
||||
checkboxField.setAccessible(true);
|
||||
Field radioButtonField = ListMenuItemView.class.getDeclaredField("mRadioButton");
|
||||
radioButtonField.setAccessible(true);
|
||||
|
||||
for (int i = 0; i < listView.getChildCount(); i++) {
|
||||
View v = listView.getChildAt(i);
|
||||
if (!(v instanceof ListMenuItemView)) continue;
|
||||
ListMenuItemView iv = (ListMenuItemView) v;
|
||||
|
||||
CheckBox check = (CheckBox) checkboxField.get(iv);
|
||||
if (check != null) {
|
||||
MDTintHelper.setTint(check, ThemeSingleton.get().positiveColor);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
check.setBackground(null);
|
||||
}
|
||||
}
|
||||
|
||||
RadioButton radioButton = (RadioButton) radioButtonField.get(iv);
|
||||
if (radioButton != null) {
|
||||
MDTintHelper.setTint(radioButton, ThemeSingleton.get().positiveColor);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
radioButton.setBackground(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
listView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
//noinspection deprecation
|
||||
listView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue