今日のメモ (2)
続き
どうも PreferenceActivity なるソレがある模様。ざっくり案を以下に控え。まずは res/xml/pref.xml からで以下?
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/title"> <EditTextPreference android:key="google_id" android:title="@string/google_id_title" android:summary="@string/google_id_summary" android:dialogTitle="@string/google_id_dialogtitle" /> <EditTextPreference android:key="google_passwd" android:title="@string/google_passwd_title" android:summary="@string/google_passwd_summary" android:dialogTitle="@string/google_passwd_dialogtitle" /> </PreferenceCategory> </PreferenceScreen>
これで良いのかな。とりあえず試しに作ってみる事に。次世代創造機構.jp さんからコードを頂いたんですが、リンクが貼れません。とりあえずサンプルをでっち上げ。Manifest に Application Nodes なエントリ書いとかないと startActivity() の呼び出しで ActivityNotFoundException が、な事を忘れててハマる。
以下が res/xml/pref.xml
<?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="@string/title"> <CheckBoxPreference android:key="language" android:title="言語" android:defaultValue="false" android:summary="日本語、英語を切り替える"> </CheckBoxPreference> </PreferenceCategory> </PreferenceScreen>
で、本体が以下。
package com.example.adroid.psample; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Preference extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Button button = new Button(this); button.setTextColor(0xff00ffff); if(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("language", false) == true) { button.setText("Setting"); } else { button.setText("Settei-Suru"); } setContentView(button); button.setOnClickListener(this); } public void onClick(View v) { final Intent intent = new Intent(getApplicationContext(), Setting.class); startActivity(intent); } }
startActivity() される Setting が以下。
package com.example.adroid.psample; import android.os.Bundle; import android.preference.PreferenceActivity; public class Setting extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref); } }
onResume() とか追加しようと思ったんですが面倒なのでスルー。マージしようと思ったんですが、リファクタリングが先な模様。それにしても例外処理ってウザ杉 (を
追記
認証後のアクセスも POST の方が良いのかな、って事で試してみました。あと手続き分けてそれぞれ例外を throw する形に。ここまでヤると Http なやりとりは別なスレッドにしたい所かも。
で、試してみたんですが、GAE 側で get しか定義してなかった件orz