2009年5月29日金曜日

Android - 再描画 -

onDraw() メソッド以外の場所で描画関数を呼び出してはならない。
その代わり、
invalidate()  メソッド
を呼び出して、再描画が必要な領域にマークを付ける。
将来のある時点で、ウィンドウマネージャがすべての
再描画が必要な領域を統合して、 onDraw() を呼び出す。

2009年5月28日木曜日

Android - Input -

キーボード、Dパッド、タッチスクリーン、トラックボールなど
さまざまな入力形式の可能性がある

KeyCode of DPAD
  1. @Override  
  2. public boolean onKeyDown(int keyCode, KeyEvent event) {  
  3.   switch (keyCode) {  
  4.   case KeyEvent.KEYCODE_DPAD_UP:  
  5.     select(selX, selY - 1);  
  6.     break;  
  7.   case KeyEvent.KEYCODE_DPAD_DOWN:  
  8.     select(selX, selY + 1);  
  9.     break;  
  10.   case KeyEvent.KEYCODE_DPAD_LEFT:  
  11.     select(selX - 1, selY);  
  12.     break;  
  13.   case KeyEvent.KEYCODE_DPAD_RIGHT:  
  14.     select(selX + 1, selY);  
  15.     break;  
  16.   default:  
  17.     return super.onKeyDown(keyCode, event);  
  18.   }  
  19.   return true;  
  20. }  


タッチパネル
  1. @Override  
  2. public boolean onTouchEvent(MotionEvent event) {  
  3.   if (event.getAction() != MotionEvent.ACTION_DOWN)  
  4.     return super.onTouchEvent(event);  
  5.     
  6.   select((int) (event.getX()) / width), (int) (event.getY() / height));  
  7.   game.showKeypadOrError(selX, selY);  
  8.   return true;  
  9. }  



More...

Android - Text -

  1. @Override  
  2. protected void onDraw(Canvas canvas) {  
  3.   Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG);  
  4.   // フォントの高さ  
  5.   foreground.setTextSize(height * 0.75f);  
  6.   // アスペクト比  
  7.   foreground.setTextScaleX(width / height);  
  8.   foreground.setTextAlign(Paint.Align.CENTER);  
  9.   
  10.   FontMetrics fm = foreground.getFontMetrics();  
  11.   float x = width / 2;  
  12.   float y = height / 2 - (fm.ascent + fm.descent) / 2;  
  13.   
  14.   canvas.drawText("Hello!"100100, foreground);  
  15. }  


public float getFontMetrics (Paint.FontMetrics metrics)
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc. If metrics is not null, return the fontmetric values in it.

public float ascent
The recommended distance above the baseline for singled spaced text.
public float descent
The recommended distance below the baseline for singled spaced text.


More...

Android - 2D graphics -

2D グラフィックスライブラリは android.graphics

Color クラス
Paint クラス
Canvas クラス
View クラス
Path クラス
etc..

More...

Color

アルファ、赤、緑、青 (ARGB) の4つの値で色を表現する。
アルファは透明度で、
アルファ = 0 : 透明
アルファ = 255 : 不透明

・色の指定方法
Colorクラスの静的定数
  1. int color = Color.BLUE;  // 青  
  2. int color = Color.argb(1272550255);   // 半透明の紫  


XML リソースファイルで定義
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.   <color name="color1">#7fff00ff</color>  
  4. </resources>  


・色の参照

XML ファイルで付けた名前で参照
  1. android:background="@color/color1";  


Java コードで取得
  1. int color = getResources().getColor(R.color.color1);  


getResources() : 現在の Activity に対応する ResourceManager クラスを返す
getColor() : Resource ID に対応する色を Manager に問い合わせる



Paint

グラフィックスの描画で必要なスタイル、色、その他の情報を管理

・描画色を設定
  1. Paint cPaint = new Paint();  
  2. cPaint.setColor(Color.LTGRAY);  // light gray  


Canvas

描画対象のキャンバスを表現

・キャンバスに描画する
View.onDraw() メソッドをオーバーライドする
  1. static public class GraphicsView extends View {  
  2.   public GraphicsView(Context context) {  
  3.     super(context);  
  4.   }  
  5.   @Override  
  6.   protected void onDraw(Canvas canvas) {  
  7.      // Drawing commands  
  8.   }  
  9. }  



