Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui.base; | 5 package org.chromium.ui.base; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
| 9 import android.content.ActivityNotFoundException; | 9 import android.content.ActivityNotFoundException; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 activity.startActivityForResult(intent, requestCode); | 123 activity.startActivityForResult(intent, requestCode); |
| 124 } catch (ActivityNotFoundException e) { | 124 } catch (ActivityNotFoundException e) { |
| 125 return START_INTENT_FAILURE; | 125 return START_INTENT_FAILURE; |
| 126 } | 126 } |
| 127 | 127 |
| 128 storeCallbackData(requestCode, callback, errorId); | 128 storeCallbackData(requestCode, callback, errorId); |
| 129 return requestCode; | 129 return requestCode; |
| 130 } | 130 } |
| 131 | 131 |
| 132 @Override | 132 @Override |
| 133 public int addIntentCallback(IntentCallback callback, Integer errorId) { | |
|
Ted C
2016/04/19 21:30:24
I'd be tempted to do something more like this:
pu
| |
| 134 Activity activity = getActivity().get(); | |
| 135 if (activity == null) return START_INTENT_FAILURE; | |
| 136 | |
| 137 int requestCode = generateNextRequestCode(); | |
| 138 | |
| 139 storeCallbackData(requestCode, callback, errorId); | |
| 140 return requestCode; | |
| 141 } | |
| 142 | |
| 143 @Override | |
| 133 public void cancelIntent(int requestCode) { | 144 public void cancelIntent(int requestCode) { |
| 134 Activity activity = getActivity().get(); | 145 Activity activity = getActivity().get(); |
| 135 if (activity == null) return; | 146 if (activity == null) return; |
| 136 activity.finishActivity(requestCode); | 147 activity.finishActivity(requestCode); |
| 137 } | 148 } |
| 138 | 149 |
| 139 /** | 150 /** |
| 140 * Responds to the intent result if the intent was created by the native win dow. | 151 * Responds to the intent result if the intent was created by the native win dow. |
| 141 * @param requestCode Request code of the requested intent. | 152 * @param requestCode Request code of the requested intent. |
| 142 * @param resultCode Result code of the requested intent. | 153 * @param resultCode Result code of the requested intent. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 Activity activity = getActivity().get(); | 327 Activity activity = getActivity().get(); |
| 317 if (activity == null) return false; | 328 if (activity == null) return false; |
| 318 | 329 |
| 319 int requestCode = generateNextRequestCode(); | 330 int requestCode = generateNextRequestCode(); |
| 320 mOutstandingPermissionRequests.put(requestCode, callback); | 331 mOutstandingPermissionRequests.put(requestCode, callback); |
| 321 activity.requestPermissions(permissions, requestCode); | 332 activity.requestPermissions(permissions, requestCode); |
| 322 return true; | 333 return true; |
| 323 } | 334 } |
| 324 } | 335 } |
| 325 } | 336 } |
| OLD | NEW |