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

Commit 7af238e1 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Add support for MIDI USB configuration to MIDI settings screen

Change-Id: I41b7ef2090b8887d5d3c05494de9dd1fb4dd65eb
parent 9a9c3615
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -2276,10 +2276,12 @@
    <string name="usb_mtp_summary">Lets you transfer media files on Windows, or using Android File Transfer on Mac (see www.android.com/filetransfer)</string>
    <!-- Storage setting.  Title for PTP checkbox [CHAR LIMIT=30]-->
    <string name="usb_ptp_title">Camera (PTP)</string>
    <!-- Storage setting.  Label for installer CD [CHAR LIMIT=30]-->
    <string name="usb_ptp_summary">Lets you transfer photos using camera software, and transfer any files on computers that don\'t support MTP</string>
    <!-- Storage setting.  Summary for PTP checkbox [CHAR LIMIT=NONE]-->
    <string name="usb_label_installer_cd">"Install file-transfer tools"</string>
    <string name="usb_ptp_summary">Lets you transfer photos using camera software, and transfer any files on computers that don\'t support MTP</string>
    <!-- Storage setting.  Title for MIDI checkbox [CHAR LIMIT=30]-->
    <string name="usb_midi_title">MIDI</string>
    <!-- Storage setting.  Summary for MIDI checkbox [CHAR LIMIT=NONE]-->
    <string name="usb_midi_summary">Lets MIDI enabled applications work over USB with MIDI software on your computer.</string>

    <!-- Section header above list of other users storage [CHAR LIMIT=32] -->
    <string name="storage_other_users">Other users</string>
+6 −0
Original line number Diff line number Diff line
@@ -32,4 +32,10 @@
        android:summary="@string/usb_ptp_summary"
        />

    <CheckBoxPreference
        android:key="usb_midi"
        android:title="@string/usb_midi_title"
        android:summary="@string/usb_midi_summary"
        />

</PreferenceScreen>
+15 −0
Original line number Diff line number Diff line
@@ -41,10 +41,12 @@ public class UsbSettings extends SettingsPreferenceFragment {

    private static final String KEY_MTP = "usb_mtp";
    private static final String KEY_PTP = "usb_ptp";
    private static final String KEY_MIDI = "usb_midi";

    private UsbManager mUsbManager;
    private CheckBoxPreference mMtp;
    private CheckBoxPreference mPtp;
    private CheckBoxPreference mMidi;
    private boolean mUsbAccessoryMode;

    private final BroadcastReceiver mStateReceiver = new BroadcastReceiver() {
@@ -68,6 +70,7 @@ public class UsbSettings extends SettingsPreferenceFragment {

        mMtp = (CheckBoxPreference)root.findPreference(KEY_MTP);
        mPtp = (CheckBoxPreference)root.findPreference(KEY_PTP);
        mMidi = (CheckBoxPreference)root.findPreference(KEY_MIDI);

        UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
        if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
@@ -107,27 +110,37 @@ public class UsbSettings extends SettingsPreferenceFragment {
        if (UsbManager.USB_FUNCTION_MTP.equals(function)) {
            mMtp.setChecked(true);
            mPtp.setChecked(false);
            mMidi.setChecked(false);
        } else if (UsbManager.USB_FUNCTION_PTP.equals(function)) {
            mMtp.setChecked(false);
            mPtp.setChecked(true);
            mMidi.setChecked(false);
        } else if (UsbManager.USB_FUNCTION_MIDI.equals(function)) {
            mMtp.setChecked(false);
            mPtp.setChecked(false);
            mMidi.setChecked(true);
        } else  {
            mMtp.setChecked(false);
            mPtp.setChecked(false);
            mMidi.setChecked(false);
        }
        UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
        if (um.hasUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER)) {
            Log.e(TAG, "USB is locked down");
            mMtp.setEnabled(false);
            mPtp.setEnabled(false);
            mMidi.setEnabled(true);
        } else if (!mUsbAccessoryMode) {
            //Enable MTP and PTP switch while USB is not in Accessory Mode, otherwise disable it
            Log.e(TAG, "USB Normal Mode");
            mMtp.setEnabled(true);
            mPtp.setEnabled(true);
            mMidi.setEnabled(true);
        } else {
            Log.e(TAG, "USB Accessory Mode");
            mMtp.setEnabled(false);
            mPtp.setEnabled(false);
            mMidi.setEnabled(false);
        }
    }

@@ -151,6 +164,8 @@ public class UsbSettings extends SettingsPreferenceFragment {
            function = UsbManager.USB_FUNCTION_MTP;
        } else if (preference == mPtp && mPtp.isChecked()) {
            function = UsbManager.USB_FUNCTION_PTP;
        } else if (preference == mMidi && mMidi.isChecked()) {
            function = UsbManager.USB_FUNCTION_MIDI;
        }

        mUsbManager.setCurrentFunction(function, true);