常用的自定义UI组件- 一:TimeView
来源:互联网 发布:优化探究化学 编辑:程序博客网 时间:2024/06/15 20:48
最近做蛋疼的机顶盒项目,以后遇到哪些常用的组件,记录于此。
反编译 youku视频TV偷来的。。也希望各位童鞋多学习别人的代码,为己所用。
当然还有其他的办法,比如监听系统发出的广播等等。等有时间再把那个贴上来。
效果图:右上角的时间
http://img.blog.csdn.net/20140630144648750?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGVlaHUxOTg3/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
TimeView.java
package com.youku.tv.widget;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.Calendar;
import java.util.Date;
public class TimeView extends LinearLayout{
class ClockHandler extends Handler {
private void post()
{
sendMessageDelayed(obtainMessage(0), 1000 * (60 - Calendar.getInstance().get(13)));
}
public void handleMessage(Message message){
super.handleMessage(message);
if(!mStopped){
updateClock();
post();
}
}
public void startScheduleUpdate(){
mStopped = false;
post();
}
public void stopScheduleUpdate(){
mStopped = true;
removeMessages(0);
}
private boolean mStopped;
final TimeView this$0;
ClockHandler(){
super();
this$0 = TimeView.this;
}
}
public TimeView(Context context, AttributeSet attributeset){
super(context, attributeset);
mContext = getContext();
((LayoutInflater)context.getSystemService("layout_inflater")).inflate(R.layout.time_simple, this);
mHour = (TextView)findViewById(R.id.system_hour);
mMinute = (TextView)findViewById(R.id.system_minute);
mClockUpdater = new ClockHandler();
}
protected void onAttachedToWindow(){
super.onAttachedToWindow();
updateClock();
mClockUpdater.startScheduleUpdate();
}
protected void onDetachedFromWindow(){
super.onDetachedFromWindow();
mClockUpdater.stopScheduleUpdate();
}
protected void onVisibilityChanged(View view, int i)
{
super.onVisibilityChanged(view, i);
}
void updateClock()
{
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
int k = calendar.get(5);
int l = calendar.get(11);
int i1 = calendar.get(12);
if(mHour != null)
{
TextView textview2 = mHour;
Object aobj2[] = new Object[1];
aobj2[0] = Integer.valueOf(l);
textview2.setText(String.format("%2d:", aobj2));
}
if(mMinute != null)
if(i1 < 10)
{
TextView textview1 = mMinute;
Object aobj1[] = new Object[1];
aobj1[0] = Integer.valueOf(i1);
textview1.setText(String.format("0%d", aobj1));
} else
{
TextView textview = mMinute;
Object aobj[] = new Object[1];
aobj[0] = Integer.valueOf(i1);
textview.setText(String.format("%2d", aobj));
}
invalidate();
}
private static final String TAG = "TimeView";
private ClockHandler mClockUpdater;
private Context mContext;
private TextView mHour;
private TextView mMinute;
}
time_simple.xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@id/system_minute"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="01"
android:textColor="@color/timecolor"
android:textSize="@dimen/px42" />
<TextView
android:id="@id/system_hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/system_minute"
android:text="55"
android:textColor="@color/timecolor"
android:textSize="@dimen/px42" />
</RelativeLayout>
- 常用的自定义UI组件- 一:TimeView
- 实时显示时间的TimeView(自定义view实践)
- Android 常用的UI组件
- Android常用的UI组件
- 录音计时的TimeView
- 自定义UI组件 心得分享 (一) (List组件)
- Android常用的UI组件及应用
- Android 常用的UI组件 2
- android自定义UI组件
- android UI自定义组件
- Unity自定义UI组件(一)函数图篇(上)
- Unity自定义UI组件(一)函数图篇(上)
- 常用UI组件(widgets)之文本框(TextView)(一)
- 常用ui组件总结
- vue 常用ui组件
- vuejs 常用ui组件
- vue 常用ui组件
- vue常用UI组件
- JavaWeb的各种中文乱码终极解决方法!!
- Cocos2D-X弹出对话框的实现与封装
- Mysql错误:Ignoring query to other database解决方法
- 如何解压RPM包
- HTTP头信息及响应码
- 常用的自定义UI组件- 一:TimeView
- Linux编程细节3-内核-数据结构
- linux硬链接与软链接
- Android 百度地图 java.lang.UnsatisfiedLinkError: Couldn't load vi_voslib: findLibrary returned null
- 广州SAP FICO课程培训在即
- Linux编程细节4-内核-进程管理
- 分享一个项目missian(hessian over mina)
- 函数属性__attribute__
- service 电话监听器并上传到服务器