Hide usb mode chooser dialog after disconnected
Add a UsbDisconnectedReceiver to listen usb state event, and hide the usb mode chooser dialog if usb disconnected. Change-Id: I871f56cb5a310e20950926180d9747dd9fad9754 Signed-off-by: Du, Changbin <changbin.du@intel.com> Signed-off-by: Zhiquan Liu <zhiquan.liu@intel.com>
This commit is contained in:
committed by
Zhiquan Liu
parent
142193550e
commit
93df36a1c7
@@ -20,7 +20,12 @@ import android.annotation.Nullable;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -49,6 +54,19 @@ public class UsbModeChooserActivity extends Activity {
|
||||
private AlertDialog mDialog;
|
||||
private LayoutInflater mLayoutInflater;
|
||||
|
||||
private BroadcastReceiver mDisconnectedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (UsbManager.ACTION_USB_STATE.equals(action)) {
|
||||
boolean connected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
|
||||
if (!connected) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
||||
@@ -84,6 +102,20 @@ public class UsbModeChooserActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
IntentFilter filter = new IntentFilter(UsbManager.ACTION_USB_STATE);
|
||||
registerReceiver(mDisconnectedReceiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
unregisterReceiver(mDisconnectedReceiver);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
private void inflateOption(final int mode, boolean selected, LinearLayout container) {
|
||||
View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);
|
||||
|
||||
|
Reference in New Issue
Block a user