void reqest Windowint ID ID ID ID Window

  • Slides: 46
Download presentation

void reqest. Window(int ID) 【機能】ウィンドウの特徴IDの設定 【引数】 ID : 特徴ID Window. FEATURE_ACTION_BAR_OVERLAY Window. FEATURE_ACTION_MODE_OVERLAY Window.

void reqest. Window(int ID) 【機能】ウィンドウの特徴IDの設定 【引数】 ID : 特徴ID Window. FEATURE_ACTION_BAR_OVERLAY Window. FEATURE_ACTION_MODE_OVERLAY Window. FEATURE_CONTEXT_MENU Window. FEATURE_CUSTOM_TITLE Window. FEATURE_INDETERMINATE_PROGRESS Window. FEATURE_LEFT_ICON Window. FEATURE_NO_TITLE Window. FEATURE_OPTION_PANEL Window. FEATURE_PROGRESS Window. FEATURE_RIGHT_ICON B. reqest. Window 概要 アクションバー コンテンツをオーバーレイするアクションバー 表示スペースが存在しないとき、コンテンツの オーバーレイを許可するアクションバー コンテキストメニュー カスタムタイトル 不確定プログレス 左アイコン タイトルなし オプションパネル プログレス 右アイコン

K. 円の描画 [Canvasクラス] void draw. Circle(float cx, float cy, float radius, Paint paint) 【機能】円の描画

K. 円の描画 [Canvasクラス] void draw. Circle(float cx, float cy, float radius, Paint paint) 【機能】円の描画 【引数】cx : 中心点のX座標 cy : 中心点のY座標 radius : 半径 paint : 描画オブジェクト cx radius cy 中心点

package jp. eclipse; import android. content. Context; A. import android. graphics. Canvas; import android.

package jp. eclipse; import android. content. Context; A. import android. graphics. Canvas; import android. graphics. Color; import android. graphics. Paint; import android. graphics. Path; import android. graphics. Rect. F; import android. view. View; //図形描画 public class Graphics. View extends View { //コンストラクタ public Graphics. View(Context context) { super(context); set. Background. Color(Color. WHITE); } //描画 protected void on. Draw(Canvas canvas){ //描画オブジェクト生成 Paint p = new Paint(); p. set. Anti. Alias(true); (4)プログラムの入力 Graphics. View. java(その1)

//線分描画 p. set. Stroke. Width(1); Graphics. View. java(その2) p. set. Style(Paint. Style. STROKE); p.

//線分描画 p. set. Stroke. Width(1); Graphics. View. java(その2) p. set. Style(Paint. Style. STROKE); p. set. Color(Color. argb(255, 0, 0)); canvas. draw. Line(50, 10, 50, 90, p); //連続線分描画 p. set. Style(Paint. Style. STROKE); p. set. Color(Color. argb(255, 0, 255, 0)); Path path = new Path(); path. move. To(110, 10); path. line. To(170, 20); path. line. To(130, 50); path. line. To(190, 60); canvas. draw. Path(path, p); //矩形描画 p. set. Style(Paint. Style. STROKE); p. set. Color(Color. argb(255, 0, 0, 255)); canvas. draw. Rect(new Rect(10, 100, 90, 180), p); //矩形塗り潰し p. set. Style(Paint. Style. FILL); p. set. Color(Color. argb(255, 0, 0, 255)); canvas. draw. Rect(new Rect(110, 100, 190, 180), p);

//角丸矩形描画 Graphics. View. java(その3) p. set. Style(Paint. Style. STROKE); p. set. Color(Color. argb(255, 0,

//角丸矩形描画 Graphics. View. java(その3) p. set. Style(Paint. Style. STROKE); p. set. Color(Color. argb(255, 0, 255, 0)); canvas. draw. Round. Rect(new Rect. F(10, 200, 90, 280), 10, p); //角丸矩形塗り潰し p. set. Style(Paint. Style. FILL); p. set. Color(Color. argb(255, 0, 255, 0)); canvas. draw. Round. Rect(new Rect. F(110, 200, 190, 280), 10, p); //円描画 p. set. Style(Paint. Style. STROKE); p. set. Color(Color. argb(255, 0, 255)); canvas. draw. Circle(50, 340, p); //円塗り潰し p. set. Style(Paint. Style. FILL); p. set. Color(Color. argb(255, 0, 255)); canvas. draw. Circle(150, 340, p); } }