Path

直線、曲線、矩形などのベクター描画コマンドを持つ

・円形パスを定義
  1. @Override  
  2. protected void onDraw(Canvas canvas) {  
  3.  Path circle = new Path();  
  4.  circle.addCircle(150150100, Path.Direction.CW);  
  5.  Paint cPaint = new Paint();  
  6.  Paint tPaint = new Paint();  
  7.  cPaint.setStyle(Paint.Style.STROKE);  
  8.  cPaint.setColor(Color.YELLOW);  
  9.  tPaint.setColor(Color.WHITE);  
  10.  canvas.drawPath(circle, cPaint);  
  11.    
  12.  final String ss = "Happy Birthday To You !!! Happy Birthday To You !!! Happy Birthday To You !!! Happy Birthday To You !!!";  
  13.  canvas.drawTextOnPath(ss, circle, 020, tPaint);    
  14. }  


Direction.CW : right hand



  1. // 色設定  
  2. paint.setColor(Color.argb(255,255,0,0));  
  3. // アンチエイリアス  
  4. paint.setAntiAlias(true);  
  5. // 塗りつぶし  
  6. paint.setStyle(Paint.Style.FILL);  
  7. // 塗りつぶしなし  
  8. paint.setStyle(Paint.Style.STROKE);  
  9. // 枠線の幅  
  10. paint.setStrokeWidth(2);  
  11. // 直線  
  12. canvas.drawLine(25,5,25,5+40,paint);  
  13. // パス  
  14. Path path = new Path();  
  15. path.moveTo(550,50);  
  16. path.lineTo(55+30,55);  
  17. path.lineTo(55+10,5+20);  
  18. path.lineTo(55+40,5+25);  
  19. path.lineTo(550,5+40);  
  20. canvas.drawPath(path, paint);  
  21. // 四角  
  22. canvas.drawRect(new Rect(004040), paint);  
  23. canvas.drawRect(004040, paint);  
  24. // 角丸四角  
  25. canvas.drawRoundRect(new RectF(004040), 1010, paint);  
  26. canvas.drawRoundRect(0040401010, paint);  
  27. // 円  
  28. canvas.drawCircle(100100150, paint);  


PathEffect クラスを使うと面白い効果が作れる

2009年5月27日水曜日

Android - リストからの選択 -

android.util.Log クラスは、Android のシステムログに
メッセージを出力するメソッドを持っている

・Log.e():エラー
・Log.w():警告
・Log.i():情報
・Log.d():デバッグ
・Log.v():冗長

Eclipse でこのログをみるには
[Window] -> [Show View] -> [Other...] -> [Android] -> [LogCat]




More...

Sudoku/res/values/strings.xml
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.  <string name="app_name">Sudoku</string>  
  4.  <string name="main_title">Android Sudoku</string>  
  5.  <string name="continue_label">Continue</string>  
  6.  <string name="new_game_label">New Game</string>  
  7.  <string name="about_label">About</string>  
  8.  <string name="about_title">About Android Sudoku</string>  
  9.  <string name="about_text">\  
  10.  Sudoku is a logic-based number placement puzzle.  
  11.  Starting with a partially completed 9x9 grid, the  
  12.  objective is to fill the grid so that each row,  
  13.  each column, and each of the 3x3 boxes   
  14.  (also called <i>blocks</i>) contains the digits  
  15.  1 to 9 exactly once.  
  16.  </string>  
  17.  <string name="exit_label">Exit</string>  
  18.  <string name="settings_label">Settings...</string>  
  19.  <string name="settings_title">Sudoku settings</string>  
  20.  <string name="settings_shortcut">s</string>  
  21.  <string name="music_title">Music</string>  
  22.  <string name="music_summary">Play background music</string>  
  23.  <string name="hints_title">Hints</string>  
  24.  <string name="hints_summary">Show hints during play</string>  
  25.  <string name="new_game_title">Difficulty</string>  
  26.  <string name="easy_label">Easy</string>  
  27.  <string name="medium_label">Medium</string>  
  28.  <string name="hard_label">Hard</string>  
  29. </resources>  


リストの形式を記述

Sudoku/res/values/arrays.xml
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.  <array name="difficulty">  
  4.   <item>@string/easy_label</item>  
  5.   <item>@string/medium_label</item>  
  6.   <item>@string/hard_label</item>  
  7.  </array>  
  8. </resources>  


