DoCoMoのニュータイプ、Xperiaのタッチパネルについてである。
Androidのタッチパネルではタッチした強さを取得できる。
はずなんだ。
取得方法は
onTouchEvent(MotionEvent event) 内の getPressure() メソッドで0.0から1.0の値が取得できるはず。
少なくともHT-03Aでは取得できていたが、Xperiaでは常に1.0が返ってくるようだ。
こんなコードを書いてしらべた。
// package略
// import略
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int a = event.getAction();
String act = "";
if (a == MotionEvent.ACTION_CANCEL) {
act = "ACTION_CANCEL";
}
if (a == MotionEvent.ACTION_DOWN) {
act = "ACTION_DOWN";
}
if (a == MotionEvent.ACTION_MOVE) {
act = "ACTION_MOVE";
}
if (a == MotionEvent.ACTION_OUTSIDE) {
act = "ACTION_OUTSIDE";
}
if (a == MotionEvent.ACTION_UP) {
act = "ACTION_UP";
}
((TextView)findViewById(R.id.touch_action)).setText(act);
((TextView)findViewById(R.id.touch_x)).setText(""+event.getX());
((TextView)findViewById(R.id.touch_y)).setText(""+event.getY());
int size = event.getHistorySize();
String histPress = " size=" + size;
for (int i = 0;i < size;i++) {
if (i > 1) break;
histPress = histPress + "," + event.getHistoricalPressure(i);
}
((TextView)findViewById(R.id.touch_pressure)).setText(histPress);
String histSize = " size=" + size;
for (int i = 0;i < size;i++) {
if (i > 1) break;
histSize = histSize + "," + event.getHistoricalSize(i);
}
((TextView)findViewById(R.id.touch_size)).setText(histSize);
return true;
}
}
// layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/title"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MotionEvent.getX()=" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/touch_x"
android:text="0" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MotionEvent.getY()=" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/touch_y" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MotionEvent.getSize()=" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/touch_size" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MotionEvent.getPressure()=" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/touch_pressure" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MotionEvent.getAction()=" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/touch_action" />
</LinearLayout>
</LinearLayout>
同様にタッチした範囲もgetSize()で取得できるのだが、Xperiaは常に0.0を返すのであった。
これは機種依存なのかもしれない。
マルチタッチをサポートしてたらタッチした範囲は求められそうだが、Xperiaのタッチパネルにはこんな情報もあり、機種的に取得ができないのかもしれん。
幅広い端末をサポートするなら、タッチパネルのプレッシャーを測り知ろうとしてはならぬのかもしれない。
Xperiaを猛烈に強くタッチしても「私にプレッシャーをかけるパイロットとは・・・」などとは言ってくれなさそうである。
はたしてXperia君はAndroidOS2.X にアップデートして真のニュータイプになれるのであろうか。
Related posts:
- Androidで音声処理1
- Xperiaのカメラ
- HT-03Aでプレビューの映像データをビットマップデータに変換して保存する
- HT-03Aでプレビューの映像データをビットマップデータに変換するところ補足
関連記事はYARPP関連記事プラグインによって表示されています。



