diff --git a/gui-android/java/org/echoline/drawterm/MainActivity.java b/gui-android/java/org/echoline/drawterm/MainActivity.java index 2e9b852..22b3fe2 100644 --- a/gui-android/java/org/echoline/drawterm/MainActivity.java +++ b/gui-android/java/org/echoline/drawterm/MainActivity.java @@ -18,6 +18,7 @@ import android.view.Display; import android.view.MotionEvent; import android.view.View; +import android.view.Window; import android.view.Menu; import android.view.MenuItem; import android.view.WindowManager; @@ -211,10 +212,8 @@ public void onClick(final View view) { } }); - int rid = res.getIdentifier("navigation_bar_height", "dimen", "android"); - if (rid > 0) { - hp -= res.getDimensionPixelSize(rid); - } + View contentView = findViewById(Window.ID_ANDROID_CONTENT); + hp -= contentView.getTop(); LinearLayout ll = (LinearLayout)findViewById(R.id.dtButtons); hp -= ll.getHeight(); @@ -279,7 +278,7 @@ public void onClick(final View view) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mainActivity = this; diff --git a/gui-android/java/org/echoline/drawterm/MySurfaceView.java b/gui-android/java/org/echoline/drawterm/MySurfaceView.java index fe71676..8fe9bd0 100644 --- a/gui-android/java/org/echoline/drawterm/MySurfaceView.java +++ b/gui-android/java/org/echoline/drawterm/MySurfaceView.java @@ -9,6 +9,7 @@ import android.view.SurfaceView; import android.view.SurfaceHolder; import android.view.View; +import android.view.Window; import android.widget.CheckBox; import android.widget.EditText; @@ -44,29 +45,40 @@ public MySurfaceView(Context context, int w, int h, float ws, float hs) { @Override public boolean onTouch(View v, MotionEvent event) { + View contentView = mainActivity.findViewById(Window.ID_ANDROID_CONTENT); + View buttonsarea = mainActivity.findViewById(R.id.dtButtons); + int buttons = 0; CheckBox left = (CheckBox)mainActivity.findViewById(R.id.mouseLeft); CheckBox middle = (CheckBox)mainActivity.findViewById(R.id.mouseMiddle); CheckBox right = (CheckBox)mainActivity.findViewById(R.id.mouseRight); CheckBox up = (CheckBox)mainActivity.findViewById(R.id.mouseUp); CheckBox down = (CheckBox)mainActivity.findViewById(R.id.mouseDown); - int buttons = (left.isChecked()? 1: 0) | - (middle.isChecked()? 2: 0) | - (right.isChecked()? 4: 0) | - (up.isChecked()? 8: 0) | - (down.isChecked()? 16: 0); + CheckBox mnative = (CheckBox)mainActivity.findViewById(R.id.mouseNative); + + if (mnative.isChecked()){ + buttons = 0; + buttons |= event.getButtonState() == MotionEvent.BUTTON_PRIMARY ? 1 : 0; + buttons |= event.getButtonState() == MotionEvent.BUTTON_SECONDARY ? 4 : 0; + buttons |= event.getButtonState() == MotionEvent.BUTTON_TERTIARY ? 2 : 0; + } else { + buttons = (left.isChecked()? 1: 0) | + (middle.isChecked()? 2: 0) | + (right.isChecked()? 4: 0) | + (up.isChecked()? 8: 0) | + (down.isChecked()? 16: 0); + } + + float correction = (event.getRawY()-contentView.getY())/screenHeight * contentView.getY(); + mouse[0] = Math.round(event.getRawX()-contentView.getX()); + mouse[1] = Math.round(event.getRawY()-contentView.getY()-buttonsarea.getHeight()+correction); + if (event.getAction() == MotionEvent.ACTION_DOWN) { - mouse[0] = Math.round(event.getX()); - mouse[1] = Math.round(event.getY()); mouse[2] = buttons; mainActivity.setMouse(mouse); } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - mouse[0] = Math.round(event.getX()); - mouse[1] = Math.round(event.getY()); mouse[2] = buttons; mainActivity.setMouse(mouse); } else if (event.getAction() == MotionEvent.ACTION_UP) { - mouse[0] = Math.round(event.getX()); - mouse[1] = Math.round(event.getY()); mouse[2] = 0; mainActivity.setMouse(mouse); } diff --git a/gui-android/res/layout/drawterm_main.xml b/gui-android/res/layout/drawterm_main.xml index cb5c9f3..25c4a45 100644 --- a/gui-android/res/layout/drawterm_main.xml +++ b/gui-android/res/layout/drawterm_main.xml @@ -40,5 +40,9 @@ android:text="kb" android:layout_width="wrap_content" android:layout_height="wrap_content" /> +