Skip to content

Commit 701a9c6

Browse files
committed
优化气泡提示
1 parent 7034c7b commit 701a9c6

File tree

8 files changed

+143
-53
lines changed

8 files changed

+143
-53
lines changed

README.md

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ allprojects {
1717
```groovy
1818
dependencies {
1919
//多个物联网相关基础工具类
20-
implementation 'com.github.wave-chtj:BaseIotUtils:2.6.1'
20+
implementation 'com.github.wave-chtj:BaseIotUtils:2.7.0'
2121
}
2222
```
2323

@@ -58,43 +58,63 @@ public class App extends Application {
5858

5959
## base_iotutils 物联基础工具类说明
6060

61-
| 编号 | 工具类 | 工具名称 | 实现功能 |
62-
|-----|-----------------------------|--------------|--------------------------|
63-
| 01 | AudioUtils | 音频管理 | 播放继续暂停 |
64-
| 02 | AppsUtils | App的相关工具 | 查询应用以及 app 的信息 |
65-
| 03 | AdaptationUtils | 屏幕适配 | pt 单位适配 |
61+
| 编号 | 工具类 | 工具名称 | 实现功能 |
62+
|-----|-----------------------------|--------------|-----------------------|
63+
| 01 | AudioUtils | 音频管理 | 播放继续暂停 |
64+
| 02 | AppsUtils | App的相关工具 | 查询应用以及 app 的信息 |
65+
| 03 | AdaptationUtils | 屏幕适配 | pt 单位适配 |
6666
| 04 | TranscodingUtils | 编码转换工具类 | 10/16/ascii,字节数组等相互转换 |
67-
| 05 | DownloadUtils | 多任务下载管理 | 下载,暂停,状态回调 |
68-
| 06 | DisplayUtils | 屏幕相关 | 屏幕信息获取(高宽像素等) |
69-
| 07 | DialogUtils | 对话框相关 | 普通对话框、带输入框对话框 |
70-
| 08 | DeviceUtils | 设备的相关信息 | 设备出厂自带参数 |
71-
| 09 | EncryptUtils | 加密工具类 | 获取字符串,文件MD5 |
72-
| 10 | FileUtils | 文件工具类 | 写入/读取文件相关信息 |
73-
| 11 | FormatViewsUtils | 文本滚动工具 | TextView滚动最新一行 |
74-
| 12 | GlobalDialogUtils | 应用上层弹窗 | SYSTEM_ALERT_WINDOW |
75-
| 13 | HttpUtils | 网络请求工具类 | get,post请求 |
76-
| 14 | JsonFormatUtils | JSON格式化工具 | JSON字符串格式化 |
77-
| 15 | KLog | 日志打印 | 日志标记打印 |
78-
| 16 | KeyBoardUtils | 软键盘管理 | 打开,关闭 |
79-
| 17 | NotifyUtils | 通知工具类 | 自定义 notification,动态调参 |
80-
| 18 | NetUtils | 网络工具类 | 网络类型/状态等获取 |
81-
| 19 | NetMonitorUtils | 网络变化广播 | 网络变化回调 |
82-
| 20 | ObjectUtils | 通用对象管理工具 | 判空,比较,随机 |
83-
| 21 | PermissionsUtils | 权限申请工具类 | 多权限申请 |
84-
| 22 | RegularTools | 正则工具类 | 通用正则结果获取 |
85-
| 23 | SerialPort/SerialPortFinder | 串口相关工具类 | 打开,通讯,关闭 |
86-
| 24 | SPUtils | 存储工具类 | SharedPreferences 读写 |
87-
| 25 | ShellUtils | adb 相关工具类 | adb 命令执行 |
88-
| 26 | ServiceUtils | Service 管理工具 | 启动,停止,判断存活等 |
89-
| 27 | StatusBarUtils | 沉浸式状态栏 | 状态栏变色 |
90-
| 28 | ToastUtils | 系统的 Toast 封装 | 成功,失败,警告等提示 |
91-
| 29 | TimeUtils | 时间工具类 | Date 时间日期转换 |
92-
| 30 | TPoolSingleUtils/TPoolUtils | 线程池管理 | 线程重用 |
93-
| 31 | UriPathUtils | Uri 转真实路径 | android7.0uri 转换 |
94-
| 32 | ZipUtils | 压缩相关 | 压缩解压,批量等 |
67+
| 05 | DownloadUtils | 多任务下载管理 | 下载,暂停,状态回调 |
68+
| 06 | DisplayUtils | 屏幕相关 | 屏幕信息获取(高宽像素等) |
69+
| 07 | DialogUtils | 对话框相关 | 普通对话框、带输入框对话框 |
70+
| 08 | DeviceUtils | 设备的相关信息 | 设备出厂自带参数 |
71+
| 09 | EncryptUtils | 加密工具类 | 获取字符串,文件MD5 |
72+
| 10 | FileUtils | 文件工具类 | 写入/读取文件相关信息 |
73+
| 11 | FormatViewsUtils | 文本滚动工具 | TextView滚动最新一行 |
74+
| 12 | GlobalDialogUtils | 应用上层弹窗 | SYSTEM_ALERT_WINDOW |
75+
| 13 | HttpUtils | 网络请求工具类 | get,post请求 |
76+
| 14 | JsonFormatUtils | JSON格式化工具 | JSON字符串格式化 |
77+
| 15 | KLog | 日志打印 | 日志标记打印 |
78+
| 16 | KeyBoardUtils | 软键盘管理 | 打开,关闭 |
79+
| 17 | NotifyUtils | 通知工具类 | 自定义 notification,动态调参 |
80+
| 18 | NetUtils | 网络工具类 | 网络类型/状态等获取 |
81+
| 19 | NetMonitorUtils | 网络变化广播 | 网络变化回调 |
82+
| 20 | ObjectUtils | 通用对象管理工具 | 判空,比较,随机 |
83+
| 21 | PermissionsUtils | 权限申请工具类 | 多权限申请 |
84+
| 22 | RegularTools | 正则工具类 | 通用正则结果获取 |
85+
| 23 | SerialPort/SerialPortFinder | 串口相关工具类 | 打开,通讯,关闭 |
86+
| 24 | SPUtils | 存储工具类 | SharedPreferences 读写 |
87+
| 25 | ShellUtils | adb 相关工具类 | adb 命令执行 |
88+
| 26 | ServiceUtils | Service 管理工具 | 启动,停止,判断存活等 |
89+
| 27 | StatusBarUtils | 沉浸式状态栏 | 状态栏变色 |
90+
| 28 | ToastUtils | 系统的 Toast 封装 | 成功,失败,警告等提示 |
91+
| 29 | TimeUtils | 时间工具类 | Date 时间日期转换 |
92+
| 30 | TPoolSingleUtils/TPoolUtils | 线程池管理 | 线程重用 |
93+
| 31 | UriPathUtils | Uri 转真实路径 | android7.0uri 转换 |
94+
| 32 | ZipUtils | 压缩相关 | 压缩解压,批量等 |
95+
| 33 | PopupWindowTools | 气泡提示 | 某个控件的上,下,左,右弹出 |
9596

9697
## base_iotutils 工具调用方式,及图片展示
9798

99+
#### PopupWindowTools 气泡提示
100+
101+
```java
102+
//气泡提示
103+
PopupWindowTools popupWindowTools=new PopupWindowTools(this);
104+
popupWindowTools.setBubbleText("这个一个气泡提示");
105+
popupWindowTools.show(btnView, Gravity.TOP);
106+
107+
//下拉选项菜单
108+
List<String> options = Arrays.asList("选项A", "选项B", "选项C");
109+
PopupWindowTools.showDropdownPopup(this, customButtonGridView.getSelectButton(), options, new OnPopupItemClickListener() {
110+
@Override
111+
public void onItemClick(int position, String itemText) {
112+
// 这里你可以接收到点击项的 position 和文本
113+
Toast.makeText(MainActivity.this, "点击了第 " + position + " 项:" + itemText, Toast.LENGTH_SHORT).show();
114+
}
115+
});
116+
```
117+
98118
#### FileUtils 文件操作 读写,删除,文件大小等
99119

100120
```java

app/src/main/java/com/ichtj/basetools/MainActivity.java

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import android.os.Environment;
77
import android.os.Handler;
88
import android.view.Gravity;
9-
import android.view.View;
109
import android.widget.Button;
10+
import android.widget.Toast;
1111

1212
import androidx.annotation.Nullable;
1313

@@ -32,6 +32,7 @@
3232
import com.face_chtj.base_iotutils.ToastUtils;
3333
import com.face_chtj.base_iotutils.UriPathUtils;
3434
import com.face_chtj.base_iotutils.callback.IDismissListener;
35+
import com.face_chtj.base_iotutils.view.OnPopupItemClickListener;
3536
import com.ichtj.basetools.allapp.AllAppAty;
3637
import com.ichtj.basetools.audio.AudioAty;
3738
import com.ichtj.basetools.base.BaseActivity;
@@ -71,6 +72,7 @@
7172
import com.ichtj.basetools.webviews.WebViewAty;
7273

7374
import java.io.InputStream;
75+
import java.util.Arrays;
7476
import java.util.HashMap;
7577
import java.util.List;
7678
import java.util.Map;
@@ -80,6 +82,7 @@ public class MainActivity extends BaseActivity implements CustomButtonGridView.O
8082
private static final String TAG = MainActivity.class.getSimpleName ( );
8183
private CustomButtonGridView customButtonGridView;
8284
private static final int REQUEST_CODE_INSTALL_UNKNOWN_APPS = 1234;
85+
private int VIEW_FALG=0;
8386
@Override
8487
protected void onCreate(@Nullable Bundle savedInstanceState) {
8588
super.onCreate (savedInstanceState);
@@ -92,18 +95,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
9295

9396
public Map<Integer, String> getDisplayBtn() {
9497
Map<Integer, String> btnList = new HashMap<> ( );
95-
Space ramSpace = null;
96-
try {
97-
ramSpace = FStorageTools.getRamSpace (FStorageTools.TYPE_MB);
98-
} catch (Throwable throwable) {
99-
throwable.printStackTrace ( );
100-
}
101-
Space sdSpace = null;
102-
try {
103-
sdSpace = FStorageTools.getSdcardSpace (FStorageTools.TYPE_MB);
104-
} catch (Throwable throwable) {
105-
throwable.printStackTrace ( );
106-
}
98+
Space ramSpace = FStorageTools.getRamSpace (FStorageTools.TYPE_MB);
99+
Space sdSpace = FStorageTools.getSdcardSpace (FStorageTools.TYPE_MB);
107100
btnList.put (FKey.KEY_IMEI, "IMEI:" + DeviceUtils.getImeiOrMeid ( ));
108101
btnList.put (FKey.KEY_ICCID, "ICCID:" + NetUtils.getLteIccid ( ));
109102
btnList.put (FKey.KEY_SERIAL, getString (R.string.main_serial, OptionTools.getSerialNo ( )));
@@ -115,11 +108,7 @@ public Map<Integer, String> getDisplayBtn() {
115108
btnList.put (FKey.KEY_RAM, getString (R.string.main_running_memory, ramSpace.getTotalSize ( ) + "MB/" + ramSpace.getUseSize ( ) + "MB/" + ramSpace.getAvailableSize ( ) + "MB"));
116109
btnList.put (FKey.KEY_SD_SPACE, getString (R.string.main_sdcard_memory, sdSpace.getTotalSize ( ) + "MB/" + sdSpace.getUseSize ( ) + "MB/" + sdSpace.getAvailableSize ( ) + "MB"));
117110
btnList.put (FKey.KEY_ETH_MODE, getString (R.string.main_eth_mode, FEthTools.getIpMode (BaseIotUtils.getContext ( ))));
118-
try {
119-
btnList.put (FKey.KEY_DBM, getString (R.string.main_lte_dbm, FLteTools.getDbm ( )));
120-
} catch (Throwable throwable) {
121-
btnList.put (FKey.KEY_DBM, getString (R.string.main_lte_dbm, "0 dBm 0 asu"));
122-
}
111+
btnList.put (FKey.KEY_DBM, getString (R.string.main_lte_dbm, FLteTools.getDbm ( )));
123112
btnList.put (FKey.KEY_SERIAL_PORT, getString (R.string.main_serial_rw));
124113
btnList.put (FKey.KEY_TIMERD, getString (R.string.main_timer));
125114
btnList.put (FKey.KEY_SCREEN, getString (R.string.main_screen_about));
@@ -166,6 +155,7 @@ public Map<Integer, String> getDisplayBtn() {
166155
btnList.put (FKey.KEY_MQTT_TEST, getString (R.string.main_test_mqtt));
167156
btnList.put (FKey.KEY_WEBVIEW_TEST, getString (R.string.main_test_webview));
168157
btnList.put (FKey.KEY_POPWINDOW, getString(R.string.main_popwindow_toast));
158+
btnList.put (FKey.KEY_DROP_POPWINDOW, getString(R.string.main_pull_down_option_box));
169159
return btnList;
170160
}
171161

@@ -428,9 +418,31 @@ public void run() {
428418
startAty (WebViewAty.class);
429419
break;
430420
case FKey.KEY_POPWINDOW:
421+
++VIEW_FALG;
422+
int gravityValue=Gravity.TOP;
423+
if (VIEW_FALG==1){
424+
gravityValue=Gravity.BOTTOM;
425+
}else if(VIEW_FALG==2){
426+
gravityValue=Gravity.LEFT;
427+
}else if(VIEW_FALG==3){
428+
gravityValue=Gravity.RIGHT;
429+
}else if(VIEW_FALG>=4){
430+
gravityValue=Gravity.TOP;
431+
VIEW_FALG=0;
432+
}
431433
PopupWindowTools bubblePopupWindow = new PopupWindowTools(MainActivity.this);
432434
bubblePopupWindow.setBubbleText("这是一条气泡消息");
433-
bubblePopupWindow.show(customButtonGridView.getSelectButton(), Gravity.TOP);//view的上部展示
435+
bubblePopupWindow.show(customButtonGridView.getSelectButton(), gravityValue);//view的上部展示
436+
break;
437+
case FKey.KEY_DROP_POPWINDOW:
438+
List<String> options = Arrays.asList("选项A", "选项B", "选项C");
439+
PopupWindowTools.showDropdownPopup(this, customButtonGridView.getSelectButton(), options, new OnPopupItemClickListener() {
440+
@Override
441+
public void onItemClick(int position, String itemText) {
442+
// 这里你可以接收到点击项的 position 和文本
443+
Toast.makeText(MainActivity.this, "点击了第 " + position + " 项:" + itemText, Toast.LENGTH_SHORT).show();
444+
}
445+
});
434446
break;
435447
}
436448
}

app/src/main/java/com/ichtj/basetools/util/FKey.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,5 @@ public class FKey {
5959
public static final int KEY_MQTT_TEST=55;//Mqtt测试
6060
public static final int KEY_WEBVIEW_TEST=56;//WebView测试
6161
public static final int KEY_POPWINDOW=57;//气泡提示
62+
public static final int KEY_DROP_POPWINDOW=58;//下拉选项框
6263
}

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,5 @@
108108
<string name="main_not_found_table_failed">not found table.xls</string>
109109
<string name="main_screenshot_succ_toast">截屏成功,位置:/sdcard/目录下</string>
110110
<string name="main_popwindow_toast">气泡提示</string>
111+
<string name="main_pull_down_option_box">下拉选项框</string>
111112
</resources>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<string name="main_not_found_table_failed">not found table.xls</string>
111111
<string name="main_screenshot_succ_toast">截屏成功,位置:/sdcard/目录下</string>
112112
<string name="main_popwindow_toast">气泡提示</string>
113+
<string name="main_pull_down_option_box">下拉选项框</string>
113114
<declare-styleable name="TopTitleView">
114115
<attr name="name" format="string"></attr>
115116
<attr name="rightName" format="string"></attr>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.face_chtj.base_iotutils.view;
2+
3+
public interface OnPopupItemClickListener {
4+
void onItemClick(int position, String itemText);
5+
}

base_iotutils/src/main/java/com/face_chtj/base_iotutils/view/PopupWindowTools.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@
99
import android.graphics.drawable.ColorDrawable;
1010
import android.os.Build;
1111
import android.view.Gravity;
12+
import android.view.LayoutInflater;
1213
import android.view.View;
1314
import android.view.ViewGroup;
1415
import android.view.WindowManager;
16+
import android.widget.AdapterView;
17+
import android.widget.ArrayAdapter;
18+
import android.widget.ListView;
1519
import android.widget.PopupWindow;
1620
import android.widget.TextView;
1721

22+
import androidx.core.content.ContextCompat;
23+
1824
import com.face_chtj.base_iotutils.R;
1925

26+
import java.util.List;
27+
2028
public class PopupWindowTools extends PopupWindow {
2129
public static int DEFAULT_MARGIN;
2230
private BubbleLayout bubbleView;
@@ -166,6 +174,42 @@ public void setYOffset(int yOffset) {
166174
mYOffset = yOffset;
167175
}
168176

177+
public static void showDropdownPopup(Context context, View anchorView, final List<String> items, final OnPopupItemClickListener listener) {
178+
// 创建 ListView
179+
ListView listView = new ListView(context);
180+
listView.setBackgroundColor(Color.WHITE);
181+
listView.setBackground(ContextCompat.getDrawable(context,R.drawable.ic_popwindon_bg));
182+
listView.setDivider(new ColorDrawable(Color.LTGRAY));
183+
listView.setDividerHeight(1);
184+
listView.setPadding(10, 10, 10, 10);
185+
186+
// 设置适配器
187+
ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, items);
188+
listView.setAdapter(adapter);
189+
190+
// 创建 PopupWindow,宽度与锚定控件一致
191+
final PopupWindow popupWindow = new PopupWindow(listView,
192+
anchorView.getWidth(),
193+
WindowManager.LayoutParams.WRAP_CONTENT,
194+
true);
195+
196+
popupWindow.setOutsideTouchable(true);
197+
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
198+
199+
// 设置点击事件回调
200+
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
201+
@Override
202+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
203+
popupWindow.dismiss(); // 先关闭
204+
if (listener != null) {
205+
listener.onItemClick(position, items.get(position));
206+
}
207+
}
208+
});
209+
210+
// 显示下拉菜单
211+
popupWindow.showAsDropDown(anchorView, 0, 0, Gravity.START);
212+
}
169213

170214
/**
171215
* @param parent 展示的view
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
3+
<stroke android:width="1dp" android:color="@color/gray"/>
4+
<solid android:color="@color/white" />
5+
<corners android:radius="10dp" android:topRightRadius="0dp" android:topLeftRadius="0dp"/>
6+
</shape>

0 commit comments

Comments
 (0)