Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 45c515b0 authored by Adam Powell's avatar Adam Powell
Browse files

Action bar work for phones

Tweak sizing and layouts for action bar on smaller devices. The action
bar's size is now partially dependent on form factor and orientation
to conserve screen space, especially in landscape mode.

Alter the max action menu items for smaller devices. Disallow text on
action menu items with a horizontal width of less than 480dp when an
icon is available.

Remove the "Done" text on the action mode close button. (TODO: get a
properly sized 9-patch resource for this - the current one has an
intrinsic width that is too large.)

When setting an action bar icon as a resource ID, the bar will attempt
to load a mipmapped resource that is the closest available for the
target size.

Change-Id: I2498c640666ade310fdd1d3a2078bd4000b392a2
parent 9f0df630
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -861,7 +861,7 @@ public class ActionBarImpl extends ActionBar {

    @Override
    public void setIcon(int resId) {
        mActionView.setIcon(mContext.getResources().getDrawable(resId));
        mActionView.setIcon(resId);
    }

    @Override
@@ -871,7 +871,7 @@ public class ActionBarImpl extends ActionBar {

    @Override
    public void setLogo(int resId) {
        mActionView.setLogo(mContext.getResources().getDrawable(resId));
        mActionView.setLogo(resId);
    }

    @Override
+4 −0
Original line number Diff line number Diff line
@@ -104,6 +104,10 @@ public abstract class BaseMenuPresenter implements MenuPresenter {
     * @param childIndex Index within the parent to insert at
     */
    protected void addItemView(View itemView, int childIndex) {
        final ViewGroup currentParent = (ViewGroup) itemView.getParent();
        if (currentParent != null) {
            currentParent.removeView(itemView);
        }
        ((ViewGroup) mMenuView).addView(itemView, childIndex);
    }

+3 −1
Original line number Diff line number Diff line
@@ -523,7 +523,9 @@ public final class MenuItemImpl implements MenuItem {
    }

    public boolean showsTextAsAction() {
        return (mShowAsAction & SHOW_AS_ACTION_WITH_TEXT) == SHOW_AS_ACTION_WITH_TEXT;
        return (mShowAsAction & SHOW_AS_ACTION_WITH_TEXT) == SHOW_AS_ACTION_WITH_TEXT &&
                mMenu.getContext().getResources().getBoolean(
                        com.android.internal.R.bool.allow_action_menu_item_text_with_icon);
    }

    public void setShowAsAction(int actionEnum) {
+29 −3
Original line number Diff line number Diff line
@@ -30,11 +30,13 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ActionMode;
import android.view.Gravity;
@@ -85,7 +87,6 @@ public class ActionBarView extends ViewGroup {
    private CharSequence mSubtitle;
    private Drawable mIcon;
    private Drawable mLogo;
    private Drawable mDivider;

    private View mHomeLayout;
    private View mHomeAsUpView;
@@ -211,8 +212,6 @@ public class ActionBarView extends ViewGroup {

        mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
        
        mDivider = a.getDrawable(R.styleable.ActionBar_divider);

        a.recycle();
        
        mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
@@ -434,6 +433,10 @@ public class ActionBarView extends ViewGroup {
        }
    }

    public void setIcon(int resId) {
        setIcon(mContext.getResources().getDrawableForDensity(resId, getPreferredIconDensity()));
    }

    public void setLogo(Drawable logo) {
        mLogo = logo;
        if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
@@ -441,6 +444,29 @@ public class ActionBarView extends ViewGroup {
        }
    }

    public void setLogo(int resId) {
        mContext.getResources().getDrawable(resId);
    }

    /**
     * @return Drawable density to load that will best fit the available height.
     */
    private int getPreferredIconDensity() {
        final Resources res = mContext.getResources();
        final int availableHeight = getLayoutParams().height -
                mIconView.getPaddingTop() - mIconView.getPaddingBottom();
        int iconSize = res.getDimensionPixelSize(android.R.dimen.app_icon_size);

        if (iconSize * DisplayMetrics.DENSITY_LOW > availableHeight) {
            return DisplayMetrics.DENSITY_LOW;
        } else if (iconSize * DisplayMetrics.DENSITY_MEDIUM > availableHeight) {
            return DisplayMetrics.DENSITY_MEDIUM;
        } else if (iconSize * DisplayMetrics.DENSITY_HIGH > availableHeight) {
            return DisplayMetrics.DENSITY_HIGH;
        }
        return DisplayMetrics.DENSITY_XHIGH;
    }

    public void setNavigationMode(int mode) {
        final int oldMode = mNavigationMode;
        if (mode != oldMode) {
+39 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2010 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<view xmlns:android="http://schemas.android.com/apk/res/android"
      class="com.android.internal.widget.ActionBarView$HomeView"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:background="?android:attr/selectableItemBackground" >
    <ImageView android:id="@android:id/up"
               android:src="?android:attr/homeAsUpIndicator"
               android:layout_gravity="center_vertical|left"
               android:visibility="gone"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginRight="-12dip" />
    <ImageView android:id="@android:id/home"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:paddingLeft="16dip"
               android:paddingRight="16dip"
               android:paddingTop="4dip"
               android:paddingBottom="4dip"
               android:adjustViewBounds="true"
               android:layout_gravity="center"
               android:scaleType="fitCenter" />
</view>
Loading