Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit d93c070

Browse files
committed
- Toolbar & Menu improvments/fix
1 parent 8d054be commit d93c070

File tree

11 files changed

+52
-52
lines changed

11 files changed

+52
-52
lines changed

app/src/main/java/de/dlyt/yanndroid/oneuiexample/MainActivity.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,8 @@ public void onVoiceInputClick(Intent intent) {
187187
case R.id.info:
188188
startActivity(new Intent().setClass(mContext, AboutActivity.class));
189189
break;
190-
case R.id.item1:
191-
case R.id.item2:
192-
case R.id.item3:
193-
item.setBadge(item.getBadge() + 1);
194-
break;
195190
}
191+
item.setBadge(item.getBadge() + 1);
196192
return true;
197193
});
198194

app/src/main/res/menu/main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<item
66
android:id="@+id/search"
7-
android:icon="@drawable/ic_samsung_search"
7+
88
android:title="@string/action_search"
99
app:showAsAction="always" />
1010

yanndroid/oneui/src/main/java/de/dlyt/yanndroid/oneui/layout/ToolbarLayout.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ public void onAttachedToWindow() {
288288
protected void onConfigurationChanged(Configuration newConfig) {
289289
super.onConfigurationChanged(newConfig);
290290
refreshLayout(newConfig);
291-
resetToolbarHeight();
292291
}
293292

294293
private AppCompatActivity getActivity() {
@@ -370,13 +369,9 @@ private void resetToolbarHeight() {
370369
if (toolbar != null) {
371370
toolbar.setPaddingRelative(mSelectMode || mSearchMode || navigationButtonVisible ? 0 : getResources().getDimensionPixelSize(R.dimen.sesl_action_bar_content_inset), getToolbarTopPadding(), 0, 0);
372371

373-
TypedValue typedValue = new TypedValue();
374-
if (getActivity().getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true)) {
375-
int height = TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics());
376-
ViewGroup.LayoutParams lp = toolbar.getLayoutParams();
377-
lp.height = height + getToolbarTopPadding();
378-
toolbar.setLayoutParams(lp);
379-
}
372+
ViewGroup.LayoutParams lp = toolbar.getLayoutParams();
373+
lp.height += getToolbarTopPadding();
374+
toolbar.setLayoutParams(lp);
380375
} else
381376
Log.w(TAG + ".resetToolbarHeight", "toolbar is null.");
382377
}

