Merge "Hide usb mode chooser dialog after disconnected"
am: b913bf926e
* commit 'b913bf926e04280d0864cc36c759eddf88cf8b21':
Hide usb mode chooser dialog after disconnected
This commit is contained in:
@@ -20,7 +20,12 @@ import android.annotation.Nullable;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.hardware.usb.UsbManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -49,6 +54,19 @@ public class UsbModeChooserActivity extends Activity {
|
|||||||
private AlertDialog mDialog;
|
private AlertDialog mDialog;
|
||||||
private LayoutInflater mLayoutInflater;
|
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
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
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) {
|
private void inflateOption(final int mode, boolean selected, LinearLayout container) {
|
||||||
View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);
|
View v = mLayoutInflater.inflate(R.layout.radio_with_summary, container, false);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user