Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93df36a1 authored by Du, Changbin's avatar Du, Changbin Committed by Zhiquan Liu
Browse files

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: default avatarDu, Changbin <changbin.du@intel.com>
Signed-off-by: default avatarZhiquan Liu <zhiquan.liu@intel.com>
parent 14219355
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -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);