ソフトバンク、『X06HT HTC Desire』の予約開始


4月1日より、ソフトバンクモバイルのAndroid搭載スマートフォン「HTC Desire」の予約を開始しました

全国のソフトバンクモバイル携帯電話取り扱い店にて、1人1台まで受け付けるそうです

実質負担額は2万前後だとか

詳しくは公式サイトより

NTT docomo が 『Xperia (SO-01B)』を販売開始


4月1日より、NTT docomo から Google の Android OS を搭載したSony Ericsson製のスマートフォン『Xperia (SO-01B)』の販売を開始しました

詳しくは公式サイトより

スペシャルサイトがめっちゃかっこいいです

TimePickerDialog を使ってみた

TimePickerDialog は
java.lang.Object
  ↳ android.app.Dialog
    ↳ android.app.AlertDialog
      ↳ android.app.TimePickerDialog
を使います

というわけで、TimePickerDialog をいじってみた

サンプルプログラム
import java.util.Calendar;

import android.app.Activity;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TimePicker;

public class TimePickerDialogTest extends Activity {
  final Calendar calendar = Calendar.getInstance();
  // カレンダーから現在の '時' を取得
  int mHour = calendar.get(Calendar.HOUR_OF_DAY);
  // カレンダーから現在の '分' を取得
  int mMinute = calendar.get(Calendar.MINUTE);

  TimePickerDialog timePickerDialog;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    
    // TImePickerDialog の時刻が変更された時に呼び出されるコールバックを登録
    TimePickerDialog.OnTimeSetListener listener = new TimePickerDialog.OnTimeSetListener() {
      public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        mHour = hourOfDay; // '時' を取得
        mMinute = minute;  // '分' を取得
      }
    };

    // TimePickerDialog の作成
    timePickerDialog = new TimePickerDialog(
      this,     // 第1引数 : Context
      listener, // 第2引数 : TimePickerDialog.OnTimeSetListener
      mHour,    // 第3引数 : 時
      mMinute,  // 第4引数 : 分
      true      // 第5引数 : 24時間表示(true)かAM/PM表示(false)か
    );

    // Dialog の Positive Button を設定
    timePickerDialog.setButton(
      DialogInterface.BUTTON_POSITIVE,
      "Positive", 
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          // Positive Button がクリックされた時の動作
        }
      }    
    );

    // Dialog の Negative Button を設定
    timePickerDialog.setButton(
      DialogInterface.BUTTON_NEGATIVE, 
      "Negative", 
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          // Negative Button がクリックされた時の動作
        }
      }
    );
  
    // Dialog の Neutral Button を設定
    timePickerDialog.setButton(
      DialogInterface.BUTTON_NEUTRAL, 
      "Neutral", 
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          // Neutral Button がクリックされた時の動作
        }
      }
    );

    // TimePickerDialog の表示
    timePickerDialog.show();
  }
}

プログラムを実行すると...


AM/PM表示のとき

こんな感じ!

ProgressDialog を使ってみた

ProgressDilaog は
java.lang.Object
  ↳ android.app.Dialog
    ↳ android.app.AlertDialog
      ↳ android.app.ProgressDialog
を使います

というわけで、ProgressDialog をいじってみた

サンプルプログラム
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;

