• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 
17 package android.support.v4.app;
18 
19 import android.content.Intent;
20 import android.content.IntentSender;
21 import android.os.Bundle;
22 import android.support.annotation.Nullable;
23 
24 /**
25  * Base class for {@code FragmentActivity} to be able to use v16 APIs.
26  *
27  * @hide
28  */
29 abstract class BaseFragmentActivityJB extends BaseFragmentActivityHoneycomb {
30 
31     // We need to keep track of whether startActivityForResult originated from a Fragment, so we
32     // can conditionally check whether the requestCode collides with our reserved ID space for the
33     // request index (see above). Unfortunately we can't just call
34     // super.startActivityForResult(...) to bypass the check when the call didn't come from a
35     // fragment, since we need to use the ActivityCompat version for backward compatibility.
36     boolean mStartedActivityFromFragment;
37 
38     @Override
startActivityForResult(Intent intent, int requestCode, @Nullable Bundle options)39     public void startActivityForResult(Intent intent, int requestCode,
40             @Nullable Bundle options) {
41         // If this was started from a Fragment we've already checked the upper 16 bits were not in
42         // use, and then repurposed them for the Fragment's index.
43         if (!mStartedActivityFromFragment) {
44             if (requestCode != -1) {
45                 checkForValidRequestCode(requestCode);
46             }
47         }
48         super.startActivityForResult(intent, requestCode, options);
49     }
50 
51     @Override
startIntentSenderForResult(IntentSender intent, int requestCode, @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)52     public void startIntentSenderForResult(IntentSender intent, int requestCode,
53             @Nullable Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags,
54             Bundle options) throws IntentSender.SendIntentException {
55         // If this was started from a Fragment we've already checked the upper 16 bits were not in
56         // use, and then repurposed them for the Fragment's index.
57         if (!mStartedIntentSenderFromFragment) {
58             if (requestCode != -1) {
59                 checkForValidRequestCode(requestCode);
60             }
61         }
62         super.startIntentSenderForResult(intent, requestCode, fillInIntent, flagsMask, flagsValues,
63                 extraFlags, options);
64     }
65 }
66