実行結果やエラー結果を、処理の完了後に報告できるようにしたい場合。
各種報告メッセージを格納していくカスタムクラスを作ればどうか。
するとフォーマットが常に一定になるのでわかりやすそう。
class ResultReport{
private $type; //種別
private $result; //成功失敗フラグ
private $input; //インプット内容
private $output; //アウトプット結果
private $massage; //報告文(エラーの場合はその詳細原因とか)
//各種ゲッター
//各種セッター
} //class
みたいな。
仕事中に気づいたプログラミング上のTipsや備忘録をメモしておくための場所です。
[PHP][Android]など
ブログ主:いしいたける
メインのWebサイト(マンガ) : http://loveandcomic.com/
2014年10月31日金曜日
2014年10月25日土曜日
【Android】アニメーション終了を検知する
アプリの起動時に表示されるスプラッシュ画面なんかをフェイドアウトなどのアニメーションをしてから遷移させたい場合。
アニメーションの終了を検知するリスナーメソッドがあるのでそれを使うといい。
■該当のフラグメントクラスに AnimationListener を implements させる。
■必須メソッドを実装する。
◆onAnimationStart(Animation animation)
◆onAnimationRepeat(Animation animation)
◆onAnimationEnd(Animation animation) →終了時の動作をここに書く
■該当のアニメーションインスタンスに .setAnimationListener(this) とする。
ここでの引数は「AnimationListener を implements したクラスのインスタンス=自分自身のフラグメントクラスのインスタンス」
こういう感じ。
-----------
//ImageViewのオブジェクト取得
ImageView splash02 = (ImageView)rootView.findViewById(R.id.splash02_animation_imageview);
//アニメーションで使う、フェードアウトにかかる時間(ミリ秒)
int duration_animation = 1*1000;
//複合アニメーション作成
//【1】インスタンスを生成
AnimationSet animation_set = new AnimationSet(true);
splash02_container = (ViewGroup) getActivity().findViewById(R.id.splash02_container);
//【2】基本のアニメーションを生成
//フェードアウト
AlphaAnimation fade_out_animation = new AlphaAnimation(1.0f, 0.0f);
//拡大
ScaleAnimation expand_out_animation = new ScaleAnimation(
1.0f,
20.0f,
1.0f,
20.0f,
(splash02.getWidth())/2,
(splash02.getHeight())/2
);
//【3】生成したアニメーションを追加
animation_set.addAnimation(fade_out_animation);
animation_set.addAnimation(expand_out_animation);
//アニメーションを適用
animation_set.setDuration(duration_animation);
//アニメーション終了感知リスナーを登録 onAnimationEnd()メソッドが実行される
animation_set.setAnimationListener(this);
//アニメーションをスタート
splash02_container.startAnimation(animation_set);
-----------
アニメーションの終了を検知するリスナーメソッドがあるのでそれを使うといい。
■該当のフラグメントクラスに AnimationListener を implements させる。
■必須メソッドを実装する。
◆onAnimationStart(Animation animation)
◆onAnimationRepeat(Animation animation)
◆onAnimationEnd(Animation animation) →終了時の動作をここに書く
■該当のアニメーションインスタンスに .setAnimationListener(this) とする。
ここでの引数は「AnimationListener を implements したクラスのインスタンス=自分自身のフラグメントクラスのインスタンス」
こういう感じ。
-----------
//ImageViewのオブジェクト取得
ImageView splash02 = (ImageView)rootView.findViewById(R.id.splash02_animation_imageview);
//アニメーションで使う、フェードアウトにかかる時間(ミリ秒)
int duration_animation = 1*1000;
//複合アニメーション作成
//【1】インスタンスを生成
AnimationSet animation_set = new AnimationSet(true);
splash02_container = (ViewGroup) getActivity().findViewById(R.id.splash02_container);
//【2】基本のアニメーションを生成
//フェードアウト
AlphaAnimation fade_out_animation = new AlphaAnimation(1.0f, 0.0f);
//拡大
ScaleAnimation expand_out_animation = new ScaleAnimation(
1.0f,
20.0f,
1.0f,
20.0f,
(splash02.getWidth())/2,
(splash02.getHeight())/2
);
//【3】生成したアニメーションを追加
animation_set.addAnimation(fade_out_animation);
animation_set.addAnimation(expand_out_animation);
//アニメーションを適用
animation_set.setDuration(duration_animation);
//アニメーション終了感知リスナーを登録 onAnimationEnd()メソッドが実行される
animation_set.setAnimationListener(this);
//アニメーションをスタート
splash02_container.startAnimation(animation_set);
-----------
2014年10月23日木曜日
【concrete5】toolsのPHPのURL
concrete5でAjaxを使いたい場合、toolsディレクトリに入れたPHPだったら、
■URLを持てる
■concrete5の定数やメソッドが使える
■ヘッダーとか背景とかの余計なレンダリングはされない
というふうになる。
ただ、URLがわかりにくい。
パッケージ内のPHPのURL
/index.php/tools/packages/パッケージ名/PHPファイルの拡張子を取った名前
確認の仕方
■パッケージ名:my_package
■PHPファイル名:my_test.php
■つまり「/packages/my_package/tools/my_test.php」の場合
// get files called "my_test" located in /packages/my_package/tools/
echo Loader::helper('concrete/urls')->getToolsURL('my_test', 'my_package');
こうなる。
■URLを持てる
■concrete5の定数やメソッドが使える
■ヘッダーとか背景とかの余計なレンダリングはされない
というふうになる。
ただ、URLがわかりにくい。
パッケージ内のPHPのURL
/index.php/tools/packages/パッケージ名/PHPファイルの拡張子を取った名前
確認の仕方
■パッケージ名:my_package
■PHPファイル名:my_test.php
■つまり「/packages/my_package/tools/my_test.php」の場合
// get files called "my_test" located in /packages/my_package/tools/
echo Loader::helper('concrete/urls')->getToolsURL('my_test', 'my_package');
こうなる。
【concrete5】データベース使用時にプリペアステートメントを使う
こんなかんじで書いた。
////////////////////
//データベースインスタンス
$db = Loader::db();
//プリペアステートメントの使用
$prepare = $db->Prepare("
SELECT COUNT(*)
FROM Users
WHERE uName = ?
");
$values = array("admin");
$search_result = $db->GetOne($prepare, $values);
////////////////////
//データベースインスタンス
$db = Loader::db();
//プリペアステートメントの使用
$prepare = $db->Prepare("
SELECT COUNT(*)
FROM Users
WHERE uName = ?
");
$values = array("admin");
$search_result = $db->GetOne($prepare, $values);
2014年10月8日水曜日
【Android】.setVisibility(View.INVISIBLE) と .setVisibility(View.GONE) との違い
ビュー要素を見えなくしたい時、以下のようなコードを書く。
◆ビュー要素.setVisibility(View.INVISIBLE)
◆ビュー要素.setVisibility(View.GONE)
ふたつの違いは、「その要素が入るべきスペースが詰められるかそうでないか」である。
◆ビュー要素.setVisibility(View.INVISIBLE)
→見えなくなるだけで場所は占領したまま。
◆ビュー要素.setVisibility(View.GONE)
→見えなくなるし、存在自体が消え去ったようにスペースも詰められる。
◆ビュー要素.setVisibility(View.INVISIBLE)
◆ビュー要素.setVisibility(View.GONE)
ふたつの違いは、「その要素が入るべきスペースが詰められるかそうでないか」である。
◆ビュー要素.setVisibility(View.INVISIBLE)
→見えなくなるだけで場所は占領したまま。
◆ビュー要素.setVisibility(View.GONE)
→見えなくなるし、存在自体が消え去ったようにスペースも詰められる。
登録:
投稿 (Atom)