The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Daniel Lehmann | 72af89f | 2010-10-18 15:15:59 -0700 | [diff] [blame] | 17 | package com.android.contacts.activities; |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 21 | import android.app.Dialog; |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 22 | import android.content.ComponentName; |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 23 | import android.content.DialogInterface; |
| 24 | import android.content.Intent; |
| 25 | import android.database.Cursor; |
| 26 | import android.net.Uri; |
| 27 | import android.os.Bundle; |
Daniel Lehmann | afeae64 | 2010-10-18 14:40:53 -0700 | [diff] [blame] | 28 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Dmitri Plotnikov | e1cd679 | 2009-07-27 20:28:17 -0700 | [diff] [blame] | 29 | import android.provider.ContactsContract.Contacts; |
Jeff Sharkey | 3f0b7b8 | 2009-08-12 11:28:53 -0700 | [diff] [blame] | 30 | import android.provider.ContactsContract.Intents; |
Jeff Sharkey | 3926127 | 2009-06-03 19:15:09 -0700 | [diff] [blame] | 31 | import android.provider.ContactsContract.PhoneLookup; |
Jeff Sharkey | 3f0b7b8 | 2009-08-12 11:28:53 -0700 | [diff] [blame] | 32 | import android.provider.ContactsContract.RawContacts; |
Tyler Gunn | 0319222 | 2014-09-10 15:20:09 -0700 | [diff] [blame] | 33 | import android.telecom.PhoneAccount; |
Jay Shrauner | e320c0b | 2015-03-05 12:45:18 -0800 | [diff] [blame] | 34 | import android.text.TextUtils; |
Jeff Sharkey | 73714ff | 2009-08-23 22:13:04 -0700 | [diff] [blame] | 35 | import android.util.Log; |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 36 | |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 37 | import com.android.contacts.common.ContactsUtils; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 38 | import com.android.contacts.ContactsActivity; |
| 39 | import com.android.contacts.R; |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 40 | import com.android.contacts.common.activity.RequestPermissionsActivity; |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 41 | import com.android.contacts.common.util.ImplicitIntentsUtil; |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 42 | import com.android.contacts.util.NotifyingAsyncQueryHandler; |
| 43 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 44 | /** |
| 45 | * Handle several edge cases around showing or possibly creating contacts in |
| 46 | * connected with a specific E-mail address or phone number. Will search based |
| 47 | * on incoming {@link Intent#getData()} as described by |
Jeff Sharkey | 73714ff | 2009-08-23 22:13:04 -0700 | [diff] [blame] | 48 | * {@link Intents#SHOW_OR_CREATE_CONTACT}. |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 49 | * <ul> |
| 50 | * <li>If no matching contacts found, will prompt user with dialog to add to a |
| 51 | * contact, then will use {@link Intent#ACTION_INSERT_OR_EDIT} to let create new |
| 52 | * contact or edit new data into an existing one. |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 53 | * <li>If one matching contact found, directly show {@link Intent#ACTION_VIEW} |
| 54 | * that specific contact. |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 55 | * <li>If more than one matching found, show list of matching contacts using |
| 56 | * {@link Intent#ACTION_SEARCH}. |
| 57 | * </ul> |
| 58 | */ |
Dmitri Plotnikov | 6f667b5 | 2011-01-09 12:53:13 -0800 | [diff] [blame] | 59 | public final class ShowOrCreateActivity extends ContactsActivity |
| 60 | implements NotifyingAsyncQueryHandler.AsyncQueryListener { |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 61 | static final String TAG = "ShowOrCreateActivity"; |
| 62 | static final boolean LOGD = false; |
| 63 | |
| 64 | static final String[] PHONES_PROJECTION = new String[] { |
Jeff Sharkey | 3926127 | 2009-06-03 19:15:09 -0700 | [diff] [blame] | 65 | PhoneLookup._ID, |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 66 | PhoneLookup.LOOKUP_KEY, |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 69 | static final String[] CONTACTS_PROJECTION = new String[] { |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 70 | Email.CONTACT_ID, |
| 71 | Email.LOOKUP_KEY, |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 72 | }; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 73 | |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 74 | static final int CONTACT_ID_INDEX = 0; |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 75 | static final int LOOKUP_KEY_INDEX = 1; |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 76 | |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 77 | static final int CREATE_CONTACT_DIALOG = 1; |
| 78 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 79 | static final int QUERY_TOKEN = 42; |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 80 | |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 81 | private NotifyingAsyncQueryHandler mQueryHandler; |
| 82 | |
| 83 | private Bundle mCreateExtras; |
| 84 | private String mCreateDescrip; |
| 85 | private boolean mCreateForce; |
| 86 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 87 | @Override |
| 88 | protected void onCreate(Bundle icicle) { |
| 89 | super.onCreate(icicle); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 90 | |
Brian Attwell | bdd3264 | 2015-05-08 17:03:15 -0700 | [diff] [blame] | 91 | if (RequestPermissionsActivity.startPermissionActivity(this)) { |
| 92 | return; |
| 93 | } |
| 94 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 95 | // Create handler if doesn't exist, otherwise cancel any running |
| 96 | if (mQueryHandler == null) { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 97 | mQueryHandler = new NotifyingAsyncQueryHandler(this, this); |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 98 | } else { |
| 99 | mQueryHandler.cancelOperation(QUERY_TOKEN); |
| 100 | } |
| 101 | |
| 102 | final Intent intent = getIntent(); |
| 103 | final Uri data = intent.getData(); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 104 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 105 | // Unpack scheme and target data from intent |
| 106 | String scheme = null; |
| 107 | String ssp = null; |
| 108 | if (data != null) { |
| 109 | scheme = data.getScheme(); |
| 110 | ssp = data.getSchemeSpecificPart(); |
| 111 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 112 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 113 | // Build set of extras for possible use when creating contact |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 114 | mCreateExtras = new Bundle(); |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 115 | Bundle originalExtras = intent.getExtras(); |
| 116 | if (originalExtras != null) { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 117 | mCreateExtras.putAll(originalExtras); |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 118 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 119 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 120 | // Read possible extra with specific title |
Jeff Sharkey | 549aa16 | 2009-05-21 01:33:30 -0700 | [diff] [blame] | 121 | mCreateDescrip = intent.getStringExtra(Intents.EXTRA_CREATE_DESCRIPTION); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 122 | if (mCreateDescrip == null) { |
| 123 | mCreateDescrip = ssp; |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 124 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 125 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 126 | // Allow caller to bypass dialog prompt |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 127 | mCreateForce = intent.getBooleanExtra(Intents.EXTRA_FORCE_CREATE, false); |
| 128 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 129 | // Handle specific query request |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 130 | if (ContactsUtils.SCHEME_MAILTO.equals(scheme)) { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 131 | mCreateExtras.putString(Intents.Insert.EMAIL, ssp); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 132 | |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 133 | Uri uri = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, Uri.encode(ssp)); |
Jeff Sharkey | 3926127 | 2009-06-03 19:15:09 -0700 | [diff] [blame] | 134 | mQueryHandler.startQuery(QUERY_TOKEN, null, uri, CONTACTS_PROJECTION, null, null, null); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 135 | |
Jay Shrauner | 1cd88e3 | 2014-09-05 15:37:55 -0700 | [diff] [blame] | 136 | } else if (PhoneAccount.SCHEME_TEL.equals(scheme)) { |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 137 | mCreateExtras.putString(Intents.Insert.PHONE, ssp); |
Jeff Sharkey | 3926127 | 2009-06-03 19:15:09 -0700 | [diff] [blame] | 138 | |
| 139 | Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, ssp); |
| 140 | mQueryHandler.startQuery(QUERY_TOKEN, null, uri, PHONES_PROJECTION, null, null, null); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 141 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 142 | } else { |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 143 | Log.w(TAG, "Invalid intent:" + getIntent()); |
| 144 | finish(); |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 145 | } |
| 146 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 147 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 148 | @Override |
| 149 | protected void onStop() { |
| 150 | super.onStop(); |
| 151 | if (mQueryHandler != null) { |
| 152 | mQueryHandler.cancelOperation(QUERY_TOKEN); |
| 153 | } |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Jeff Sharkey | 3f0b7b8 | 2009-08-12 11:28:53 -0700 | [diff] [blame] | 156 | /** {@inheritDoc} */ |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 157 | public void onQueryComplete(int token, Object cookie, Cursor cursor) { |
| 158 | if (cursor == null) { |
Jeff Sharkey | 2409705 | 2009-08-24 15:27:31 -0700 | [diff] [blame] | 159 | // Bail when problem running query in background |
| 160 | finish(); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
| 163 | |
| 164 | // Count contacts found by query |
| 165 | int count = 0; |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 166 | long contactId = -1; |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 167 | String lookupKey = null; |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 168 | try { |
| 169 | count = cursor.getCount(); |
| 170 | if (count == 1 && cursor.moveToFirst()) { |
| 171 | // Try reading ID if only one contact returned |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 172 | contactId = cursor.getLong(CONTACT_ID_INDEX); |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 173 | lookupKey = cursor.getString(LOOKUP_KEY_INDEX); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 174 | } |
| 175 | } finally { |
| 176 | cursor.close(); |
| 177 | } |
| 178 | |
Jay Shrauner | e320c0b | 2015-03-05 12:45:18 -0800 | [diff] [blame] | 179 | if (count == 1 && contactId != -1 && !TextUtils.isEmpty(lookupKey)) { |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 180 | // If we only found one item, jump right to viewing it |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 181 | final Uri contactUri = Contacts.getLookupUri(contactId, lookupKey); |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 182 | final Intent viewIntent = new Intent(Intent.ACTION_VIEW, contactUri); |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 183 | ImplicitIntentsUtil.startActivityInApp(this, viewIntent); |
Jeff Sharkey | e897162 | 2009-09-17 15:42:36 -0700 | [diff] [blame] | 184 | finish(); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 185 | |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 186 | } else if (count > 1) { |
| 187 | // If more than one, show pick list |
| 188 | Intent listIntent = new Intent(Intent.ACTION_SEARCH); |
Katherine Kuan | 9856fce | 2011-06-01 10:24:09 -0700 | [diff] [blame] | 189 | listIntent.setComponent(new ComponentName(this, PeopleActivity.class)); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 190 | listIntent.putExtras(mCreateExtras); |
| 191 | startActivity(listIntent); |
| 192 | finish(); |
| 193 | |
| 194 | } else { |
| 195 | // No matching contacts found |
| 196 | if (mCreateForce) { |
| 197 | // Forced to create new contact |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 198 | Intent createIntent = new Intent(Intent.ACTION_INSERT, RawContacts.CONTENT_URI); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 199 | createIntent.putExtras(mCreateExtras); |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 200 | createIntent.setType(RawContacts.CONTENT_TYPE); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 201 | |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 202 | ImplicitIntentsUtil.startActivityInApp(this, createIntent); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 203 | finish(); |
| 204 | |
| 205 | } else { |
Dmitri Plotnikov | 7d40224 | 2011-01-09 16:52:08 -0800 | [diff] [blame] | 206 | showDialog(CREATE_CONTACT_DIALOG); |
| 207 | } |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | protected Dialog onCreateDialog(int id) { |
| 213 | switch(id) { |
| 214 | case CREATE_CONTACT_DIALOG: |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 215 | // Prompt user to insert or edit contact |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 216 | final Intent createIntent = new Intent(Intent.ACTION_INSERT_OR_EDIT); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 217 | createIntent.putExtras(mCreateExtras); |
Dmitri Plotnikov | 3946659 | 2009-07-27 11:23:51 -0700 | [diff] [blame] | 218 | createIntent.setType(RawContacts.CONTENT_ITEM_TYPE); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 219 | |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 220 | final CharSequence message = getResources().getString( |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 221 | R.string.add_contact_dlg_message_fmt, mCreateDescrip); |
| 222 | |
Brian Attwell | 53e4201 | 2014-10-22 11:15:14 -0700 | [diff] [blame] | 223 | return new AlertDialog.Builder(this) |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 224 | .setMessage(message) |
| 225 | .setPositiveButton(android.R.string.ok, |
| 226 | new IntentClickListener(this, createIntent)) |
| 227 | .setNegativeButton(android.R.string.cancel, |
| 228 | new IntentClickListener(this, null)) |
Makoto Onuki | 3b10fd0 | 2010-11-15 16:12:12 -0800 | [diff] [blame] | 229 | .setOnCancelListener(new DialogInterface.OnCancelListener() { |
| 230 | @Override |
| 231 | public void onCancel(DialogInterface dialog) { |
| 232 | finish(); // Close the activity. |
| 233 | }}) |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 234 | .create(); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 235 | } |
Megha Joshi | fdaff64 | 2009-09-23 03:21:07 -0700 | [diff] [blame] | 236 | return super.onCreateDialog(id); |
Jeff Sharkey | 3f17759 | 2009-05-18 15:23:12 -0700 | [diff] [blame] | 237 | } |
| 238 | |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 239 | /** |
| 240 | * Listener for {@link DialogInterface} that launches a given {@link Intent} |
| 241 | * when clicked. When clicked, this also closes the parent using |
| 242 | * {@link Activity#finish()}. |
| 243 | */ |
| 244 | private static class IntentClickListener implements DialogInterface.OnClickListener { |
| 245 | private Activity mParent; |
| 246 | private Intent mIntent; |
| 247 | |
| 248 | /** |
| 249 | * @param parent {@link Activity} to use for launching target. |
| 250 | * @param intent Target {@link Intent} to launch when clicked. |
| 251 | */ |
| 252 | public IntentClickListener(Activity parent, Intent intent) { |
| 253 | mParent = parent; |
| 254 | mIntent = intent; |
| 255 | } |
| 256 | |
| 257 | public void onClick(DialogInterface dialog, int which) { |
| 258 | if (mIntent != null) { |
Brian Attwell | c6100ff | 2015-02-19 21:35:36 -0800 | [diff] [blame] | 259 | ImplicitIntentsUtil.startActivityInApp(mParent, mIntent); |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 260 | } |
| 261 | mParent.finish(); |
| 262 | } |
| 263 | } |
The Android Open Source Project | 37a16ac | 2009-03-18 17:39:48 -0700 | [diff] [blame] | 264 | } |