From b61da23be761a874ccd610835946f0b9b352b22f Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sat, 29 Sep 2018 00:49:05 +0200 Subject: [PATCH] Enable java 8 --- app/build.gradle | 9 +- .../main/java/com/termux/app/DialogUtils.java | 33 +-- .../java/com/termux/app/ExtraKeysView.java | 137 ++++++------- .../java/com/termux/app/TermuxActivity.java | 192 ++++++------------ .../java/com/termux/app/TermuxInstaller.java | 61 ++---- .../java/com/termux/app/TermuxService.java | 9 +- .../TermuxFileReceiverActivity.java | 85 +++----- terminal-emulator/build.gradle | 5 + .../com/termux/terminal/ByteQueueTest.java | 6 +- .../termux/terminal/CursorAndScreenTest.java | 2 +- .../com/termux/terminal/TextStyleTest.java | 2 +- .../java/com/termux/terminal/WcWidthTest.java | 4 - terminal-view/build.gradle | 7 +- 13 files changed, 208 insertions(+), 344 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 5e182ab1..280ab8af 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,8 +4,8 @@ android { compileSdkVersion 28 dependencies { - implementation 'com.android.support:support-annotations:27.1.1' - implementation "com.android.support:support-core-ui:27.1.1" + implementation "com.android.support:support-annotations:28.0.0" + implementation "com.android.support:support-core-ui:28.0.0" implementation project(":terminal-view") } @@ -24,6 +24,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { diff --git a/app/src/main/java/com/termux/app/DialogUtils.java b/app/src/main/java/com/termux/app/DialogUtils.java index 8e8be19f..4900f75d 100644 --- a/app/src/main/java/com/termux/app/DialogUtils.java +++ b/app/src/main/java/com/termux/app/DialogUtils.java @@ -9,7 +9,6 @@ import android.view.KeyEvent; import android.view.ViewGroup.LayoutParams; import android.widget.EditText; import android.widget.LinearLayout; -import android.widget.TextView; public final class DialogUtils { @@ -31,13 +30,10 @@ public final class DialogUtils { final AlertDialog[] dialogHolder = new AlertDialog[1]; input.setImeActionLabel(activity.getResources().getString(positiveButtonText), KeyEvent.KEYCODE_ENTER); - input.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - onPositive.onTextSet(input.getText().toString()); - dialogHolder[0].dismiss(); - return true; - } + input.setOnEditorActionListener((v, actionId, event) -> { + onPositive.onTextSet(input.getText().toString()); + dialogHolder[0].dismiss(); + return true; }); 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) .setTitle(titleText).setView(layout) - .setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface d, int whichButton) { - onPositive.onTextSet(input.getText().toString()); - } - }); + .setPositiveButton(positiveButtonText, (d, whichButton) -> onPositive.onTextSet(input.getText().toString())); if (onNeutral != null) { - builder.setNeutralButton(neutralButtonText, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - onNeutral.onTextSet(input.getText().toString()); - } - }); + builder.setNeutralButton(neutralButtonText, (dialog, which) -> onNeutral.onTextSet(input.getText().toString())); } if (onNegative == null) { builder.setNegativeButton(android.R.string.cancel, null); } else { - builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - onNegative.onTextSet(input.getText().toString()); - } - }); + builder.setNegativeButton(negativeButtonText, (dialog, which) -> onNegative.onTextSet(input.getText().toString())); } if (onDismiss != null) builder.setOnDismissListener(onDismiss); diff --git a/app/src/main/java/com/termux/app/ExtraKeysView.java b/app/src/main/java/com/termux/app/ExtraKeysView.java index cd62740b..72e95cc1 100644 --- a/app/src/main/java/com/termux/app/ExtraKeysView.java +++ b/app/src/main/java/com/termux/app/ExtraKeysView.java @@ -108,17 +108,17 @@ public final class ExtraKeysView extends GridLayout { private PopupWindow popupWindow; private int longPressCount; - /** @deprecated, call readSpecialButton(SpecialButton.CTRL); */ + /** @deprecated call readSpecialButton(SpecialButton.CTRL); */ public boolean readControlButton() { return readSpecialButton(SpecialButton.CTRL); } - /** @deprecated, call readSpecialButton(SpecialButton.ALT); */ + /** @deprecated call readSpecialButton(SpecialButton.ALT); */ public boolean readAltButton() { return readSpecialButton(SpecialButton.ALT); } - /** @deprecated, call readSpecialButton(SpecialButton.FN); */ + /** @deprecated call readSpecialButton(SpecialButton.FN); */ public boolean readFnButton() { return readSpecialButton(SpecialButton.FN); } @@ -269,7 +269,6 @@ public final class ExtraKeysView extends GridLayout { put("PAGEDOWN", "PGDN"); put("PAGE_DOWN", "PGDN"); - put("PAGE_DOWN", "PGDN"); put("PAGE-DOWN", "PGDN"); put("DELETE", "DEL"); @@ -296,15 +295,14 @@ public final class ExtraKeysView extends GridLayout { */ static int maximumLength(String[][] matrix) { int m = 0; - for (int i = 0; i < matrix.length; i++) - m = Math.max(m, matrix[i].length); + for (String[] aMatrix : matrix) m = Math.max(m, aMatrix.length); return m; } /** * 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 * 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 @@ -350,79 +348,70 @@ public final class ExtraKeysView extends GridLayout { button.setPadding(0, 0, 0, 0); final Button finalButton = button; - button.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); - View root = getRootView(); - if(Arrays.asList("CTRL", "ALT", "FN").contains(buttonText)) { - ToggleButton self = (ToggleButton) finalButton; - self.setChecked(self.isChecked()); - self.setTextColor(self.isChecked() ? INTERESTING_COLOR : TEXT_COLOR); - } else { - sendKey(root, buttonText); - } + button.setOnClickListener(v -> { + finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); + View root = getRootView(); + if(Arrays.asList("CTRL", "ALT", "FN").contains(buttonText)) { + ToggleButton self = (ToggleButton) finalButton; + self.setChecked(self.isChecked()); + self.setTextColor(self.isChecked() ? INTERESTING_COLOR : TEXT_COLOR); + } else { + sendKey(root, buttonText); } }); - button.setOnTouchListener(new OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - final View root = getRootView(); - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - longPressCount = 0; - v.setBackgroundColor(BUTTON_PRESSED_COLOR); - if (Arrays.asList("UP", "DOWN", "LEFT", "RIGHT").contains(buttonText)) { - scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); - scheduledExecutor.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - longPressCount++; - sendKey(root, buttonText); - } - }, 400, 80, TimeUnit.MILLISECONDS); + button.setOnTouchListener((v, event) -> { + final View root = getRootView(); + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + longPressCount = 0; + v.setBackgroundColor(BUTTON_PRESSED_COLOR); + if (Arrays.asList("UP", "DOWN", "LEFT", "RIGHT").contains(buttonText)) { + scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); + scheduledExecutor.scheduleWithFixedDelay(() -> { + longPressCount++; + sendKey(root, buttonText); + }, 400, 80, TimeUnit.MILLISECONDS); + } + return true; + + case MotionEvent.ACTION_MOVE: + // These two keys have a Move-Up button appearing + if (Arrays.asList("/", "-").contains(buttonText)) { + if (popupWindow == null && event.getY() < 0) { + v.setBackgroundColor(BUTTON_COLOR); + String text = "-".equals(buttonText) ? "|" : "\\"; + popup(v, text); } - return true; - - case MotionEvent.ACTION_MOVE: - // These two keys have a Move-Up button appearing - if (Arrays.asList("/", "-").contains(buttonText)) { - if (popupWindow == null && event.getY() < 0) { - v.setBackgroundColor(BUTTON_COLOR); - String text = "-".equals(buttonText) ? "|" : "\\"; - popup(v, text); - } - if (popupWindow != null && event.getY() > 0) { - v.setBackgroundColor(BUTTON_PRESSED_COLOR); - popupWindow.dismiss(); - popupWindow = null; - } + if (popupWindow != null && event.getY() > 0) { + v.setBackgroundColor(BUTTON_PRESSED_COLOR); + popupWindow.dismiss(); + popupWindow = null; } - return true; - - case MotionEvent.ACTION_UP: - case MotionEvent.ACTION_CANCEL: - v.setBackgroundColor(BUTTON_COLOR); - if (scheduledExecutor != null) { - scheduledExecutor.shutdownNow(); - scheduledExecutor = null; + } + return true; + + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: + v.setBackgroundColor(BUTTON_COLOR); + if (scheduledExecutor != null) { + scheduledExecutor.shutdownNow(); + scheduledExecutor = null; + } + if (longPressCount == 0) { + if (popupWindow != null && Arrays.asList("/", "-").contains(buttonText)) { + popupWindow.setContentView(null); + popupWindow.dismiss(); + popupWindow = null; + sendKey(root, "-".equals(buttonText) ? "|" : "\\"); + } else { + v.performClick(); } - if (longPressCount == 0) { - if (popupWindow != null && Arrays.asList("/", "-").contains(buttonText)) { - popupWindow.setContentView(null); - popupWindow.dismiss(); - popupWindow = null; - sendKey(root, "-".equals(buttonText) ? "|" : "\\"); - } else { - v.performClick(); - } - } - return true; - - default: - return true; - } + } + return true; + + default: + return true; } }); diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 7ed9b1fa..48ce0fe2 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -11,8 +11,6 @@ import android.content.ClipData; import android.content.ClipboardManager; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; -import android.content.DialogInterface.OnShowListener; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; @@ -40,19 +38,13 @@ import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Gravity; -import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.View.OnClickListener; -import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.WindowManager; 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.EditText; import android.widget.ListView; @@ -245,22 +237,19 @@ public final class TermuxActivity extends Activity implements ServiceConnection } else { layout = inflater.inflate(R.layout.extra_keys_right, collection, false); final EditText editText = layout.findViewById(R.id.text_input); - editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - TerminalSession session = getCurrentTermSession(); - if (session != null) { - if (session.isRunning()) { - String textToSend = editText.getText().toString(); - if (textToSend.length() == 0) textToSend = "\n"; - session.write(textToSend); - } else { - removeFinishedSession(session); - } - editText.setText(""); + editText.setOnEditorActionListener((v, actionId, event) -> { + TerminalSession session = getCurrentTermSession(); + if (session != null) { + if (session.isRunning()) { + String textToSend = editText.getText().toString(); + if (textToSend.length() == 0) textToSend = "\n"; + session.write(textToSend); + } else { + removeFinishedSession(session); } - return true; + editText.setText(""); } + return true; }); } collection.addView(layout); @@ -286,47 +275,23 @@ public final class TermuxActivity extends Activity implements ServiceConnection }); View newSessionButton = findViewById(R.id.new_session_button); - newSessionButton.setOnClickListener(new OnClickListener() { - @Override - 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, - new DialogUtils.TextSetListener() { - @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); - return true; - } + newSessionButton.setOnClickListener(v -> addNewSession(false, null)); + newSessionButton.setOnLongClickListener(v -> { + DialogUtils.textInput(TermuxActivity.this, R.string.session_new_named_title, null, R.string.session_new_named_positive_button, + text -> addNewSession(false, text), R.string.new_session_failsafe, text -> addNewSession(true, text) + , -1, null, null); + return true; }); - findViewById(R.id.toggle_keyboard_button).setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); - getDrawer().closeDrawers(); - } + findViewById(R.id.toggle_keyboard_button).setOnClickListener(v -> { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); + getDrawer().closeDrawers(); }); - findViewById(R.id.toggle_keyboard_button).setOnLongClickListener(new OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - toggleShowExtraKeys(); - return true; - } + findViewById(R.id.toggle_keyboard_button).setOnLongClickListener(v -> { + toggleShowExtraKeys(); + return true; }); registerForContextMenu(mTerminalView); @@ -477,34 +442,25 @@ public final class TermuxActivity extends Activity implements ServiceConnection } }; listView.setAdapter(mListViewAdapter); - listView.setOnItemClickListener(new OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - TerminalSession clickedSession = mListViewAdapter.getItem(position); - switchToSession(clickedSession); - getDrawer().closeDrawers(); - } + listView.setOnItemClickListener((parent, view, position, id) -> { + TerminalSession clickedSession = mListViewAdapter.getItem(position); + switchToSession(clickedSession); + getDrawer().closeDrawers(); }); - listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { - final TerminalSession selectedSession = mListViewAdapter.getItem(position); - renameSession(selectedSession); - return true; - } + listView.setOnItemLongClickListener((parent, view, position, id) -> { + final TerminalSession selectedSession = mListViewAdapter.getItem(position); + renameSession(selectedSession); + return true; }); if (mTermService.getSessions().isEmpty()) { if (mIsVisible) { - TermuxInstaller.setupIfNeeded(TermuxActivity.this, new Runnable() { - @Override - public void run() { - if (mTermService == null) return; // Activity might have been destroyed. - try { - addNewSession(false, null); - } catch (WindowManager.BadTokenException e) { - // Activity finished - ignore. - } + TermuxInstaller.setupIfNeeded(TermuxActivity.this, () -> { + if (mTermService == null) return; // Activity might have been destroyed. + try { + addNewSession(false, null); + } catch (WindowManager.BadTokenException e) { + // Activity finished - ignore. } }); } else { @@ -535,12 +491,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection @SuppressLint("InflateParams") void renameSession(final TerminalSession sessionToRename) { - DialogUtils.textInput(this, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, new DialogUtils.TextSetListener() { - @Override - public void onTextSet(String text) { - sessionToRename.mSessionName = text; - mListViewAdapter.notifyDataSetChanged(); - } + DialogUtils.textInput(this, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> { + sessionToRename.mSessionName = text; + mListViewAdapter.notifyDataSetChanged(); }, -1, null, -1, null, null); } @@ -717,37 +670,28 @@ public final class TermuxActivity extends Activity implements ServiceConnection Collections.reverse(Arrays.asList(urls)); // Latest first. // Click to copy url to clipboard: - final AlertDialog dialog = new AlertDialog.Builder(TermuxActivity.this).setItems(urls, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int which) { - String url = (String) urls[which]; - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - 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(); - } + final AlertDialog dialog = new AlertDialog.Builder(TermuxActivity.this).setItems(urls, (di, which) -> { + String url = (String) urls[which]; + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + 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(); }).setTitle(R.string.select_url_dialog_title).create(); // Long press to open URL: - dialog.setOnShowListener(new OnShowListener() { - @Override - public void onShow(DialogInterface di) { - ListView lv = dialog.getListView(); // this is a ListView with your "buds" in it - lv.setOnItemLongClickListener(new OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { - dialog.dismiss(); - String url = (String) urls[position]; - Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - try { - startActivity(i, null); - } catch (ActivityNotFoundException e) { - // If no applications match, Android displays a system message. - startActivity(Intent.createChooser(i, null)); - } - return true; - } - }); - } + dialog.setOnShowListener(di -> { + ListView lv = dialog.getListView(); // this is a ListView with your "buds" in it + lv.setOnItemLongClickListener((parent, view, position, id) -> { + dialog.dismiss(); + String url = (String) urls[position]; + Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); + try { + startActivity(i, null); + } catch (ActivityNotFoundException e) { + // If no applications match, Android displays a system message. + startActivity(Intent.createChooser(i, null)); + } + return true; + }); }); dialog.show(); @@ -777,12 +721,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection final AlertDialog.Builder b = new AlertDialog.Builder(this); b.setIcon(android.R.drawable.ic_dialog_alert); b.setMessage(R.string.confirm_kill_process); - b.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - getCurrentTermSession().finishIfRunning(); - } + b.setPositiveButton(android.R.string.yes, (dialog, id) -> { + dialog.dismiss(); + getCurrentTermSession().finishIfRunning(); }); b.setNegativeButton(android.R.string.no, null); b.show(); @@ -803,12 +744,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection // The startActivity() call is not documented to throw IllegalArgumentException. // However, crash reporting shows that it sometimes does, so catch it here. new AlertDialog.Builder(this).setMessage(R.string.styling_not_installed) - .setPositiveButton(R.string.styling_install, new DialogInterface.OnClickListener() { - @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(); + .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(); } return true; } diff --git a/app/src/main/java/com/termux/app/TermuxInstaller.java b/app/src/main/java/com/termux/app/TermuxInstaller.java index 26e798ee..3ca3bf75 100644 --- a/app/src/main/java/com/termux/app/TermuxInstaller.java +++ b/app/src/main/java/com/termux/app/TermuxInstaller.java @@ -4,9 +4,6 @@ import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; 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.Environment; import android.os.UserManager; @@ -60,12 +57,7 @@ final class TermuxInstaller { boolean isPrimaryUser = um.getSerialNumberForUser(android.os.Process.myUserHandle()) == 0; if (!isPrimaryUser) { new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_not_primary_user_message) - .setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - System.exit(0); - } - }).setPositiveButton(android.R.string.ok, null).show(); + .setOnDismissListener(dialog -> System.exit(0)).setPositiveButton(android.R.string.ok, null).show(); return; } @@ -136,46 +128,29 @@ final class TermuxInstaller { throw new RuntimeException("Unable to rename staging folder"); } - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - whenDone.run(); - } - }); + activity.runOnUiThread(whenDone); } catch (final Exception e) { Log.e(EmulatorDebug.LOG_TAG, "Bootstrap error", e); - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_body) - .setNegativeButton(R.string.bootstrap_error_abort, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - activity.finish(); - } - }).setPositiveButton(R.string.bootstrap_error_try_again, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - TermuxInstaller.setupIfNeeded(activity, whenDone); - } + activity.runOnUiThread(() -> { + try { + new AlertDialog.Builder(activity).setTitle(R.string.bootstrap_error_title).setMessage(R.string.bootstrap_error_body) + .setNegativeButton(R.string.bootstrap_error_abort, (dialog, which) -> { + dialog.dismiss(); + activity.finish(); + }).setPositiveButton(R.string.bootstrap_error_try_again, (dialog, which) -> { + dialog.dismiss(); + TermuxInstaller.setupIfNeeded(activity, whenDone); }).show(); - } catch (WindowManager.BadTokenException e) { - // Activity already dismissed - ignore. - } + } catch (WindowManager.BadTokenException e1) { + // Activity already dismissed - ignore. } }); } finally { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - progress.dismiss(); - } catch (RuntimeException e) { - // Activity already dismissed - ignore. - } + activity.runOnUiThread(() -> { + try { + progress.dismiss(); + } catch (RuntimeException e) { + // Activity already dismissed - ignore. } }); } diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java index 0dd2d30c..51a1b254 100644 --- a/app/src/main/java/com/termux/app/TermuxService.java +++ b/app/src/main/java/com/termux/app/TermuxService.java @@ -343,12 +343,9 @@ public final class TermuxService extends Service implements SessionChangedCallba } public void onBackgroundJobExited(final BackgroundJob task) { - mHandler.post(new Runnable() { - @Override - public void run() { - mBackgroundTasks.remove(task); - updateNotification(); - } + mHandler.post(() -> { + mBackgroundTasks.remove(task); + updateNotification(); }); } diff --git a/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java b/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java index 6fafbe36..1081e4cf 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java +++ b/app/src/main/java/com/termux/filepicker/TermuxFileReceiverActivity.java @@ -2,7 +2,6 @@ package com.termux.filepicker; import android.app.Activity; import android.app.AlertDialog; -import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.net.Uri; @@ -83,17 +82,7 @@ public class TermuxFileReceiverActivity extends Activity { void showErrorDialogAndQuit(String message) { mFinishOnDismissNameDialog = false; - new AlertDialog.Builder(this).setMessage(message).setOnDismissListener(new DialogInterface.OnDismissListener() { - @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(); + new AlertDialog.Builder(this).setMessage(message).setOnDismissListener(dialog -> finish()).setPositiveButton(android.R.string.ok, (dialog, which) -> finish()).show(); } void handleContentUri(final Uri uri, String subjectFromIntent) { @@ -119,54 +108,40 @@ public class TermuxFileReceiverActivity extends Activity { } 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() { - @Override - public void onTextSet(String text) { - File outFile = saveStreamWithName(in, text); - if (outFile == null) return; + DialogUtils.textInput(this, R.string.file_received_title, attachmentFileName, R.string.file_received_edit_button, text -> { + File outFile = saveStreamWithName(in, text); + if (outFile == null) return; - final File editorProgramFile = new File(EDITOR_PROGRAM); - if (!editorProgramFile.isFile()) { - showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-file-editor\n\n" - + "Create this file as a script or a symlink - it will be called with the received file as only argument."); - return; - } + final File editorProgramFile = new File(EDITOR_PROGRAM); + if (!editorProgramFile.isFile()) { + showErrorDialogAndQuit("The following file does not exist:\n$HOME/bin/termux-file-editor\n\n" + + "Create this file as a script or a symlink - it will be called with the received file as only argument."); + return; + } - // Do this for the user if necessary: - //noinspection ResultOfMethodCallIgnored - editorProgramFile.setExecutable(true); + // Do this for the user if necessary: + //noinspection ResultOfMethodCallIgnored + editorProgramFile.setExecutable(true); - final Uri scriptUri = new Uri.Builder().scheme("file").path(EDITOR_PROGRAM).build(); + final Uri scriptUri = new Uri.Builder().scheme("file").path(EDITOR_PROGRAM).build(); - Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, scriptUri); - executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); - executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{outFile.getAbsolutePath()}); - startService(executeIntent); - finish(); - } + Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE, scriptUri); + executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); + executeIntent.putExtra(TermuxService.EXTRA_ARGUMENTS, new String[]{outFile.getAbsolutePath()}); + startService(executeIntent); + finish(); + }, + R.string.file_received_open_folder_button, text -> { + if (saveStreamWithName(in, text) == null) return; + + Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE); + executeIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, TERMUX_RECEIVEDIR); + executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); + startService(executeIntent); + finish(); }, - R.string.file_received_open_folder_button, new DialogUtils.TextSetListener() { - @Override - public void onTextSet(String text) { - if (saveStreamWithName(in, text) == null) return; - - Intent executeIntent = new Intent(TermuxService.ACTION_EXECUTE); - executeIntent.putExtra(TermuxService.EXTRA_CURRENT_WORKING_DIRECTORY, TERMUX_RECEIVEDIR); - executeIntent.setClass(TermuxFileReceiverActivity.this, TermuxService.class); - startService(executeIntent); - finish(); - } - }, - android.R.string.cancel, new DialogUtils.TextSetListener() { - @Override - public void onTextSet(final String text) { - finish(); - } - }, new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - if (mFinishOnDismissNameDialog) finish(); - } + android.R.string.cancel, text -> finish(), dialog -> { + if (mFinishOnDismissNameDialog) finish(); }); } diff --git a/terminal-emulator/build.gradle b/terminal-emulator/build.gradle index 2f66e83c..320e549d 100644 --- a/terminal-emulator/build.gradle +++ b/terminal-emulator/build.gradle @@ -46,6 +46,11 @@ android { path "src/main/jni/Android.mk" } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } tasks.withType(Test) { diff --git a/terminal-emulator/src/test/java/com/termux/terminal/ByteQueueTest.java b/terminal-emulator/src/test/java/com/termux/terminal/ByteQueueTest.java index 51439e3c..1eb0278b 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/ByteQueueTest.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/ByteQueueTest.java @@ -17,13 +17,13 @@ public class ByteQueueTest extends TestCase { public void testCompleteWrites() throws Exception { 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]; assertEquals(3, q.read(arr, true)); 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)); 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 { ByteQueue q = new ByteQueue(10); 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 { diff --git a/terminal-emulator/src/test/java/com/termux/terminal/CursorAndScreenTest.java b/terminal-emulator/src/test/java/com/termux/terminal/CursorAndScreenTest.java index 92c41f0f..12635425 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/CursorAndScreenTest.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/CursorAndScreenTest.java @@ -1,6 +1,6 @@ package com.termux.terminal; -import junit.framework.Assert; +import org.junit.Assert; public class CursorAndScreenTest extends TerminalTestCase { diff --git a/terminal-emulator/src/test/java/com/termux/terminal/TextStyleTest.java b/terminal-emulator/src/test/java/com/termux/terminal/TextStyleTest.java index 48134335..153458e0 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/TextStyleTest.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/TextStyleTest.java @@ -56,7 +56,7 @@ public class TextStyleTest extends TestCase { public void testEncodingProtected() { long encoded = TextStyle.encode(TextStyle.COLOR_INDEX_FOREGROUND, TextStyle.COLOR_INDEX_BACKGROUND, 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, TextStyle.CHARACTER_ATTRIBUTE_STRIKETHROUGH | TextStyle.CHARACTER_ATTRIBUTE_PROTECTED); assertTrue((TextStyle.decodeEffect(encoded) & TextStyle.CHARACTER_ATTRIBUTE_PROTECTED) != 0); diff --git a/terminal-emulator/src/test/java/com/termux/terminal/WcWidthTest.java b/terminal-emulator/src/test/java/com/termux/terminal/WcWidthTest.java index 53c097cd..60e4ace4 100644 --- a/terminal-emulator/src/test/java/com/termux/terminal/WcWidthTest.java +++ b/terminal-emulator/src/test/java/com/termux/terminal/WcWidthTest.java @@ -58,10 +58,6 @@ public class WcWidthTest extends TestCase { assertWidthIs(0, 0x2060); } - public void testWatch() { - - } - public void testSofthyphen() { // http://osdir.com/ml/internationalization.linux/2003-05/msg00006.html: // "Existing implementation practice in terminals is that the SOFT HYPHEN is diff --git a/terminal-view/build.gradle b/terminal-view/build.gradle index 10c52e38..bdce542a 100644 --- a/terminal-view/build.gradle +++ b/terminal-view/build.gradle @@ -20,7 +20,7 @@ android { compileSdkVersion 28 dependencies { - implementation 'com.android.support:support-annotations:27.1.1' + implementation "com.android.support:support-annotations:28.0.0" api project(":terminal-emulator") } @@ -36,6 +36,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies {