1/* 2 * Copyright (C) 2012 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.internal.view; 18 19import android.content.Context; 20import android.content.res.Resources; 21import android.content.res.TypedArray; 22import android.os.Build; 23import android.support.v7.appcompat.R; 24 25/** 26 * Allows components to query for various configuration policy decisions about how the action bar 27 * should lay out and behave on the current device. 28 * 29 * @hide 30 */ 31public class ActionBarPolicy { 32 33 private Context mContext; 34 35 public static ActionBarPolicy get(Context context) { 36 return new ActionBarPolicy(context); 37 } 38 39 private ActionBarPolicy(Context context) { 40 mContext = context; 41 } 42 43 public int getMaxActionButtons() { 44 return mContext.getResources().getInteger(R.integer.abc_max_action_buttons); 45 } 46 47 public boolean showsOverflowMenuButton() { 48 // Only show overflow on HC+ devices 49 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 50 } 51 52 public int getEmbeddedMenuWidthLimit() { 53 return mContext.getResources().getDisplayMetrics().widthPixels / 2; 54 } 55 56 public boolean hasEmbeddedTabs() { 57 // The embedded tabs policy changed in Jellybean; give older apps the old policy 58 // so they get what they expect. 59 return mContext.getResources().getBoolean(R.bool.abc_action_bar_embed_tabs_pre_jb); 60 } 61 62 public int getTabContainerHeight() { 63 TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, 64 R.attr.actionBarStyle, 0); 65 int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0); 66 Resources r = mContext.getResources(); 67 if (!hasEmbeddedTabs()) { 68 // Stacked tabs; limit the height 69 height = Math.min(height, 70 r.getDimensionPixelSize(R.dimen.abc_action_bar_stacked_max_height)); 71 } 72 a.recycle(); 73 return height; 74 } 75 76 public boolean enableHomeButtonByDefault() { 77 // Older apps get the home button interaction enabled by default. 78 // Newer apps need to enable it explicitly. 79 return mContext.getApplicationInfo().targetSdkVersion < 14; // ICE_CREAM_SANDWICH 80 } 81 82 public int getStackedTabMaxWidth() { 83 return mContext.getResources().getDimensionPixelSize( 84 R.dimen.abc_action_bar_stacked_tab_max_width); 85 } 86} 87