B. Draw. Figure. Activity. java] package jp. eclipse; import android. app. Activity; import android.

B. Draw. Figure. Activity. java] package jp. eclipse; import android. app. Activity; import android. os. Bundle; import android. view. Window; public class Draw. Figure. Activity extends Activity { /** Called when the activity is first created. */ @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); request. Window. Feature(Window. FEATURE_NO_TITLE); set. Content. View(new Graphics. View(this)); } }

B. プログラム例(その1) package jp. eclips; import android. app. Activity; import android. os. Bundle; import

B. プログラム例(その1) package jp. eclips; import android. app. Activity; import android. os. Bundle; import android. content. *; import android. graphics. *; import android. view. *; import android. widget. *; public class Touch. VActivity extends Activity { /** Called when the activity is first created. */ Touch. View tv; @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); Linear. Layout layout=new Linear. Layout(this); set. Content. View(layout); tv=new Touch. View(this); layout. add. View(tv); }

プログラム例(その2) class Touch. View extends View{ float x, y; //コンストラクタ public Touch. View(Context context)

プログラム例(その2) class Touch. View extends View{ float x, y; //コンストラクタ public Touch. View(Context context) { super(context); x = -10; y = -10; } // 画面にタッチしたときのメソッド public boolean on. Touch. Event(Motion. Event e){ x = e. get. X(); y = e. get. Y(); //タッチしたときの位置 this. invalidate(); //再描画 return true; } protected void on. Draw(Canvas canvas){ super. on. Draw(canvas); Paint paint=new Paint(); paint. set. Color(Color. YELLOW); paint. set. Style(Paint. Style. FILL); canvas. draw. Circle(x, y, 10, paint); } } }

package jp. eclipse; import java. util. *; import android. app. Activity; import android. os.

package jp. eclipse; import java. util. *; import android. app. Activity; import android. os. Bundle; import android. content. *; import android. graphics. *; import android. view. View; import android. widget. *; public class Random. VActivity extends Activity { /** Called when the activity is first created. */ static final int num=50; Random rn = new Random(); Random. View rv; @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); Linear. Layout LL=new Linear. Layout(this); set. Content. View(LL); rv=new Random. View(this); LL. add. View(rv); } B. プログラム例(その1)

B. プログラム例(その2) class Random. View extends View{ Array. List <Ball> b 1; public Random.

B. プログラム例(その2) class Random. View extends View{ Array. List <Ball> b 1; public Random. View(Context context) { super(context); b 1=new Array. List<Ball>(); for (int i=0; i<num; i++){ b 1. add(new Ball(460, 762)); } } protected void on. Draw(Canvas canvas){ super. on. Draw(canvas); Paint p =new Paint(); for (int i=0; i<num; i++){ Ball b=b 1. get(i); p. set. Color(Color. rgb(b. r, b. g, b. b)); p. set. Style(Paint. Style. FILL); canvas. draw. Circle(b. x, b. y, 10, p); } } }

B. プログラム例(その3) class Ball{ public int x, y, r, g, b; public Ball(int W,

B. プログラム例(その3) class Ball{ public int x, y, r, g, b; public Ball(int W, int H){ x=rn. next. Int(W); y=rn. next. Int(H); r=rn. next. Int(256); g=rn. next. Int(256); } } }

B. 関連するクラス 【android. widget. View. Flipper クラス】 View. Flipperオブジ ェクトを作成する。 【android. widget. View. Animation

B. 関連するクラス 【android. widget. View. Flipper クラス】 View. Flipperオブジ ェクトを作成する。 【android. widget. View. Animation クラス】 set. In. Animation(Animation anim) 画面に表示されるときに再生されるアニ メーションの指定 set. Out. Animation(Animation anim) 画面に表示されるときに再生されるアニ メーションの指定 void show. Next() ューに移動 void show. Previous() ューに移動 【android. view. animation. Translate. Animation クラス】 translate. Animation(float fxd, txd, float fyd, float tyd) 移動アニメーションを作成 次のビ 前のビ float 指定した

package jp. eclipse; C. プログラム例(その1) import java. util. *; import android. app. Activity; import

package jp. eclipse; C. プログラム例(その1) import java. util. *; import android. app. Activity; import android. os. *; import android. content. *; import android. graphics. *; import android. view. View. On. Touch. Listener; import android. view. animation. *; import android. widget. *; public class Random. VActivity extends Activity { /** Called when the activity is first created. */ static final int num=50; View. Flipper vf; Random. View[] rv=new Random. View[3]; //ビューを 3つ用意 Linear. Layout[] LL=new Linear. Layout[3]; float x; Random rn = new Random(); @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); Linear. Layout LLp = new Linear. Layout(this); set. Content. View(LLp);

vf =new View. Flipper(this); プログラム例(その2) for (int i=0; i<rv. length; i++){ LL[i]=new Linear. Layout(this);

vf =new View. Flipper(this); プログラム例(その2) for (int i=0; i<rv. length; i++){ LL[i]=new Linear. Layout(this); rv[i]=new Random. View(this); //円を描くビュー LL[i]. add. View(rv[i]); vf. add. View(LL[i]); //View. Flipperに追加 } LLp. add. View(vf); set. Content. View(LLp); LLp. set. On. Touch. Listener(new Flip. Touch. Listener()); } class Flip. Touch. Listener implements On. Touch. Listener{ public boolean on. Touch(View v, Motion. Event e) { int ev=e. get. Action(); if(ev==Motion. Event. ACTION_DOWN) x=e. get. X(); else if(ev==Motion. Event. ACTION_UP){ if(x>e. get. X()){// 右方向に進むようめくった場合 Translate. Animation in. Anim = //入ってくるアニメーション new Translate. Animation(rv[0]. get. Width(), 0, 0, 0); Translate. Animation out. Anim= //出ていくアニメーション new Translate. Animation(0, -rv[0]. get. Width(), 0, 0);

プログラム例(その3) out. Anim. set. Duration(1000); //再生時間を 1000ミリ秒とする vf. set. In. Animation(in. Anim); //画面に表示されるときのアニメ vf.

プログラム例(その3) out. Anim. set. Duration(1000); //再生時間を 1000ミリ秒とする vf. set. In. Animation(in. Anim); //画面に表示されるときのアニメ vf. set. In. Animation(out. Anim); //画面から消えるときのアニメ vf. show. Next(); //次ページに進む } else if(x<e. get. X()){// 左方向に進むようめくった場合 Translate. Animation in. Anim= //入ってくるアニメーション new Translate. Animation(-rv[0]. get. Width(), 0, 0, 0); Translate. Animation out. Anim= //出ていくアニメーション new Translate. Animation(0, rv[0]. get. Width(), 0, 0); out. Anim. set. Duration(1000); vf. set. In. Animation(in. Anim); vf. set. In. Animation(out. Anim); vf. show. Previous(); //前ページに戻る } } return true; } }

class Random. View extends View{ プログラム例(その4) Array. List<Ball> b 1; public Random. View(Context context)

class Random. View extends View{ プログラム例(その4) Array. List<Ball> b 1; public Random. View(Context context) { super(context); b 1=new Array. List<Ball>(); for (int i=0; i<num; i++) b 1. add(new Ball(460, 762)); } protected void on. Draw(Canvas canvas){ super. on. Draw(canvas); Paint p =new Paint(); for (int i=0; i<num; i++){ Ball b=b 1. get(i); p. set. Color(Color. rgb(b. r, b. g, b. b)); p. set. Style(Paint. Style. FILL); canvas. draw. Circle(b. x, b. y, 10, p); } } } class Ball{ public int x, y, r, g, b; public Ball(int W, int H){ x=rn. next. Int(W); y=rn. next. Int(H); r=rn. next. Int(256); g=rn. next. Int(256); } } }

B. 関連するクラス 【android. os. Handler クラス】 Handler() ハンドラを作成。 boolean post. Delayed 実行を指定 時間(dm)だけ遅延する (Runnable

B. 関連するクラス 【android. os. Handler クラス】 Handler() ハンドラを作成。 boolean post. Delayed 実行を指定 時間(dm)だけ遅延する (Runnable r, long dm) void remove. Callbacks() 処理を取り除く。 実行待ちの 【android. app. Activity クラス】 Object get. System. Service(String name) システムサービスを取得。 Window get. Window() ウィンドウ を取得。 boolean request. Window. Feature(int id) フィーチャを指定。 【android. view. Window クラス】 void add. Flags(int f) 加。 【android. view. Window. Manager インターフェース】 Display get. Default. Display() ディスプレイを取得。 フラグを追

C. プログラム例(その1) package jp. eclipse; import android. app. Activity; import android. os. Bundle; import

C. プログラム例(その1) package jp. eclipse; import android. app. Activity; import android. os. Bundle; import android. os. Handler; import android. content. *; import android. graphics. *; import android. view. *; import android. widget. *; // Runnableインターフェースを実装する(inplements Runnableを追加) public class Ball. Move. Activity extends Activity implements Runnable { /** Called when the activity is first created. */ Screen. View sv; Handler hn; float x, y, dx, dy; float max. Left, max. Bottom; public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); //画面をフルスクリーンにする get. Window(). add. Flags(Window. Manager. Layout. Params. FLAG_FULLSCREEN); //タイトル消去 request. Window. Feature(Window. FEATURE_NO_TITLE); Linear. Layout ll = new Linear. Layout(this); set. Content. View(ll);

C. プログラム例(その2) //画面範囲の設定 Window. Manager wm = (Window. Manager)get. System. Service(WINDOW_SERVICE); Display dp =

C. プログラム例(その2) //画面範囲の設定 Window. Manager wm = (Window. Manager)get. System. Service(WINDOW_SERVICE); Display dp = wm. get. Default. Display(); max. Left = dp. get. Width() -10; max. Bottom = dp. get. Height()-10; hn = new Handler(); hn. post. Delayed(this, 5); // Runメソッドを遅らせて実行 sv = new Screen. View(this); ll. add. View(sv); //ビューの追加 } public void run() { if(x<=10 || x>=max. Left) dx = -dx; //反射 if(y<=10 || y>=max. Bottom) dy = -dy; x+=dx; y+=dy; sv. invalidate(); //移動と再描画 hn. post. Delayed(this, 5); //遅らせて繰り返す } public void on. Destroy() { // 画面破棄のとき解除 super. on. Destroy(); hn. remove. Callbacks(this); }

C. プログラム例(その3) class Screen. View extends View { public Screen. View(Context cn) { //

C. プログラム例(その3) class Screen. View extends View { public Screen. View(Context cn) { // 初期設定 super(cn); x = 100; y = 100; dx = 5; dy = 5; } protected void on. Draw(Canvas cs) { super. on. Draw(cs); Paint p = new Paint(); p. set. Color(Color. YELLOW); p. set. Style(Paint. Style. FILL); cs. draw. Circle(x, y, 10, p); } } }

B. プログラム例(その1) package jp. eclipse. coord; import java. util. *; import android. app. *;

B. プログラム例(その1) package jp. eclipse. coord; import java. util. *; import android. app. *; import android. os. *; import android. content. *; import android. graphics. *; import android. view. View. *; import android. widget. *; public class Coord. Activity extends Activity { /** Called when the activity is first created. */ Coord. View cv; @Override public void on. Create(Bundle saved. Instance. State) { super. on. Create(saved. Instance. State); Linear. Layout LL=new Linear. Layout(this); set. Content. View(LL); cv=new Coord. View(this); LL. add. View(cv); set. Content. View(LL); }

プログラム例(その2) class Coord. View extends View{ public Coord. View(Context context) { super(context); } protected

プログラム例(その2) class Coord. View extends View{ public Coord. View(Context context) { super(context); } protected void on. Draw(Canvas cs){ super. on. Draw(cs); int w=cs. get. Width(); int h=cs. get. Height(); int r = w / 3; cs. draw. Color(Color. rgb(255, 128)); cs. save(); // キャンバス保存 Paint p=new Paint(); p. set. Color(Color. argb(50, 255, 0, 0)); cs. translate(w / 2, h/3 -r); // 平行移動 for(int i=0; i<64; i++){ cs. scale(0. 9 F, 0. 9 F); cs. rotate(20 f); // スケーリングと回転 cs. draw. Rect(new Rect(0, 0, r, r), p); } cs. restore(); // キャンバス回復 p. set. Color(Color. argb(50, 0, 0, 255)); cs. translate(w / 2, h/3+r); // 平行移動 for(int i=0; i<64; i++){ cs. scale(0. 9 F, 0. 9 F); cs. rotate(20 f); // スケーリングと回転 cs. draw. Rect(new Rect(0, 0, r, r), p); } } }