Sudoku/src/org/example/sudoku/Sudoku.java
  1. package org.example.sudoku;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.content.Intent;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.view.Menu;  
  9. import android.view.MenuInflater;  
  10. import android.view.MenuItem;  
  11. import android.app.AlertDialog;  
  12. import android.content.DialogInterface;  
  13. import android.util.Log;  
  14.   
  15. public class Sudoku extends Activity implements OnClickListener{  
  16.     /** Called when the activity is first created. */  
  17.     @Override  
  18.     public void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.main);  
  21.   
  22.         View continueButton = this.findViewById(R.id.continue_button);  
  23.         continueButton.setOnClickListener(this);  
  24.         View newButton = this.findViewById(R.id.new_button);  
  25.         newButton.setOnClickListener(this);  
  26.         View aboutButton = this.findViewById(R.id.about_button);  
  27.         aboutButton.setOnClickListener(this);  
  28.         View exitButton = this.findViewById(R.id.exit_button);  
  29.         exitButton.setOnClickListener(this);  
  30.     }  
  31.       
  32.     public void onClick(View v) {  
  33.      switch(v.getId()){  
  34.      case R.id.about_button:  
  35.       Intent i = new Intent(this, About.class);  
  36.       startActivity(i);  
  37.       break;  
  38.      case R.id.new_button:  
  39.       openNewGameDialog();  
  40.       break;  
  41.      case R.id.exit_button:  
  42.       finish();  
  43.       break;  
  44.      }  
  45.     }  
  46.   
  47.     @Override  
  48.     public boolean onCreateOptionsMenu(Menu menu){  
  49.      super.onCreateOptionsMenu(menu);  
  50.      MenuInflater inflater = getMenuInflater();  
  51.      inflater.inflate(R.menu.menu, menu);  
  52.      return true;  
  53.     }  
  54.       
  55.     @Override  
  56.     public boolean onOptionsItemSelected(MenuItem item){  
  57.      switch (item.getItemId()){  
  58.      case R.id.settings:  
  59.       startActivity(new Intent(this, Settings.class));  
  60.       return true;  
  61.      }  
  62.      return false;  
  63.     }  
  64.       
  65.     private void openNewGameDialog() {  
  66.      new AlertDialog.Builder(this)  
  67.       .setTitle(R.string.new_game_title)  
  68.       .setItems(R.array.difficulty,   
  69.       new DialogInterface.OnClickListener() {  
  70.        public void onClick(DialogInterface dialoginterface, int i) {  
  71.         startGame(i);  
  72.        }  
  73.       })  
  74.       .show();  
  75.     }  
  76.       
  77.     private static final String TAG = "Sudoku";  
  78.       
  79.     private void startGame(int i) {  
  80.      Log.d(TAG, "clicked on " + i);  
  81.      // start game here  
  82.     }  
  83. }  


Exit ボタンを押したとき、Activity を破棄するために
finish()
を呼び出す



New Game をクリックすると難易度の選択ポップアップが表示される



Android Menu action

MENU ボタンを押したときの動作を追加する

Sudoku/res/value/strings.xml
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.     <string name="app_name">Sudoku</string>  
  4.     <string name="main_title">Android Sudoku</string>  
  5.     <string name="continue_label">Continue</string>  
  6.     <string name="new_game_label">New Game</string>  
  7.     <string name="about_label">About</string>  
  8.     <string name="about_title">About Android Sudoku</string>  
  9.     <string name="about_text">\  
  10.  Sudoku is a logic-based number placement puzzle.  
  11.  Starting with a partially completed 9x9 grid, the  
  12.  objective is to fill the grid so that each row,  
  13.  each column, and each of the 3x3 boxes   
  14.  (also called <i>blocks</i>) contains the digits  
  15.  1 to 9 exactly once.  
  16.     </string>  
  17.     <string name="exit_label">Exit</string>  
  18.     <string name="settings_label">Settings...</string>  
  19.     <string name="settings_title">Sudoku settings</string>  
  20.     <string name="settings_shortcut">s</string>  
  21.     <string name="music_title">Music</string>  
  22.     <string name="music_summary">Play background music</string>  
  23.     <string name="hints_title">Hints</string>  
  24.     <string name="hints_summary">Show hints during play</string>  
  25. </resources>  



Sudoku/res/menu/menu.xml
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <menu xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <item  
  4.         android:id="@+id/settings"  
  5.         android:title="@string/settings_label"  
  6.         android:alphabeticShortcut="@string/settings_shortcut"  
  7.     />  
  8. </menu>  


Sudoku/src/org/example/sudoku/Sudoku.java
  1. package org.example.sudoku;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.content.Intent;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8. import android.view.Menu;  
  9. import android.view.MenuInflater;  
  10. import android.view.MenuItem;  
  11.   
  12. public class Sudoku extends Activity implements OnClickListener{  
  13.     /** Called when the activity is first created. */  
  14.     @Override  
  15.     public void onCreate(Bundle savedInstanceState) {  
  16.         super.onCreate(savedInstanceState);  
  17.         setContentView(R.layout.main);  
  18.   
  19.         View continueButton = this.findViewById(R.id.continue_button);  
  20.         continueButton.setOnClickListener(this);  
  21.         View newButton = this.findViewById(R.id.new_button);  
  22.         newButton.setOnClickListener(this);  
  23.         View aboutButton = this.findViewById(R.id.about_button);  
  24.         aboutButton.setOnClickListener(this);  
  25.         View exitButton = this.findViewById(R.id.exit_button);  
  26.         exitButton.setOnClickListener(this);  
  27.     }  
  28.       
  29.     public void onClick(View v) {  
  30.         switch(v.getId()){  
  31.         case R.id.about_button:  
  32.             Intent i = new Intent(this, About.class);  
  33.             startActivity(i);  
  34.             break;  
  35.         }  
  36.     }  
  37.   
  38.     @Override  
  39.     public boolean onCreateOptionsMenu(Menu menu){  
  40.         super.onCreateOptionsMenu(menu);  
  41.         MenuInflater inflater = getMenuInflater();  
  42.         inflater.inflate(R.menu.menu, menu);  
  43.         return true;  
  44.     }  
  45.       
  46.     @Override  
  47.     public boolean onOptionsItemSelected(MenuItem item){  
  48.         switch (item.getItemId()){  
  49.         case R.id.settings:  
  50.             startActivity(new Intent(this, Settings.class));  
  51.             return true;  
  52.         }  
  53.         return false;  
  54.     }  
  55. }  


Sudoku/res/xml/settings.xml
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <preferencescreen xmlns:android="http://schemas.android.com/apk/res/android">  
  3.     <checkboxpreference  
  4.         android:key="music"  
  5.         android:title="@string/music_title"  
  6.         android:summary="@string/music_summary"  
  7.         android:defaultValue="true" />  
  8.     <checkboxpreference  
  9.         android:key="hints"  
  10.         android:title="@string/hints_title"  
  11.         android:summary="@string/hints_summary"  
  12.         android:defaultValue="true" />  
  13. </checkboxpreference  
  14. </checkboxpreference  
  15. </preferencescreen>  


Sudoku/src/org/example/sudoku/Settings.java
  1. package org.example.sudoku;  
  2.   
  3. import android.os.Bundle;  
  4. import android.preference.PreferenceActivity;  
  5.   
  6. public class Settings extends PreferenceActivity {  
  7.     @Override  
  8.     protected void onCreate(Bundle savedInstanceState) {  
  9.         super.onCreate(savedInstanceState);  
  10.         addPreferencesFromResource(R.xml.settings);  
  11.     }  
  12. }  


Sudoku/AndroidManifest.xml
  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <manifest  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   package="org.example.sudoku"  
  5.   android:versionCode="1"  
  6.   android:versionName="1.0">  
  7.     <application <brbr="">      android:icon="@drawable/icon"   
  8.       android:label="@string/app_name">  
  9.     <activity <brbr="">      android:name=".Sudoku"  
  10.       android:label="@string/app_name">  
  11.       <intent-filter>  
  12.       <action android:name="android.intent.action.MAIN">  
  13.       <category android:name="android.intent.category.LAUNCHER">  
  14.       </category></action></intent-filter>  
  15.     </activity>  
  16.     <activity <brbr="">      android:name=".About"  
  17.       android:label="@string/about_title"  
  18.       android:theme="@android:style/Theme.Dialog">  
  19.     </activity>  
  20.     <activity <brbr="">      android:name=".Settings"  
  21.       android:label="@string/settings_title">  
  22.     </activity>  
  23.   </application>  
  24.   <uses-sdk android:minsdkversion="3">  
  25.    
  26. </uses-sdk></manifest  


