Merge "Updated styles and metrics."

This commit is contained in:
Adam Powell
2010-10-11 11:26:57 -07:00
committed by Android (Google) Code Review
18 changed files with 628 additions and 203 deletions

View File

@@ -0,0 +1,72 @@
/*
* 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.
*/
package android.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
public class ButtonGroup extends LinearLayout {
private Drawable mDivider;
private Drawable mButtonBackground;
public ButtonGroup(Context context) {
this(context, null);
}
public ButtonGroup(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.buttonGroupStyle);
}
public ButtonGroup(Context context, AttributeSet attrs, int defStyleRes) {
super(context, attrs, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.ButtonGroup);
mDivider = a.getDrawable(com.android.internal.R.styleable.ButtonGroup_divider);
mButtonBackground = a.getDrawable(
com.android.internal.R.styleable.ButtonGroup_buttonBackground);
a.recycle();
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (getChildCount() > 0) {
super.addView(makeDividerView(), index, makeDividerLayoutParams());
if (index >= 0) {
index++;
}
}
child.setBackgroundDrawable(mButtonBackground);
super.addView(child, index, params);
}
private ImageView makeDividerView() {
ImageView result = new ImageView(mContext);
result.setImageDrawable(mDivider);
result.setScaleType(ImageView.ScaleType.FIT_XY);
return result;
}
private LayoutParams makeDividerLayoutParams() {
return new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
}
}

View File

@@ -589,7 +589,7 @@ public class Spinner extends AbsSpinner implements OnClickListener {
setAnchorView(Spinner.this);
setModal(true);
setPromptPosition(POSITION_PROMPT_BELOW);
setPromptPosition(POSITION_PROMPT_ABOVE);
setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Spinner.this.setSelection(position);

View File

@@ -734,6 +734,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
case com.android.internal.R.styleable.TextView_textSelectHandle:
mTextSelectHandleRes = a.getResourceId(attr, 0);
break;
case com.android.internal.R.styleable.TextView_textLineHeight:
int lineHeight = a.getDimensionPixelSize(attr, 0);
if (lineHeight != 0) {
setLineHeight(lineHeight);
}
}
}
a.recycle();
@@ -1063,6 +1069,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
* or last-line padding.
*/
public int getLineHeight() {
if (mLineHeight != 0) {
return mLineHeight;
}
return FastMath.round(mTextPaint.getFontMetricsInt(null) * mSpacingMult
+ mSpacingAdd);
}
@@ -1655,9 +1664,26 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
TextAppearance_textStyle, -1);
setTypefaceByIndex(typefaceIndex, styleIndex);
int lineHeight = appearance.getDimensionPixelSize(
com.android.internal.R.styleable.TextAppearance_textLineHeight, 0);
if (lineHeight != 0) {
setLineHeight(lineHeight);
}
appearance.recycle();
}
/**
* Set the height of a line of text in pixels. This value will override line height
* values stored in the font modified by lineSpacingExtra and lineSpacingMultiplier.
*
* @param lineHeight Desired height of a single line of text in pixels
*/
public void setLineHeight(int lineHeight) {
mLineHeight = lineHeight;
}
/**
* @return the size (in pixels) of the default text size in this TextView.
*/
@@ -8449,6 +8475,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
private float mSpacingMult = 1;
private float mSpacingAdd = 0;
private int mLineHeight = 0;
private static final int LINES = 1;
private static final int EMS = LINES;