If you think the Android project vitdroid-android 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
package com.googlecode.android.widgets.DateSlider.timeview;
/*fromwww.java2s.com*/import android.content.Context;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.googlecode.android.widgets.DateSlider.TimeObject;
/**
* This is a more complex implementation of the TimeView consisting of a LinearLayout with
* two TimeViews. This allows primary text and sub-text, such as the name of the day
* and the day of the month. This class expects the text that it is passed via
* {@link #setVals(TimeObject)} or {@link #setVals(TimeView)} to contian the primary
* string followed by a space and then the secondary string.
*/publicclass TimeLayoutView extends LinearLayout implements TimeView {
protectedlong endTime, startTime;
protected String text;
protectedboolean isCenter=false, isOutOfBounds=false;
protected TextView topView, bottomView;
/**
* constructor
*
* @param context
* @param isCenterView true if the element is the centered view in the ScrollLayout
* @param topTextSize text size of the top TextView in dps
* @param bottomTextSize text size of the bottom TextView in dps
* @param lineHeight LineHeight of the top TextView
*/public TimeLayoutView(Context context, boolean isCenterView, int topTextSize, int bottomTextSize, float lineHeight) {
super(context);
setupView(context, isCenterView, topTextSize, bottomTextSize, lineHeight);
}
/**
* Setting up the top TextView and bottom TextVew
* @param context
* @param isCenterView true if the element is the centered view in the ScrollLayout
* @param topTextSize text size of the top TextView in dps
* @param bottomTextSize text size of the bottom TextView in dps
* @param lineHeight LineHeight of the top TextView
*/protectedvoid setupView(Context context, boolean isCenterView, int topTextSize, int bottomTextSize, float lineHeight) {
setOrientation(VERTICAL);
topView = new TextView(context);
topView.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.BOTTOM);
topView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, topTextSize);
bottomView = new TextView(context);
bottomView.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP);
bottomView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, bottomTextSize);
topView.setLineSpacing(0, lineHeight);
if (isCenterView) {
isCenter = true;
topView.setTypeface(Typeface.DEFAULT_BOLD);
topView.setTextColor(0xFF333333);
bottomView.setTypeface(Typeface.DEFAULT_BOLD);
bottomView.setTextColor(0xFF444444);
topView.setPadding(0, 5-(int)(topTextSize/15.0), 0, 0);
} else {
topView.setPadding(0, 5, 0, 0);
topView.setTextColor(0xFF666666);
bottomView.setTextColor(0xFF666666);
}
addView(topView);addView(bottomView);
}
publicvoid setVals(TimeObject to) {
text = to.text.toString();
setText();
this.startTime = to.startTime;
this.endTime = to.endTime;
}
publicvoid setVals(TimeView other) {
text = other.getTimeText().toString();
setText();
startTime = other.getStartTime();
endTime = other.getEndTime();
}
/**
* sets the TextView texts by splitting the text into two
*/protectedvoid setText() {
String[] splitTime = text.split(" ");
topView.setText(splitTime[0]);
bottomView.setText(splitTime[1]);
}
public String getTimeText() {
return text;
}
publiclong getStartTime() {
return startTime;
}
publiclong getEndTime() {
return endTime;
}
publicboolean isOutOfBounds() {
return isOutOfBounds;
}
publicvoid setOutOfBounds(boolean outOfBounds) {
if (outOfBounds && !isOutOfBounds) {
topView.setTextColor(0x44666666);
bottomView.setTextColor(0x44666666);
}
elseif (!outOfBounds && isOutOfBounds) {
topView.setTextColor(0xFF666666);
bottomView.setTextColor(0xFF666666);
}
isOutOfBounds = outOfBounds;
}
}