Skip to content

Commit b4569a2

Browse files
committed
Library fixes
-fixed location of upper arrow pointer -decreased size of vertical list icons -code cleanup
1 parent a726c8b commit b4569a2

File tree

7 files changed

+30
-39
lines changed

7 files changed

+30
-39
lines changed

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion 21
88
targetSdkVersion 28
99
versionCode 3
10-
versionName "2.01"
10+
versionName "2.04"
1111
}
1212
buildTypes {
1313
release {

library/src/main/java/com/gsd/mpm/materialpopupmenu/GoogleTextView.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public GoogleTextView(Context context) {
1616
public GoogleTextView(Context context, AttributeSet attrs) {
1717
super(context, attrs);
1818
setFont();
19-
2019
}
2120

2221
private void setFont() {
@@ -27,10 +26,8 @@ private void setFont() {
2726
public GoogleTextView(Context context, AttributeSet attrs, int defStyle) {
2827
super(context, attrs, defStyle);
2928
setFont();
30-
3129
}
3230

33-
3431
@Override
3532
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
3633
if(focused)
@@ -43,7 +40,6 @@ public void onWindowFocusChanged(boolean focused) {
4340
super.onWindowFocusChanged(focused);
4441
}
4542

46-
4743
@Override
4844
public boolean isFocused() {
4945
return true;

library/src/main/java/com/gsd/mpm/materialpopupmenu/PopUpMenu.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@
1616
import android.view.animation.Animation;
1717
import android.view.animation.AnimationUtils;
1818
import android.view.animation.Interpolator;
19-
import android.widget.FrameLayout;
2019
import android.widget.HorizontalScrollView;
2120
import android.widget.ImageView;
2221
import android.widget.LinearLayout;
2322
import android.widget.PopupWindow.OnDismissListener;
2423
import android.widget.ScrollView;
2524
import android.widget.TextView;
2625

27-
import java.util.ArrayList;
28-
import java.util.List;
29-
3026
import androidx.core.content.ContextCompat;
3127
import androidx.core.graphics.drawable.DrawableCompat;
3228

29+
import java.util.ArrayList;
30+
import java.util.List;
31+
3332
public class PopUpMenu extends PopupWindows implements OnDismissListener {
3433

3534
private ImageView mArrowUp, mArrowDown;
@@ -45,9 +44,6 @@ public class PopUpMenu extends PopupWindows implements OnDismissListener {
4544
private ScrollView vertScroll;
4645
private View menu_header, menu_footer, top_menu_footer, top_menu_header;
4746

48-
private List<ActionItem> mActionItemList = new ArrayList<>();
49-
private List<ActionItem> mActionItemVerticalList = new ArrayList<>();
50-
5147
private boolean mDidAction;
5248
private boolean mAnimateTrack;
5349
private boolean isLight;
@@ -68,17 +64,22 @@ public class PopUpMenu extends PopupWindows implements OnDismissListener {
6864
private int mBodyColor;
6965
private boolean enableHeaderTitle;
7066

67+
private float iconDensity;
68+
69+
private List<ActionItem> mActionItemList = new ArrayList<>();
70+
private List<ActionItem> mActionItemVerticalList = new ArrayList<>();
71+
7172
private ActionItem getActionItem(int index) {
7273
return mActionItemList.get(index);
7374
}
74-
7575
private ActionItem getVertActionItem(int index) {
7676
return mActionItemVerticalList.get(index);
7777
}
7878

7979
public PopUpMenu(Context context) {
8080
super(context);
8181
setRootViewId(R.layout.quick_action_menu);
82+
iconDensity = context.getResources().getDisplayMetrics().density * 48;
8283
}
8384

8485
//Set Menu Title or Text
@@ -209,9 +210,8 @@ public void themeVerticalIcons(boolean enable) {
209210
}
210211

211212
//Set a custom anim style
212-
public int setAnimStyle(int mAnimStyle) {
213+
public void setAnimStyle(int mAnimStyle) {
213214
this.mAnimStyle = mAnimStyle;
214-
return mAnimStyle;
215215
}
216216

217217
//Set Light or Dark styled icons and text
@@ -442,10 +442,11 @@ private void setAnimationStyle(int screenWidth, int requestedX, boolean onTop) {
442442
private void showArrow(int whichArrow, int requestedX) {
443443
final ImageView showArrow = (whichArrow == R.id.arrow_up) ? mArrowUp : mArrowDown;
444444
final View hideArrow = (whichArrow == R.id.arrow_up) ? mArrowDown : mArrowUp;
445-
final int arrowWidth = mArrowUp.getMeasuredWidth();
445+
final int arrowWidth = (int) iconDensity;
446446
showArrow.setVisibility(View.VISIBLE);
447447
showArrow.setColorFilter(getBodyColor(), PorterDuff.Mode.SRC_IN);
448-
ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams)showArrow.getLayoutParams();
448+
ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams)
449+
showArrow.getLayoutParams();
449450
param.leftMargin = requestedX - arrowWidth / 2;
450451
hideArrow.setVisibility(View.INVISIBLE);
451452
}

library/src/main/java/com/gsd/mpm/materialpopupmenu/PopupWindows.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ void preShow() {
3232
if (mRootView == null)
3333
throw new IllegalStateException("Needs a root view!");
3434
onShow();
35-
36-
mWindow.setBackgroundDrawable(mBackground);
35+
mWindow.setBackgroundDrawable(mBackground);
3736
mWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
3837
mWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
3938
mWindow.setTouchable(true);
4039
mWindow.setFocusable(true);
4140
mWindow.setOutsideTouchable(true);
42-
4341
mWindow.setContentView(mRootView);
4442
}
4543

library/src/main/res/layout/quick_action_item.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
android:focusable="true"
1010
android:background="?android:selectableItemBackground">
1111

12-
<ImageView
12+
<androidx.appcompat.widget.AppCompatImageView
1313
android:id="@+id/iv_icon"
1414
android:scaleType="centerInside"
1515
android:layout_width="42dp"

library/src/main/res/layout/quick_action_list_item.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
android:focusable="true"
1010
android:background="?android:selectableItemBackground">
1111

12-
<ImageView
12+
<androidx.appcompat.widget.AppCompatImageView
1313
android:id="@+id/iv_icon"
1414
android:layout_alignParentStart="true"
15-
android:layout_width="42dp"
16-
android:layout_height="42dp"
15+
android:layout_width="38dp"
16+
android:layout_height="38dp"
1717
android:src="@drawable/ic_settings"/>
1818

1919
<com.gsd.mpm.materialpopupmenu.GoogleTextView
@@ -29,7 +29,7 @@
2929
android:textSize="14sp"
3030
android:text="Title"/>
3131

32-
<ImageView
32+
<androidx.appcompat.widget.AppCompatImageView
3333
android:id="@+id/iv_item"
3434
android:layout_alignParentEnd="true"
3535
android:scaleType="centerInside"

library/src/main/res/layout/quick_action_menu.xml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="wrap_content"
4-
android:layout_height="wrap_content"
5-
android:gravity="center">
4+
android:layout_height="wrap_content">
65

76
<LinearLayout
87
android:id="@+id/header2"
98
android:orientation="vertical"
109
android:layout_marginStart="8dp"
1110
android:layout_width="match_parent"
12-
android:layout_height="wrap_content" >
11+
android:layout_height="wrap_content">
12+
13+
<androidx.appcompat.widget.AppCompatImageView
14+
android:id="@+id/arrow_up"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:src="@drawable/up_arrow" />
1318

1419
<View
1520
android:id="@+id/top_menu_header"
@@ -21,12 +26,12 @@
2126
android:layout_width="match_parent"
2227
android:layout_height="22dp"
2328
android:paddingStart="8dp"
29+
android:paddingEnd="8dp"
2430
android:gravity="center|start"
2531
android:textSize="12sp"
2632
style="@style/Base.TextAppearance.AppCompat.Subhead"
2733
android:text="Menu Title" />
2834

29-
3035
<ScrollView
3136
android:id="@+id/vert_scroll"
3237
android:layout_width="match_parent"
@@ -48,14 +53,6 @@
4853

4954
</LinearLayout>
5055

51-
<ImageView
52-
android:id="@+id/arrow_up"
53-
android:layout_width="wrap_content"
54-
android:layout_height="wrap_content"
55-
android:layout_marginTop="32dp"
56-
android:layout_above="@id/header2"
57-
android:src="@drawable/up_arrow" />
58-
5956
<View
6057
android:id="@+id/menu_header"
6158
android:layout_marginStart="8dp"
@@ -86,11 +83,10 @@
8683
android:layout_height="4dp"
8784
android:layout_below="@id/scroll"/>
8885

89-
<ImageView
86+
<androidx.appcompat.widget.AppCompatImageView
9087
android:id="@+id/arrow_down"
9188
android:layout_width="wrap_content"
9289
android:layout_height="wrap_content"
93-
android:layout_marginBottom="22dp"
9490
android:layout_below="@id/menu_footer"
9591
android:src="@drawable/down_arrow" />
9692

0 commit comments

Comments
 (0)