Android clock to use on old phones

I came across a bit of a conundrum when trying to figure out what I’m going to do with my old phone. So what better way than to add some cool space stuff to it. This is a clock with the space video playing in the background! Originally I wanted to make a rotary engine clock, but rotary engines are really confusing to make animate based off the second hand so I put the video in instead. This is how I did it:

filename: /src/com/solex/clock/MainActivity.java

package com.solex.clock;

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

import android.media.MediaPlayer;
import android.os.Handler;
import android.os.Handler.Callback;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.provider.Settings.System;
import android.text.format.DateFormat;
import android.view.Menu;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.VideoView;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_main);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  //Keep the screen from turning off
		
		/*	SCRAPPING ROTARY ANIMATION
		ImageView rotatingHand = (ImageView) findViewById(R.id.rotatingHand);
		Animation rotatingHandAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_engine);
		rotatingHand.startAnimation(rotatingHandAnimation);
		
		ImageView rotatingCenter = (ImageView) findViewById(R.id.innerCircle);
		Animation rotatingCenterAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_engine);
		rotatingCenter.startAnimation(rotatingCenterAnimation); 
		*/
		
		
		final VideoView videoView = (VideoView)findViewById(R.id.myvideoview);
		videoView.setVideoPath("android.resource://com.solex.clock/drawable/earth");  //This points to the mp4 video
		
		videoView.start();
		
		videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
			@Override
			public void onCompletion(MediaPlayer arg0){
				videoView.start();
			}
		});
		
		
		
		//CLOCK
		
		
		
		final Handler handler = new Handler();
		
		final Runnable TheUiTask = new Runnable() {
			@Override
			public void run() {
				
				Date date = new Date();
				Date time = new Date();
				
				TextView dateView = (TextView) (findViewById(R.id.dateView));
				TextView timeView = (TextView) (findViewById(R.id.clockView));
				
				Typeface type = Typeface.createFromAsset(getAssets(), "fonts/toyomr2.ttf");
				dateView.setTypeface(type);
				timeView.setTypeface(type);
						
				CharSequence currentDate = DateFormat.format("EEEE, MMMM d, yyyy ", date.getTime());
				CharSequence currentTime = DateFormat.format("hh:mm:ss a", time.getTime());
				
				
				
				timeView.setText(currentTime);
				dateView.setText(currentDate);
			
			}
		};
		
		class UiTask extends TimerTask {
	        @Override 
	        public void run() {
	            
	            handler.post(TheUiTask);
	            
	        }
	    }
		
		Timer timer = new Timer();
		timer.schedule(new UiTask(), 1000, 1000);
			
	}


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

Leave a Reply

Your email address will not be published.