If you think the Android project Wardrobe_app listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2013 Google Inc./*fromwww.java2s.com*/
*
* 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 com.android.busolo.apps.wardrobe.widget;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;
publicclass EllipsizedTextView extends TextView {
privatestaticfinalint MAX_ELLIPSIZE_LINES = 100;
privateint mMaxLines;
public EllipsizedTextView(Context context) {
this(context, null, 0);
}
public EllipsizedTextView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public EllipsizedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Attribute initialization
final TypedArray a = context.obtainStyledAttributes(attrs, newint[]{
android.R.attr.maxLines
}, defStyle, 0);
mMaxLines = a.getInteger(0, 1);
a.recycle();
}
@Override
publicvoid setText(CharSequence text, BufferType type) {
CharSequence newText = getWidth() == 0 || mMaxLines > MAX_ELLIPSIZE_LINES ? text :
TextUtils.ellipsize(text, getPaint(), getWidth() * mMaxLines,
TextUtils.TruncateAt.END, false, null);
super.setText(newText, type);
}
@Override
protectedvoid onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
if (width > 0 && oldWidth != width) {
setText(getText());
}
}
@Override
publicvoid setMaxLines(int maxlines) {
super.setMaxLines(maxlines);
mMaxLines = maxlines;
}
}