ActionBarActivityDelegateHC.java revision 0bf48858279237f95d6aad565a074490745491cd
1/*
2 * Copyright (C) 2013 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
17package android.support.v7.app;
18
19import android.annotation.TargetApi;
20import android.content.Context;
21import android.os.Build;
22import android.support.v7.appcompat.R;
23import android.support.v7.internal.view.SupportActionModeWrapper;
24import android.support.v7.internal.widget.NativeActionModeAwareLayout;
25import android.view.ActionMode;
26import android.view.View;
27
28@TargetApi(Build.VERSION_CODES.HONEYCOMB)
29class ActionBarActivityDelegateHC extends ActionBarActivityDelegateBase
30        implements NativeActionModeAwareLayout.OnActionModeForChildListener {
31
32    private NativeActionModeAwareLayout mNativeActionModeAwareLayout;
33
34    ActionBarActivityDelegateHC(ActionBarActivity activity) {
35        super(activity);
36    }
37
38    @Override
39    void onSubDecorInstalled() {
40        // NativeActionModeAwareLayout is used to notify us when a native Action Mode is started
41        mNativeActionModeAwareLayout = (NativeActionModeAwareLayout) mActivity
42                .findViewById(R.id.action_bar_root);
43
44        // Can be null when using FEATURE_ACTION_BAR_OVERLAY
45        if (mNativeActionModeAwareLayout != null) {
46            mNativeActionModeAwareLayout.setActionModeForChildListener(this);
47        }
48    }
49
50    // From NativeActionModeAwareLayout.OnActionModeForChildListener
51    @Override
52    public ActionMode startActionModeForChild(View originalView, ActionMode.Callback callback) {
53        Context context = originalView.getContext();
54
55        // Try and start a support action mode, wrapping the callback
56        final android.support.v7.view.ActionMode supportActionMode = startSupportActionMode(
57                new SupportActionModeWrapper.CallbackWrapper(context, callback));
58
59        if (supportActionMode != null) {
60            // If we received a support action mode, wrap and return it
61            return new SupportActionModeWrapper(mActivity, supportActionMode);
62        }
63        return null;
64    }
65}
66