极力推荐文章:欢迎收藏
阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android
本篇文章主要介绍 Android
开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
一、实现效果
一、实现效果
仿华为USB Mode
弹窗实现效果如下:
底部USB mode 弹窗实现
二、主要实现思路
主要实现思路如下:USB
发送/取消通知的同时,控制弹窗Dialog
的显示/消失。
三、主要实现代码
连接USB
发送/取消通知主要实现是在UsbDeviceManager.java
类中,类路径如下:frameworks\base\services\usb\java\com\android\server\usb\UsbDeviceManager.java
,通过查看此类代码,实现想要的功能。
// add start by wj for usb mode
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.view.WindowManager;
import android.view.Gravity;
// add end by wj for usb mode
/**
* UsbDeviceManager manages USB state in device mode.
*/
public class UsbDeviceManager implements ActivityManagerInternal.ScreenObserver {
private static final String TAG = UsbDeviceManager.class.getSimpleName();
... ...
// add start by wj for usb mode
private static UsbHandler mHandler;
private static AlertDialog mServiceDialog = null;
// add end by wj for usb mode
... ...
protected void updateUsbNotification(boolean force) {
if (mNotificationManager == null || !mUseUsbNotification
|| ("0".equals(getSystemProperty("persist.charging.notify", "")))) {
return;
}
// Dont show the notification when connected to a USB peripheral
// and the link does not support PR_SWAP and DR_SWAP
if (mHideUsbNotification && !mSupportsAllCombinations) {
if (mUsbNotificationId != 0) {
mNotificationManager.cancelAsUser(null, mUsbNotificationId,
UserHandle.ALL);
mUsbNotificationId = 0;
Slog.d(TAG, "Clear notification");
}
return;
}
int id = 0;
int titleRes = 0;
Resources r = mContext.getResources();
CharSequence message = r.getText(
com.android