Tuesday, 22 May 2012

Get the difference between two Calendar

Modify the exercise "android.app.TimePickerDialog", calculate the difference between time and next set time in TimePickerDialog.

Get the difference between two Calendar


package com.exercise.AndroidTime;

import java.util.Calendar;

import android.app.Activity;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class AndroidTimeActivity extends Activity {

TimePicker myTimePicker;
Button buttonstartSetDialog;
TextView textPrompt;

TimePickerDialog timePickerDialog;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

textPrompt = (TextView)findViewById(R.id.prompt);

buttonstartSetDialog = (Button)findViewById(R.id.startSetDialog);
buttonstartSetDialog.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
openTimePickerDialog(false);

}});

}


private void openTimePickerDialog(boolean is24r){
Calendar calendar = Calendar.getInstance();

timePickerDialog = new TimePickerDialog(
AndroidTimeActivity.this,
onTimeSetListener,
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
is24r);
timePickerDialog.setTitle("TimePickerDialog Title");
timePickerDialog.setMessage("TimePickerDialog Message");

timePickerDialog.show();

}

OnTimeSetListener onTimeSetListener
= new OnTimeSetListener(){

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

Calendar calNow = Calendar.getInstance();
Calendar calSet = (Calendar) calNow.clone();

calSet.set(Calendar.HOUR_OF_DAY, hourOfDay);
calSet.set(Calendar.MINUTE, minute);

String stringPrompt = "Current Time is: " + calNow.getTime() + " / " + calNow.getTimeInMillis() + "\n"
+ "Set Time is: " + calSet.getTime() + " / " + calSet.getTimeInMillis() + "\n"
+ "calSet.compareTo(calNow) = " + calSet.compareTo(calNow) + "\n\n";

if(calSet.compareTo(calNow) > 0){
//Today Set time not yet passed
long diff = calSet.getTimeInMillis() - calNow.getTimeInMillis();
stringPrompt += "Millis to set time = " + diff;
}else{
//Today Set time passed, count to tomorrow
calSet.add(Calendar.DATE, 1);
long diff = calSet.getTimeInMillis() - calNow.getTimeInMillis();
stringPrompt += "Millis to tomorrow set time = " + diff;
}

textPrompt.setText(stringPrompt);
}};

}


<?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" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/startSetDialog"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Set Target Time"/>
<TextView
android:id="@+id/prompt"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>


Related:
- java.util.Calendar


java.util.Calendar

java.util.Calendar is an abstract base class for converting between a Date object and a set of integer fields such as YEAR, MONTH, DAY, HOUR, and so on.

Example of usage of Calendar.

Calendar


package com.exercise.AndroidCalendar;

import java.util.Calendar;
import java.util.Locale;

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

public class AndroidCalendarActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

TextView prompt = new TextView(this);
setContentView(prompt);
prompt.setText(getCalendarPrompt());
}

private String getCalendarPrompt(){
Calendar rightNow = Calendar.getInstance();

String p = rightNow + "\n\n"
+ rightNow.get(Calendar.YEAR) + "-"
+ rightNow.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US) + "-"
+ rightNow.get(Calendar.DATE) + "\n"
+ "DAY_OF_YEAR: " + rightNow.get(Calendar.DAY_OF_YEAR) + "\n"
+ "DAY_OF_MONTH: " + rightNow.get(Calendar.DAY_OF_MONTH) + "\n"
+ "DAY_OF_WEEK: " + rightNow.get(Calendar.DAY_OF_WEEK) + "\n"
+ "\n"
+ "getTime(): " + rightNow.getTime() + "\n"
+ "getTimeInMillis(): " + rightNow.getTimeInMillis() + "\n"
+ "\n";

return p;
}
}


Related:
- Get the difference between two Calendar


Monday, 21 May 2012

An HP Ultrabook with a Matte Finish (June 2012)

I ran across this a couple of weeks back, but I didn't have time to write about it.



HP EliteBook Folio 9470m

The HP EliteBook 9470m will be a 14" 3.5 pound ultrabook coming out in June 2012. Why am I blogging about it? HP announced a number of Ultrabook and Sleekbook notebooks a week or two ago. This machine (if I'm not mistaken) is the only one with a matte display. The base price should be around $1000.



