ようへい

2012年4月21日土曜日

4/21 Android ニュースひとまとめ

有料Androidアプリはビジネスにならないという声がよく聞かれますが、その辺に関してはやはり同意見でしょうか?

「Androidの有料アプリで、大手デベロッパーとしてのクオリティを保つと、採算性を維持するのが難しいのは事実だと思います。端末の動作検証を しっかりやるとなると、そのコストも大きいですし、それをやっても機種依存の問題を潰しきれていない状況だと感じます。この点でiOSに比べて不利だと思います。また、私自身も、余裕を持てる収入を得られていないのが現実です」

今後も道具屋シリーズの新作はリリースされると思っていいのでしょうか?

「今後もリリースの予定はありますが、マンネリ化しないように、次回はゲームの世界観を大きく変えたいと思います」
「道具屋の冒険」作者に聞く Androidアプリ“個人開発者”の現実 | 【EXドロイド(エックスドロイド)】
http://exdroid.jp/d/34685/
やはり、有料アプリとして動作保証を行うために検証等のコストが増え、あまり採算が取れないみたいですね。
趣味の一環であればいいのかもしれませんが、アプリ開発で生活するというレベルに持っていくには、なかなか厳しそう。
次回作は世界観が変わるとのこと。
楽しみに待ちたいと思います。
関連記事

[Android アプリレビュー] クルーズ大紀行

情報
クルーズ大紀行
クルーズ大紀行
6週目でゴールド絨毯引継
クルーズ大紀行
各種カイロくん像引継
クルーズ大紀行
シアター引継
クルーズ大紀行
かなり邪道なプレイ
クルーズ大紀行
クルーザーを運営するゲーム。
相性を考えて施設を配置したり、アイテムで品質、料金をアップしたり、ゆけむり温泉郷と同じようなシステム。
活力という新しいシステムが導入されており、建築のアイテムによって、活力を上昇させることが出来る。
活力が貯まるとオーラが発生し、ファンが増えやすくなる。
ファンが増えると、国王の招待イベントを発生させることが出来る。
国王に満足してもらえると、新しい国を紹介してもらうことができ、新しい客や、アイテムを獲得できる。
ゆけむり温泉郷を楽しめた人は同じように楽しめる。逆に、クルーズ大紀行にハマった人はゆけむり温泉郷も楽しめるはず。
攻略
16年4月でクリアとなる。
クリア時に引き継がれる項目は以下。
  • 銅、銀、金カイロくん像
  • シアター
  • シアターの演目
  • 200,000で購入可能な各種絨毯
現在6週目に突入。 ここまでやると、色々と縛りプレイをやっているのだが、銅、銀、金カイロくん像、シアター(カイロ祭り)を手に入れていれば最終的に1Fのみでクリアできることが分かった。 国王や審査員は窓側の部屋に泊まらせて近くにカイロくん像を置く。 シアターの演目はカイロ祭り。オーラが発生する事でファンが増えやすくなる。 私が1Fのみのプレイで設置する施設は、船室、自販機、ATM、観光案内所、レストラン(屋外)のみ。 国王、審査員向けにゆくゆく豪華な船室を1部屋設置しても良い。 また、船内への入り口を一つに絞ることで、客の活力を効率的に高めることが出来る。 入り口付近の床を撤去する事で、その入り口から出入りしなくなる。 私は、右上の入り口以外は閉鎖した。 また、入り口近くに、銅カイロくん像を設置。これで、船内に入るすべての客の活力アップを行える。 船内の通路は活力が上がる絨毯にする。 これでだいぶ資金に余裕ができると思うので、アイテム購入や、投資に思う存分お金を使うことが出来る。 アイテムは惜しみなく使う。 りんごは大量に購入可能なので、船室に使用するのがオススメ。 船体を無拡張でクリアしたこともあったが、あまり面白くなかったw 通路次第で迷路みたいな船内にすることもできます。
クルーズ大紀行
動作
アプリケーションの安定性
価格
コストパフォーマンスが良いかどうか
関連記事

Hello, Views (Spinner編)

