http://mybd.sitemix.jp/pic_24FJ64GB002_2.html
回路図(必要な所だけ)
後は、 PIC24FJ64GB002でAndroid Accessory:ADK
の記事を参考に進める。
試す場合は自己責任でお願いします。
パソコンやアンドロイド端末が壊れる可能性があります。
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//データベース作成
SQLiteDatabase db;
db = openOrCreateDatabase( "TestData.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null );
//テーブル作成
String sql = "CREATE TABLE IF NOT EXISTS table_name ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "name TEXT);";
db.execSQL(sql);
//レコードの追加
ContentValues val = new ContentValues();
val.put( "name", "sakkura" );
db.insert( "table_name", null, val );
db.close();
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="ABCDEFGHIJKLMNOPQRSTUVWXYZ" />
</LinearLayout>
| ディスプレイ・サイズ | 約 4.6インチ |
| 赤外線通信対応 | IrSimpleTM/IrSSTMには非対応です。 |
| Bluetooth®通信 | Bluetooth® 4.0 |
| GPS | オートGPS/海外GPS対応 |
| モーションセンサー | 取扱説明書 34p |
| 電子コンパス | 取扱説明書 129p |
| 温度センサー | 取扱説明書 24p |
| 湿度センサー | 取扱説明書 24p |
| RGBセンサー | 取扱説明書 24p |
| 近接センサー | 取扱説明書 24p |
| FMトランスミッタ | 取扱説明書 24p |
| 指紋センサー | 取扱説明書 24p |
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
waitTime();// 時間のかかる処理
Toast.makeText(this, "時間の掛かる処理終了後に実行されるはず", Toast.LENGTH_LONG).show();
}
private void waitTime() {
// TODO 自動生成されたメソッド・スタブ
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
import android.os.Bundle;
import android.app.Activity;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
waitTime();// 時間のかかる処理
}
}).start();
Toast.makeText(this, "時間の掛かる処理終了前に表示されるはず", Toast.LENGTH_LONG).show();
}
private void waitTime() {
// TODO 自動生成されたメソッド・スタブ
try {
Thread.sleep(10 * 1000);
} catch (InterruptedException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
}
}
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
private TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView1);
final Handler handler = new Handler();
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
final int num = waitTime();//時間のかかる処理
handler.post(new Runnable() {
public void run() {
//int num = waitTime();// ここに置いたら別スレッドにならない
textView.setText("UIを変更::" + num);
}
});
}
}).start();
Toast.makeText(this, "これが先に実行されるはず", Toast.LENGTH_LONG).show();
}
private int waitTime() {
// TODO 自動生成されたメソッド・スタブ
try {
Thread.sleep(10 * 1000);//10秒待つ
} catch (InterruptedException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
return 2012;
}
}
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private MyHTTPD server;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
//File am = new File("/data/data/com.example.servertest/lib/", "");//
File am = new File("/mnt/sdcard/", "");//
try {
server = new MyHTTPD(8080, am);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onPause() {
super.onPause();
if (server != null)
server.stop();
}
private class MyHTTPD extends NanoHTTPD {
public MyHTTPD(int port, File wwwroot) throws IOException {
super(port, wwwroot);
// TODO 自動生成されたコンストラクター・スタブ
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content">
<!-- フォーカスされていない -->
<!-- ボタンが押されていない -->
<item android:state_focused="false"
android:state_pressed="false">
<layer-list>
<item><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="270"
android:startColor="#000000"
android:centerColor="#ffffff"
android:endColor="#000000"
android:type="linear" />
<corners android:radius="4dip" />
<stroke android:width="1dip"
android:color="#ffffff" />
<padding android:top="5dip"
android:bottom="5dip"/>
</shape></item>
</layer-list></item>
<!-- フォーカスされていない -->
<!-- ボタンが押されている -->
<item android:state_focused="false"
android:state_pressed="true"><layer-list>
<item><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="270"
android:startColor="#ffffff"
android:centerColor="#000000"
android:endColor="#ffffff"
android:type="linear" />
<corners android:radius="4dip" />
<stroke android:width="1dip"
android:color="#ffffff" />
</shape></item>
</layer-list></item>
<!-- フォーカスされた -->
<!-- ボタンが押されていない -->
<item android:state_focused="true"
android:state_pressed="false"><layer-list>
<item><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="270"
android:startColor="#000000"
android:centerColor="#ffffff"
android:endColor="#000000"
android:type="linear" />
<corners android:radius="4dip" />
<stroke android:width="1dip"
android:color="#FF6600" />
</shape></item>
</layer-list></item>
<!-- フォーカスされた -->
<!-- ボタンが押されている -->
<item android:state_focused="true"
android:state_pressed="true"><layer-list>
<item><shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:angle="270"
android:startColor="#ffffff"
android:centerColor="#000000"
android:endColor="#ffffff"
android:type="linear" />
<corners android:radius="4dip" />
<stroke android:width="1dip"
android:color="#CC6600" />
</shape></item>
</layer-list></item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="button" >
<item name="android:layout_marginTop">1dip</item>
<item name="android:layout_marginBottom">1dip</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" ><Button
android:id="@+id/button1"
style="@style/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@layout/mybutton"
android:text="Button" />
<Button
android:id="@+id/button2"
style="@style/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@layout/mybutton"
android:text="Button" />
</LinearLayout>
package com.example.servertest;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
private MyHTTPD server;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onResume() {
super.onResume();
try {
server = new MyHTTPD(8080, null);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onPause() {
super.onPause();
if (server != null)
server.stop();
}
private class MyHTTPD extends NanoHTTPD {
public MyHTTPD(int port, File wwwroot) throws IOException {
super(port, wwwroot);
// TODO 自動生成されたコンストラクター・スタブ
}
@Override
public Response serve(String uri, String method, Properties header,
Properties parms, Properties files) {
System.out.println(method + " '" + uri + "' ");
String msg = "<html><body><h1>Hello server</h1>\n";
msg += "</body></html>\n";
return new NanoHTTPD.Response(HTTP_OK, MIME_HTML, msg);
}
}
}
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView)findViewById(R.id.videoView1);
videoView.setMediaController(new MediaController(this));
String LINK = "http://www.xxx.jp/xxx/xxx.mp4";
Uri uri=Uri.parse(LINK);
VideoView video=(VideoView)findViewById(R.id.videoView1);
video.setVideoURI(uri);
video.start();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
AVDでは再生は出来るが画質が悪い、import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.LinearLayout;
public class CountdownTimerActivity extends Activity {
/** Called when the activity is first created. */
private boolean mTimerRunning = false;
private boolean doubleTapFlag = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout listView = (LinearLayout) findViewById(R.id.LinearLayout1);
//ダブルタップの間隔取得
final int doubleTime = ViewConfiguration.getDoubleTapTimeout();
listView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.i("TAG", "タップされた");
// 二重起動を防止する
if (!mTimerRunning) {
mTimerRunning = true;
// カウントダウンする
new CountDownTimer(doubleTime, 1) {
// カウントダウン処理
public void onTick(long millisUntilFinished) {
}
// カウントが0になった時の処理
public void onFinish() {
if( doubleTapFlag ){
Log.v("LOG", "ダブルタップ");
doubleTapFlag = false;
}else{
Log.i("LOG", "シングルタップ");
}
mTimerRunning = false;
}
}.start();
}else{
//ダブルタップ
doubleTapFlag = true;
}
return false;
}
});
}
}