Skip to content

Commit

Permalink
fix keyboard bug(s), allow empty password
Browse files Browse the repository at this point in the history
  • Loading branch information
echoline committed Oct 4, 2020
1 parent c5f3365 commit eaa5241
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 74 deletions.
15 changes: 7 additions & 8 deletions gui-android/java/org/echoline/drawterm/DrawTermThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

public class DrawTermThread extends Thread {
private MainActivity m;
private String c, a, u, p;
private String p;
private String []args;

public DrawTermThread(String c, String a, String u, String p, MainActivity m) {
this.c = c;
this.a = a;
this.u = u;
this.p = p;
public DrawTermThread(String []args, String p, MainActivity m) {
this.m = m;
this.p = p;
this.args = args;
}

@Override
public void run() {
String args[] = {"drawterm", "-p", "-h", c, "-a", a, "-u", u};
m.setPass(p);
if (p != null && !p.equals(""))
m.setPass(p);
m.dtmain(args);
m.runOnUiThread(new Runnable() {
@Override
Expand Down
111 changes: 64 additions & 47 deletions gui-android/java/org/echoline/drawterm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public class MainActivity extends Activity {
private Map<String, ?> map;
private MainActivity mainActivity;
private boolean dtrunning = false;

static {
System.loadLibrary("drawterm");
Expand Down Expand Up @@ -67,6 +68,59 @@ public void populateServers(Context context) {
la.add(key);
}
ll.setAdapter(la);

dtrunning = false;
}

public void runDrawterm(String []args, String pass) {
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();

int wp = dm.widthPixels;
int hp = dm.heightPixels;

setContentView(R.layout.drawterm_main);

Button kbutton = (Button)findViewById(R.id.keyboardToggle);
kbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}
});

int rid = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (rid > 0) {
hp -= res.getDimensionPixelSize(rid);
}
LinearLayout ll = findViewById(R.id.dtButtons);
hp -= ll.getHeight();

int w = (int)(wp * (160.0/dm.xdpi));
int h = (int)(hp * (160.0/dm.ydpi));
float ws = (float)wp/w;
float hs = (float)hp/h;
// only scale up
if (ws < 1) {
ws = 1;
w = wp;
}
if (hs < 1) {
hs = 1;
h = hp;
}

MySurfaceView mView = new MySurfaceView(mainActivity, w, h, ws, hs);
mView.getHolder().setFixedSize(w, h);

LinearLayout l = findViewById(R.id.dlayout);
l.addView(mView, 1, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

DrawTermThread t = new DrawTermThread(args, pass, mainActivity);
t.start();

dtrunning = true;
}

public void serverButtons() {
Expand Down Expand Up @@ -95,52 +149,8 @@ public void onClick(final View view) {
String user = ((EditText)findViewById(R.id.userName)).getText().toString();
String pass = ((EditText)findViewById(R.id.passWord)).getText().toString();

Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();

int wp = dm.widthPixels;
int hp = dm.heightPixels;

setContentView(R.layout.drawterm_main);

Button kbutton = (Button)findViewById(R.id.keyboardToggle);
kbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}
});

int rid = res.getIdentifier("navigation_bar_height", "dimen", "android");
if (rid > 0) {
hp -= res.getDimensionPixelSize(rid);
}
LinearLayout ll = findViewById(R.id.dtButtons);
hp -= ll.getHeight();

int w = (int)(wp * (160.0/dm.xdpi));
int h = (int)(hp * (160.0/dm.ydpi));
float ws = (float)wp/w;
float hs = (float)hp/h;
// only scale up
if (ws < 1) {
ws = 1;
w = wp;
}
if (hs < 1) {
hs = 1;
h = hp;
}

MySurfaceView mView = new MySurfaceView(mainActivity, w, h, ws, hs);
mView.getHolder().setFixedSize(w, h);

LinearLayout l = findViewById(R.id.dlayout);
l.addView(mView, 1, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

DrawTermThread t = new DrawTermThread(cpu, auth, user, pass, mainActivity);
t.start();
String args[] = {"drawterm", "-p", "-h", cpu, "-a", auth, "-u", user};
runDrawterm(args, pass);
}
});
}
Expand Down Expand Up @@ -170,10 +180,15 @@ public void onClick(View v) {
@Override
public boolean dispatchKeyEvent(KeyEvent event)
{
if (!dtrunning) {
super.dispatchKeyEvent(event);
return false;
}

int k = event.getUnicodeChar();
if (k == 0) {
k = event.getDisplayLabel();
if (k != 0)
if (k >= 'A' && k <= 'Z')
k |= 0x20;
}

Expand Down Expand Up @@ -249,6 +264,8 @@ else if (event.getAction() == KeyEvent.ACTION_UP) {
@Override
public void onBackPressed()
{
if (!dtrunning)
super.onBackPressed();
}

public void setClipBoard(String str) {
Expand Down
32 changes: 18 additions & 14 deletions gui-android/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<android.widget.FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.echoline.drawterm.MainActivity">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="org.echoline.drawterm.MainActivity">

<include layout="@layout/content_main" />
<include layout="@layout/content_main" />

<Button
android:id="@+id/fab"
android:text="add server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end">

<Button
android:id="@+id/fab"
android:text="add server"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

</android.widget.FrameLayout>
4 changes: 2 additions & 2 deletions gui-android/res/layout/drawterm_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<LinearLayout
android:layout_width="match_parent"
android:layout_height="14pt"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center_horizontal"
android:orientation="horizontal"
Expand Down Expand Up @@ -39,6 +39,6 @@
android:id="@+id/keyboardToggle"
android:text="kb"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
3 changes: 0 additions & 3 deletions gui-android/res/values/dimens.xml

This file was deleted.

0 comments on commit eaa5241

Please sign in to comment.