Spinner | Android Developers
http://developer.android.com/intl/ja/resources/tutorials/views/hello-spinner.html JavaScriptのセレクトオブジェクト、C#等のコンボボックスですね。
HelloSpinnerというプロジェクトを作成します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="@string/planet_prompt"
    />
    <Spinner 
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:prompt="@string/planet_prompt"
    />
</LinearLayout>
res/values/strings.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, HelloSpinnerActivity!</string>
    <string name="app_name">HelloSpinner</string>
    <string name="planet_prompt">Choose a planet</string>
    <string-array name="planets_array">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
        <item>Jupiter</item>
        <item>Saturn</item>
        <item>Uranus</item>
        <item>Neptune</item>
    </string-array>

</resources>
HelloSpinnerActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloSpinner;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class HelloSpinnerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.planets_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
    }
}
Spennerのアイテムが選択された際にアプリケーションに通知を行うコールバックメソッドを定義します。 HelloSpinnerActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloSpinner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class HelloSpinnerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.planets_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
    }

    public class MyOnItemSelectedListener implements OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
          Toast.makeText(parent.getContext(), "The planet is " +
              parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
        }

        public void onNothingSelected(@SuppressWarnings("rawtypes") AdapterView parent) {
          // Do nothing.
        }
    }
}
MyOnItemSelectedListenerをSpennerに登録します。 HelloSpinnerActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloSpinner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class HelloSpinnerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Spinner spinner = (Spinner) findViewById(R.id.spinner);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.planets_array, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);

        spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    }

    public class MyOnItemSelectedListener implements OnItemSelectedListener {

        public void onItemSelected(AdapterView<?> parent,
            View view, int pos, long id) {
          Toast.makeText(parent.getContext(), "The planet is " +
              parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
        }

        public void onNothingSelected(@SuppressWarnings("rawtypes") AdapterView parent) {
          // Do nothing.
        }
    }
}
実行します。
今回出てきたキーワードについて解説。
Spenner
JavaScriptでのセレクトオブジェクト、C#でのコンボボックス
setDropDownViewResource
Spennerで表示されるビューを指定
simple_spinner_dropdown_item
Androidで定義されているレイアウトファイルのID
setDropDownViewResourceにセットすると、項目の隣にラジオボタンのようなオブジェクトが表示される
setOnItemSelectedListener
Spennerのアイテムがセレクトされた際のイベントリスナ登録
getItemAtPosition
選択されたビューの取得
@SuppressWarnings
Javaのアノテーション
parentがraw型とのことで、警告が発生したため、@SuppressWarnings("rawtypes")を追記。
これで警告を無効化できます。
関連記事

2012年4月20日金曜日

Hello, Views (Form Stuff編)

Form Stuff | Android Developers
http://developer.android.com/intl/ja/resources/tutorials/views/hello-formstuff.html フォーム要素のチュートリアルです。
HelloFormStuffというプロジェクトを作成します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>
カスタムボタンを配置します。
チュートリアルページの3つの画像をローカルに保存し、res/drawable/ ディレクトリに保存します。
res/drawable/に android_button.xml を作成し、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/android_pressed"
          android:state_pressed="true" />
    <item android:drawable="@drawable/android_focused"
          android:state_focused="true" />
    <item android:drawable="@drawable/android_normal" />
</selector>
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />

</LinearLayout>
HelloFormStuffActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class HelloFormStuffActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
実行します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />

</LinearLayout>
HelloFormStuffActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class HelloFormStuffActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HelloFormStuffActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
    }
}
実行します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />
    
    <CheckBox android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_label" />

</LinearLayout>
res/values/strings.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, HelloFormStuffActivity!</string>
    <string name="app_name">HelloFormStuff</string>
    <string name="checkbox_label">check it out</string>

</resources>
HelloFormStuffActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

