Skip to content

Commit

Permalink
Improve termux-dialog to support password and titles
Browse files Browse the repository at this point in the history
Also bump version to 0.5.

See termux/termux-app#3
  • Loading branch information
fornwall committed Oct 27, 2015
1 parent 7719bd7 commit 1fb834c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 57 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.termux.api"
android:sharedUserId="com.termux"
android:versionCode="4"
android:versionName="0.4" >
android:versionCode="5"
android:versionName="0.5" >

<uses-feature android:name="android.hardware.touchscreen" android:required="false" />

Expand Down
123 changes: 68 additions & 55 deletions app/src/main/java/com/termux/api/DialogActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.termux.api;

import java.io.PrintWriter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -14,71 +12,86 @@
import com.termux.api.util.ResultReturner;
import com.termux.api.util.ResultReturner.ResultWriter;

import java.io.PrintWriter;

public class DialogActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_textarea_input);
}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}
String title = null;
Intent i = getIntent();
if (i != null) {
title = i.getStringExtra("input_title");
}

@Override
protected void onResume() {
super.onResume();
if (title == null) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
} else {
setTitle(title);
}
setContentView(R.layout.dialog_textarea_input);

EditText textInput = (EditText) findViewById(R.id.text_input);
EditText textInput = (EditText) findViewById(R.id.text_input);

String inputHint = getIntent().getStringExtra("input_hint");
if (inputHint != null) {
textInput.setHint(inputHint);
}
boolean multiLine = getIntent().getBooleanExtra("multiple_lines", false);

String inputType = getIntent().getStringExtra("input_type");
if ("password".equals(inputType)) {
textInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
String inputHint = getIntent().getStringExtra("input_hint");
if (inputHint != null) {
textInput.setHint(inputHint);
}

String inputType = getIntent().getStringExtra("input_type");
if ("password".equals(inputType)) {
textInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else if (multiLine) {
textInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
} else {
textInput.setInputType(InputType.TYPE_CLASS_TEXT);
}

findViewById(R.id.cancel_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ResultReturner.returnData(DialogActivity.this, getIntent(), new ResultWriter() {
@Override
public void writeResult(PrintWriter out) throws Exception {
runOnUiThread(new Runnable() {
@Override
public void run() {
finish();
}
});
}
});
}
});
@Override
public void onClick(View v) {
ResultReturner.returnData(DialogActivity.this, getIntent(), new ResultWriter() {
@Override
public void writeResult(PrintWriter out) throws Exception {
runOnUiThread(new Runnable() {
@Override
public void run() {
finish();
}
});
}
});
}
});

findViewById(R.id.ok_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ResultReturner.returnData(DialogActivity.this, getIntent(), new ResultWriter() {
@Override
public void writeResult(PrintWriter out) throws Exception {
String text = ((EditText) findViewById(R.id.text_input)).getText().toString();
out.println(text.trim());
runOnUiThread(new Runnable() {
@Override
public void run() {
finish();
}
});
}
});
}
});
}

findViewById(R.id.ok_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ResultReturner.returnData(DialogActivity.this, getIntent(), new ResultWriter() {
@Override
public void writeResult(PrintWriter out) throws Exception {
String text = ((EditText) findViewById(R.id.text_input)).getText().toString();
out.println(text.trim());
runOnUiThread(new Runnable() {
@Override
public void run() {
finish();
}
});
}
});
}
});
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
}

}
2 changes: 2 additions & 0 deletions app/src/main/res/layout/dialog_textarea_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="16dp"
android:paddingBottom="24dp"
android:orientation="vertical" >

<EditText
Expand Down

0 comments on commit 1fb834c

Please sign in to comment.