Week #11 Challenge: Android

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 21482 Views - Last Post: 24 March 2010 - 04:08 AM

#16 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Week #11 Challenge: Android

Posted 17 March 2010 - 06:22 PM

View Postskyhawk133, on 17 March 2010 - 01:54 PM, said:

Remember, the goal of these challenges if for you to try new things. Just because you don't have a need for it, doesn't mean there isn't value in trying it. It may turn you on to a whole new arena that you never realized you enjoyed.


Indeed. I understand that. But because I have absolutely no use for an Android application, and don't see myself getting a device with Android on it in the foreseeable future, my personal projects are more important to me right now. It's got nothing to do with the challenge and everything to do with me. I'll probably kill this one off at the same time I kill the Java one off (polyglot programming anyone? :D).
Was This Post Helpful? 0
  • +
  • -

#17 Melon Bread  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 43
  • Joined: 08-March 10

Re: Week #11 Challenge: Android

Posted 19 March 2010 - 07:27 AM

Just A Side Note:
Motorola Has There own Versoin Of Eclpise For Andoid phones, Motodev Studios
http://developer.mot.../motodevstudio/

It's A Sorta of AIO, here is The Features of It (Grabbed From There Webpage)
Posted Image



I have Been Using It And It Has Worked Great
Was This Post Helpful? 0
  • +
  • -

#18 aniri  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 657
  • Joined: 24-November 09

Re: Week #11 Challenge: Android

Posted 24 March 2010 - 04:08 AM

I've never worked with android before. Pretty cool!

I've done a small tabbed application that shows the time :P Pretty useless I know, but at least I got to play with android :)

Shows the digital clock in the first tab and analog clock in the second.

Looks like this:
Posted ImagePosted Image

And here's the code:
main class, Clocky.java
package com.example.clocky;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class Clocky extends TabActivity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {  
		super.onCreate(savedInstanceState);  
		
		TabHost host = getTabHost();  
		host.addTab(host.newTabSpec("Digital").setIndicator("Digital").setContent(new Intent(this, Tab1Activity.class)));  
		host.addTab(host.newTabSpec("Analog").setIndicator("Analog").setContent(new Intent(this, Tab2Activity.class)));  
	}  
}


Tab1Activity.java
package com.example.clocky;

import java.util.Calendar;
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Tab1Activity extends Activity implements Runnable
{  
	private TextView tv2;
	private String time = "";
	
	@Override  
	protected void onCreate(Bundle savedInstanceState) 
	{  
		super.onCreate(savedInstanceState);
		
		LinearLayout ll = new LinearLayout(this);
        ll.setOrientation(LinearLayout.VERTICAL);
		
		TextView tv1 = new TextView(this);
        tv1.setText("Digital Clock:");
        
        ll.addView(tv1);
        
        tv2 = new TextView(this);
        
        Calendar cal = Calendar.getInstance();
	    Date d = cal.getTime();
	    String time = "";
	    
	    int hour = d.getHours();
	    int min = d.getMinutes();
	    int sec = d.getSeconds();
	    
	    time += hour + " : " + min + " : " + sec;
	    
        tv2.setText(time);
        
        ll.addView(tv2);
        
        setContentView(ll);
        
        Thread thread = new Thread(this);
        thread.start();
  
	} 
	
	public void run() 
	{
		while(true)
        {
            updateTime();
	
	        try
	        {
	        	Thread.sleep(1000);
	        }
	        catch(Exception e)
	        {
	        	e.printStackTrace();
	        }
        }
	}
	
	private void updateTime()
	{
		Calendar cal = Calendar.getInstance();
	    Date d = cal.getTime();
	    
	    time = "";
	    
	    int hour = d.getHours();
	    int min = d.getMinutes();
	    int sec = d.getSeconds();
	    
	    time += hour + " : " + min + " : " + sec;
	    
	    handler.sendEmptyMessage(0);
	}

	private Handler handler = new Handler() 
	{
		@Override
		public void handleMessage(Message msg) 
		{
			tv2.setText(time);
		}
	};
}  


Tab2Activity.java
package com.example.clocky;

import android.app.Activity;
import android.os.Bundle;

public class Tab2Activity extends Activity
{  
	@Override  
	protected void onCreate(Bundle savedInstanceState) 
	{  
		super.onCreate(savedInstanceState);  
		setContentView(R.layout.tab2);  
	}  
}  


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


AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.clocky"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Clocky"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Tab1Activity"></activity>  
		<activity android:name="Tab2Activity"></activity>  
    </application>
</manifest> 

Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2