yanndroid/oneui/src/main/java/de/dlyt/yanndroid/oneui/menu/ActionButtonMenuItemView.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ActionButtonMenuItemView extends LinearLayout {
2525
private MenuItem menuItem;
2626
private ToolbarImageButton iconView;
2727
private TextView badgeView;
28+
private TextView titleView;
2829

2930
public ActionButtonMenuItemView(Context context, MenuItem menuItem) {
3031
super(context);
@@ -55,6 +56,7 @@ private void initView() {
5556
inflater.inflate(R.layout.menu_item_action_button, this, true);
5657
iconView = findViewById(R.id.menu_item_icon);
5758
badgeView = findViewById(R.id.menu_item_badge);
59+
titleView = findViewById(R.id.menu_item_title);
5860

5961
iconView.setBackgroundResource(R.drawable.sesl_action_bar_item_background);
6062
}
@@ -73,6 +75,16 @@ public void updateView() {
7375
iconView.setImageDrawable(menuItem.getIcon());
7476
iconView.setTooltipText(menuItem.getTitle());
7577

78+
if (menuItem.getIcon() == null) {
79+
iconView.setVisibility(GONE);
80+
titleView.setVisibility(VISIBLE);
81+
titleView.setText(menuItem.getTitle());
82+
} else {
83+
iconView.setVisibility(VISIBLE);
84+
titleView.setVisibility(GONE);
85+
}
86+
87+
7688
badgeCount = menuItem.getBadge();
7789
} else if (menu != null) {
7890
badgeCount = menu.getTotalBadgeCount();
@@ -100,5 +112,6 @@ public void updateView() {
100112
@Override
101113
public void setOnClickListener(@Nullable OnClickListener l) {
102114
iconView.setOnClickListener(l);
115+
titleView.setOnClickListener(l);
103116
}
104117
}

yanndroid/oneui/src/main/java/de/dlyt/yanndroid/oneui/menu/PopupListView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import android.content.Context;
44
import android.widget.ListView;
55

6-
public class PopupListView extends ListView {
6+
class PopupListView extends ListView {
77
private int mMaxHeight;
88

9-
public PopupListView(Context context) {
9+
PopupListView(Context context) {
1010
super(context);
1111
}
1212

@@ -16,7 +16,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
1616
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
1717
}
1818

19-
public void setMaxHeight(int maxHeight) {
19+
void setMaxHeight(int maxHeight) {
2020
mMaxHeight = maxHeight;
2121
invalidate();
2222
}

yanndroid/oneui/src/main/java/de/dlyt/yanndroid/oneui/menu/PopupMenu.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.dlyt.yanndroid.oneui.menu;
22

3-
import android.annotation.SuppressLint;
43
import android.content.Context;
54
import android.util.TypedValue;
65
import android.view.KeyEvent;
@@ -29,6 +28,9 @@ public class PopupMenu {
2928
private PopupListView listView;
3029
private PopupMenuAdapter popupMenuAdapter;
3130

31+
private int xoff = 0;
32+
private int yoff = 0;
33+
3234
public PopupMenu(View anchor) {
3335
this.context = anchor.getContext();
3436
this.anchor = anchor;
@@ -89,7 +91,7 @@ public void onMenuItemUpdate(MenuItem menuItem) {
8991
popupMenuListener.onMenuItemUpdate(menuItem);
9092
}
9193
});
92-
subPopupMenu.show();
94+
subPopupMenu.show(xoff, yoff);
9395
popupWindow.dismiss();
9496
} else if (popupMenuListener != null && popupMenuListener.onMenuItemClick(clickedMenuItem)) {
9597
popupWindow.dismiss();
@@ -153,6 +155,8 @@ public void show() {
153155
}
154156

155157
public void show(int xoff, int yoff) {
158+
this.xoff = xoff;
159+
this.yoff = yoff;
156160
popupWindow.showAsDropDown(anchor, xoff, yoff);
157161
updatePopupSize();
158162
((View) ReflectUtils.genericGetField(popupWindow, "mBackgroundView")).setClipToOutline(true);

yanndroid/oneui/src/main/res/layout/menu_item_action_button.xml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="@dimen/sesl_overflow_button_min_width"
3+
android:layout_width="wrap_content"
44
android:layout_height="?actionBarSize">
55

6+
<TextView
7+
android:id="@+id/menu_item_title"
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:layout_gravity="center"
11+
android:background="@drawable/sesl_btn_transparent"
12+
android:fontFamily="@string/sesl_font_family_regular"
13+
android:gravity="center"
14+
android:singleLine="true"
15+
android:textColor="@color/item_color"
16+
android:textSize="20sp"
17+
android:textStyle="bold"
18+
android:visibility="gone" />
19+
620
<de.dlyt.yanndroid.oneui.sesl.widget.ToolbarImageButton
721
android:id="@+id/menu_item_icon"
8-
android:layout_width="match_parent"
22+
android:layout_width="@dimen/sesl_overflow_button_min_width"
923
android:layout_height="match_parent"
1024
android:layout_gravity="center" />
1125

1226
<TextView
1327
android:id="@+id/menu_item_badge"
1428
android:layout_width="@dimen/sesl_menu_item_badge_size"
1529
android:layout_height="@dimen/sesl_menu_item_badge_size"
16-
android:layout_gravity="end|top"
17-
android:layout_marginTop="@dimen/sesl_menu_item_badge_top_margin"
30+
android:layout_gravity="end|center_vertical"
1831
android:layout_marginEnd="7.0dip"
32+
android:layout_marginBottom="8.5dp"
1933
android:background="@drawable/sesl_noti_badge"
2034
android:duplicateParentState="true"
2135
android:gravity="center"

yanndroid/oneui/src/main/res/layout/menu_item_popup_item.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
android:minWidth="@dimen/sesl_popup_menu_item_min_width"
99
android:minHeight="@dimen/sesl_popup_menu_item_min_height"
1010
android:orientation="horizontal"
11-
android:paddingStart="@dimen/sesl_popup_menu_item_start_padding"
11+
android:paddingStart="@dimen/sesl_popup_menu_item_padding"
1212
android:paddingTop="@dimen/sesl_popup_menu_item_top_padding"
13-
android:paddingEnd="@dimen/sesl_popup_menu_item_end_padding"
13+
android:paddingEnd="@dimen/sesl_popup_menu_item_padding"
1414
android:paddingBottom="@dimen/sesl_popup_menu_item_bottom_padding">
1515

1616
<ImageView

yanndroid/oneui/src/main/res/layout/navigation_button_badge_layout.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="@dimen/sesl_menu_item_badge_size"
44
android:layout_height="@dimen/sesl_menu_item_badge_size"
5-
android:layout_gravity="end|center|top"
5+
android:layout_gravity="end|center_vertical"
66
android:layout_marginStart="23.0dip"
7-
android:layout_marginTop="@dimen/sesl_menu_item_badge_top_margin"
87
android:layout_marginEnd="7.0dip"
8+
android:layout_marginBottom="8.5dp"
99
android:background="@drawable/sesl_noti_badge"
1010
android:clickable="false"
1111
android:duplicateParentState="true"

yanndroid/oneui/src/main/res/layout/sesl_action_menu_item_badge.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)