| Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 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 |  | 
|  | 17 | package com.android.internal.view; | 
|  | 18 |  | 
|  | 19 | import com.android.internal.R; | 
|  | 20 |  | 
|  | 21 | import android.content.Context; | 
| Justin Koh | 4207fda | 2013-03-01 13:01:58 -0800 | [diff] [blame] | 22 | import android.content.res.Configuration; | 
| Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 23 | import android.content.res.Resources; | 
|  | 24 | import android.content.res.TypedArray; | 
|  | 25 | import android.os.Build; | 
|  | 26 | import android.view.ViewConfiguration; | 
|  | 27 |  | 
|  | 28 | /** | 
|  | 29 | * Allows components to query for various configuration policy decisions | 
|  | 30 | * about how the action bar should lay out and behave on the current device. | 
|  | 31 | */ | 
|  | 32 | public class ActionBarPolicy { | 
|  | 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.max_action_buttons); | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | public boolean showsOverflowMenuButton() { | 
| Justin Koh | 4207fda | 2013-03-01 13:01:58 -0800 | [diff] [blame] | 48 | return !ViewConfiguration.get(mContext).hasPermanentMenuKey() || | 
|  | 49 | ((mContext.getResources().getConfiguration().uiMode & | 
|  | 50 | Configuration.UI_MODE_TYPE_TELEVISION) == | 
|  | 51 | Configuration.UI_MODE_TYPE_TELEVISION); | 
| Adam Powell | b8139af | 2012-04-19 13:52:46 -0700 | [diff] [blame] | 52 | } | 
|  | 53 |  | 
|  | 54 | public int getEmbeddedMenuWidthLimit() { | 
|  | 55 | return mContext.getResources().getDisplayMetrics().widthPixels / 2; | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | public boolean hasEmbeddedTabs() { | 
|  | 59 | final int targetSdk = mContext.getApplicationInfo().targetSdkVersion; | 
|  | 60 | if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) { | 
|  | 61 | return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs); | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | // The embedded tabs policy changed in Jellybean; give older apps the old policy | 
|  | 65 | // so they get what they expect. | 
|  | 66 | return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb); | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | public int getTabContainerHeight() { | 
|  | 70 | TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, | 
|  | 71 | com.android.internal.R.attr.actionBarStyle, 0); | 
|  | 72 | int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0); | 
|  | 73 | Resources r = mContext.getResources(); | 
|  | 74 | if (!hasEmbeddedTabs()) { | 
|  | 75 | // Stacked tabs; limit the height | 
|  | 76 | height = Math.min(height, | 
|  | 77 | r.getDimensionPixelSize(R.dimen.action_bar_stacked_max_height)); | 
|  | 78 | } | 
|  | 79 | a.recycle(); | 
|  | 80 | return height; | 
|  | 81 | } | 
|  | 82 |  | 
|  | 83 | public boolean enableHomeButtonByDefault() { | 
|  | 84 | // Older apps get the home button interaction enabled by default. | 
|  | 85 | // Newer apps need to enable it explicitly. | 
|  | 86 | return mContext.getApplicationInfo().targetSdkVersion < | 
|  | 87 | Build.VERSION_CODES.ICE_CREAM_SANDWICH; | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | public int getStackedTabMaxWidth() { | 
|  | 91 | return mContext.getResources().getDimensionPixelSize( | 
|  | 92 | R.dimen.action_bar_stacked_tab_max_width); | 
|  | 93 | } | 
|  | 94 | } |