MENU ボタンを押すと、Settings... が表示されるようになった



Settings... をクリックすると、設定項目が表示される




 

Android - テーマを使う -

Android には、名前で参照できる複数のテーマがあらかじめパッケージング
されている

http://developer.android.com/reference/android/R.style.html

android:theme="@android:style/Theme.Dialog"

AndroidManifest.xml
に追加

Sudoku/AndroidManifest.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <manifest  
  3.   xmlns:android="http://schemas.android.com/apk/res/android"  
  4.   package="org.example.sudoku"  
  5.   android:versionCode="1"  
  6.   android:versionName="1.0">  
  7.   <application <brbr="">    android:icon="@drawable/icon"   
  8.     android:label="@string/app_name">  
  9.     <activity  
  10.       android:name=".Sudoku"  
  11.       android:label="@string/app_name">  
  12.       <intent-filter>  
  13.       <action android:name="android.intent.action.MAIN">  
  14.       <category android:name="android.intent.category.LAUNCHER">  
  15.       </category></action></intent-filter>  
  16.       
  17.     <activity <brbr="">      android:name=".About"  
  18.       android:label="@string/about_title"  
  19.       android:theme="@android:style/Theme.Dialog">  
  20.     </activity>  
  21.   </activity  
  22. </application>  
  23.   <uses-sdk android:minsdkversion="3">  
  24.    
  25. </uses-sdk></manifest  




サブクラス化して、デフォルト値をオーバーライドすることもできる。
また、
カスタムテーマは res/values/styles.xml で定義できる

Android で数独 - onClick -

新しい Activity を定義して起動する。

レイアウトを設定
Sudoku/res/layout/about.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <scrollview  
  3.  xmlns:android="http://schemas.android.com/apk/res/android"  
  4.  android:layout_width="fill_parent"  
  5.  android:layout_height="fill_parent"  
  6.  android:padding="10dip"  
  7. >  
  8. <textview  
  9.  android:id="@+id/about_content"  
  10.  android:layout_width="wrap_content"  
  11.  android:layout_height="wrap_content"  
  12.  android:text="@string/about_text"  
  13. />  
  14.   
  15. </textview  
  16. </scrollview  


More...

Sudoku/res/values/strings.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.  <string name="app_name">Sudoku</string>  
  4.  <string name="main_title">Android Sudoku</string>  
  5.  <string name="continue_label">Continue</string>  
  6.  <string name="new_game_label">New Game</string>  
  7.  <string name="about_label">About</string>  
  8.  <string name="about_title">About Android Sudoku</string>  
  9.  <string name="about_text">\  
  10.  Sudoku is a logic-based number placement puzzle.  
  11.  Starting with a partially completed 9x9 grid, the  
  12.  objective is to fill the grid so that each row,  
  13.  each column, and each of the 3x3 boxes   
  14.  (also called <i>blocks</i>) contains the digits  
  15.  1 to 9 exactly once.  
  16.  </string>  
  17.  <string name="exit_label">Exit</string>  
  18. </resources>  


Sudoku/src/org/example/sudoku/About.java

  1. package org.example.sudoku;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5.   
  6. public class About extends Activity{  
  7.  @Override  
  8.  protected void onCreate(Bundle saveInstanceState) {  
  9.   super.onCreate(saveInstanceState);  
  10.   setContentView(R.layout.about);  
  11.  }  
  12. }  


Sudoku/src/org/example/sudoku/Sudoku.java

  1. package org.example.sudoku;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.content.Intent;  
  6. import android.view.View;  
  7. import android.view.View.OnClickListener;  
  8.   
  9. public class Sudoku extends Activity implements OnClickListener{  
  10.     /** Called when the activity is first created. */  
  11.     @Override  
  12.     public void onCreate(Bundle savedInstanceState) {  
  13.         super.onCreate(savedInstanceState);  
  14.         setContentView(R.layout.main);  
  15.   
  16.         View continueButton = this.findViewById(R.id.continue_button);  
  17.         continueButton.setOnClickListener(this);  
  18.         View newButton = this.findViewById(R.id.new_button);  
  19.         newButton.setOnClickListener(this);  
  20.         View aboutButton = this.findViewById(R.id.about_button);  
  21.         aboutButton.setOnClickListener(this);  
  22.         View exitButton = this.findViewById(R.id.exit_button);  
  23.         exitButton.setOnClickListener(this);  
  24.     }  
  25.       
  26.     public void onClick(View v) {  
  27.      switch(v.getId()){  
  28.      case R.id.about_button:  
  29.       Intent i = new Intent(this, About.class);  
  30.       startActivity(i);  
  31.       break;  
  32.      }  
  33.     }  
  34.       
  35. }  


