summaryrefslogtreecommitdiffstats
path: root/src/com/android/terminal/TerminalView.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2013-02-23 15:42:10 -0800
committerJeff Sharkey <jsharkey@android.com>2013-02-23 15:48:24 -0800
commitde15e79aadde33fd8c880c19bd4fc6caca0bf795 (patch)
treed6f5867abab2baaf174e2066c5389971c3681e9d /src/com/android/terminal/TerminalView.java
parentcedf158c17dc147163734ad1070032ff934d1b2e (diff)
downloadandroid_packages_apps_Terminal-de15e79aadde33fd8c880c19bd4fc6caca0bf795.tar.gz
android_packages_apps_Terminal-de15e79aadde33fd8c880c19bd4fc6caca0bf795.tar.bz2
android_packages_apps_Terminal-de15e79aadde33fd8c880c19bd4fc6caca0bf795.zip
Service to host long-lived terminals, tab UI.
Bind to new TerminalService when UI is running, and keep service started as long as terminals are active. Use ViewPager to show multiple active terminals, and menu items to open/close terminals. Anti-alias terminal text. Reduce callback logging. Add method to stop a running shell; still need to kill child process. Change-Id: I8efcb43aeaf8813762cd0ceebcd5388fc51ebaab
Diffstat (limited to 'src/com/android/terminal/TerminalView.java')
-rw-r--r--src/com/android/terminal/TerminalView.java41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/com/android/terminal/TerminalView.java b/src/com/android/terminal/TerminalView.java
index 35192e9..64aeabd 100644
--- a/src/com/android/terminal/TerminalView.java
+++ b/src/com/android/terminal/TerminalView.java
@@ -35,11 +35,11 @@ import com.android.terminal.Terminal.TerminalClient;
*/
public class TerminalView extends View {
private static final String TAG = "Terminal";
+ private static final boolean LOGD = true;
private static final int MAX_RUN_LENGTH = 128;
private final Context mContext;
- private final Terminal mTerm;
private final Paint mBgPaint = new Paint();
private final Paint mTextPaint = new Paint();
@@ -49,6 +49,8 @@ public class TerminalView extends View {
/** Screen coordinates to draw chars into */
private final float[] mPos;
+ private Terminal mTerm;
+
private int mCharTop;
private int mCharWidth;
private int mCharHeight;
@@ -59,7 +61,7 @@ public class TerminalView extends View {
private TerminalClient mClient = new TerminalClient() {
@Override
public void damage(int startRow, int endRow, int startCol, int endCol) {
- Log.d(TAG, "damage(" + startRow + ", " + endRow + ", " + startCol + ", " + endCol + ")");
+ if (LOGD) Log.d(TAG, "damage(" + startRow + ", " + endRow + ", " + startCol + ", " + endCol + ")");
// Invalidate region on screen
final int top = startRow * mCharHeight;
@@ -86,10 +88,9 @@ public class TerminalView extends View {
}
};
- public TerminalView(Context context, Terminal term) {
+ public TerminalView(Context context) {
super(context);
mContext = context;
- mTerm = term;
mRun = new Terminal.CellRun();
mRun.data = new char[MAX_RUN_LENGTH];
@@ -110,20 +111,37 @@ public class TerminalView extends View {
});
}
+ public void setTerminal(Terminal term) {
+ final Terminal orig = mTerm;
+ if (orig != null) {
+ orig.setClient(null);
+ }
+ mTerm = term;
+ if (term != null) {
+ term.setClient(mClient);
+ }
+ updateTerminalSize();
+ }
+
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
- mTerm.setClient(mClient);
+ if (mTerm != null) {
+ mTerm.setClient(mClient);
+ }
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
- mTerm.setClient(null);
+ if (mTerm != null) {
+ mTerm.setClient(null);
+ }
}
public void setTextSize(float textSize) {
mTextPaint.setTypeface(Typeface.MONOSPACE);
+ mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(textSize);
// Read metrics to get exact pixel dimensions
@@ -149,11 +167,10 @@ public class TerminalView extends View {
* and request that {@link Terminal} change to that size.
*/
public void updateTerminalSize() {
- if (getWidth() > 0 && getHeight() > 0) {
+ if (getWidth() > 0 && getHeight() > 0 && mTerm != null) {
final int rows = getHeight() / mCharHeight;
final int cols = getWidth() / mCharWidth;
mTerm.resize(rows, cols);
- mTerm.flushDamage();
}
}
@@ -169,6 +186,12 @@ public class TerminalView extends View {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
+ if (mTerm == null) {
+ Log.w(TAG, "onDraw() without a terminal");
+ canvas.drawColor(Color.MAGENTA);
+ return;
+ }
+
final long start = SystemClock.elapsedRealtime();
// Only draw dirty region of console
@@ -210,6 +233,6 @@ public class TerminalView extends View {
}
final long delta = SystemClock.elapsedRealtime() - start;
- Log.d(TAG, "onDraw() took " + delta + "ms");
+ if (LOGD) Log.d(TAG, "onDraw() took " + delta + "ms");
}
}