Loading res/layout/alarm_time.xml +3 −2 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ android:gravity="center_vertical" android:clickable="true" android:background="@drawable/item_background"> <LinearLayout <com.android.deskclock.widget.EllipsizeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="48dp" Loading @@ -112,8 +112,9 @@ android:layout_width="wrap_content" style="@style/alarm_label_bold" android:textColor="@color/clock_white" android:ellipsize="none" android:singleLine="true"/> </LinearLayout> </com.android.deskclock.widget.EllipsizeLayout> <ImageView android:id="@+id/expand" android:layout_width="48dp" Loading res/layout/world_clock_item.xml +4 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ android:layout_height="wrap_content" android:paddingBottom="@dimen/medium_space" android:orientation="vertical"> <LinearLayout <com.android.deskclock.widget.EllipsizeLayout android:id="@+id/city_name_digital" android:layout_height="wrap_content" android:layout_width="match_parent" Loading @@ -28,7 +28,7 @@ android:layout_marginLeft="@dimen/label_margin_small" > <include layout="@layout/world_clock_label"/> </LinearLayout> </com.android.deskclock.widget.EllipsizeLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> Loading @@ -45,7 +45,7 @@ android:hand_hour="@drawable/clock_analog_hour" android:hand_minute="@drawable/clock_analog_minute"/> </FrameLayout> <LinearLayout <com.android.deskclock.widget.EllipsizeLayout android:id="@+id/city_name_analog" android:layout_height="wrap_content" android:layout_width="match_parent" Loading @@ -54,5 +54,5 @@ android:gravity="center" > <include layout="@layout/world_clock_label"/> </LinearLayout> </com.android.deskclock.widget.EllipsizeLayout> </LinearLayout> res/layout/world_clock_label.xml +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ style="@style/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="none" android:ellipsize="end" android:singleLine="true" android:textColor="@color/clock_white"/> Loading res/layout/world_clock_list_item.xml +3 −3 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ android:layout_marginLeft="@dimen/circle_margin" android:orientation="horizontal"> <View <Space android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> Loading @@ -32,7 +32,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"/> <View <Space android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> Loading @@ -42,7 +42,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"/> <View <Space android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> Loading src/com/android/deskclock/widget/EllipsizeLayout.java 0 → 100644 +73 −0 Original line number Diff line number Diff line package com.android.deskclock.widget; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; /** * When this layout is in the Horizontal orientation and one and only one child * is a TextView with a non-null android:ellipsize, this layout will reduce * android:maxWidth of that TextView to ensure the other children are within the * layout. This layout has no effect if the children have weights. */ public class EllipsizeLayout extends LinearLayout { public EllipsizeLayout(Context context) { this(context, null); } public EllipsizeLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getOrientation() == HORIZONTAL && (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY)) { int totalLength = 0; boolean outOfSpec = false; TextView ellipView = null; final int count = getChildCount(); for (int ii = 0; ii < count && !outOfSpec; ++ii) { final View child = getChildAt(ii); if (child != null && child.getVisibility() != GONE) { if (child instanceof TextView) { final TextView tv = (TextView) child; if (tv.getEllipsize() != null) { if (ellipView == null) { ellipView = tv; // clear maxWidth on mEllipView before measure ellipView.setMaxWidth(Integer.MAX_VALUE); } else { // TODO: support multiple android:ellipsize outOfSpec = true; } } } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child .getLayoutParams(); outOfSpec |= (lp.weight > 0f); measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); totalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; } } outOfSpec |= (ellipView == null) || (totalLength == 0); final int parentWidth = MeasureSpec.getSize(widthMeasureSpec); if (!outOfSpec && totalLength > parentWidth) { int maxWidth = ellipView.getMeasuredWidth() - (totalLength - parentWidth); // TODO: Respect android:minWidth (easy with @TargetApi(16)) int minWidth = 0; if (maxWidth < minWidth) { maxWidth = minWidth; } ellipView.setMaxWidth(maxWidth); } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } Loading
res/layout/alarm_time.xml +3 −2 Original line number Diff line number Diff line Loading @@ -94,7 +94,7 @@ android:gravity="center_vertical" android:clickable="true" android:background="@drawable/item_background"> <LinearLayout <com.android.deskclock.widget.EllipsizeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="48dp" Loading @@ -112,8 +112,9 @@ android:layout_width="wrap_content" style="@style/alarm_label_bold" android:textColor="@color/clock_white" android:ellipsize="none" android:singleLine="true"/> </LinearLayout> </com.android.deskclock.widget.EllipsizeLayout> <ImageView android:id="@+id/expand" android:layout_width="48dp" Loading
res/layout/world_clock_item.xml +4 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ android:layout_height="wrap_content" android:paddingBottom="@dimen/medium_space" android:orientation="vertical"> <LinearLayout <com.android.deskclock.widget.EllipsizeLayout android:id="@+id/city_name_digital" android:layout_height="wrap_content" android:layout_width="match_parent" Loading @@ -28,7 +28,7 @@ android:layout_marginLeft="@dimen/label_margin_small" > <include layout="@layout/world_clock_label"/> </LinearLayout> </com.android.deskclock.widget.EllipsizeLayout> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> Loading @@ -45,7 +45,7 @@ android:hand_hour="@drawable/clock_analog_hour" android:hand_minute="@drawable/clock_analog_minute"/> </FrameLayout> <LinearLayout <com.android.deskclock.widget.EllipsizeLayout android:id="@+id/city_name_analog" android:layout_height="wrap_content" android:layout_width="match_parent" Loading @@ -54,5 +54,5 @@ android:gravity="center" > <include layout="@layout/world_clock_label"/> </LinearLayout> </com.android.deskclock.widget.EllipsizeLayout> </LinearLayout>
res/layout/world_clock_label.xml +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ style="@style/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ellipsize="none" android:ellipsize="end" android:singleLine="true" android:textColor="@color/clock_white"/> Loading
res/layout/world_clock_list_item.xml +3 −3 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ android:layout_marginLeft="@dimen/circle_margin" android:orientation="horizontal"> <View <Space android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> Loading @@ -32,7 +32,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"/> <View <Space android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> Loading @@ -42,7 +42,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content"/> <View <Space android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent"/> Loading
src/com/android/deskclock/widget/EllipsizeLayout.java 0 → 100644 +73 −0 Original line number Diff line number Diff line package com.android.deskclock.widget; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; /** * When this layout is in the Horizontal orientation and one and only one child * is a TextView with a non-null android:ellipsize, this layout will reduce * android:maxWidth of that TextView to ensure the other children are within the * layout. This layout has no effect if the children have weights. */ public class EllipsizeLayout extends LinearLayout { public EllipsizeLayout(Context context) { this(context, null); } public EllipsizeLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (getOrientation() == HORIZONTAL && (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY)) { int totalLength = 0; boolean outOfSpec = false; TextView ellipView = null; final int count = getChildCount(); for (int ii = 0; ii < count && !outOfSpec; ++ii) { final View child = getChildAt(ii); if (child != null && child.getVisibility() != GONE) { if (child instanceof TextView) { final TextView tv = (TextView) child; if (tv.getEllipsize() != null) { if (ellipView == null) { ellipView = tv; // clear maxWidth on mEllipView before measure ellipView.setMaxWidth(Integer.MAX_VALUE); } else { // TODO: support multiple android:ellipsize outOfSpec = true; } } } final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child .getLayoutParams(); outOfSpec |= (lp.weight > 0f); measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); totalLength += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; } } outOfSpec |= (ellipView == null) || (totalLength == 0); final int parentWidth = MeasureSpec.getSize(widthMeasureSpec); if (!outOfSpec && totalLength > parentWidth) { int maxWidth = ellipView.getMeasuredWidth() - (totalLength - parentWidth); // TODO: Respect android:minWidth (easy with @TargetApi(16)) int minWidth = 0; if (maxWidth < minWidth) { maxWidth = minWidth; } ellipView.setMaxWidth(maxWidth); } } super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }