经常使用的自己定义UI组件- 一:TimeView
近期做蛋疼的机顶盒项目,以后遇到哪些经常使用的组件,记录于此。
反编译 youku视频TV偷来的。。也希望各位童鞋多学习别人的代码,为己所用。
当然还有其它的办法,比方监听系统发出的广播等等。等有时间再把那个贴上来。
效果图:右上角的时间
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的更多相关文章
- Atitit.web ui 组件化 vs mvc
Atitit.web ui 组件化 vs mvc 组件化 与 mvc并不矛盾..单双方适用的地方有所不同.. React推荐以组件的方式去重新思考UI构成,将UI上每一个功能相对独立的模块定 ...
- AngularJs的UI组件ui-Bootstrap分享(十二)——Rating
Rating是一个用于打分或排名的控件.看一个最简单的例子: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo" x ...
- AngularJs的UI组件ui-Bootstrap分享(八)——Tooltip和Popover
tooltip和popover是轻量的.可扩展的.用于提示的指令.对于移动端来讲,这两个指令虽然可以正常工作,但是从用户体验的角度并不推荐使用. 先说tooltip,tooltip有三种使用方式: ( ...
- AngularJs的UI组件ui-Bootstrap分享(七)——Buttons和Dropdown
在ui-Bootstrap中,Buttons控件和Dropdown控件与form表单中的按钮和下拉框名字很像,但实际上这两个控件有新的含义. 先说Buttons,它是一组按钮,用来实现form表单中的 ...
- 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(六)Picker View视图 学习笔记
想对PickerView进行操作,只能在代码中操作. 下面 ,再添加三个label组件,然后将所有组件配置到代码中(看代码),然后要实现对PickerView的操作,就要实现它的DataSource协 ...
- Android UI组件----ListView列表控件详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- Android UI组件学习
android.view.View类是全部UI组件的父类. 如果一些属性的内容本类找不到的时候一定要到父类之中进行查找. 所谓的学习组件的过程就是一个文档的查找过程. ※ Android之中所有的组件 ...
- 第1组UI组件:布局管理器
1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...
- 1.引入必要的文件 2.加载 UI 组件的方式 4.Parser 解析器
//引入 jQuery 核心库,这里采用的是 2.0 <scripttype="text/javascript"src="easyui/jquery.min.js& ...
随机推荐
- mockito学习
mockito学习 写一个测试用例,如果在测试类上面添加了注解@RunWith(SpringJUnit4ClassRunner.class),必须添加@ContextConfiguration(&qu ...
- 学习日记-----ORM
ORM ORM(Object Relation Mapping)对象关系映射 实质:将数据库中 的业务数据用对象的形式表现出来,使用ORM在业务逻辑层和数据访问层之间充当桥梁 核心原则: 简单性 传达 ...
- Android学习手记(4) BroadcastReceiver监听电池信息
Android 中,Broadcast是一种在应用程序之间进行传输信息的机制.BroadcastReceiver对发送过来的Broadcast进行过滤和响应.根据这种机制,我们可以获取电池现有电量等信 ...
- android 瀑布流(图片浏览)
效果图: 瀑流流实现涉及的知识点 1.ScrollView滚动视图,我们这里用的是自定义ScrollView /** * Created by Spring on 2015/11/2. * 自定义Sc ...
- Probably at least one of the constraints in the following list is one you don't want.
这个提示并不是出错,不理会它我的程序也没出现什么问题 但是处于强迫症,还是努力寻找解决的方法... 最终发现问题如下: 在xib各种绘制和添加约束的UITableViewCell之后,在某一特定情况想 ...
- DOM基础之“寻找”子节点
今天学习了JS中的DOM的内容,虽然小菜的理解不深,但希望能够记录下来,慢慢一点一点的进步,有更深的理解了,再回来补充. 首先,关于DOM的概念: 1.概念:DOM = document(文档)Obj ...
- intent.setFlags方法中参数值的含义
intent.setFlags()方法中参数的含义 1.FLAG_ACTIVITY_NEW_TASK: 例如现在栈一的情况是:A B C(C位于栈顶),C通过intent跳转到D,并且这个I ...
- epoll 中EPOLLIN 和 EPOLLOUT
epoll主要是事件回调运行的,我们使用socket的时候主要使用两个事件 EPOLLOUT事件:EPOLLOUT事件只有在连接时触发一次,表示可写,其他时候想要触发,那你要先准备好下面条件:1.某次 ...
- javascript将form表单中的元素值封装成json格式
把form表单中的元素值封装成json function toJSON(form)//form是要进行封装的form表单对象,dom对象,可以通过document.mainForm获得,mainFor ...
- validate()的配置项
1.submitHandler //通过验证成功后运行的函数 代码: $("#mainForm").validate({ ...... rules:{ username:{//此处 ...