I'm still waiting around to see what we are gonna get from Apple. Their new slim 15' MacBook pros could be interesting. But it is nice to have some alternatives.



Here are a couple of detailed reviews on this machine:



Laptop Review

Lilliputing

The Google I/O Countdown Contest



Android Power is launching a huge giveaway that'll take us all the way up to the big event - Google I/O. You'll have a chance to score awesome Android prizes each week from now through the start of I/O -- and from high-end tablets to standout Android swag, there's plenty of cool stuff just waiting to be won.

Details: The Google I/O Countdown Contest: Win a free Toshiba Excite 10 tablet!


android.app.TimePickerDialog

android.app.TimePickerDialog is dialog that prompts the user for the time of day using a TimePicker.

TimePickerDialog


Note:
  • If the TimePickerDialog closed by "Set" button, OnTimeSetListener and OnDismissListener will be called.
  • If the TimePickerDialog closed by "Cancel" button, only OnDismissListener will be called.
  • If the TimePickerDialog closed by "BACK" system button, OnCancelListener and OnDismissListener will be called.

package com.exercise.AndroidTime;

import java.util.Calendar;

import android.app.Activity;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnShowListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class AndroidTimeActivity extends Activity {

TimePicker myTimePicker;
Button buttonStartDialog12, buttonStartDialog24;
TextView info;

TimePickerDialog timePickerDialog;

String dialogMsg;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

info = (TextView)findViewById(R.id.info);

buttonStartDialog12 = (Button)findViewById(R.id.startDialog12);
buttonStartDialog12.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
openTimePickerDialog(false);

}});

buttonStartDialog24 = (Button)findViewById(R.id.startDialog24);
buttonStartDialog24.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View v) {
openTimePickerDialog(true);

}});
}


private void openTimePickerDialog(boolean is24r){
Calendar calendar = Calendar.getInstance();
timePickerDialog = new TimePickerDialog(
AndroidTimeActivity.this,
onTimeSetListener,
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
is24r);
timePickerDialog.setTitle("TimePickerDialog Title");
timePickerDialog.setMessage("TimePickerDialog Message");

timePickerDialog.setOnShowListener(new OnShowListener(){

@Override
public void onShow(DialogInterface arg0) {
dialogMsg = "OnShow\n";
info.setText(dialogMsg);
}});

timePickerDialog.setOnCancelListener(new OnCancelListener(){

@Override
public void onCancel(DialogInterface dialog) {
dialogMsg += "OnCancel\n";
info.setText(dialogMsg);

}});
timePickerDialog.setOnDismissListener(new OnDismissListener(){

@Override
public void onDismiss(DialogInterface arg0) {
dialogMsg += "OnDismiss\n";
info.setText(dialogMsg);
}});

timePickerDialog.show();

}

OnTimeSetListener onTimeSetListener
= new OnTimeSetListener(){

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
dialogMsg += "OnTimeSet " + hourOfDay + " : " + minute + "\n";
info.setText(dialogMsg);
}};

}


<?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" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/startDialog12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start TimePickerDialog in AM/PM mode "/>
<Button
android:id="@+id/startDialog24"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start TimePickerDialog in 24hr mode "/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
>
<TextView
android:id="@+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>


Related:
- android.widget.TimePicker


Sunday, 20 May 2012

Really Cool Looking CSS3 Buttons

One of the advantages of CSS3 is you can create some really good looking widgets without images. After looking around a bit for some really good examples, I have decided these buttons on Web Designer Wall are the best.



The buttons look really good in Webkit and Firefox and the CSS is relatively simple. Believe me, you can find some really complex stuff out there. Anyway, if you are looking for some really good buttons to use on your site, check it out.

5.1.1 Jailbreak

Planetbeing, pod2g, and members of cdev are on their way to the HitB venue in Amsterdam. I wish I could have joined with them and been a part of the fun. This week is going to be very big for jailbreakers and newcomers to iOS devices stuck on 5.1.1 without any jailbreak.




These guys deserve your donations and your thanks. Pod and nikias did some amazing things. Planetbeing stepped in and resurrected some 'old' things to make them useful for this jailbreak. 





Any updates will be posted on cdev's main blog as well as here.