| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.view; |
| 18 |
|
| 19 |
import android.compat.annotation.UnsupportedAppUsage; |
| 20 |
import android.content.Context; |
| 21 |
import android.content.res.Configuration; |
| 22 |
import android.content.res.Resources; |
| 23 |
import android.content.res.TypedArray; |
| 24 |
import android.os.Build; |
| 25 |
|
| 26 |
import com.android.internal.R; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public class ActionBarPolicy { |
| 33 |
@UnsupportedAppUsage |
| 34 |
private Context mContext; |
| 35 |
|
| 36 |
@UnsupportedAppUsage |
| 37 |
public static ActionBarPolicy get(Context context) { |
| 38 |
return new ActionBarPolicy(context); |
| 39 |
} |
| 40 |
|
| 41 |
@UnsupportedAppUsage |
| 42 |
private ActionBarPolicy(Context context) { |
| 43 |
mContext = context; |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
@UnsupportedAppUsage |
| 52 |
public int getMaxActionButtons() { |
| 53 |
final Configuration config = mContext.getResources().getConfiguration(); |
| 54 |
final int width = config.screenWidthDp; |
| 55 |
final int height = config.screenHeightDp; |
| 56 |
final int smallest = config.smallestScreenWidthDp; |
| 57 |
if (smallest > 600 || (width > 960 && height > 720) || (width > 720 && height > 960)) { |
| 58 |
|
| 59 |
return 5; |
| 60 |
} else if (width >= 500 || (width > 640 && height > 480) || (width > 480 && height > 640)) { |
| 61 |
|
| 62 |
return 4; |
| 63 |
} else if (width >= 360) { |
| 64 |
|
| 65 |
return 3; |
| 66 |
} else { |
| 67 |
return 2; |
| 68 |
} |
| 69 |
} |
| 70 |
@UnsupportedAppUsage |
| 71 |
public boolean showsOverflowMenuButton() { |
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
@UnsupportedAppUsage |
| 76 |
public int getEmbeddedMenuWidthLimit() { |
| 77 |
return mContext.getResources().getDisplayMetrics().widthPixels / 2; |
| 78 |
} |
| 79 |
|
| 80 |
@UnsupportedAppUsage |
| 81 |
public boolean hasEmbeddedTabs() { |
| 82 |
final int targetSdk = mContext.getApplicationInfo().targetSdkVersion; |
| 83 |
if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) { |
| 84 |
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs); |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
final Configuration configuration = mContext.getResources().getConfiguration(); |
| 90 |
final int width = configuration.screenWidthDp; |
| 91 |
final int height = configuration.screenHeightDp; |
| 92 |
return configuration.orientation == Configuration.ORIENTATION_LANDSCAPE || |
| 93 |
width >= 480 || (width >= 640 && height >= 480); |
| 94 |
} |
| 95 |
|
| 96 |
@UnsupportedAppUsage |
| 97 |
public int getTabContainerHeight() { |
| 98 |
TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, |
| 99 |
com.android.internal.R.attr.actionBarStyle, 0); |
| 100 |
int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0); |
| 101 |
Resources r = mContext.getResources(); |
| 102 |
if (!hasEmbeddedTabs()) { |
| 103 |
|
| 104 |
height = Math.min(height, |
| 105 |
r.getDimensionPixelSize(R.dimen.action_bar_stacked_max_height)); |
| 106 |
} |
| 107 |
a.recycle(); |
| 108 |
return height; |
| 109 |
} |
| 110 |
|
| 111 |
public boolean enableHomeButtonByDefault() { |
| 112 |
|
| 113 |
|
| 114 |
return mContext.getApplicationInfo().targetSdkVersion < |
| 115 |
Build.VERSION_CODES.ICE_CREAM_SANDWICH; |
| 116 |
} |
| 117 |
|
| 118 |
@UnsupportedAppUsage |
| 119 |
public int getStackedTabMaxWidth() { |
| 120 |
return mContext.getResources().getDimensionPixelSize( |
| 121 |
R.dimen.action_bar_stacked_tab_max_width); |
| 122 |
} |
| 123 |
} |