Sudoku/AndroidManifest.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <manifest  
  3.    xmlns:android="http://schemas.android.com/apk/res/android"  
  4.    package="org.example.sudoku"  
  5.    android:versionCode="1"  
  6.    android:versionName="1.0">  
  7.    <application <brbr="">      android:icon="@drawable/icon"   
  8.       android:label="@string/app_name">  
  9.       <activity  
  10.         android:name=".Sudoku"  
  11.         android:label="@string/app_name">  
  12.       <intent-filter>  
  13.         <action android:name="android.intent.action.MAIN">  
  14.         <category android:name="android.intent.category.LAUNCHER">  
  15.       </category></action></intent-filter>  
  16.         
  17.       <activity  
  18.         android:name=".About"  
  19.         android:label="@string/about_title">  
  20.         
  21.    </activity  
  22. </activity  
  23. </application>  
  24.    <uses-sdk android:minsdkversion="3">  
  25.    
  26. </uses-sdk></manifest  


About ボタンをクリックするとこんな感じ



2009年5月26日火曜日

Android で数独 - ユーザインタフェースのレイアウト -

Android で数独を作ってみる。

Project name : Sudoku
Package name : org.example.sudoku
Activity : Sudoku
Application name : Sudoku



More...

XML でユーザインタフェースを設定しているのが
res/layout/main.xml
これを書き換えれば OK

Sudoku/res/layout/main.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <linearlayout <brbr="">xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:orientation="vertical"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     >  
  7. <textview <brbr="">    android:layout_width="fill_parent"   
  8.     android:layout_height="wrap_content"   
  9.     android:text="@string/main_title"  
  10.     />  
  11. <button  
  12.     android:layout_width="fill_parent"  
  13.     android:layout_height="wrap_content"  
  14.     android:text="@string/continue_label"  
  15.     />  
  16. <button  
  17.     android:layout_width="fill_parent"  
  18.     android:layout_height="wrap_content"  
  19.     android:text="@string/new_game_label"  
  20.     />  
  21. <button  
  22.     android:layout_width="fill_parent"  
  23.     android:layout_height="wrap_content"  
  24.     android:text="@string/about_label"  
  25.     />  
  26. <button  
  27.     android:layout_width="fill_parent"  
  28.     android:layout_height="wrap_content"  
  29.     android:text="@string/exit_label"  
  30.     />  
  31. </button  
  32. </button  
  33. </button  
  34. </button  
  35. </textview></linearlayout>  






もう少しカスタマイズ

Sudoku/res/layout/main.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <linearlayout <brbr="">xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:background="@color/background"  
  4.     android:orientation="horizontal"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_height="fill_parent"  
  7.     android:padding="30dip"  
  8. >  
  9. <linearlayout  
  10.     android:layout_width="fill_parent"  
  11.     android:layout_height="wrap_content"  
  12.     android:layout_gravity="center"  
  13.     android:orientation="vertical"  
  14. >    
  15. <textview <brbr="">    android:layout_width="wrap_content"   
  16.     android:layout_height="wrap_content"   
  17.     android:text="@string/main_title"  
  18.     android:layout_gravity="center"  
  19.     android:layout_marginBottom="25dip"  
  20.     android:textSize="24.5sp"  
  21.     />  
  22. <button  
  23.     android:id="@+id/continue_button"  
  24.     android:layout_width="fill_parent"  
  25.     android:layout_height="wrap_content"  
  26.     android:text="@string/continue_label"  
  27.     />  
  28. <button  
  29.     android:id="@+id/new_button"  
  30.     android:layout_width="fill_parent"  
  31.     android:layout_height="wrap_content"  
  32.     android:text="@string/new_game_label"  
  33.     />  
  34. <button  
  35.     android:id="@+id/about_button"  
  36.     android:layout_width="fill_parent"  
  37.     android:layout_height="wrap_content"  
  38.     android:text="@string/about_label"  
  39.     />  
  40. <button  
  41.     android:id="@+id/exit_button"  
  42.     android:layout_width="fill_parent"  
  43.     android:layout_height="wrap_content"  
  44.     android:text="@string/exit_label"  
  45.     />  
  46. </button  
  47. </button  
  48. </button  
  49. </button  
  50. </textview></linearlayout  
  51. </linearlayout>   


