mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-05 18:25:31 +08:00
Added: Add annotations and modifiers
This commit is contained in:
@@ -12,6 +12,9 @@ import android.media.SoundPool;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.ListView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.termux.R;
|
||||
import com.termux.shared.termux.shell.command.runner.terminal.TermuxSession;
|
||||
import com.termux.shared.termux.interact.TextInputDialogUtils;
|
||||
@@ -108,14 +111,14 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
|
||||
|
||||
@Override
|
||||
public void onTextChanged(TerminalSession changedSession) {
|
||||
public void onTextChanged(@NonNull TerminalSession changedSession) {
|
||||
if (!mActivity.isVisible()) return;
|
||||
|
||||
if (mActivity.getCurrentSession() == changedSession) mActivity.getTerminalView().onScreenUpdated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTitleChanged(TerminalSession updatedSession) {
|
||||
public void onTitleChanged(@NonNull TerminalSession updatedSession) {
|
||||
if (!mActivity.isVisible()) return;
|
||||
|
||||
if (updatedSession != mActivity.getCurrentSession()) {
|
||||
@@ -129,7 +132,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionFinished(final TerminalSession finishedSession) {
|
||||
public void onSessionFinished(@NonNull TerminalSession finishedSession) {
|
||||
TermuxService service = mActivity.getTermuxService();
|
||||
|
||||
if (service == null || service.wantsToStop()) {
|
||||
@@ -174,7 +177,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCopyTextToClipboard(TerminalSession session, String text) {
|
||||
public void onCopyTextToClipboard(@NonNull TerminalSession session, String text) {
|
||||
if (!mActivity.isVisible()) return;
|
||||
|
||||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
@@ -182,7 +185,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPasteTextFromClipboard(TerminalSession session) {
|
||||
public void onPasteTextFromClipboard(@Nullable TerminalSession session) {
|
||||
if (!mActivity.isVisible()) return;
|
||||
|
||||
ClipboardManager clipboard = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
@@ -194,7 +197,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBell(TerminalSession session) {
|
||||
public void onBell(@NonNull TerminalSession session) {
|
||||
if (!mActivity.isVisible()) return;
|
||||
|
||||
switch (mActivity.getProperties().getBellBehaviour()) {
|
||||
@@ -213,7 +216,7 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorsChanged(TerminalSession changedSession) {
|
||||
public void onColorsChanged(@NonNull TerminalSession changedSession) {
|
||||
if (mActivity.getCurrentSession() == changedSession)
|
||||
updateBackgroundColor();
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ tasks.withType(Test) {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.annotation:annotation:1.3.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package com.termux.terminal;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The interface for communication between {@link TerminalSession} and its client. It is used to
|
||||
* send callbacks to the client when {@link TerminalSession} changes or for sending other
|
||||
@@ -7,19 +10,19 @@ package com.termux.terminal;
|
||||
*/
|
||||
public interface TerminalSessionClient {
|
||||
|
||||
void onTextChanged(TerminalSession changedSession);
|
||||
void onTextChanged(@NonNull TerminalSession changedSession);
|
||||
|
||||
void onTitleChanged(TerminalSession changedSession);
|
||||
void onTitleChanged(@NonNull TerminalSession changedSession);
|
||||
|
||||
void onSessionFinished(TerminalSession finishedSession);
|
||||
void onSessionFinished(@NonNull TerminalSession finishedSession);
|
||||
|
||||
void onCopyTextToClipboard(TerminalSession session, String text);
|
||||
void onCopyTextToClipboard(@NonNull TerminalSession session, String text);
|
||||
|
||||
void onPasteTextFromClipboard(TerminalSession session);
|
||||
void onPasteTextFromClipboard(@Nullable TerminalSession session);
|
||||
|
||||
void onBell(TerminalSession session);
|
||||
void onBell(@NonNull TerminalSession session);
|
||||
|
||||
void onColorsChanged(TerminalSession session);
|
||||
void onColorsChanged(@NonNull TerminalSession session);
|
||||
|
||||
void onTerminalCursorStateChange(boolean state);
|
||||
|
||||
|
@@ -25,7 +25,7 @@ public class Errno {
|
||||
public static final Errno ERRNO_FAILED = new Errno(TYPE, Activity.RESULT_FIRST_USER + 1, "Failed");
|
||||
|
||||
/** The errno type. */
|
||||
protected String type;
|
||||
protected final String type;
|
||||
/** The errno code. */
|
||||
protected final int code;
|
||||
/** The errno message. */
|
||||
@@ -34,7 +34,7 @@ public class Errno {
|
||||
private static final String LOG_TAG = "Errno";
|
||||
|
||||
|
||||
public Errno(final String type, final int code, final String message) {
|
||||
public Errno(@NonNull final String type, final int code, @NonNull final String message) {
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
@@ -47,19 +47,22 @@ public class Errno {
|
||||
return "type=" + type + ", code=" + code + ", message=\"" + message + "\"";
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the {@link Errno} of a specific type and code.
|
||||
*
|
||||
|
@@ -4,6 +4,7 @@ import android.os.Build;
|
||||
import android.system.Os;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.common.io.RecursiveDeleteOption;
|
||||
import com.termux.shared.file.filesystem.FileType;
|
||||
@@ -97,6 +98,7 @@ public class FileUtils {
|
||||
* @param path The {@code path} to convert.
|
||||
* @return Returns the {@code normalized path}.
|
||||
*/
|
||||
@Nullable
|
||||
public static String normalizePath(String path) {
|
||||
if (path == null) return null;
|
||||
|
||||
@@ -247,7 +249,7 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the type of file that exists at {@code filePath}.
|
||||
* Get the type of file that exists at {@code filePath}.
|
||||
*
|
||||
* This function is a wrapper for
|
||||
* {@link FileTypes#getFileType(String, boolean)}
|
||||
@@ -260,6 +262,7 @@ public class FileUtils {
|
||||
* returned.
|
||||
* @return Returns the {@link FileType} of file.
|
||||
*/
|
||||
@NonNull
|
||||
public static FileType getFileType(final String filePath, final boolean followLinks) {
|
||||
return FileTypes.getFileType(filePath, followLinks);
|
||||
}
|
||||
@@ -1446,8 +1449,8 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static class ReadSerializableObjectResult {
|
||||
public Error error;
|
||||
public Serializable serializableObject;
|
||||
public final Error error;
|
||||
public final Serializable serializableObject;
|
||||
|
||||
ReadSerializableObjectResult(Error error, Serializable serializableObject) {
|
||||
this.error = error;
|
||||
|
@@ -94,7 +94,7 @@ public class FileUtilsErrno extends Errno {
|
||||
|
||||
|
||||
/** Defines the {@link Errno} mapping to get a shorter version of {@link FileUtilsErrno}. */
|
||||
public static Map<Errno, Errno> ERRNO_SHORT_MAPPING = new HashMap<Errno, Errno>() {{
|
||||
public static final Map<Errno, Errno> ERRNO_SHORT_MAPPING = new HashMap<Errno, Errno>() {{
|
||||
put(ERRNO_FILE_NOT_FOUND_AT_PATH, ERRNO_FILE_NOT_FOUND_AT_PATH_SHORT);
|
||||
|
||||
put(ERRNO_NON_REGULAR_FILE_FOUND, ERRNO_NON_REGULAR_FILE_FOUND_SHORT);
|
||||
|
@@ -82,6 +82,7 @@ public class FileTypes {
|
||||
* returned.
|
||||
* @return Returns the {@link FileType} of file.
|
||||
*/
|
||||
@NonNull
|
||||
public static FileType getFileType(final String filePath, final boolean followLinks) {
|
||||
if (filePath == null || filePath.isEmpty()) return FileType.NO_EXIST;
|
||||
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package com.termux.shared.termux.terminal;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.termux.shared.logger.Logger;
|
||||
import com.termux.terminal.TerminalSession;
|
||||
import com.termux.terminal.TerminalSessionClient;
|
||||
@@ -10,31 +13,31 @@ public class TermuxTerminalSessionClientBase implements TerminalSessionClient {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(TerminalSession changedSession) {
|
||||
public void onTextChanged(@NonNull TerminalSession changedSession) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTitleChanged(TerminalSession updatedSession) {
|
||||
public void onTitleChanged(@NonNull TerminalSession updatedSession) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSessionFinished(final TerminalSession finishedSession) {
|
||||
public void onSessionFinished(@NonNull TerminalSession finishedSession) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCopyTextToClipboard(TerminalSession session, String text) {
|
||||
public void onCopyTextToClipboard(@NonNull TerminalSession session, String text) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPasteTextFromClipboard(TerminalSession session) {
|
||||
public void onPasteTextFromClipboard(@Nullable TerminalSession session) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBell(TerminalSession session) {
|
||||
public void onBell(@NonNull TerminalSession session) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onColorsChanged(TerminalSession changedSession) {
|
||||
public void onColorsChanged(@NonNull TerminalSession changedSession) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user