[[FrontPage]]
*利用に当たって [#o1fd4b33]
四国GTUG の宣伝をお願いします。
*バージョン [#jaa7b48b]
PADE ( PortableAndroidDeveloerEnviroment )
*何をするもの? [#l47c97c9]
-Androidアプリの開発一式をまとめたものです
-インストール不要。一発起動。
--通常の環境構築はめんどくさいよね
---ダウンロードに2,3時間+設定に1時間+あれ?ダウンロード途中で失敗してる+あれ?これも足りないよ!
--セミナーなどで起こりがちな、環境構築するだけで1日使っちゃったということが防げます。
*利用にあたって [#o1fd4b33]
-四国GTUG の宣伝をお願いします。
-ダウンロードはこちら
-- http://49.212.145.78/PADE/
*PADEバージョン [#jaa7b48b]
-4.0 Android SDK r17 ベース「あま~いアプリ開発」で使用
-4.1 「おいしいアプリ開発」#5 徳島でつかったやつで、設定ファイルが Import 一発で設定できるようになっています。
-5 Android SDK r18を使ってAndroid エミュレータの劇的改善。5月~6月作成予定
-?? 6月末の Google I/O でさらに新しいAndroid SDK が出てくるかな? 7/21使用予定

*構成ソフト [#f1926e40]
**Windows版 [#g6b2be98]
-32/64bit共用
--32bitのアプリケーションを収録。64bit環境でも32bitのものを利用します。
-Eclipse
-Java
--jPortable という、J2RE6のポータブル版が入っている
-ADT
-Android SDK
**Mac版 [#v0bbcf15]
-32/64bit共用
-Eclipse
-ADT
-Android SDK
-Mac版はJava入っていない
**Linux版 [#f967e691]
-32/64bit共用
-Eclipse
-ADT
-Android SDK
-Linux版はJavaどうだったかな?
*ライセンス [#kd7a8084]
個々のライセンスの調査
配布物に含まれるソフトウェアの個々のライセンスについて(再配布項目のみ抜粋)
-Eclipse
--http://www.eclipse.org/licenses/edl-v10.html
--要旨「Redistributions in binary form must reproduce the above copyright notice」
-Java
--jPortable という、J2RE6のポータブル版が入っている
--このライセンスはオリジナルJ2RE6の「Oracle Binary Code License Agreement for the Java SE Platform Products and JavaFX」と同じ
--http://www.oracle.com/technetwork/java/javase/terms/license/index.html
--この「SUPPLEMENTAL LICENSE TERMS」のC.およびD.が該当箇所
 C.  LICENSE TO DISTRIBUTE SOFTWARE.  Subject to the terms and conditions of this Agreement and restrictions and exceptions set forth in the  README File, including, but not limited to the Java Technology Restrictions and    Limitations on Redistribution of these Supplemental Terms, Oracle grants you a non-exclusive, non-transferable, limited license without fees to reproduce and distribute the Software, provided that (i) you distribute the Software complete and unmodified and only bundled as part of, and for the sole purpose of running, your Programs, (ii) the Programs add significant and primary functionality to the Software, (iii) you do not distribute additional  software intended to replace any component(s) of the Software, (iv) you do not remove or alter any proprietary legends or notices contained in the Software, (v) you only distribute the Software subject to a license agreement that: (a) is a complete, unmodified reproduction of this Agreement; or (b) protects Oracle's interests consistent with the terms contained in this Agreement and that includes the notice set forth in Section H, and (vi) you agree to defend and indemnify Oracle and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including  attorneys' fees)  incurred in connection  with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software.  The license set forth in this Section C does not extend to the Software identified in Section G.
 
 D.  LICENSE TO DISTRIBUTE REDISTRIBUTABLES.  Subject to the terms and conditions of this Agreement and restrictions and exceptions set forth in the README File, including but not limited to the Java Technology Restrictions and Limitations on Redistribution of these Supplemental Terms, Oracle grants you a non-exclusive, non-transferable, limited license without fees to reproduce and distribute those files specifically identified as redistributable in the README File ("Redistributables") provided that: (i) you distribute the Redistributables complete and unmodified, and only bundled as part of Programs, (ii) the Programs add significant and primary functionality to the Redistributables, (iii) you do not distribute additional software intended to supersede any component(s) of the Redistributables (unless otherwise specified in the applicable README File), (iv) you do not remove or alter any proprietary legends or notices contained in or on the Redistributables, (v) you only distribute the Redistributables pursuant to a license agreement that: (a) is a complete, unmodified reproduction of this Agreement; or (b) protects Oracle's interests consistent with the terms contained in the Agreement and includes the notice set forth in Section H, (vi) you agree to defend and indemnify Oracle and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Software.  The license set forth in this Section D does not extend to the Software identified in Section G.
--要旨はこれ「you distribute the Redistributables complete and unmodified , and only bundled as part of Programs」
--「あなたは完全で変更されていない再配布物をプログラムの一部としてバンドルして配布することだけができる」

-ADT および Android SDK
--ライセンス記述はここ?? http://developer.android.com/license.html
--それともここ? http://source.android.com/source/licenses.html
-Android SDK
--ライセンス記述ページ。isoイメージ内にも同様のファイルが入っている http://developer.android.com/license.html
-Android ADT
--Eclipse Public License - v 1.0
--kxml2 - 2.3.0.jar については BSD license 
---cf., http://source.android.com/source/licenses.html


*使い方 [#i38a8567]

[[PADEを使った学習]]もご覧ください。

**ISOファイルのマウント [#u85b282a]
**ISOファイル [#p4da642f]
-ISOファイルをダウンロードして、MD5に異常がなければDVDに書き込むかISOファイルを直接マウントして使います。
-ISOファイルを直接マウントしたほうが高速に使用できます。
-DVDに書き込む場合、
--Windows7では「右クリック」-「ディスク イメージの書き込み」
--WindowsXP/Vistaなどでは DVD Decriptorなどを使用
**ISOファイルを直接マウントする [#u85b282a]

Windowsの場合
マウント Portable WinCDEmuをダウンロードしてください
isoファイルをマウントするには、Portable WinCDEmuをダウンロードして利用してください

**Ecripseは英語 [#wb18ab4a]
英語の方が使いやすい
*クライアントドライバー [#x480c184]
自分の手持ちのドライバはぐぐってください。ADBドライバーという名前でぐぐってください。
googleドライバーというのはisoファイルの中に入っているので入れるときに聞かれたらそれを使って下さい
英語の方が使いやすいため
**クライアントドライバー [#x480c184]
-自分の手持ちの機種に応じてドライバをPCにインストールする必要があります。
-ドライバはADBドライバーという名前でぐぐってください。
--機種のメーカページで公開していることが多いです
-googleドライバーというのはisoファイルの中に入っています。
--入れるときに聞かれたらそれを使って下さい

**PADE4 [#d0338981]
ダブルクリックで実行
最初にワークスペースの設定
自分のファイルシステム上で書き込みしていいところを指定する
**PADE4の実行 [#d0338981]
-PADE4ファイルをダブルクリック
-最初にワークスペースの設定
-自分のファイルシステム上で書き込みしていいところを指定する

**Eclipseの設定 [#xbc42554]
Window-Android SDK Manager
Android 2.2を選択
-Window-Android SDK Manager
-Android 2.2を選択

**レシピ1 [#h22ae9c0]
-プロジェクトを立ち上げる。Package Nameは自分のドメインを指定
-特になければcom.exampleで。但しこの名前だとマーケットに登録できない
-RUNする
-Android Device Chooserをキャンセルして
-Android Virtual Device Managerで「New」を選んでNameをてきとうに
-Start-Launch
-しばらくすると仮想マシンが出現する
-5分ぐらいで画面が出てくる
-Hello worldはvalueのstringに入っている
**レシピ2 [#y430be03]
-res-layout-main.xmlをダブルクリック
-Graphical layoutを設定して
-layoutのmain.xmlで
-From widgetsにあるボタンをぐりぐりもってきてドラッグするだけ
-saveしてください

**レシピ3 [#t2e766b3]
-ボタンにコードを割り振り [#l19492cf]
-Button button = (Button)findViewByID(R.id.button1);
を11行目と12行目の間にタイプ
このままではエラーが出るので
Ctfl+Shift+Oでインポートを自動補完
 import android.widget.Button;
が増えるのでエラーが出なくなる
-その次に [#y8adf4f3]
 button.setOnClickListener(new OnClickListener() {
   public void onClick(View v) {
    Toast.makeText(HelloWorldActivity.this, "Hello!", Toast.LENGTH_LONG).show();
   }
 });
-これでCtl+Shift+Oを押すとOrganize Importsでandroid.content.DialogInterface.OnClickListener と android.view.View.OnCliclKistenerを選択するようになるがandroid.view.View.OnCliclKistenerを選択する。これはOnClickListenerの引数で判断しないといけない(判断は上級者向)
**レシピ04 国際化 [#ha8cd907]
res-values-strings.xmlをディレクトリごとコピー
valuesとvalues-jaとの二つにする。
values-ja/strings.xmlを日本語に書き換える
**レシピ05 タイマー [#ie84e1c5]
Toast行を以下に入れ替え
 new Thread() {
    @Override
    public void run() {
       try{
         Thread.sleep(10 * 1000);
       } catch (InterruptedException e){
         e.printStackTrace();
       }
       handler.post(new Runnable(){
         public void run() {
           Toast.makeText(HelloWorldActivity.this,"Hello!", Toast.LENGTH_LONG).show();
         } 
       });
 }}.start();
ハンドラを作っておく
 public class HelloPADE2Activity extends Activity {
の下に一行追加
 private Handler handler = new Handler();
Ctl+Shift+Oでimportを増やしておく
**レシピ06:ログ出力 [#t0994725]
**スィーツ07:明示的Intent [#zb2c30a6]
 public class HelloPADEActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button button = (Button)findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {
        	  public void onClick(View v) {
                    // new Thread() {
                    // @Override
                    // public void run() {
                    // Log.v("hello", "Error");
                    // try {
                    // new NumberFormatException();
                    // Thread.sleep(10 * 1000);
                    // } catch (InterruptedException e) {
                    // e.printStackTrace();
                    // }
                    // handler.post(new Rnnable() {
                    // public void run() {
                    // Toast.makeText(HelloWorldActivity.this,
                    // "Hello!", Toast.LENGTH_LOGNG).show();
                    // }
                    // });
                    // }
                    // }.start();
                    EditText text = (EditText) findViewById(R.id.editText1);
                    String value = text.getText().toString();
 
                    Intent intent = new Intent(HelloWorldActivity.this,
                           SecondActivity.class);
                    intent.putExtra("text",value);
                    startActivityForResult(intent, 0);
                 }
               });
             }
 
             @Override
             protected void on ActibityResult(int requestCode, int resultCode, Intent data) {
                if (requestCode == 0 && resultCode ==1) {
                  String value = data.getExtras().getString("result");
                  Toast.makeText(this, value, Toast.LENGTH_LONG).show();
             }
         }
     }


***セカンドアクティビティ [#ja184720]
 package jp.cane.android.sweet;
 
 import android.app.Activityl
 import android.content.Intent;
 import android.os.Bundle;
 
 public class SecondActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
 
        Intent intent = getIntent();
        String value = intent.getExtras().getString("text");
 
        // Toast.makeText(this,value,Toast.LENGTH_LONG.show();
 
        value = "こんにちは、" + value;
 
        Intent data = new Intent();
        data.putExtra("result",value);
        setResult(1);
        finish();
    }
 }


**スィーツ08:暗黙的Intent [#w009031b]
 package jp.cane.android.sweet;
 
 import android.app.Activityl
 import android.content.Intent;
 import android.os.Bundle;
 
 public class SecondActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
 
        Intent intent = getIntent();
        String value = intent.getExtras().getString("text");
 
        // Toast.makeText(this,value,Toast.LENGTH_LONG.show();
 
        value = "こんにちは、" + value;
 
        Intent data = new Intent();
        data.putExtra("result",value);
        setResult(1);
        finish();
    }
 }


**スィーツ09:返り値をIntentで受け取る [#f4a6eb3e]
**スィーツ10:サービス [#v02906ed]
New-classで、MainService.java できたらextendedのサービスを追加
を以下のように作る
package jp.cone.android.sweet;{
 
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
 
 public class MainService extends Service {
  @Override
  public void onCreate()
   super.onCreate();
  
  }
 
  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }
 }

その次に、以下のように拡張する
 public class MainService extends Service implements Runnable {
  private Handler handler = new Handler();
 
  @Override
  public void onCreate()
   super.onCreate();
 
   new Thread(this).start();
  }
 
  @Override
  public IBinder onBind(Intent intent) {
    return null;
  }
 
  public void run() {
     while (true) {
       try {
         Thread.sleep(3 * 1000);
       } catch (InterruptedException e) {
         e.printStackTrace();
       }
       handler.post(new Runnable() {
         public void run() {
            Toast.makeText(MainService.this, "Hello", Toast.LENGTH_LONG).show();
         }
       });
     }
   }
 }
このサービスは問題があって、AndroidOSから勝手にkillされる。それを防ぐためにはstartforgroundとかをやると終了されなくなる。


 
**お口直し:Bluetooth通信 [#rf3f2d03]

MainService.javaを書き換え


    public void run() {
      handler.post(new Runnable() {
        public void run() {
           adapter = BluetoothAdapter.getDefaultAdapter();
        }
      });
      while (adapter == null) {
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
 
       }
       while (true)
         // try {
         // Tread.sleep(3 * 1000);
         // } catch (InterruptedException e) {
         // e.printStackTrace();
         // }
         // handler.post(new Runnable() {
         // public void run() {
         // Toast.makeText(MainService.this, "Hello", Toast.LENGTH_LONG).show();
         // }
         // });
         try {
            BluetoothSocket socket;
            if (true) { // server
              BluetoothServerSocket ssocket = adapter
               .listenUsingRfcommWithServiceRecord("BTChat",
                  UUID.fromString(UI_MODE_SERVICE));
              socket = ssocket.accept();
            } else { // client
              socket = adapter.getRemoteDevice("00:11:22:33:44:55")
                 .createRfcommSockeToServiceRecord(
                     UUID.fromString(UI_MODE_SERVICE));
              socket.connect();
            }
            // if server , move below one line to "point B".
            socket.getOutputStream().write("hogehoge\n".getBytes());

            InputStream is = socket.getInputStream();
            BufferedReader reader = new BufferdReader(
                 new InputStreamReader(is));
 
            final String line = reader.readLine();
 
            handler.post(new Runnable() {
               public void run() {
                  Toast.makeText(MainService.this, line,
                        Toast.LENGTH_LONG).show();
                  }
            });

         // point B
 
            
         } catch (IOException e) {
             // TODO Auto-genereted catch block
             e.printStackTrace
         }


パーミッションを追加する必要がある
res-AndroidManifest.xmlのAndroid Manifest Permissionsでon.BLUETOOTH

on.BLUETOOTH_ADMIN


アクティビティを追加する度に




**Eclipse Tips [#d7677b1e]
-コメントアウト 反転させてCtl+/
-Ctl+Space機能はよく使う(補完候補)
-行番号 Windows-Preferences-General-Editors-Text Editors-Show line numbers
-Ctl+Shift+FでインデントFix
-エラーマークにカーソルを合わせるとエラー詳細



トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS