近期做蛋疼的机顶盒项目,以后遇到哪些经常使用的组件,记录于此。

反编译 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的更多相关文章

  1. Atitit.web ui  组件化 vs  mvc

    Atitit.web ui  组件化 vs  mvc   组件化  与 mvc并不矛盾..单双方适用的地方有所不同.. React推荐以组件的方式去重新思考UI构成,将UI上每一个功能相对独立的模块定 ...

  2. AngularJs的UI组件ui-Bootstrap分享(十二)——Rating

    Rating是一个用于打分或排名的控件.看一个最简单的例子: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo" x ...

  3. AngularJs的UI组件ui-Bootstrap分享(八)——Tooltip和Popover

    tooltip和popover是轻量的.可扩展的.用于提示的指令.对于移动端来讲,这两个指令虽然可以正常工作,但是从用户体验的角度并不推荐使用. 先说tooltip,tooltip有三种使用方式: ( ...

  4. AngularJs的UI组件ui-Bootstrap分享(七)——Buttons和Dropdown

    在ui-Bootstrap中,Buttons控件和Dropdown控件与form表单中的按钮和下拉框名字很像,但实际上这两个控件有新的含义. 先说Buttons,它是一组按钮,用来实现form表单中的 ...

  5. 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(六)Picker View视图 学习笔记

    想对PickerView进行操作,只能在代码中操作. 下面 ,再添加三个label组件,然后将所有组件配置到代码中(看代码),然后要实现对PickerView的操作,就要实现它的DataSource协 ...

  6. Android UI组件----ListView列表控件详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...

  7. Android UI组件学习

    android.view.View类是全部UI组件的父类. 如果一些属性的内容本类找不到的时候一定要到父类之中进行查找. 所谓的学习组件的过程就是一个文档的查找过程. ※ Android之中所有的组件 ...

  8. 第1组UI组件:布局管理器

    1 布局管理的来源 为了让UI在不同的手机屏幕上都能运行良好----不同手机屏幕的分辨率/尺寸并不完全相同,如果让程序手动控制每个组件的大小.位置,会给编程带来巨大的麻烦.为了解决这个问题.andro ...

  9. 1.引入必要的文件 2.加载 UI 组件的方式 4.Parser 解析器

    //引入 jQuery 核心库,这里采用的是 2.0 <scripttype="text/javascript"src="easyui/jquery.min.js& ...

随机推荐

  1. (转)C#静态构造函数

    静态构造函数是C#的一个新特性,在编程过程中用处并不广,它的主要目的是用于初始化一些静态的变量. 因为这个构造函数是属于类的,而不属于任何一个实例,所以这个构造函数只会被执行一次,而且是在创建此类的第 ...

  2. [译]一个灵活的 Trello 敏捷工作流

    [译]一个灵活的 Trello 敏捷工作流 翻译自 An Agile Trello Workflow That Keeps Tasks Flexible Getting things done 可不只 ...

  3. linux内核学习之进程管理------task_struct结构体

    struct task_struct { volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */ struct t ...

  4. Linux中的搜索命令

    find find是最常见和最强大的查找命令,在磁盘中查找文件,用它找到任何你想找的文件,就是速度有点慢. find    path    -option    [    -print ]    [ ...

  5. 【转】setStyleSheet用法

    [转自]http://blog.csdn.net/seanyxie/article/details/5925723 使用setStyleSheet来设置图形界面的外观: QT Style Sheets ...

  6. keepalived + nginx

    本文主要介绍keepalived的安装,Nginx自行解决,也可以使用httpd.随便任何服务都可以... keepalived 官网http://www.keepalived.org/index.h ...

  7. keybd_event 转载

    转自 http://apps.hi.baidu.com/share/detail/14468670 Option Explicit Private Declare Sub keybd_event Li ...

  8. javascript控制图片等比例缩放

    <SCRIPT language="JavaScript"> function DrawImage(ImgD,FitWidth,FitHeight){ var imag ...

  9. 一个使用CSocket类的网络通信实例

    http://www.cppblog.com/changshoumeng/archive/2010/05/14/115413.html 3.8 一个使用CSocket类的网络通信实例 本例采用CSoc ...

  10. [Python 3.x 官方文档翻译]The Python Tutorial Python教程

    Python is an easy to learn, powerful programming language. It has efficient high-level data structur ...