Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions gui-android/java/org/echoline/drawterm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
34 changes: 23 additions & 11 deletions gui-android/java/org/echoline/drawterm/MySurfaceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions gui-android/res/layout/drawterm_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
android:text="kb"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/mouseNative"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>