public class HelloFormStuffActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HelloFormStuffActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
        
        final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
        checkbox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks, depending on whether it's now checked
                if (((CheckBox) v).isChecked()) {
                    Toast.makeText(HelloFormStuffActivity.this, "Selected", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuffActivity.this, "Not selected", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
実行します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />
    
    <CheckBox android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_label" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <RadioButton android:id="@+id/radio_red"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/red" />
        <RadioButton android:id="@+id/radio_blue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/blue" />
    </RadioGroup>

</LinearLayout>
res/values/strings.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, HelloFormStuffActivity!</string>
    <string name="app_name">HelloFormStuff</string>
    <string name="checkbox_label">check it out</string>
    <string name="red">Red</string>
    <string name="blue">Blue</string>

</resources>
HelloFormStuffActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class HelloFormStuffActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HelloFormStuffActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
        
        final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
        checkbox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks, depending on whether it's now checked
                if (((CheckBox) v).isChecked()) {
                    Toast.makeText(HelloFormStuffActivity.this, "Selected", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuffActivity.this, "Not selected", Toast.LENGTH_SHORT).show();
                }
            }
        });
        
        final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
        final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
        radio_red.setOnClickListener(radio_listener);
        radio_blue.setOnClickListener(radio_listener);
    }
    
    private OnClickListener radio_listener = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            Toast.makeText(HelloFormStuffActivity.this, rb.getText(), Toast.LENGTH_SHORT).show();
        }
    };
}
実行します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />
    
    <CheckBox android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_label" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <RadioButton android:id="@+id/radio_red"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/red" />
        <RadioButton android:id="@+id/radio_blue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/blue" />
    </RadioGroup>

    <ToggleButton android:id="@+id/togglebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textOn="@string/vibrate_on"
        android:textOff="@string/vibrate_off"/>

</LinearLayout>
res/values/strings.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, HelloFormStuffActivity!</string>
    <string name="app_name">HelloFormStuff</string>
    <string name="checkbox_label">check it out</string>
    <string name="red">Red</string>
    <string name="blue">Blue</string>
    <string name="vibrate_on">Vibrate on</string>
    <string name="vibrate_off">Vibrate off</string>

</resources>
HelloFormStuffActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;
import android.widget.ToggleButton;

public class HelloFormStuffActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HelloFormStuffActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
        
        final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
        checkbox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks, depending on whether it's now checked
                if (((CheckBox) v).isChecked()) {
                    Toast.makeText(HelloFormStuffActivity.this, "Selected", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuffActivity.this, "Not selected", Toast.LENGTH_SHORT).show();
                }
            }
        });
        
        final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
        final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
        radio_red.setOnClickListener(radio_listener);
        radio_blue.setOnClickListener(radio_listener);
        
        final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
        togglebutton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                if (togglebutton.isChecked()) {
                    Toast.makeText(HelloFormStuffActivity.this, "Checked", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuffActivity.this, "Not checked", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
    
    private OnClickListener radio_listener = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            Toast.makeText(HelloFormStuffActivity.this, rb.getText(), Toast.LENGTH_SHORT).show();
        }
    };
}
実行します。
res/layout/main.xmlを開き、以下のように変更します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />

    <EditText
        android:id="@+id/edittext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text" />
    
    <CheckBox android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_label" />

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <RadioButton android:id="@+id/radio_red"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/red" />
        <RadioButton android:id="@+id/radio_blue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/blue" />
    </RadioGroup>

    <ToggleButton android:id="@+id/togglebutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textOn="@string/vibrate_on"
        android:textOff="@string/vibrate_off"/>
    
    <RatingBar android:id="@+id/ratingbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="1.0"/>

</LinearLayout>
HelloFormStuffActivity.javaを開き、以下のように変更します。
package jp.blogspot.logroid.helloFormStuff;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.Toast;
import android.widget.ToggleButton;

