(2011-02の一覧)
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
2011-02-06 Sun (他の年の同じ日: 2006)
前のエントリ/次のエントリにタイトル付加
2011-02-06-3 / カテゴリ: [perl][chalow] / [permlink]
アイテム毎ページの次へ/前へに、そのタイトルをつける。
テンプレ例
--- chalow.20110206 2011-01-23 16:42:29.715835927 +0900
+++ chalow 2011-02-06 03:59:16.342571765 +0900
@@ -763,15 +763,21 @@
my $ymdi_before;
my $ymdi_after;
+ my $before_title;
+ my $after_title;
if ($i > 1) {
$ymdi_before = $ymd."-".($i-1);
+ $before_title = $ent->{$i-1}->{ho};
} elsif ($idx < @day_list - 1) {
my $day_b = $day_list[$idx + 1];
$ymdi_before = $day_b."-".$cl->{all}->{$day_b}{curid};
+ $before_title = $cl->{all}->{$day_b}->{$cl->{all}->{$day_b}{curid}}->{ho};
}
if ($i != $ent->{curid}) {
$ymdi_after = $ymd."-".($i+1);
+ $after_title = $ent->{$i+1}->{ho};
} elsif ($idx > 0) {
my $day_a = $day_list[$idx - 1];
$ymdi_after = $day_a."-1";
+ $after_title = $cl->{all}->{$day_a}->{1}->{ho};
}
@@ -794,4 +800,6 @@
$t->param(back => $ymdi_before);
$t->param(next => $ymdi_after);
+ $t->param(back_title => $before_title);
+ $t->param(next_title => $after_title);
my $ccc = $item->{c}; $ccc =~ s!^<br />!!g;# ad hoc
現在の処理対象アイテムのタイトル取得は
$t->param(header_text => $item->{ho};
にあるので、特定のアイテムのタイトルは
$cl->{all}->{"YYYYmmdd"}->{x}->{ho};
で取れる。テンプレ例
--- cl.conf.20110206 2011-01-23 16:42:37.523566691 +0900 +++ cl.conf 2011-02-06 03:58:01.367043689 +0900 @@ -362,6 +362,6 @@ <div id="content"> <p class="calendar"><a href="<TMPL_VAR name=ym>.html"><TMPL_VAR name=ym></a> / <a href="<TMPL_VAR name=ymd>.html"><TMPL_VAR name=ymd></a></p> -<TMPL_IF name=back><a href="<TMPL_VAR name=back>.html">前のエントリ</a> / </TMPL_IF> -<TMPL_IF name=next><a href="<TMPL_VAR name=next>.html">次のエントリ</a></TMPL_IF> +<TMPL_IF name=back><a href="<TMPL_VAR name=back>.html">前のエントリ(<TMPL_VAR name=back_title>)</a> / </TMPL_IF> +<TMPL_IF name=next><a href="<TMPL_VAR name=next>.html">次のエントリ(<TMPL_VAR name=next_title>)</a></TMPL_IF> <!-- start:<TMPL_VAR name=ymdi> --> <div class="day">
[
コメント ]
AlarmManagerで単純にブロードキャストを投げるだけ
2011-02-06-2 / カテゴリ: [Java][Android] / [permlink]
__軽く__ググってみても、「指定Activityを起動」「BroadcastReceiverをextendsした自前レシーバで受ける」しか見つけられなかったので「特定Activityが生きてれば受ける、なければ無視」をお試し。
ちなみに、定期/定時処理の実装は以下の方法がある(ほかにも有るかも。知らないだけで)
するようなイメージみたい。(thanks! @amay077さん)
AlarmManagerはシステムレベルで動作するので、アプリの寿命と独立してるのがポイント。
指定時間にブロードキャストでなく、単にActivityを起動するだけなら、
AlarmManager.ELAPSED_REALTIME で「○msec後」に起動設定になる。
「Y年m月d日H時M分S秒に」の場合は、AlarmManager.RTC を使う
前記のAlarmManager#setは、指定時間に単に起動するのみ。
定期的に実行するにはAlarmManager#setRepeating()を使う。
キューに入ってるアラームを停止するにはcancel()
参考
Service(サービス)関連 mucchinのAndroid戦記
AlarmManagerで指定した時間に処理させる - Tech Booster
AlarmManager - 愚鈍人
Taosoftware: AlarmManager1 AndroidでCronみたいなことをするには
AlarmManagerの使用 - すにぺっと
ちなみに、定期/定時処理の実装は以下の方法がある(ほかにも有るかも。知らないだけで)
| Timer | アプリで管理 |
| AlarmManager | システム(android)で管理 |
AlarmManagerはシステムレベルで動作するので、アプリの寿命と独立してるのがポイント。
public final static String INTENT_ACTION = "alarmmgr_broadcast"; : : AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); Intent intent = new Intent(INTENT_ACTION); PendingIntent pending = PendingIntent.getBroadcast(this, 0, intent, 0); long current = SystemClock.elapsedRealtime(); // 5秒後(current + 5*1000)にpending発動(1回きり) am.set(AlarmManager.ELAPSED_REALTIME, current + 5*1000, pending);このBroadcastを受けるには[2011-02-06-1]の例で。
指定時間にブロードキャストでなく、単にActivityを起動するだけなら、
Intent intent = new Intent(this, FooBar.class); PendingIntent pending = PendingIntent.getActivity(this, 0, intent, 0);こんな感じで。サービス起動もいけそう(getService()で)。
AlarmManager.ELAPSED_REALTIME で「○msec後」に起動設定になる。
「Y年m月d日H時M分S秒に」の場合は、AlarmManager.RTC を使う
Calendar cal = Calendar.getInstance(); cal.set(2011, 1, 6, 3, 0, 0); // 2011-02-06 03:00:00 の場合。monthは0オリジン(-1する) long next = cal.getTimeInMillis(); Log.d(TAG, "current: " + next); am.set(AlarmManager.RTC, next, pending);
前記のAlarmManager#setは、指定時間に単に起動するのみ。
定期的に実行するにはAlarmManager#setRepeating()を使う。
キューに入ってるアラームを停止するにはcancel()
am.cancel(pending);キャンセルは、Intentが同じ(filterEquals()がtrue)ものが対象らしい。
Remove any alarms with a matching Intent. Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.
AlarmManager#cancel
参考
Service(サービス)関連 mucchinのAndroid戦記
AlarmManagerで指定した時間に処理させる - Tech Booster
AlarmManager - 愚鈍人
Taosoftware: AlarmManager1 AndroidでCronみたいなことをするには
AlarmManagerの使用 - すにぺっと
[
コメント ]
レシーバおぼえがき(BroadcastReceiver)
2011-02-06-1 / カテゴリ: [Java][Android] / [permlink]
そのActivityがtopにいる場合にブロードキャストを受けるには。
(rergisterReceive()を複数叩いて複数のレシーバを受ける場合は必要)
おまけ
↑のInternalは別クラス(ブロードキャスト元)
投げる部分はこんな感じ。(適当)
public class FooBar extends Activity {
:
:
// スレッドの通知を受けるためのレシーバ
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, " onReceive(" + context + ", " + intent + ")");
if (intent.getAction().equals(Internal.INTENT_ACTION)) {
Log.d(TAG, "intent val: " + intent.getIntExtra(Internal.INTENT_VAL, 0));
}
}
};
@Override
public void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
// レシーバの登録
registerReceiver(mReceiver, new IntentFilter(Internal.INTENT_ACTION));
}
@Override
public void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
// レシーバの解除
unregisterReceiver(mReceiver);
}
:
registerReceiver()第2引数でフィルタを設定しているので、onReceive()内でgetAction()でAction名をチェックしてるのはこの例では冗長。(rergisterReceive()を複数叩いて複数のレシーバを受ける場合は必要)
おまけ
↑のInternalは別クラス(ブロードキャスト元)
投げる部分はこんな感じ。(適当)
public class Internal extends Activity {
public final static String INTENT_ACTION = "internal_thread_broadcast";
public final static String INTENT_VAL = "internal_thread_val";
private int mCount = 0;
// 中略
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
// TODO 自動生成されたメソッド・スタブ
try {
for (;;) {
Thread.sleep(1000);
mCount ++;
Log.d(TAG, "running count("+ mCount + ")");
Intent intent = new Intent(INTENT_ACTION);
intent.putExtra(INTENT_VAL, mCount);
sendBroadcast(intent);
}
} catch (InterruptedException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
});
thread.start();
// 後略
Referrer (Inside):
[2011-02-06-2]
[
コメント ]
2013 : 01 02 03 04 05 06 07 08 09 10 11 12
2012 : 01 02 03 04 05 06 07 08 09 10 11 12
2011 : 01 02 03 04 05 06 07 08 09 10 11 12
2010 : 01 02 03 04 05 06 07 08 09 10 11 12
2009 : 01 02 03 04 05 06 07 08 09 10 11 12
2008 : 01 02 03 04 05 06 07 08 09 10 11 12
2007 : 01 02 03 04 05 06 07 08 09 10 11 12
2006 : 01 02 03 04 05 06 07 08 09 10 11 12
2005 : 01 02 03 04 05 06 07 08 09 10 11 12
2004 : 01 02 03 04 05 06 07 08 09 10 11 12
最終更新時間: 2013-05-02 16:12
