diff options
author | Mike Lockwood <lockwood@android.com> | 2011-03-10 12:12:31 -0500 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2011-03-10 14:35:33 -0500 |
commit | 024b4f14945bd2a285f730faa3a0fdbb6c47abc1 (patch) | |
tree | 6bb68d7fe716e9d5b41512e504f51216e6983822 /packages/SystemUI/src/com/android/systemui/usb | |
parent | 0837fde9fd9e29f8ef66a3fe00764e15a6f3d515 (diff) | |
download | frameworks_base-024b4f14945bd2a285f730faa3a0fdbb6c47abc1.zip frameworks_base-024b4f14945bd2a285f730faa3a0fdbb6c47abc1.tar.gz frameworks_base-024b4f14945bd2a285f730faa3a0fdbb6c47abc1.tar.bz2 |
Support for USB accessory URIs
If a USB accessory is attached and we have no application that supports it,
display a dialog offering the user the option to visit the accessory's website
if the accessory has a URI.
Bug: 4073248
Change-Id: I30e2a802493fb6e203532a7f79402379c40bc3b8
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/usb')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/usb/UsbAccessoryUriActivity.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbAccessoryUriActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbAccessoryUriActivity.java new file mode 100644 index 0000000..eefb1c6 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbAccessoryUriActivity.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.usb; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.ActivityNotFoundException; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.hardware.usb.UsbAccessory; +import android.hardware.usb.UsbManager; +import android.os.Bundle; +import android.util.Log; + +import com.android.internal.app.AlertActivity; +import com.android.internal.app.AlertController; + +import com.android.systemui.R; + +/** + * If the attached USB accessory has a URL associated with it, and that URL is valid, + * show this dialog to the user to allow them to optionally visit that URL for more + * information or software downloads. + * Otherwise (no valid URL) this activity does nothing at all, finishing immediately. + */ +public class UsbAccessoryUriActivity extends AlertActivity + implements DialogInterface.OnClickListener { + + private static final String TAG = "UsbAccessoryUriActivity"; + + private UsbAccessory mAccessory; + private Uri mUri; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + Intent intent = getIntent(); + mAccessory = (UsbAccessory)intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY); + String uriString = intent.getStringExtra("uri"); + mUri = (uriString == null ? null : Uri.parse(uriString)); + + // sanity check before displaying dialog + if (mUri == null) { + Log.e(TAG, "could not parse Uri " + uriString); + finish(); + return; + } + String scheme = mUri.getScheme(); + if (!"http".equals(scheme) && !"https".equals(scheme)) { + Log.e(TAG, "Uri not http or https: " + mUri); + finish(); + return; + } + + final AlertController.AlertParams ap = mAlertParams; + ap.mTitle = mAccessory.getDescription(); + if (ap.mTitle == null || ap.mTitle.length() == 0) { + ap.mTitle = getString(R.string.title_usb_accessory); + } + ap.mMessage = getString(R.string.usb_accessory_uri_prompt, mUri); + ap.mPositiveButtonText = getString(R.string.label_view); + ap.mNegativeButtonText = getString(R.string.label_ignore); + ap.mPositiveButtonListener = this; + ap.mNegativeButtonListener = this; + + setupAlert(); + } + + public void onClick(DialogInterface dialog, int which) { + if (which == AlertDialog.BUTTON_POSITIVE) { + // launch the browser + Intent intent = new Intent(Intent.ACTION_VIEW, mUri); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + try { + startActivity(intent); + } catch (ActivityNotFoundException e) { + Log.e(TAG, "startActivity failed for " + mUri); + } + } + finish(); + } +} |