test

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/linearLayoutBinary"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:layout_marginTop="35dp">

        <LinearLayout
            android:id="@+id/linearLayoutHours2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:gravity="bottom">      
            <View
                android:id="@+id/lblHour_2_2"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblHour_2_1"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayoutHours1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:gravity="bottom">
            <View
                android:id="@+id/lblHour_1_4"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblHour_1_3"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblHour_1_2"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblHour_1_1"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayoutMinutes2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginLeft="25dp"
            android:gravity="bottom">
            <View
                android:id="@+id/lblMinutes_2_3"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblMinutes_2_2"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblMinutes_2_1"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF" />
        </LinearLayout>
        
        <LinearLayout
            android:id="@+id/linearLayoutMinutes1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:gravity="bottom">
            <View
                android:id="@+id/lblMinutes_1_4"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblMinutes_1_3"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblMinutes_1_2"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblMinutes_1_1"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF" />
		</LinearLayout>
        
        <LinearLayout
            android:id="@+id/linearLayoutSeconds2"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginLeft="25dp"
            android:gravity="bottom">
            <View
                android:id="@+id/lblSeconds_2_3"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblSeconds_2_2"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblSeconds_2_1"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF" />
		</LinearLayout>
		
        <LinearLayout
            android:id="@+id/linearLayoutSeconds1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            android:gravity="bottom">
            <View
                android:id="@+id/lblSeconds_1_4"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblSeconds_1_3"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblSeconds_1_2"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF"
        		android:layout_marginBottom="10dp" />
            <View
                android:id="@+id/lblSeconds_1_1"
        		android:layout_height="55dp"
        		android:layout_width="55dp"
        		android:background="#66FFFFFF" />
        </LinearLayout>
    </LinearLayout>
  
</LinearLayout>


package sekagra.android.binaryclock;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class BinaryClockActivity extends Activity {
    private Timer _timer;
    private Runnable Timer_Tick = new Runnable() {
        public void run() {
            Date __date = new Date();

            //Set the labels to display the current time
     /*       ((TextView) findViewById(R.id.lblHours)).setText(String.format("%02d", __date.getHours()));
            ((TextView) findViewById(R.id.lblMinutes)).setText(String.format("%02d", __date.getMinutes()));
            ((TextView) findViewById(R.id.lblSeconds)).setText(String.format("%02d", __date.getSeconds()));
*/
            //Set the views to display the current in its binary representation
            SetDigit((LinearLayout) findViewById(R.id.linearLayoutHours2), __date.getHours() / 10);
            SetDigit((LinearLayout) findViewById(R.id.linearLayoutHours1), __date.getHours() % 10);

            SetDigit((LinearLayout) findViewById(R.id.linearLayoutMinutes2), __date.getMinutes() / 10);
            SetDigit((LinearLayout) findViewById(R.id.linearLayoutMinutes1), __date.getMinutes() % 10);

            SetDigit((LinearLayout) findViewById(R.id.linearLayoutSeconds2), __date.getSeconds() / 10);
            SetDigit((LinearLayout) findViewById(R.id.linearLayoutSeconds1), __date.getSeconds() % 10);
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        //Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        //set screenOrientation landscape
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        setContentView(R.layout.main);

        _timer = new Timer(true);
        _timer.schedule(new TimerTask() {
            public void run() {
                TimerMethod(); //every tick executes this method in the background thread
            }
        }, 100, 200);

    }

    //pass the job to a method on the UI
    private void TimerMethod() {
        this.runOnUiThread(Timer_Tick);
    }

    private void SetDigit(LinearLayout group, int digit) {
        //Convert the digit to an boolean array
        boolean[] __values = IntToBoolArray(digit, group.getChildCount());

        //Iterate through all blocks an apply the correct color
        for (int i = 0; i < group.getChildCount(); i++) {
            //reverse, because the binary clock shows the digits from the bottom to the top
            if (__values[i])
                group.getChildAt(group.getChildCount() - 1 - i).setBackgroundColor(0xFFFFFFFF);
            else
                group.getChildAt(group.getChildCount() - 1 - i).setBackgroundColor(0x66FFFFFF);
        }
    }

    private boolean[] IntToBoolArray(int value, int digits) {
        boolean[] __binary = new boolean[digits];

        for (int i = 0; value > 0 || i < digits; i++) {
            __binary[i] = (value % 2) != 0;
            value /= 2;
        }

        return __binary;
    }
}



转载于:https://my.oschina.net/u/243601/blog/159988

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值