经常使用的自己定义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& ...
随机推荐
- CentOS安装JDK7
1.下载jdk-7-linux-x64.rpm(http://www.Oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-downlo ...
- Windows Server 2008关闭internet explorer增强的安全配置
服务器系统要求很高的安全性,所以微软给ie添加了安全增强.这就使得ie在Internet区域的安全级别一直是最高的,而且无法进行整体调整. 关闭IE SEC服务器系统要求很高的安全性,所以微软给ie添 ...
- MySQL查询执行的基础
当希望MySQL能够以更高的性能运行查询时,最好的办法就是弄清楚MySQL是如何优化和执行查询的.一旦理解这一点,很多查询优化实际上就是遵循一些原则让优化器能够按照预想的合理的方式运行. 换句话说,是 ...
- impdp/expdp 总结
impdp/expdp 1.创建DIRECTORY create directory dir_dp as '/tmp'; --建议将DIRECTORY 建在 /tmp 表下面,该目录肯定存 ...
- phpcms v9教程 联动搜索在房地产网站开发中的应用
开发简述:使用phpcms v9系统,修改源文件5个,创建模型:楼盘.出售.出租.中介.小区,增加联动菜单:楼盘,增加用户组:房产中介.实现功能:游客发布信息.会员申请中介.楼盘全方位展示.报名团购. ...
- ssh登陆设置快捷方式
在自己的环境下配置 ~/.ssh/config Host k231 HostName 192.168.1.231 User kyee 原来ssh 登陆192.168.1.231 的命令是 ssh ky ...
- 转:VC++获取屏幕大小第一篇 像素大小GetSystemMetrics
VC++获取屏幕大小第一篇 像素大小 GetSystemMetrics>和<VC++获取屏幕大小第二篇物理大小GetDeviceCaps 上>和<VC++获取屏幕大小第三篇物理 ...
- 为什么c程序里一定要写main函数
一. 学习过程 编写程序f.c: 对其进行编译,正常通过,再对其进行连接,出现错误: 显示的出错信息为: 翻译成中文是:在c0s模块没有定义符号’_main’. 那么这个错误信息可能与文件c0s.ob ...
- BroadcastReceiver 案例
BroadcastReceiver 可以接收来自系统和应用的广播,他的生命周期非常简单,只是从对象开始调用他到运行onReceiver方法之后就结束了.要想使用BroadcastReceiver和使用 ...
- SpringBoot笔记一
1 开始 1.1 spring介绍 Spring Boot使开发独立的,产品级别的基于Spring的应用变得非常简单,你只需"just run". 我们为Spring平台及第三方库 ...