Sudoku/res/values/colors.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <resources>  
  3.  <color name="background">#3500ffff</color>  
  4. </resources>  




横長モードだとはみ出してしまう
ちなみにエミュレータで横長モードにするには Ctrl + F11



ので、横長用のレイアウトを作る

Sudoku/res/layout-land/main.xml

  1. <!--xml version="1.0" encoding="utf-8"?-->  
  2. <linearlayout  
  3.  xmlns:android="http://schemas.android.com/apk/res/android"  
  4.  android:background="@color/background"  
  5.  android:layout_height="fill_parent"  
  6.  android:layout_width="fill_parent"  
  7.  android:padding="15dip"  
  8.  android:orientation="horizontal"  
  9. >  
  10. <linearlayout <brbr=""> android:orientation="vertical"  
  11.  android:layout_height="wrap_content"  
  12.  android:layout_width="fill_parent"  
  13.  android:layout_gravity="center"  
  14.  android:paddingLeft="20dip"  
  15.  android:paddingRight="20dip"  
  16. >  
  17. <textview  
  18.  android:text="@string/main_title"  
  19.  android:layout_height="wrap_content"  
  20.  android:layout_width="wrap_content"  
  21.  android:layout_gravity="center"  
  22.  android:layout_marginBottom="20dip"  
  23.  android:textSize="24.5sp"   
  24. />  
  25. <tablelayout  
  26.  android:layout_height="wrap_content"  
  27.  android:layout_width="wrap_content"  
  28.  android:layout_gravity="center"  
  29.  android:stretchColumns="*"  
  30. >  
  31. <tablerow>  
  32. <button  
  33.  android:id="@+id/continue_button"  
  34.  android:text="@string/continue_label"  
  35. />  
  36. <button  
  37.  android:id="@+id/new_button"  
  38.  android:text="@string/new_game_label"  
  39. />  
  40. </button  
  41. </button  
  42. </tablerow>  
  43. <tablerow>  
  44. <button  
  45.  android:id="@+id/about_button"  
  46.  android:text="@string/about_label"  
  47. />  
  48. <button  
  49.  android:id="@+id/exit_button"  
  50.  android:text="@string/exit_label"  
  51. />  
  52. </button  
  53. </button  
  54. </tablerow>  
  55.   
  56. </tablelayout  
  57. </textview  
  58. </linearlayout>  
  59.   
  60.   
  61. </linearlayout  


直った



1Q84

村上春樹の新刊

予約が殺到しているらしい。
ほとぼりが冷めたら読んでみたいな。

Android Project の作成

Eclipse を起動

[File] -> [New] -> [Project] -> [Android Project]
を選択して Next をクリック



More...

Project name : Hello
Contents : Create new project in workspace
Use default location
Build Target : Android 1.5
Properties : Hello, Android
Package name : org.example.hello
Create Activity : Hello
Min SDK Version : 3



エラーがでる!
Eclipse3.4 と JDK1.6 の組み合わせではエラーがでるらしい。
Compiler compliance level を JDK1.5にする。



[Window] -> [Preferences] -> [Java] -> [Compiler]
JDK Compliance の Compiler compliance level を 1.5 にする



エミュレータ上で実行

Project で右クリック -> [Run As] -> [Android Application]



AVD (Android Virtual Devices) が無いので追加しますか?と聞かれる
Yes をクリック



Name : my_android1.5
Target : Android 1.5 - 1.5
Skin : Default (HVGA)

Create AVD をクリック



追加された my_android1.5 を選択して Finish をクリック



Launch a new Android Virtual Devices

my_android1.5 をチェックして OK をクリック



エミュレータが起動










2009年5月25日月曜日

Eclipse で Android

