約 4,675,192 件
https://w.atwiki.jp/skill2linux/pages/22.html
RSS リーダの作成 以下の記事を参考に作成。 というか、ほぼそのままです…。 全然、整理をつけていないので、そのうち纏めます…。 http //itpro.nikkeibp.co.jp/article/COLUMN/20100105/342883/?k2 メイン画面(レイアウト) ?xml version="1.0" encoding="utf-8"? !-- mainアクティビティ用 -- LinearLayout xmlns android="http //schemas.android.com/apk/res/android" android orientation="vertical" android layout_width="fill_parent" android layout_height="fill_parent" !-- リストビュー -- ListView android id="@android id/list" android layout_width="wrap_content" android layout_height="wrap_content" / !-- リストが空のときに表示 -- /LinearLayout 行(レイアウト) ?xml version="1.0" encoding="utf-8"? LinearLayout android id="@+id/item_container" android layout_width="fill_parent" android layout_height="wrap_content" android orientation="vertical" xmlns android="http //schemas.android.com/apk/res/android" TextView android id="@+id/item_title" android layout_width="fill_parent" android layout_height="wrap_content" android textColor="#ffffff" android textSize="18sp" android lines="1" / TextView android id="@+id/item_descr" android layout_width="fill_parent" android layout_height="wrap_content" android lines="2" android ellipsize="end" / /LinearLayout 詳細画面(レイアウト) ?xml version="1.0" encoding="utf-8"? !-- item_detail.xml -- LinearLayout android layout_width="fill_parent" android layout_height="wrap_content" android orientation="vertical" xmlns android="http //schemas.android.com/apk/res/android" TextView android id="@+id/item_detail_title" android layout_width="fill_parent" android layout_height="wrap_content" android textAppearance="?android attr/textAppearanceLarge" android background="@android drawable/dark_header" / TextView android id="@+id/item_detail_descr" android layout_width="fill_parent" android layout_height="wrap_content" / /LinearLayout メイン画面 package jp.co.persil.rss; import java.util.ArrayList; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ListView; public class PersilRSS extends ListActivity { // ------------------------------------------------------------ // メンバ // ------------------------------------------------------------ private ArrayList Item mItems; private RssListAdapter mAdapter; // ------------------------------------------------------------ // 定数 // ------------------------------------------------------------ public static final String RSS_FEED_URL = "http //itpro.nikkeibp.co.jp/rss/ITpro.rdf"; public static final int MENU_ITEM_RELOAD = Menu.FIRST; // ------------------------------------------------------------ // 【EVENT】Activity 作成 // ------------------------------------------------------------ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { // スーパークラスの呼出 super.onCreate(savedInstanceState); setContentView(R.layout.main); // Itemオブジェクトを保持するためのリストを生成し、アダプタに追加する mItems = new ArrayList Item (); mAdapter = new RssListAdapter(this, mItems); // タスクを起動する RssParserTask task = new RssParserTask(this, mAdapter); task.execute(RSS_FEED_URL); } // ------------------------------------------------------------ // 【EVENT】リストの項目を選択した時の処理 // ------------------------------------------------------------ @Override protected void onListItemClick(ListView l, View v, int position, long id) { Item item = mItems.get(position); Intent intent = new Intent(this, ItemDetailActivity.class); intent.putExtra("TITLE", item.getTitle()); intent.putExtra("DESCRIPTION", item.getDescription()); startActivity(intent); } // ------------------------------------------------------------ // 【EVENT】オプションボタン追加 // ------------------------------------------------------------ @Override public boolean onCreateOptionsMenu(Menu menu) { boolean result = super.onCreateOptionsMenu(menu); // デフォルトではアイテムを追加した順番通りに表示する menu.add(0, MENU_ITEM_RELOAD, 0, "更新"); return result; } // ------------------------------------------------------------ // 【EVENT】MENUの項目を押したときの処理 // ------------------------------------------------------------ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // 更新 case MENU_ITEM_RELOAD // アダプタを初期化し、タスクを起動する mItems = new ArrayList Item (); mAdapter = new RssListAdapter(this, mItems); // タスクはその都度生成する RssParserTask task = new RssParserTask(this, mAdapter); task.execute(RSS_FEED_URL); return true; } return super.onOptionsItemSelected(item); } // ------------------------------------------------------------ // 【METHOD】ツリービューアイテムを追加 // ------------------------------------------------------------ public void setListAdapter( RssListAdapter mAdapter) { // アダプタをリストビューにセットする ListView lv = (ListView)findViewById(android.R.id.list); lv.setAdapter(mAdapter); } } 行へのアイテム管理用 package jp.co.persil.rss; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; //RssListAdapter.java public class RssListAdapter extends ArrayAdapter Item { // ------------------------------------------------------------ // メンバ // ------------------------------------------------------------ private LayoutInflater mInflater; private TextView mTitle; private TextView mDescr; // ------------------------------------------------------------ // コンストラクタ // ------------------------------------------------------------ public RssListAdapter(Context context, List Item objects) { super(context, 0, objects); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } // ------------------------------------------------------------ // 【METHOD】1行毎に View を作成する // ------------------------------------------------------------ @Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (convertView == null) { view = mInflater.inflate(R.layout.item_row, null); } // 現在参照しているリストの位置からItemを取得する Item item = this.getItem(position); if (item != null) { // Itemから必要なデータを取り出し、それぞれTextViewにセットする String title = item.getTitle().toString(); mTitle = (TextView) view.findViewById(R.id.item_title); mTitle.setText(title); String descr = item.getDescription().toString(); mDescr = (TextView) view.findViewById(R.id.item_descr); mDescr.setText(descr); } return view; } } 画面への設定用ルーチン package jp.co.persil.rss; import java.io.IOException; import java.io.InputStream; import java.net.URL; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.app.ProgressDialog; import android.os.AsyncTask; import android.util.Xml; public class RssParserTask extends AsyncTask String, Integer, RssListAdapter { // ------------------------------------------------------------ // メンバ // ------------------------------------------------------------ private PersilRSS mActivity; private RssListAdapter mAdapter; private ProgressDialog mProgressDialog; // ------------------------------------------------------------ // コンストラクタ // ------------------------------------------------------------ public RssParserTask(PersilRSS activity, RssListAdapter adapter) { mActivity = activity; mAdapter = adapter; } // ------------------------------------------------------------ // 【Method】メインスレッドから execute 呼出時に実行される // 【Thread】メインスレッド // ------------------------------------------------------------ @Override protected void onPreExecute() { // プログレスバーを表示する mProgressDialog = new ProgressDialog(mActivity); mProgressDialog.setMessage("Now Loading..."); mProgressDialog.show(); } // ------------------------------------------------------------ // 【Method】メインスレッドから execute 呼出時に実行される // 【Thread】バックグラウンド // ------------------------------------------------------------ @Override protected RssListAdapter doInBackground(String... params) { RssListAdapter result = null; try { // HTTP経由でアクセスし、InputStreamを取得する URL url = new URL(params[0]); InputStream is = url.openConnection().getInputStream(); result = parseXml(is); } catch (Exception e) { e.printStackTrace(); } // ここで返した値は、onPostExecuteメソッドの引数として渡される return result; } // ------------------------------------------------------------ // 【Method】doInBackground のメソッド完了後に実行される // 【Thread】メインスレッド // ------------------------------------------------------------ @Override protected void onPostExecute(RssListAdapter result) { mProgressDialog.dismiss(); mActivity.setListAdapter(result); } // ------------------------------------------------------------ // 【Method】XML をパースする // ------------------------------------------------------------ public RssListAdapter parseXml(InputStream is) throws IOException, XmlPullParserException { // XML パーサをインスタンス化 XmlPullParser parser = Xml.newPullParser(); // try-catch 開始 try { // 引数で受け取ったストリームを設定 parser.setInput(is, null); // イベントタイプを設定 int eventType = parser.getEventType(); // 初期化 Item currentItem = null; // ドキュメントの最後まで繰り返し while (eventType != XmlPullParser.END_DOCUMENT) { String tag = null; switch (eventType) { // 開始タグ case XmlPullParser.START_TAG tag = parser.getName(); if (tag.equals("item")) { currentItem = new Item(); } else if (currentItem != null) { if (tag.equals("title")) { currentItem.setTitle(parser.nextText()); } else if (tag.equals("description")) { currentItem.setDescription(parser.nextText()); } } break; // 終了タグ case XmlPullParser.END_TAG tag = parser.getName(); if (tag.equals("item")) { mAdapter.add(currentItem); } break; } eventType = parser.next(); } } catch (Exception e) { e.printStackTrace(); } return mAdapter; } } アイテム管理用 package jp.co.persil.rss; public class Item { // ------------------------------------------------------------ // メンバ // ------------------------------------------------------------ private CharSequence mTitle; private CharSequence mDescription; // ------------------------------------------------------------ // コンストラクタ // ------------------------------------------------------------ public Item() { mTitle = ""; mDescription = ""; } // ------------------------------------------------------------ // 【getter】Description // ------------------------------------------------------------ public CharSequence getDescription() { return mDescription; } // ------------------------------------------------------------ // 【setter】Description // ------------------------------------------------------------ public void setDescription(CharSequence description) { mDescription = description; } // ------------------------------------------------------------ // 【getter】Title // ------------------------------------------------------------ public CharSequence getTitle() { return mTitle; } // ------------------------------------------------------------ // 【setter】Title // ------------------------------------------------------------ public void setTitle(CharSequence title) { mTitle = title; } } 行単位のアクティビティ package jp.co.persil.rss; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; public class ItemDetailActivity extends Activity { // ------------------------------------------------------------ // メンバ // ------------------------------------------------------------ private TextView mTitle; private TextView mDescr; // ------------------------------------------------------------ // コンストラクタ // ------------------------------------------------------------ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.item_detail); Intent intent = getIntent(); String title = intent.getStringExtra("TITLE"); mTitle = (TextView) findViewById(R.id.item_detail_title); mTitle.setText(title); String descr = intent.getStringExtra("DESCRIPTION"); mDescr = (TextView) findViewById(R.id.item_detail_descr); mDescr.setText(descr); } }
https://w.atwiki.jp/derax7/pages/18.html
Android クリックイベント Button start = (Button) findViewById(R.id.start); start.setOnClickListener(new OnClickListener() { public void onClick(View v) { //処理 } }); 状態保持 // ハイスコア読み込み SharedPreferences pref; pref = this.getSharedPreferences("PreferencesEx", Activity.MODE_PRIVATE); int stage = pref.getInt("stage", 0); // ハイスコアの書き込み pref = getContext().getSharedPreferences( "PreferencesEx", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putInt("stage", level); editor.commit(); isFinishing()で終了状態取得 isFinishing()を利用すると、Activityの終了状態を判別できる 画面遷移の種類 -Intentを飛ばした場合 false -ホームボタンを押した場合 false -戻るボタンを押した場合 true Androidで音を鳴らす。[SoundPool編] SoundPoolクラスの場合、基本は下記の3処理。 ①SoundPoolを new して、 ②音声ファイル読み込んで、 ③再生する SoundPool soundPool = new SoundPool(5,AudioManager.STREAM_MUSIC, 0); // ① int soundID = soundPool.load(context, R.raw.lalala, 1); // ② soundPool.play(soundID, 1.0F, 1.0F, 1, 0, 1.0F); // ③ 【①の補足】 public SoundPool (int maxStreams, int streamType, int srcQuality) 引数: maxStreams … このSoundPoolオブジェクトで同時に扱う音声(Stream)の最大数 streamType … 音声(stream)の種類。 AudioManagerクラスに定義されている srcQuality … サンプルレートの質。(現在はまだ未使用。 0 を使えとのこと) 返り値: 成功なら、SoundPoolオブジェクト 失敗なら、null 【②の補足】 音声ファイルは、res/raw/lalala.ogg に設置したという想定。ResourceIDは R.raw.lalala になる。ここから想像できると思うが、同フォルダに lalala.wav や lalala.mp3 を設置しても区別がつかない。 ちなみに、音声ファイルを安定再生するためには oggファイルが良いとのこと。 public int load (Context context, int resId, int priority) 引数: context … コンテキスト resId … 音声ファイルのリソースID priority … 優先度サンプルレートの質。(現在はまだ未使用。将来互換性のため 1 を使え) 返り値: sound ID (再生時に使用) 【③の補足】 public final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate) 引数: soundID … load()メソッドで返される soundID leftVolume … 音量[左] (範囲:0.0~1.0) rightVolume … 音量[右] (範囲:0.0~1.0) priority … ストリーム優先度 (0 = 優先度最低) loop … ループの回数 (0 = ループ無し、-1 = 無限ループ) rate … 再生レート (1.0 = 標準の再生, 範囲:0.5~2.0) 返値 成功なら、streamID(≠0) 失敗なら、0 IntentへのExtra付加 intent.putExtra("hoge", String s); getIntent().getExtras().getString("hoge"); drawableからbitmap変換 Resources res = this.getResources(); // 画像の読み込み Bitmap bm = BitmapFactory.decodeResource(res, R.drawable.blue); Intent時のタスクについて マニフェストでアクティビティに以下のオプションを追加すると、シングルタスク(新タスクを別タスクとして記憶せず、自身に積み重ねる)モードになる。HOME画面等に設定。 android launchMode="singleTask" アイコンの作成 http //android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html Spinnerの初期値設定 spinner.setSelection(0); プログレスダイアログ progressDialog = new ProgressDialog(CoordinateActivity.this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("処理を実行中です..."); progressDialog.setCancelable(true); progressDialog.show(); (・・・処理・・・) progressDialog.dismiss(); ダイアログのカスタム OnCreateDialog(int id){・・・}内でレイアウト等の適用ができる。ダイアログ生成前に呼び出され、returnでダイアログを返してやる ボタンへのクリックリスナー追加 (Button)btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(GalleryActivity.this, Main.class); startActivity(intent); } }); エラー関連 以下のエラーがでた時はどうやらメモリリークっぽい。 端末再起動で直るけど、リーク箇所の特定をしたほうがよさそう Failed to install XXX.apk on device HT0B8RX02778 Too many open files 【View】子Viewの追加&削除 追加:view.addView(child); 削除;view.removeView(child); 全削除:view.removeAllViews(); カメラにIntentを飛ばして起動 // Intent for Camera Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(i, REQUEST_CODE_CAMERA); 保存先はExtraで指定 File tmpPict = new File(Environment.getExternalStorageDirectory(), "/hogehoge/" + System.currentTimeMillis() + ".jpg"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tmpPict)); 結果をActivityResultで受け取り処理。 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_CAMERA) { 【View】layout.xmlの読み込み setContentView(R.layout.main); これは View v = this.getLayoutInflater().inflate(R.layout.main, null); setContentView(v) と置き換えられる(→addView()などに) 端末画面サイズ取得 WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Log.d("display", "w " + display.getWidth()); Log.d("display", "h " + display.getHeight()); ロケールの取得 Locale locale = Locale.getDefault(); Log.v("ロケールは", locale.toString()); 以下のようにロケール別に分岐できる if (locale.equals(Locale.JAPAN)) { ・・・・・ } 画面遷移 intentを飛ばして画面遷移 Intent intent = new Intent(this.context, 遷移先.class); startActivity(intent); ※manifestへのactivityの追加を忘れないこと! 【View】idから呼び出し TextView textViewData = (TextView)findViewById(R.id.hoge); textViewData.setText("hogehoge"); onClick()内でのボタン選別 @Override public void onClick(View v) { switch (v.getId()) { case R.id.button_animation Intent intent = new Intent(this, Animation.class); startActivity(intent); break; case R.id.button_sub Intent intent2 = new Intent(this, Sub.class); startActivity(intent2); break; default break; } } SharedPreference云々 SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this); Editor ed = SP.edit(); AdMob 最近仕様が変わったらしい AdMob導入の注意点 アニメーション private Handler myHandler = new Handler() { @Override public void handleMessage(Message msg) { if (isAttached) { // 移動処理 move(); // 再描画 invalidate(); sendEmptyMessageDelayed(0, DELAY_MILLIS); } } }; http //www.adamrocker.com/blog/181/android_animation.html
https://w.atwiki.jp/negilab/pages/15.html
Androidとは? Android Androidとは、GoogleおよびT-Mobile、HTC、モトローラ、日本からは KDDIやドコモを含む世界34社はオープン携帯プラットフォームを目指す団体「Open Handset Alliance」が開発を進める オープンソースのモバイルプラットフォーム。プログラミング言語はJava言語、開発環境はEclipseを使う。 UIはXMLレイアウトファイルで記述できる。 Androidはメーラー、SMS、カレンダー、地図、ブラウザなどのコアアプリケーションを含んで出荷される。 従来の携帯電話ではネイティブで入れ替えできなかった部分も作成できる模様。 アプリケーション実行環境というよりOSに近い印象を受ける。 特徴は次の通り。 アプリケーションフレームワーク コンポーネントの再利用が可能 Dalvik Virtual Machine モバイル用に最適化 統合ブラウザ WebKitベース グラフィックス 3DグラフィックスはOpenGL ES 1.0ベース SQLite ローカルデータをデータベース形式で保存 メディアサポート MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF GSM通話(機種依存) Bluetooth、EDGE、3G、WiFi(機種依存) カメラ、GPS、コンパス、加速度計(機種依存) デモはtoolsのemulator.exeを実行し、メニュー画面の「Application→App Demo」で閲覧可能。
https://w.atwiki.jp/conn/pages/21.html
このページは現在作成中です Androidアプリの基本構成 Androidアプリは幾つかのコンポーネントを組み合わせて作成する。コンポーネントはその役割ごとに幾つかに分類される。 Androidアプリを構成する4つのコンポーネント もっとも基本的なコンポートネントは次の4種類。 Activities 画面。アクティビティはそれぞれが独立したコンポーネントとして作成され、その組み合わせでアプリを動作させる。別のアプリから、また別のアプリ内のアクティビティを動作させることも可能。 Services 裏側でこっそり働く子。ユーザーインターフェースは持たない。ネットワークからデータをダウンロードしてきたり、別のアプリを操作中に音楽ファイルを再生したり、ユーザーの操作を邪魔することは無い。アクティビティのような他のコンポーネントから起動され、動作を指定される、サービス精神の塊のような存在。 Content Providers アプリケーションのデータへのアクセス共有を管理しデータの読み書きを行う。ファイルシステムやSQLiteなどのDB、インターネット上のデータなど、さまざまな場所に対応する。許可すれば他のアプリからデータの読み書きが可能だし、その逆も可能。動画を配信してくれる業者ではない。 Broadcast Reciever システムからの通知を受け取ったり、システム全体へ通知を発信したりする。例えばスリープに入った、バッテリーが切れ掛かっている、写真を撮った、などなどの通知を受けたり、発信したりできる。 電話を自動録音するアプリなんかだと、電話が掛かってきたという通知を受けサービスを起動し録音する、という使い方が想定される。 他にもコンポーネントには分類されないが、Androidアプリを構成する重要な要素がある。 マニフェスト アプリに属するコンポーネントを規定するのがマニフェストファイル。XML形式で記述する。 Intentフィルターで、アプリのエントリポイント(初期起動するアクティビティ)を指定する。 例:雛形アプリの AndroidManifest.xml。Intentフィルターが Activityの子要素で指定されている。 activity android name=".MainActivity" android label="@string/title_activity_main" intent-filter action android name="android.intent.action.MAIN" / category android name="android.intent.category.LAUNCHER" / /intent-filter /activity 他にも幾つかのIntent Filterアクションおよびカテゴリーがあるが、アプリアイコンから起動する場合はこの指定が必要だと覚えておけばよい。 他のアプリから 特定の Intentアクションにより起動されるアプリは、別の指定を追加する必要がある。 Intent(インテント:意図) 特定のアクティビティを指定、または「何をしたいのか」を指定し別のアプリを起動する。 同アプリ内のアクティビティ間連携にも使用される。 例:明示的に特定のアクティビティを指定し、EditTextボックスの入力値を渡している Intent intent = new Intent(this, DisplayActivity.class); EditText editText = (EditText) findViewById(R.id.input_message); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); startActivity(intent); 例:データ表示を指定し、Webページを開く Uri uri = Uri.parse("http //www.android.com"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); 簡略化のため省いているが、通常は事前に実行可能なIntentかチェックするためPackageManagerを使用する。この Intentで開かれるアプリは Intent Filterにて ACTION_VIEWアクションを受け付ける指定があるものの中から選ばれる。 リソース アプリが利用する画像ファイル、レイアウト定義、言語ごとの文字列ファイルなどをひとまとめにし、Rクラスを通じた共通のアクセス方法を提供する。画像、動画、音声などのデータファイル、XMLファイルで構成される。 リソースは異なる解像度、画面サイズ、言語に対応するディレクトリに分けて構成することで自動的に対応するディレクトリ内のファイルが利用されるように最適化される。詳細はこちら その他 基本の4コンポーネント種とリソースの他に、これらをサポートするコンポーネントが幾つかある。 Intent Fragment
https://w.atwiki.jp/anddoid/pages/35.html
android text 要素 関連タグ 使用例 android text="test" android text="@string/hello_world"
https://w.atwiki.jp/android_api/pages/17.html
Androidアプリは「アクティビティ」、「ブロードキャストレシーバー」、「サービス」、「コンテンツプロバイダ」の4つの構成要素から成り立ちます。 リソースクラスです。標準的なアンドロイドアプリケーションに使用されます。このパッケージにはアンドロイドアプリケーションを使う際の定義がされています。サードパーティの開発者が使うことのできるたくさんのアップリケーションがあります。リソースの詳細についてはリソースとアセットをご覧ください。
https://w.atwiki.jp/mywiki2010/pages/14.html
USBブート可能なx86マシンでAndroidを動作させる。 参考サイト一覧 「Android」をx86パソコンで動かそう ITpro 話題の携帯向けOS「Android」をx86パソコンで動かしてみよう (2009/02/27) ブログなど NWLab.com USB起動可能なAndoroid OSでPCからAndroidを起動してみました(2009/04/13) 即席USBブート環境構築(Windows編) ダウンロード可能なイメージファイルでお手軽にAndroidを動作させる。 (更新 2010/02/09) (1) 必要なものを用意 WindowsがインストールされたPC USBブート可能なPC(WindowsPCと同じでも良い) USBメモリ1GBもあれば十分。 FAT32でフォーマットしておく。 不慮の事故でデータが消えても困らないよう、大事なデータは事前にバックアップ。 (2) Androidのブート・イメージ入手 「USBブート・イメージ入手先」からファイルをダウンロードする。 (3) ブート・イメージの書き込み 書き込みソフトを使ってブート・イメージをUSBメモリに書き込む。 ソフト一覧 DDforWindowsWindowsXP, WindowsVistaで使用可。他Windowsでは未検証。 本ソフトでUSBから読み込んだディスクイメージはLinuxのddコマンドでそのまま使用可能。 (4) Android起動 Andoridを動かすPCでUSBブート可能になるようBIOSを設定するEeePC1000HEでは、PC起動時にESCキーを連打することでブート・ドライブを選択可能。 電源の入っていないPCのUSBポートにUSBメモリを差し込む 電源を入れるとAndroidが立ち上がる起動中にもUSBアクセスを行っているので、USBメモリは抜かないよう注意。 設定を変更した場合(表示言語など)は変更内容がUSBメモリに書き込まれ、次回起動時にも反映される。
https://w.atwiki.jp/sindroid/pages/13.html
あんどろいどなぺぇじ さて何を書こうか。 アンドロイドの構成 インストールからエミュレータ起動まで (ver 2.0用 以前のバージョンだとまた違うぽい。) ここからSDKをダウンロード →解答して適当なとこに置く →パスを通す(¥toolsまで) →プロンプトからandroidと入力するとAVDマネージャ起動 →Available Packagesからインストール ・ここで何もインストールするファイルがみつからない場合がある。 /.androidにandroidtool.cfgファイル作ってsdkman.force.http=trueと入れておくと解決するはず。 ・インストールがNothingとか出たらSDKの位置変えてみる。 (C直下とか。管理者権限だとか何か知らんけどProgram Files以下に置いてたら駄目だった。) →Virtual Devicesでデバイス作成 →そこからStartで起動 SDKリファレンス 既存バグとか チップス 他
https://w.atwiki.jp/android/pages/48.html
2008/04/15 Android Developer Challenge締め切り。 2008/03/25 「Android」搭載端末、早くも2008年秋には登場か?--グーグル幹部が発言 2008/03/23 ドコモ携帯、基本ソフトの設計簡素化へ DoCoMoでAndroid採用が決定? 2008/02/18 WCMフォーラムの会員一覧が更新。OHA企業が参加 WILLCOMコアモジュールフォーラムの会員にOHA参加企業のリビングイメージという会社が参入した模様。WILLCOMからAndroid携帯が出る可能性が出てきた。 2008/02/12 Android SDKアップデート 結構変わってます。今までのアプリを新しいSDK(m5-rc14)で動かすには再コンパイル(?)が必要です。 2008/02/11 Mobile World CongressにてAndroidの実機がぞくぞく出展された 【MWC2008】「Android」搭載プロトタイプ、半導体メーカーがこぞって出展 Android実機を披露した主な企業米フリースケール・セミコンダクタ NECエレクトロニクス 米クアルコム ルネサス テクノロジ 米テキサス・インスツルメンツ 2008/02/04 ハドソン、ゲームソフトをグーグル携帯に提供 ゲーム開発のハドソンは米グーグルが提供予定の携帯電話ソフトウエア群「アンドロイド」向けに、ゲームソフトなどの娯楽コンテンツ(情報の内容)を開発する。グーグルの携帯電話はNTTドコモなどが導入を検討しているが、国内コンテンツ大手の参入が明らかになったのは初めて。 2008/01/28 Deadline Extension for the Android Developer Challenge コンテストの締め切り延長と詳細日程の発表される (この時点から)数週間以内にUIとAPIが強化されたSDKをリリースするとのこと。 2008/04/14 Deadline to submit applications for judging 応募締め切り 2008/05/05 Announcement of the 50 first round winners, who will be eligible for the final round 1回戦の上位50人を発表 2008/06/30 Deadline for the 50 winners of the first round to submit for the final round 最終戦の締め切り 2008/07/21 Announcement of the grand prize winner and runner-up 優勝者および優秀者の発表 2008/01/24 ドコモとグーグル、iモード端末でグーグルのサービス利用可能に 「Androidプラットフォームに関しても両社で協力し、ドコモでの商用化を含む検討が進められる」と発表 2008/01/14 Google Android対応の初アプリケーション登場 初ってことはないと思うけど、OHA参加以外の企業で実機で自社アプリを動かしたのは初? 2007/12/28 ビルド済みバイナリでもAndroid Zaurusが可能に 2007/12/25 ドコモ、グーグルと提携・ネット検索メールなど、新サービス開発 この時点ではAndroidとの係わりは不明。 2007/12/15 Android SDKアップデート(英語) 2007/12/6 WILLCOMコアモジュールフォーラム、AndroidでW-SIMの通話デモ Androidをザウルスに載せた(英語) 2007/11/27 WILLCOMコアモジュールフォーラム、Androidの動作を確認 2007/11/17 Androidでスーパーマリオ(ファミコン/NES)が動いた。 2007/11/12 GoogleのAndroidプラットフォーム SDK公開 Google、Android向けアプリ開発コンテストを主催、賞金1000万ドル コンテストまとめ 2007/11/5 Googleほか34社、オープン携帯プラットフォーム「Android」を発表
https://w.atwiki.jp/android/pages/43.html
チュートリアル:ノートパッドエクササイズ1 本エクササイズではシンプルなノートリストを作ります。このノートリストを使ってユーザは新規ノートを追加することができますが、ノートの編集を行うことはできません。本エクササイズでは以下の事項をデモンストレートします。 ListActivities の基本、メニューオプションの作成・操作の基本 SQLite データベース内のノートへのアクセス/保存方法 ArrayAdapter (ListView にバインドするためのもっともシンプルな方法の一つ)を用いてデータを ListView にバインドする方法 リストビューの配置の仕方やアクティビティメニューへのアイテムの追加のやり方、アクティビティがアクティビティメニューアイテムをどのように扱うか、といったスクリーンレイアウトの基本 [エクササイズ1] [エクササイズ2?] [エクササイズ3?] [追加事項?] Step 1 Notepadv1 プロジェクトを開きます。 Notepadv1 は開始点として提供されるプロジェクトです - it takes care of some of the boilerplate work that you have already seen if you followed the Hello Android tutorial (すでにHello Android(もしもしアンドロイド)のチュートリアルで見ているかもしれませんが、共通する説明があります。) 2. browse ボタンを押し、あなたが本エクササイズをコピーしたフォルダを選択し、その中からNotepadv1を選んでOKを押してください。 a. Package Explorer で右クリックし、New- Project... を選択してください。 b. Android/Android Project を選択し、Next を押してください。 c. New Android Project のダイアログで、Create project from existing source(既存のソースからプロジェクトを作成)を選択してください. d. browse ボタンを押し、あなたが本エクササイズをコピーしたフォルダを選択し、その中からNotepadv1を選んでOKを押してください。 e. Project name 欄に Notepadv1、Location 欄に選択したパスが表示されることを確認してください。 f. Finish を押します。 g. 本エクササイズのプロジェクトが Eclipse の Package Explorer に開かれ準備が完了します。 h. もし AndroidManifest.xml にエラー表示が出ていたり、Android の zipファイルに関連する問題が表示された場合は、プロジェクトの上で右クリックし、ポップアップから、Android Tools- Fix Project Properties を選択してください。(プロジェクトがライブラリの場所を正しく見ていないので、この操作でそれを修復します。) Step 2 データへのアクセスと更新について このエクササイズにおいては、単にSQLiteデータベースを直接使ってデータを保存しますが、実際のアプリケーションでは正当なContentProviderを作成し、処理をカプセル化する方がずっと良いでしょう。 もし興味があれば、content provider やデータの保存/検索/表示などに関する情報をいろいろと見つけることが出来るでしょう。 DBHelper クラスを見てみてください - このクラスは、我々が作成するノートのデータを保持するとともにその更新も可能にする、SQLiteへのデータアクセスをカプセル化するために提供されています。 典型的にはContentProviderを用いることでこのクラスを実装します。そして実際、SDKには行っている完全なNotepadアプリケーションはそのようなContentProviderを実装しています。しかし、我々がこれからするように、単にSQLiteデータベースを直接利用していけない理由はありません。このクラスについて注意すべき重要なことは、それがSQLiteデータベースのデータの保存、参照、更新の詳細の面倒をみてくれるということです。全ての行を取得するメソッド、行IDに基づいて行を取得するメソッド、新しい行を作成するメソッド、既存の行を削除するメソッド、既存の行を更新するメソッドがあります。もしあなた自身のアプリケーションでSQLiteデータベースを利用する方法に関する入門を希望なら、このクラスを見てみるか、より良くは、ContentProviderの利用例として SDK の samples/ ディレクトリに入っている完全なNotepadアプリケーションを見てみてください。 Step 3 Layout と activity とについて ほとんどのActivityはそれに関連付けられたレイアウトを持っています。レイアウトはユーザに対してそのactivityの「顔」となります。今回の例では我々のレイアウトは画面全体を覆いノートの一覧を提供します。 しかし、フルスクリーンレイアウトはActivityにとっての唯一の選択肢ではありません。フローティングレイアウト(たとえばダイアログとか警告のように)が欲しいこともあるでしょうし、レイアウトを全く必要としないこともあるでしょう(使用するレイアウトを決めない場合、activityはユーザに見えなくなります)。 Open the notepad_list.xml file in res/layout and take a look at it This is a layout definition file with a default starting point in it, we have provided this as a convenience to get you going quickly. 1. All Android layout files must start with the XML header line ?xml version="1.0" encoding="utf-8"? . 2. Also, the next definition will often (but not always) be a layout definition of some kind, in this case a LinearLayout. 3. Note also that the xml namespace of Android should always be defined in the top level component or layout in the XML so that android tags can be used through the rest of the file xmlns android="http //schemas.android.com/apk/res/android" Step 4 We need to create the layout to hold our list. Add code inside of the LinearLayout tag so the whole file looks like this (you may have to hit the Source tab in order to edit the XML file) ?xml version="1.0" encoding="utf-8"? LinearLayout xmlns android="http //schemas.android.com/apk/res/android" android layout_width="wrap_content" android layout_height="wrap_content" ListView id="@id/android list" android layout_width="wrap_content" android layout_height="wrap_content"/ TextView id="@id/android empty" android layout_width="wrap_content" android layout_height="wrap_content" android text="@string/no_notes"/ /LinearLayout 1. The ListView and TextView can be thought as two alternative views, only one of which will be displayed at once. ListView will be used when there are notes to be shown, while the TextView (which has a default value of "No Notes Yet!" defined as a string resource, will be displayed if there aren t any notes to display). 2. The @ in the id strings of the ListView and TextView means that the XML parser should parse and expand the rest of the id string and use an ID resource. 3. And, the android list and android empty are IDs that are already provided for us by the Android platform, empty is used automatically when no data is provided in the list adapter. The List Adapter knows to look for these names specifically by default. Alternatively you could also choose to change the default empty view used by the List Adapter by using the setEmptyView(). More broadly, the android.R class is a set of predefined resources provided for you by the platform, while your project s R class is the set of resources your project has defined. Resources found in the android.R resource class can be used in the XML files by using the android name space prefix (as we see here). Step 5 Resources and the R class The folders under res/ in the Eclipse project are special. There is a specific structure to the folders and files under this folder. In particular, resources defined in these folders and files will have corresponding entries in the R class allowing them to be easily accessed and used from your application. Furthermore, they will be bundled and deployed as part of the application. To make a list view, we also need to define a view for each row in the list 1. Create a new file under res/layout called notes_row.xml. 2. Add the following contents (note again the xml header is used, and the first node defines the Android xml namespace) ?xml version="1.0" encoding="utf-8"? TextView id="@+id/text1" xmlns android="http //schemas.android.com/apk/res/android" android layout_width="wrap_content" android layout_height="wrap_content"/ 3. This is the view that will be used for each notes title row — it has only one text field in it. 4. In this case we create a new id called text1. The + after the @ in the id string indicates that the id should be automatically created if it does not already exist, so we are defining text1 on the fly and then using it. 5. After saving this file, open the R.java class in the project and look at it, you should see new definitions for notes_row and text1 (our new definitions) meaning we can now gain access to these from the our code. Step 6 Next, open the Notepadv1 class in the source. We are going to alter this class to become a list adapter and display our notes, and also allow us to add new notes Notepadv1 will be a subclass of Activity called a ListActivity, which has extra functionality to accommodate the kinds of things you might want to do with a list, for example displaying an arbitrary number of list items in rows on the screen, moving through the list items, and allowing them to be selected. Take a look through the existing code in Notepadv1 class. There are some constant definitions at the top, followed by a private field we will use to create numbered note titles, and some overrides of methods from the superclass. Step 7 Change the inheritance of Notepadv1 from Activity to ListActivity public class Notepadv1 extends ListActivity Note you will have to import ListActivity into the Notepadv1 class using Eclipse, ctrl-shift-O on Windows or Linux, or cmd-shift-O on the Mac (organize imports) will do this for you. Step 8 There are already three override methods defined onCreate, onCreateOptionsMenu and onOptionsItemSelected, we need to fill these out * onCreate() is called when the activity is started — it is a little like the "main" method for the activity. We use this to set up resources and state for the activity when it is running * onCreateOptionsMenu() is used to populate the menu for the activity. This is shown when the user hits the menu button, and has a list of options they can select (like "Create Note") * onOptionsItemSelected() is the other half of the menu equation, it is used to handle events generated from the menu (e.g. when the user selects the "Create Note" item). Step 9 Fill out the body of the onCreate() method. Here we will set the title for the activity (shown at the top of the screen), use the notepad_list layout we have created for the activity display contents, set up the DBHelper instance we will use to access notes data, then populate the list with the available note titles 1. call super() with the icicle parameter passed into our method 2. setContentView to R.layout.notepad_list 3. Create a new private class field called dbHelper of class DBHelper (before the onCreate method) 4. Back in the onCreate method, construct a DBHelper instance — assign to the dbHelper field (note, you must pass this into the constructor for DBHelper) 5. Finally, call a new method -fillData()- gets the data and populates it using the helper, we haven t defined it yet 6. onCreate() should now look like this @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.notepad_list); dbHelper = new DBHelper(this); fillData(); } And remember to add the DBHelper field definition (right under the noteNumber definition) private DBHelper dbHelper; Step 10 More on menus The notepad application we are constructing only scratches the surface with menus. You can also add shortcut keys for menu items, create submenus and even add menu items to other applications!. Fill out the body of the onCreateOptionsMenu() method. We are going to add just one menu item for now, "Add Item", using a string we will create in strings.xml, and defined with a constant we will create at the top of the class to identify the Add Item operation. 1. In strings.xml resource (under res/values), add a new string for menu_insert with text "Add Item" string name="menu_insert" Add Item /string , then save the file 2. Also, you need a menu position constant at the top of the Notepadv1 class (right under the KEY_BODY definition) public static final int INSERT_ID = Menu.FIRST; 3. In the onCreateOptionsMenu() method, add the menu item. Also take care of the result of the super call being returned. The whole method should now look like this @Override public boolean onCreateOptionsMenu(Menu menu) { boolean result = super.onCreateOptionsMenu(menu); menu.add(0, INSERT_ID, R.string.menu_insert); return result; } Step 11 Fill out the body of the onOptionsItemSelected() method This is going to handle our new "Add Note" menu item. When this is selected the onOptionsItemSelected() method will be called with the item.getId() set to INSERT_ID (the constant we used to identify the menu item). We can detect this, and take the appropriate actions 1. The super.onOptionsItemSelected(item) method call goes at the end of this method — we want to catch our events first! 2. Switch statement on item.getId() 3. case INSERT_ID 4. calls new method createNote() 5. break at the end of the case 6. return the result of the superclass onOptionsItemSelected() method at the end 7. The whole onOptionsItemSelect() method should now look like this @Override public boolean onOptionsItemSelected(Item item) { switch (item.getId()) { case INSERT_ID createNote(); break; } return super.onOptionsItemSelected(item); } Step 12 Add a new createNote() method In this first version of our application, createNote() is not going to be very useful. We will simply create a new note with a title assigned to it based on a counter ("Note 1", "Note 2"...) and with an empty body. At present we have no way of editing the contents of a note, so for now we will have to be content making one with some default values 1. String noteName = "Note " + noteNumber++; (Construct the name using "Note" and the counter we have defined in the class) 2. Call dbHelper.createRow() using noteName as the title and "" for the body 3. Call fillData() method again after adding (inefficient but simple) 4. The whole createNote() method should look like this private void createNote() { String noteName = "Note " + noteNumber++; dbHelper.createRow(noteName, ""); fillData(); } Step 13 List adapters Our example uses a very simple array adapter which binds an array or list of items into a ListView. More commonly in Android, List Adapters go hand in hand with ContentProviders, and this is also a very easy way to use lists. To bind a ContentProvider to a ListView you can use a android.widget.SimpleCursorAdapter to bind data from a ContentProvider into a ListView Define the fillData() method. This is fairly long This method uses ArrayAdapter, which is the simplest way of putting data into a ListView. ArrayAdapter takes either a List or an array of Strings, and binds them into a text view provided in the layout defined for the list row (this is the text1 field in our notes_row.xml layout). The method simply obtains a list of notes from the database helper, constructs a List of Strings using the title strings from each row, and then creates an ArrayAdapter out of those items and bound to use the notes_row we defined. private void fillData() { // We need a list of strings for the list items List String items = new ArrayList String (); // Get all of the rows from the database and create the item list List Row rows = dbHelper.fetchAllRows(); for (Row row rows) { items.add(row.title); } // Now create an array adapter and set it to display using our row ArrayAdapter String notes = new ArrayAdapter String (this, R.layout.notes_row, items); setListAdapter(notes); } 1. ArrayAdapter needs a List of Strings (List String ) containing the items to display 2. The data is read out of the database as rows, and the title field from each row is used to populate the list of strings 3. We specify the notes_row view we created as the receptacle for the data 4. If you get compiler errors about classes not being found, ctrl-shift-O or (cmd-shift-O on the mac) to organize imports. Note that for this exercise we use an ArrayAdapter, this is not a very scalable solution and more typically a SimpleCursorAdapter would be used with a ContentProvider or at least a Cursor returned from a query. See the sidebar on List Adapters for more information. Step 14 Run it! 1. Right click on the Notepadv1 project 2. From the popup menu, select Run As - Android Application 3. If you see a dialog come up, select Android Launcher as the way of running the application (you can also use the link near the top of the dialog to set this as your default for the workspace, this is recommended as it will stop the plugin from asking you this every time) 4. Add new notes by hitting the menu button and selecting Add Item from the menu Solution and Next Steps You can see the solution to this class in Notepadv1Solution from the zip file to compare with your own. Once you are ready, move on to Tutorial Exercise 2 to add the ability to create, edit and delete notes. Back to the Tutorial main page...