public class ProgressDialogTest extends Activity implements Runnable {
  ProgressDialog progressDialog;
  Thread thread;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.progressdialogtest);

    progressDialog = new ProgressDialog(this);
  
    // ProgressDialog のタイトルを設定
    progressDialog.setTitle("Title");

    // ProgressDialog のメッセージを設定
    progressDialog.setMessage("Message");

    // ProgressDialog の確定(false)/不確定(true)を設定します
    progressDialog.setIndeterminate(false);

    // ProgressDialog のスタイルを水平スタイルに設定
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    // 円スタイルの場合
    // progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    // ProgressDialog の最大値を設定 (水平の時)
    progressDialog.setMax(100);

    // ProgressDialog の初期値を設定 (水平の時)
    progressDialog.incrementProgressBy(0);

    // ProgressDialog のセカンダリ値を設定 (水平の時)
    progressDialog.incrementSecondaryProgressBy(50);

    // ProgressDialog のキャンセルが可能かどうか
    progressDialog.setCancelable(false);
 
    // ProgressDialog のキャンセルされた時に呼び出されるコールバックを登録
    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
      public void onCancel(DialogInterface dialog) {
        // Thread を停止
        stop();
      }
    });

    // Start ボタン
    findViewById(R.id.ProgressDialogTest_Button).setOnClickListener(  
      new View.OnClickListener() {  
        public void onClick(View view) {  
          // ProgressDialog を表示
          progressDialog.show();
          // Thread を起動
          init();
          start();
        }  
      }
    );

    // ProgressDialog の Cancel ボタン
    progressDialog.setButton(
      DialogInterface.BUTTON_NEGATIVE,
      "Cancel",
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          // ProgressDialog をキャンセル
          dialog.cancel(); 
        }
      }
    );
  }
 
  /** Runnable のプログラム */
  public void init() {
    thread = null;
  }
  public void start() {
    if (thread == null) {
      thread = new Thread(this);
      thread.start();
    }
  }
  public void run() {
    int count = 0;
    Thread thisThread = Thread.currentThread();
    while (thisThread == thread) {
      // 100ms毎に Progress Bar を進める
      progressDialog.setProgress(count++);  
      try {
        thread.sleep(100);  
      } catch (InterruptedException e) {
      }
      if (count >= progressDialog.getMax()) {
        // Progress が完了
        break;
      }
    }
    // Progress Dialog を消す
    progressDialog.dismiss();
  }
  public void stop() {
    thread = null;
  }
}

プログラムを実行すると...

円スタイルのとき

こんな感じ!

DatePickerDialog を使ってみた

DatePickerDialog は
java.lang.Object
  ↳ android.app.Dialog
    ↳ android.app.AlertDialog
      ↳ android.app.DatePickerDialog
を使います

というわけで、DatePickerDialog をいじってみた

サンプルプログラム
import java.util.Calendar;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.DatePicker;

public class DatePickerDialogTest extends Activity {
  final Calendar calendar = Calendar.getInstance();
  // カレンダーから現在の '年' を取得
  int mYear = calendar.get(Calendar.YEAR);
  // カレンダーから現在の '月' を取得
  int mMonth = calendar.get(Calendar.MONTH);
  // カレンダーから現在の '日' を取得
  int mDay = calendar.get(Calendar.DAY_OF_MONTH);

  DatePickerDialog datePickerDialog;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // DatePickerDialog の日付が変更されたときに呼び出されるコールバックを登録
    DatePickerDialog.OnDateSetListener listener = new DatePickerDialog.OnDateSetListener() {
      public void onDateSet(
          DatePicker view, 
          int year,
          int monthOfYear,
          int dayOfMonth) {                
        mYear = year;         // '年' を取得
        mMonth = monthOfYear; // '月' を取得
        mDay = dayOfMonth;    // '日' を取得
      }
    };

    // DatePickerDialog の作成
    datePickerDialog = new DatePickerDialog(
      this,     // 第1引数 : Context
      listener, // 第2引数 : DatePickerDialog.OnDateSetListener
      mYear,    // 第3引数 : 年
      mMonth,   // 第4引数 : 月
      mDay      // 第5引数 : 日
    );

    // Dialog の Positive Button を設定
    datePickerDialog.setButton(
      DialogInterface.BUTTON_POSITIVE,
        "Positive", 
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
            // Positive Button がクリックされた時の動作
          }
        }    
    );

    // Dialog の Negative Button を設定
    datePickerDialog.setButton(
      DialogInterface.BUTTON_NEGATIVE, 
      "Negative", 
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          // Negative Button がクリックされた時の動作
        }
      }
    );
  
    // Dialog の Neutral Button を設定
    datePickerDialog.setButton(
      DialogInterface.BUTTON_NEUTRAL, 
      "Neutral", 
      new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
          // Neutral Button がクリックされた時の動作
        }
      }
    );

    // DatePickerDialog の表示
    datePickerDialog.show();
  }
}

プログラムを実行すると...


こんな感じ!