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