1/* 2 * Copyright (C) 2015 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.content.Context; 20import android.view.ActionMode; 21import android.view.Window; 22 23class AppCompatDelegateImplV23 extends AppCompatDelegateImplV14 { 24 25 AppCompatDelegateImplV23(Context context, Window window, AppCompatCallback callback) { 26 super(context, window, callback); 27 } 28 29 @Override 30 Window.Callback wrapWindowCallback(Window.Callback callback) { 31 // Override the window callback so that we can intercept onWindowStartingActionMode(type) 32 // calls 33 return new AppCompatWindowCallbackV23(callback); 34 } 35 36 class AppCompatWindowCallbackV23 extends AppCompatWindowCallbackV14 { 37 AppCompatWindowCallbackV23(Window.Callback callback) { 38 super(callback); 39 } 40 41 @Override 42 public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int type) { 43 if (isHandleNativeActionModesEnabled()) { 44 switch (type) { 45 case ActionMode.TYPE_PRIMARY: 46 // We only take over if the type is TYPE_PRIMARY 47 return startAsSupportActionMode(callback); 48 } 49 } 50 // Else, let the call fall through to the wrapped callback 51 return super.onWindowStartingActionMode(callback, type); 52 } 53 54 @Override 55 public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) { 56 // No-op on API 23+ 57 return null; 58 } 59 } 60} 61