Enable java 8

This commit is contained in:
Fredrik Fornwall
2018-09-29 00:49:05 +02:00
parent 35df3f72c9
commit b61da23be7
13 changed files with 208 additions and 344 deletions

View File

@@ -4,8 +4,8 @@ android {
compileSdkVersion 28 compileSdkVersion 28
dependencies { dependencies {
implementation 'com.android.support:support-annotations:27.1.1' implementation "com.android.support:support-annotations:28.0.0"
implementation "com.android.support:support-core-ui:27.1.1" implementation "com.android.support:support-core-ui:28.0.0"
implementation project(":terminal-view") implementation project(":terminal-view")
} }
@@ -24,6 +24,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
} }
dependencies { dependencies {

View File

@@ -9,7 +9,6 @@ import android.view.KeyEvent;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
public final class DialogUtils { public final class DialogUtils {
@@ -31,13 +30,10 @@ public final class DialogUtils {
final AlertDialog[] dialogHolder = new AlertDialog[1]; final AlertDialog[] dialogHolder = new AlertDialog[1];
input.setImeActionLabel(activity.getResources().getString(positiveButtonText), KeyEvent.KEYCODE_ENTER); input.setImeActionLabel(activity.getResources().getString(positiveButtonText), KeyEvent.KEYCODE_ENTER);
input.setOnEditorActionListener(new TextView.OnEditorActionListener() { input.setOnEditorActionListener((v, actionId, event) -> {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
onPositive.onTextSet(input.getText().toString()); onPositive.onTextSet(input.getText().toString());
dialogHolder[0].dismiss(); dialogHolder[0].dismiss();
return true; return true;
}
}); });
float dipInPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, activity.getResources().getDisplayMetrics()); float dipInPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, activity.getResources().getDisplayMetrics());
@@ -53,31 +49,16 @@ public final class DialogUtils {
AlertDialog.Builder builder = new AlertDialog.Builder(activity) AlertDialog.Builder builder = new AlertDialog.Builder(activity)
.setTitle(titleText).setView(layout) .setTitle(titleText).setView(layout)
.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { .setPositiveButton(positiveButtonText, (d, whichButton) -> onPositive.onTextSet(input.getText().toString()));
@Override
public void onClick(DialogInterface d, int whichButton) {
onPositive.onTextSet(input.getText().toString());
}
});
if (onNeutral != null) { if (onNeutral != null) {
builder.setNeutralButton(neutralButtonText, new DialogInterface.OnClickListener() { builder.setNeutralButton(neutralButtonText, (dialog, which) -> onNeutral.onTextSet(input.getText().toString()));
@Override
public void onClick(DialogInterface dialog, int which) {
onNeutral.onTextSet(input.getText().toString());
}
});
} }
if (onNegative == null) { if (onNegative == null) {
builder.setNegativeButton(android.R.string.cancel, null); builder.setNegativeButton(android.R.string.cancel, null);
} else { } else {
builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { builder.setNegativeButton(negativeButtonText, (dialog, which) -> onNegative.onTextSet(input.getText().toString()));
@Override
public void onClick(DialogInterface dialog, int which) {
onNegative.onTextSet(input.getText().toString());
}
});
} }
if (onDismiss != null) builder.setOnDismissListener(onDismiss); if (onDismiss != null) builder.setOnDismissListener(onDismiss);

View File

@@ -108,17 +108,17 @@ public final class ExtraKeysView extends GridLayout {
private PopupWindow popupWindow; private PopupWindow popupWindow;
private int longPressCount; private int longPressCount;
/** @deprecated, call readSpecialButton(SpecialButton.CTRL); */ /** @deprecated call readSpecialButton(SpecialButton.CTRL); */
public boolean readControlButton() { public boolean readControlButton() {
return readSpecialButton(SpecialButton.CTRL); return readSpecialButton(SpecialButton.CTRL);
} }
/** @deprecated, call readSpecialButton(SpecialButton.ALT); */ /** @deprecated call readSpecialButton(SpecialButton.ALT); */
public boolean readAltButton() { public boolean readAltButton() {
return readSpecialButton(SpecialButton.ALT); return readSpecialButton(SpecialButton.ALT);
} }
/** @deprecated, call readSpecialButton(SpecialButton.FN); */ /** @deprecated call readSpecialButton(SpecialButton.FN); */
public boolean readFnButton() { public boolean readFnButton() {
return readSpecialButton(SpecialButton.FN); return readSpecialButton(SpecialButton.FN);
} }
@@ -269,7 +269,6 @@ public final class ExtraKeysView extends GridLayout {
put("PAGEDOWN", "PGDN"); put("PAGEDOWN", "PGDN");
put("PAGE_DOWN", "PGDN"); put("PAGE_DOWN", "PGDN");
put("PAGE_DOWN", "PGDN");
put("PAGE-DOWN", "PGDN"); put("PAGE-DOWN", "PGDN");
put("DELETE", "DEL"); put("DELETE", "DEL");
@@ -296,15 +295,14 @@ public final class ExtraKeysView extends GridLayout {
*/ */
static int maximumLength(String[][] matrix) { static int maximumLength(String[][] matrix) {
int m = 0; int m = 0;
for (int i = 0; i < matrix.length; i++) for (String[] aMatrix : matrix) m = Math.max(m, aMatrix.length);
m = Math.max(m, matrix[i].length);
return m; return m;
} }
/** /**
* Reload the view given parameters in termux.properties * Reload the view given parameters in termux.properties
* *
* @buttons matrix of String as defined in termux.properties extrakeys * @param buttons matrix of String as defined in termux.properties extrakeys
* Can Contain The Strings CTRL ALT TAB FN ENTER LEFT RIGHT UP DOWN or normal strings * Can Contain The Strings CTRL ALT TAB FN ENTER LEFT RIGHT UP DOWN or normal strings
* Some aliases are possible like RETURN for ENTER, LT for LEFT and more (@see controlCharsAliases for the whole list). * Some aliases are possible like RETURN for ENTER, LT for LEFT and more (@see controlCharsAliases for the whole list).
* Any string of length > 1 in total Uppercase will print a warning * Any string of length > 1 in total Uppercase will print a warning
@@ -350,9 +348,7 @@ public final class ExtraKeysView extends GridLayout {
button.setPadding(0, 0, 0, 0); button.setPadding(0, 0, 0, 0);
final Button finalButton = button; final Button finalButton = button;
button.setOnClickListener(new OnClickListener() { button.setOnClickListener(v -> {
@Override
public void onClick(View v) {
finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
View root = getRootView(); View root = getRootView();
if(Arrays.asList("CTRL", "ALT", "FN").contains(buttonText)) { if(Arrays.asList("CTRL", "ALT", "FN").contains(buttonText)) {
@@ -362,12 +358,9 @@ public final class ExtraKeysView extends GridLayout {
} else { } else {
sendKey(root, buttonText); sendKey(root, buttonText);
} }
}
}); });
button.setOnTouchListener(new OnTouchListener() { button.setOnTouchListener((v, event) -> {
@Override
public boolean onTouch(View v, MotionEvent event) {
final View root = getRootView(); final View root = getRootView();
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
@@ -375,12 +368,9 @@ public final class ExtraKeysView extends GridLayout {
v.setBackgroundColor(BUTTON_PRESSED_COLOR); v.setBackgroundColor(BUTTON_PRESSED_COLOR);
if (Arrays.asList("UP", "DOWN", "LEFT", "RIGHT").contains(buttonText)) { if (Arrays.asList("UP", "DOWN", "LEFT", "RIGHT").contains(buttonText)) {
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
scheduledExecutor.scheduleWithFixedDelay(new Runnable() { scheduledExecutor.scheduleWithFixedDelay(() -> {
@Override
public void run() {
longPressCount++; longPressCount++;
sendKey(root, buttonText); sendKey(root, buttonText);
}
}, 400, 80, TimeUnit.MILLISECONDS); }, 400, 80, TimeUnit.MILLISECONDS);
} }
return true; return true;
@@ -423,7 +413,6 @@ public final class ExtraKeysView extends GridLayout {
default: default:
return true; return true;
} }
}
}); });
LayoutParams param = new GridLayout.LayoutParams(); LayoutParams param = new GridLayout.LayoutParams();

View File

@@ -11,8 +11,6 @@ import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnShowListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
@@ -40,19 +38,13 @@ import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
@@ -245,9 +237,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
} else { } else {
layout = inflater.inflate(R.layout.extra_keys_right, collection, false); layout = inflater.inflate(R.layout.extra_keys_right, collection, false);
final EditText editText = layout.findViewById(R.id.text_input); final EditText editText = layout.findViewById(R.id.text_input);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { editText.setOnEditorActionListener((v, actionId, event) -> {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
TerminalSession session = getCurrentTermSession(); TerminalSession session = getCurrentTermSession();
if (session != null) { if (session != null) {
if (session.isRunning()) { if (session.isRunning()) {
@@ -260,7 +250,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
editText.setText(""); editText.setText("");
} }
return true; return true;
}
}); });
} }
collection.addView(layout); collection.addView(layout);
@@ -286,47 +275,23 @@ public final class TermuxActivity extends Activity implements ServiceConnection
}); });
View newSessionButton = findViewById(R.id.new_session_button); View newSessionButton = findViewById(R.id.new_session_button);
newSessionButton.setOnClickListener(new OnClickListener() { newSessionButton.setOnClickListener(v -> addNewSession(false, null));
@Override newSessionButton.setOnLongClickListener(v -> {
public void onClick(View v) {
addNewSession(false, null);
}
});
newSessionButton.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
DialogUtils.textInput(TermuxActivity.this, R.string.session_new_named_title, null, R.string.session_new_named_positive_button, DialogUtils.textInput(TermuxActivity.this, R.string.session_new_named_title, null, R.string.session_new_named_positive_button,
new DialogUtils.TextSetListener() { text -> addNewSession(false, text), R.string.new_session_failsafe, text -> addNewSession(true, text)
@Override
public void onTextSet(String text) {
addNewSession(false, text);
}
}, R.string.new_session_failsafe, new DialogUtils.TextSetListener() {
@Override
public void onTextSet(String text) {
addNewSession(true, text);
}
}
, -1, null, null); , -1, null, null);
return true; return true;
}
}); });
findViewById(R.id.toggle_keyboard_button).setOnClickListener(new OnClickListener() { findViewById(R.id.toggle_keyboard_button).setOnClickListener(v -> {
@Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
getDrawer().closeDrawers(); getDrawer().closeDrawers();
}
}); });
findViewById(R.id.toggle_keyboard_button).setOnLongClickListener(new OnLongClickListener() { findViewById(R.id.toggle_keyboard_button).setOnLongClickListener(v -> {
@Override
public boolean onLongClick(View v) {
toggleShowExtraKeys(); toggleShowExtraKeys();
return true; return true;
}
}); });
registerForContextMenu(mTerminalView); registerForContextMenu(mTerminalView);
@@ -477,35 +442,26 @@ public final class TermuxActivity extends Activity implements ServiceConnection
} }
}; };
listView.setAdapter(mListViewAdapter); listView.setAdapter(mListViewAdapter);
listView.setOnItemClickListener(new OnItemClickListener() { listView.setOnItemClickListener((parent, view, position, id) -> {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TerminalSession clickedSession = mListViewAdapter.getItem(position); TerminalSession clickedSession = mListViewAdapter.getItem(position);
switchToSession(clickedSession); switchToSession(clickedSession);
getDrawer().closeDrawers(); getDrawer().closeDrawers();
}
}); });
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { listView.setOnItemLongClickListener((parent, view, position, id) -> {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
final TerminalSession selectedSession = mListViewAdapter.getItem(position); final TerminalSession selectedSession = mListViewAdapter.getItem(position);
renameSession(selectedSession); renameSession(selectedSession);
return true; return true;
}
}); });
if (mTermService.getSessions().isEmpty()) { if (mTermService.getSessions().isEmpty()) {
if (mIsVisible) { if (mIsVisible) {
TermuxInstaller.setupIfNeeded(TermuxActivity.this, new Runnable() { TermuxInstaller.setupIfNeeded(TermuxActivity.this, () -> {
@Override
public void run() {
if (mTermService == null) return; // Activity might have been destroyed. if (mTermService == null) return; // Activity might have been destroyed.
try { try {
addNewSession(false, null); addNewSession(false, null);
} catch (WindowManager.BadTokenException e) { } catch (WindowManager.BadTokenException e) {
// Activity finished - ignore. // Activity finished - ignore.
} }
}
}); });
} else { } else {
// The service connected while not in foreground - just bail out. // The service connected while not in foreground - just bail out.
@@ -535,12 +491,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
void renameSession(final TerminalSession sessionToRename) { void renameSession(final TerminalSession sessionToRename) {
DialogUtils.textInput(this, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, new DialogUtils.TextSetListener() { DialogUtils.textInput(this, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> {
@Override
public void onTextSet(String text) {
sessionToRename.mSessionName = text; sessionToRename.mSessionName = text;
mListViewAdapter.notifyDataSetChanged(); mListViewAdapter.notifyDataSetChanged();
}
}, -1, null, -1, null, null); }, -1, null, -1, null, null);
} }
@@ -717,24 +670,17 @@ public final class TermuxActivity extends Activity implements ServiceConnection
Collections.reverse(Arrays.asList(urls)); // Latest first. Collections.reverse(Arrays.asList(urls)); // Latest first.
// Click to copy url to clipboard: // Click to copy url to clipboard:
final AlertDialog dialog = new AlertDialog.Builder(TermuxActivity.this).setItems(urls, new DialogInterface.OnClickListener() { final AlertDialog dialog = new AlertDialog.Builder(TermuxActivity.this).setItems(urls, (di, which) -> {
@Override
public void onClick(DialogInterface di, int which) {
String url = (String) urls[which]; String url = (String) urls[which];
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(url))); clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(url)));
Toast.makeText(TermuxActivity.this, R.string.select_url_copied_to_clipboard, Toast.LENGTH_LONG).show(); Toast.makeText(TermuxActivity.this, R.string.select_url_copied_to_clipboard, Toast.LENGTH_LONG).show();
}
}).setTitle(R.string.select_url_dialog_title).create(); }).setTitle(R.string.select_url_dialog_title).create();
// Long press to open URL: // Long press to open URL:
dialog.setOnShowListener(new OnShowListener() { dialog.setOnShowListener(di -> {
@Override
public void onShow(DialogInterface di) {
ListView lv = dialog.getListView(); // this is a ListView with your "buds" in it ListView lv = dialog.getListView(); // this is a ListView with your "buds" in it
lv.setOnItemLongClickListener(new OnItemLongClickListener() { lv.setOnItemLongClickListener((parent, view, position, id) -> {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
dialog.dismiss(); dialog.dismiss();
String url = (String) urls[position]; String url = (String) urls[position];
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
@@ -745,9 +691,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
startActivity(Intent.createChooser(i, null)); startActivity(Intent.createChooser(i, null));
} }
return true; return true;
}
}); });
}
}); });
dialog.show(); dialog.show();
@@ -777,12 +721,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
final AlertDialog.Builder b = new AlertDialog.Builder(this); final AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setIcon(android.R.drawable.ic_dialog_alert); b.setIcon(android.R.drawable.ic_dialog_alert);
b.setMessage(R.string.confirm_kill_process); b.setMessage(R.string.confirm_kill_process);
b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { b.setPositiveButton(android.R.string.yes, (dialog, id) -> {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss(); dialog.dismiss();
getCurrentTermSession().finishIfRunning(); getCurrentTermSession().finishIfRunning();
}
}); });
b.setNegativeButton(android.R.string.no, null); b.setNegativeButton(android.R.string.no, null);
b.show(); b.show();
@@ -803,12 +744,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
// The startActivity() call is not documented to throw IllegalArgumentException. // The startActivity() call is not documented to throw IllegalArgumentException.
// However, crash reporting shows that it sometimes does, so catch it here. // However, crash reporting shows that it sometimes does, so catch it here.
new AlertDialog.Builder(this).setMessage(R.string.styling_not_installed) new AlertDialog.Builder(this).setMessage(R.string.styling_not_installed)
.setPositiveButton(R.string.styling_install, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.styling_install, (dialog, which) -> startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.termux.styling")))).setNegativeButton(android.R.string.cancel, null).show();
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.termux.styling")));
}
}).setNegativeButton(android.R.string.cancel, null).show();
} }
return true; return true;
} }

View File

@@ -4,9 +4,6 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.os.UserManager; import android.os.UserManager;
@@ -60,12 +57,7 @@ final class TermuxInstaller {
boolean isPrimaryUser = um.getSerialNumberForUser(android.os.Process.myUserHandle()) == 0; boolean isPrimaryUser = um.getSerialNumberForUser(android.os.Process.myUserHandle()) == 0;
if (!isPrimaryUser) { if (!isPrimaryUser) {
new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_not_primary_user_message) new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_not_primary_user_message)
.setOnDismissListener(new OnDismissListener() { .setOnDismissListener(dialog -> System.exit(0)).setPositiveButton(android.R.string.ok, null).show();
@Override
public void onDismiss(DialogInterface dialog) {
System.exit(0);
}
}).setPositiveButton(android.R.string.ok, null).show();
return; return;
} }
@@ -136,47 +128,30 @@ final class TermuxInstaller {
throw new RuntimeException("Unable to rename staging folder"); throw new RuntimeException("Unable to rename staging folder");
} }
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(whenDone);
@Override
public void run() {
whenDone.run();
}
});
} catch (final Exception e) { } catch (final Exception e) {
Log.e(EmulatorDebug.LOG_TAG, "Bootstrap error", e); Log.e(EmulatorDebug.LOG_TAG, "Bootstrap error", e);
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@Override
public void run() {
try { try {
new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_body) new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_body)
.setNegativeButton(R.string.bootstrap_error_abort, new OnClickListener() { .setNegativeButton(R.string.bootstrap_error_abort, (dialog, which) -> {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); dialog.dismiss();
activity.finish(); activity.finish();
} }).setPositiveButton(R.string.bootstrap_error_try_again, (dialog, which) -> {
}).setPositiveButton(R.string.bootstrap_error_try_again, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); dialog.dismiss();
TermuxInstaller.setupIfNeeded(activity, whenDone); TermuxInstaller.setupIfNeeded(activity, whenDone);
}
}).show(); }).show();
} catch (WindowManager.BadTokenException e) { } catch (WindowManager.BadTokenException e1) {
// Activity already dismissed - ignore. // Activity already dismissed - ignore.
} }
}
}); });
} finally { } finally {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@Override
public void run() {
try { try {
progress.dismiss(); progress.dismiss();
} catch (RuntimeException e) { } catch (RuntimeException e) {
// Activity already dismissed - ignore. // Activity already dismissed - ignore.
} }
}
}); });
} }
} }

View File

@@ -343,12 +343,9 @@ public final class TermuxService extends Service implements SessionChangedCallba
} }
public void onBackgroundJobExited(final BackgroundJob task) { public void onBackgroundJobExited(final BackgroundJob task) {
mHandler.post(new Runnable() { mHandler.post(() -> {
@Override
public void run() {
mBackgroundTasks.remove(task); mBackgroundTasks.remove(task);
updateNotification(); updateNotification();
}
}); });
} }

View File

@@ -2,7 +2,6 @@ package com.termux.filepicker;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@@ -83,17 +82,7 @@ public class TermuxFileReceiverActivity extends Activity {
void showErrorDialogAndQuit(String message) { void showErrorDialogAndQuit(String message) {
mFinishOnDismissNameDialog = false; mFinishOnDismissNameDialog = false;
new AlertDialog.Builder(this).setMessage(message).setOnDismissListener(new DialogInterface.OnDismissListener() { new AlertDialog.Builder(this).setMessage(message).setOnDismissListener(dialog -> finish()).setPositiveButton(android.R.string.ok, (dialog, which) -> finish()).show();
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
}).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).show();
} }
void handleContentUri(final Uri uri, String subjectFromIntent) { void handleContentUri(final Uri uri, String subjectFromIntent) {
@@ -119,9 +108,7 @@ public class TermuxFileReceiverActivity extends Activity {
} }
void promptNameAndSave(final InputStream in, final String attachmentFileName) { void promptNameAndSave(final InputStream in, final String attachmentFileName) {
DialogUtils.textInput(this, R.string.file_received_title, attachmentFileName, R.string.file_received_edit_button, new DialogUtils.TextSetListener() { DialogUtils.textInput(this, R.string.file_received_title, attachmentFileName, R.string.file_received_edit_button, text -> {
@Override
public void onTextSet(String text) {
File outFile = saveStreamWithName(in, text); File outFile = saveStreamWithName(in, text);
if (outFile == null) return; if (outFile == null) return;
@@ -143,11 +130,8 @@ public class TermuxFileReceiverActivity extends Activity {
executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{outFile.getAbsolutePath()}); executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{outFile.getAbsolutePath()});
startService(executeIntent); startService(executeIntent);
finish(); finish();
}
}, },
R.string.file_received_open_folder_button, new DialogUtils.TextSetListener() { R.string.file_received_open_folder_button, text -> {
@Override
public void onTextSet(String text) {
if (saveStreamWithName(in, text) == null) return; if (saveStreamWithName(in, text) == null) return;
Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE); Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE);
@@ -155,18 +139,9 @@ public class TermuxFileReceiverActivity extends Activity {
executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class);
startService(executeIntent); startService(executeIntent);
finish(); finish();
}
}, },
android.R.string.cancel, new DialogUtils.TextSetListener() { android.R.string.cancel, text -> finish(), dialog -> {
@Override
public void onTextSet(final String text) {
finish();
}
}, new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (mFinishOnDismissNameDialog) finish(); if (mFinishOnDismissNameDialog) finish();
}
}); });
} }

View File

@@ -46,6 +46,11 @@ android {
path "src/main/jni/Android.mk" path "src/main/jni/Android.mk"
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
} }
tasks.withType(Test) { tasks.withType(Test) {

View File

@@ -17,13 +17,13 @@ public class ByteQueueTest extends TestCase {
public void testCompleteWrites() throws Exception { public void testCompleteWrites() throws Exception {
ByteQueue q = new ByteQueue(10); ByteQueue q = new ByteQueue(10);
assertEquals(true, q.write(new byte[]{1, 2, 3}, 0, 3)); assertTrue(q.write(new byte[]{1, 2, 3}, 0, 3));
byte[] arr = new byte[10]; byte[] arr = new byte[10];
assertEquals(3, q.read(arr, true)); assertEquals(3, q.read(arr, true));
assertArrayEquals(new byte[]{1, 2, 3}, new byte[]{arr[0], arr[1], arr[2]}); assertArrayEquals(new byte[]{1, 2, 3}, new byte[]{arr[0], arr[1], arr[2]});
assertEquals(true, q.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0, 10)); assertTrue(q.write(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 0, 10));
assertEquals(10, q.read(arr, true)); assertEquals(10, q.read(arr, true));
assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, arr); assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, arr);
} }
@@ -43,7 +43,7 @@ public class ByteQueueTest extends TestCase {
public void testWriteNotesClosing() throws Exception { public void testWriteNotesClosing() throws Exception {
ByteQueue q = new ByteQueue(10); ByteQueue q = new ByteQueue(10);
q.close(); q.close();
assertEquals(false, q.write(new byte[]{1, 2, 3}, 0, 3)); assertFalse(q.write(new byte[]{1, 2, 3}, 0, 3));
} }
public void testReadNonBlocking() throws Exception { public void testReadNonBlocking() throws Exception {

View File

@@ -1,6 +1,6 @@
package com.termux.terminal; package com.termux.terminal;
import junit.framework.Assert; import org.junit.Assert;
public class CursorAndScreenTest extends TerminalTestCase { public class CursorAndScreenTest extends TerminalTestCase {

View File

@@ -56,7 +56,7 @@ public class TextStyleTest extends TestCase {
public void testEncodingProtected() { public void testEncodingProtected() {
long encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND, long encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND,
TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH); TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH);
assertTrue((TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED) == 0); assertEquals(0, (TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED));
encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND, encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND,
TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH | TextStyle.CHARACTER_ATTRIBUTE_PROTECTED); TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH | TextStyle.CHARACTER_ATTRIBUTE_PROTECTED);
assertTrue((TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED) != 0); assertTrue((TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED) != 0);

View File

@@ -58,10 +58,6 @@ public class WcWidthTest extends TestCase {
assertWidthIs(0, 0x2060); assertWidthIs(0, 0x2060);
} }
public void testWatch() {
}
public void testSofthyphen() { public void testSofthyphen() {
// http://osdir.com/ml/internationalization.linux/2003-05/msg00006.html: // http://osdir.com/ml/internationalization.linux/2003-05/msg00006.html:
// "Existing implementation practice in terminals is that the SOFT HYPHEN is // "Existing implementation practice in terminals is that the SOFT HYPHEN is

View File

@@ -20,7 +20,7 @@ android {
compileSdkVersion 28 compileSdkVersion 28
dependencies { dependencies {
implementation 'com.android.support:support-annotations:27.1.1' implementation "com.android.support:support-annotations:28.0.0"
api project(":terminal-emulator") api project(":terminal-emulator")
} }
@@ -36,6 +36,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
} }
dependencies { dependencies {