2012年2月20日月曜日

Preferenceの使い方 2

preferences.xmlを使わずに直接書き込みを行う方法

 
     SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
     Editor e = pref.edit();
     e.putString("ip", "保存するテキスト");
     e.putString("path",  "保存するテキスト" );
     e.commit();
こんな感じ。

2012年2月9日木曜日

PendingIntent

RemoteViewやNotificationクラスに用いるPendingIntentというもの
よく理解出来ていないため少し整理してみます。

これはタイミングを指定して発行することができるIntentのようです。
new したIntentを、直ちに発行するのではなく、ボタンを押されたタイミングで発行する等に
利用するようです。
引数でIntentのインスタンスを受けとって包むので、Wrapper的な役割ですかね。

PendingIntentは、以下のstatic メソッドから取得できる
どこに対して発行するかによって、作り方が違う

getActivity(Context, int, Intent, int)
→Activityへ投げる
getBroadcast(Context, int, Intent, int)
→ブロードキャストへ投げる
getService(Context, int, Intent, int);
→Serviceへ投げる

例えば、Notificationに使う場合は、
通知バーをタップしたタイミングでIntentが発行されるという感じのようです。

PendingIntent自身はOSが管理しているものなので
PendingIntentを起動した元のActivityが死んでも、それはOSによって残り続け
通知バーをタップしたタイミングで、Intentが投げられ、
元のAcitivyが起動されるという感じのようです(自信なし)

■参考にさせて頂いたサイト:
http://y-anz-m.blogspot.com/2011/07/androidappwidget-pendingintent-putextra.html

2012年2月6日月曜日

ProgressBarの使い方


プログレスバー(進捗)の表示には、ProgressBarウィジェットを用いる。

スタイルの指定(XMLレイアウト)
android:progressBarStyle        通常の円
android:progressBarStyleHorizontal   水平方向のバー
android:progressBarStyleLarge      大きい円
android:progressBarStyleSmall      小さい円

StyleHorizontal 使用時に限り、進捗状況の表示が可能になる。

メソッド:
setMax() プログレスバーの最大値の指定。上限はint型の範囲。
setProgress() 現在の進捗の値を設定(濃い色で表示される)
setSecondaryProgress() セカンダリの値の指定(薄い色で表示される)

使用例)
ProgressBar progress = (ProgressBar) findViewById(プログレスバーWidgetのID);
progress.setMax(100);
progress.setProgress(20);
progress.setSecondaryProgress(70);