public class HelloFormStuffActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuffActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
            }
        });
        
        final EditText edittext = (EditText) findViewById(R.id.edittext);
        edittext.setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                // If the event is a key-down event on the "enter" button
                if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                  // Perform action on key press
                  Toast.makeText(HelloFormStuffActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                  return true;
                }
                return false;
            }
        });
        
        final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
        checkbox.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks, depending on whether it's now checked
                if (((CheckBox) v).isChecked()) {
                    Toast.makeText(HelloFormStuffActivity.this, "Selected", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuffActivity.this, "Not selected", Toast.LENGTH_SHORT).show();
                }
            }
        });
        
        final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
        final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
        radio_red.setOnClickListener(radio_listener);
        radio_blue.setOnClickListener(radio_listener);
        
        final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
        togglebutton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                if (togglebutton.isChecked()) {
                    Toast.makeText(HelloFormStuffActivity.this, "Checked", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(HelloFormStuffActivity.this, "Not checked", Toast.LENGTH_SHORT).show();
                }
            }
        });
        
        final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
        ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                Toast.makeText(HelloFormStuffActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
            }
        });
    }
    
    private OnClickListener radio_listener = new OnClickListener() {
        public void onClick(View v) {
            // Perform action on clicks
            RadioButton rb = (RadioButton) v;
            Toast.makeText(HelloFormStuffActivity.this, rb.getText(), Toast.LENGTH_SHORT).show();
        }
    };
}
実行します。
今回出てきたキーワードについて解説。
getAction
イベントタイプを取得する。
setOnKeyListener
キー入力があった際のイベントリスナ登録
setOnRatingBarChangeListener
レート変更があった際のイベントリスナ登録
関連記事

2012年4月19日木曜日

Android Maps API Key 取得方法

Google MapsをAndroidアプリケーション等から利用する場合、API Keyが必要になります。
ここでは、API Keyの取得手順を紹介します。

API Key取得 前提条件

  • Googleアカウントを取得済みであること
  • Java Runtime Environment (JRE)をインストール済みであること
  • Android SDKをインストール済みであること

取得手順

ここでは、デバッグ用のAPI Keyを取得する手順を例としています。
公開用のAPI Keyを取得する場合は、必要に合わせkeystoreファイルのパスを変更してください。
  1. コマンドプロンプトを起動し、JREに含まれるkeytoolにパスが通っているか確認する。
    >keytool -help
    ヘルプが表示されればパスが通っているという事になる。
  2. keystoreファイルのフィンガープリントを取得します
    >keytool -v -list -keystore "%USERPROFILE%\.android\debug.keystore"
    キーストアのパスワードを入力してください:
    
    *****************警告 警告 警告*****************
    *キーストアに保存された情報の整合性は*
    *検証されていません。整合性を検証するには*
    *キーストアのパスワードを入力する必要があります。*
    *****************警告 警告 警告*****************
    
    キーストアのタイプ: JKS
    キーストア・プロバイダ: SUN
    
    キーストアには1エントリが含まれます
    
    別名: androiddebugkey
    作成日: 2012/01/21
    エントリ・タイプ: PrivateKeyEntry
    証明書チェーンの長さ: 1
    証明書[1]:
    所有者: CN=Android Debug, O=Android, C=US
    発行者: CN=Android Debug, O=Android, C=US
    シリアル番号: 538c7f6
    有効期間の開始日: Sat Jan 21 22:33:16 JST 2012終了日: Mon Jan 13 22:33:16 JST 20
    42
    証明書のフィンガプリント:
             MD5:  **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**
             SHA1: **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**
             SHA256: **:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**:**
             署名アルゴリズム名: SHA256withRSA
             バージョン: 3
    
    拡張:
    
    #1: ObjectId: 2.5.29.14 Criticality=false
    SubjectKeyIdentifier [
    KeyIdentifier [
    0000: C2 AE C8 B6 9C 42 0E 76   CF 03 2B 03 C0 38 D3 50  .....B.v..+..8.P
    0010: A0 ED 47 69                                        ..Gi
    ]
    ]
    
    
    
    *******************************************
    *******************************************
    パスワードの入力が求められますが、そのままEnterで進めます。
  3. フィンガープリントから、API Keyを取得します。
    以下のページのMy certificate's MD5 fingerprint:に 2. で取得したMD5フィンガープリントを入力し、I have read and agree with the terms and conditionsにチェックを入れ、Generate API Keyをクリックします。
    Maps API Key Signup - Google Projects for Android
    http://code.google.com/intl/ja/android/add-ons/google-apis/maps-api-signup.html
  4. キーが表示されます。
    Android Maps API Key 取得方法
関連記事