blob: bee59dcc3513b209934d0e1b69cb5a679146bae7 [file] [log] [blame]
Adam Powellb8139af2012-04-19 13:52:46 -07001/*
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 com.android.internal.view;
18
19import com.android.internal.R;
20
21import android.content.Context;
22import android.content.res.Resources;
23import android.content.res.TypedArray;
24import android.os.Build;
Adam Powellb8139af2012-04-19 13:52:46 -070025
26/**
27 * Allows components to query for various configuration policy decisions
28 * about how the action bar should lay out and behave on the current device.
29 */
30public class ActionBarPolicy {
31 private Context mContext;
32
33 public static ActionBarPolicy get(Context context) {
34 return new ActionBarPolicy(context);
35 }
36
37 private ActionBarPolicy(Context context) {
38 mContext = context;
39 }
40
41 public int getMaxActionButtons() {
42 return mContext.getResources().getInteger(R.integer.max_action_buttons);
43 }
44
45 public boolean showsOverflowMenuButton() {
Adam Powellea04f3c2013-07-11 13:25:58 -070046 return true;
Adam Powellb8139af2012-04-19 13:52:46 -070047 }
48
49 public int getEmbeddedMenuWidthLimit() {
50 return mContext.getResources().getDisplayMetrics().widthPixels / 2;
51 }
52
53 public boolean hasEmbeddedTabs() {
54 final int targetSdk = mContext.getApplicationInfo().targetSdkVersion;
55 if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) {
56 return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs);
57 }
58
59 // The embedded tabs policy changed in Jellybean; give older apps the old policy
60 // so they get what they expect.
61 return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb);
62 }
63
64 public int getTabContainerHeight() {
65 TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar,
66 com.android.internal.R.attr.actionBarStyle, 0);
67 int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
68 Resources r = mContext.getResources();
69 if (!hasEmbeddedTabs()) {
70 // Stacked tabs; limit the height
71 height = Math.min(height,
72 r.getDimensionPixelSize(R.dimen.action_bar_stacked_max_height));
73 }
74 a.recycle();
75 return height;
76 }
77
78 public boolean enableHomeButtonByDefault() {
79 // Older apps get the home button interaction enabled by default.
80 // Newer apps need to enable it explicitly.
81 return mContext.getApplicationInfo().targetSdkVersion <
82 Build.VERSION_CODES.ICE_CREAM_SANDWICH;
83 }
84
85 public int getStackedTabMaxWidth() {
86 return mContext.getResources().getDimensionPixelSize(
87 R.dimen.action_bar_stacked_tab_max_width);
88 }
89}