Eclipse を入れるところから
Eclipse Downloads
で Eclipse IDE for Java EE Developers の Windows 版をダウンロード
展開して
C:\eclipse\eclipse.exe
を起動して

[Help] -> [Software Updates...]



More...

[Add Site...] をクリック
Location : http://dl-ssl.google.com/android/eclipse
を入力して OK



追加された android のサイトをチェックして Install... をクリック



Next をクリック



Review Licenses に同意して Finish をクリック



Install 中



終わったら再起動



[Window] -> [Preference] -> [Andorid] を選択
Android SDK のディレクトリを指定していないのでエラーがでる。




Android SDK のディレクトリを指定して OK をクリック



ちなみに、Windows に Android SDK を入れるには

Download
Installing
System Requirements

Windows 版をdownload して C:\Google に展開

[コントロールパネル] -> [システム] -> [詳細設定] -> [環境変数]
Path に
C:\Google\android-sdk-windows-1.5_r2\tools
を追加





2009年5月24日日曜日

NetBeans 6.5 で Android

[Tools] -> [Plugins] -> [Setting]



More...

Add ボタンをクリックして
Name : Android
URL : http://kenai.com/downloads/nbandroid/updates.xml



OK を押すと追加される



Available Plugins に Android が追加されている



チェックして Install をクリック



License Agreement に同意して Install をクリック



署名が無いといわれるけど Continue



Finish をクリック



Android SDK をインストール

Download
Installing
System Requirements

Windows 版をdownload して C:\Google に展開

[コントロールパネル] -> [システム] -> [詳細設定] -> [環境変数]
Path に
C:\Google\android-sdk-windows-1.5_r2\tools
を追加



NetBeans を再起動

[Tools] -> [Java Platforms] -> [Add Platform...]
Google Android Open Handheld Platform
を選択して Next



ファイル名に
C:\Google\android-sdk-windows-1.5_r2



...としたけど認識されない。うーん残念。
しょうがないから Eclipse で再チャレンジ!

2009年5月22日金曜日

筆箱に家出されまして

月曜日の講義の教室には無し。
教務科の落し物にも無し。

やっぱ立教大学かなー。
きびしー。

まぁ家出したくなるときもあるよね。

2009年5月21日木曜日

14時に30分間昼寝しました。

MITSuME の再解析の1月25日と1月26日が終了。
このへんは R band のカメラが壊れてるから、
ちょっとフレームの選択が面倒。

Fermi は GRBanalysis framework に挑戦して
みようと試みるも、前任者の wiki の情報が
足りなくてどこに何があるのかサッパリ。。。
前途多難です。

そろそろ帰ろうかな。

2009年5月20日水曜日

はてしなき解析

MITSuME の再解析は 09/01/28 と 09/01/27 が終了。
岡山のデータが 10/30 からなぜか g' band だけ
fits が反転しているという わけわからない状態に。
ちょっとパイプラインを変更して。。。手間取ってしまった。
まだまだ終わらないなぁ。
Fermi の解析もなかなか進まない。
いや、きっと前進しているはず ! たぶん

2009年5月19日火曜日

Fermi

ついに、Fermi に手を出すことに。。。
あーあ。
とりあえず Brazarでも解析してみますか。
それにしてもなんで SLAC の wiki は
こんなに情報が散乱しているのか。
キャッチアップが大変じゃないですか。
今日もバーストはおこらなそうなので、平和な BA も 後8分!

裁判所には行きたくないね

裁判員制度って5月21日から開始だったんだ
知らなかった
もうすぐですな

2009年5月8日金曜日

あたりまえと思っていたことがそうじゃない

最近、『日本人が知らない 県民地図』という本を読みました。
いやー面白いです。県によって本当にいろいろな文化があるんだなぁと。
北海道では当たり前(私は道産子です)だったことも、こっちでは
当てはまらなかったり、それはないだろと思うことが他の県では
当たり前だったり。
道民は実は寒がりってのが載ってて、そうなんだよーと1人ツッコミをいれたり。
そうそう北海道は1世帯あたりのアイス消費額が1番なんだって。
確かに実家の冷蔵庫にはいつもアイスが入ってたなぁ。
でも、研究室の先輩や後輩に本に載ってる方言を聞いても、知らないって
言われてしまった。実はマイナー?
なにはともあれ、秘密のケンミンショーは好きな番組です。