summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Marshall <tdm@cyngn.com>2014-12-31 14:42:11 -0800
committerTom Marshall <tdm@cyngn.com>2014-12-31 14:42:11 -0800
commitb424b73e40ad5a6dd2f167ed8d5f6493cebb5473 (patch)
tree923957d0e037eee861c9f0187d7140de96472d48
parentbb6bb3f5e7e67d1ed734c3abc0d9303a6ed63021 (diff)
downloadandroid_packages_apps_Terminal-b424b73e40ad5a6dd2f167ed8d5f6493cebb5473.tar.gz
android_packages_apps_Terminal-b424b73e40ad5a6dd2f167ed8d5f6493cebb5473.tar.bz2
android_packages_apps_Terminal-b424b73e40ad5a6dd2f167ed8d5f6493cebb5473.zip
Add settings for fullscreen, orientation, font size, color
Change-Id: Id631fce7fc6a40a8f982097e3b90e7c58c2cd889
-rw-r--r--AndroidManifest.xml9
-rw-r--r--jni/com_android_terminal_Terminal.cpp26
-rw-r--r--res/menu/activity.xml3
-rw-r--r--res/values/arrays.xml61
-rw-r--r--res/values/strings.xml16
-rw-r--r--res/xml/settings.xml52
-rw-r--r--src/com/android/terminal/Terminal.java7
-rw-r--r--src/com/android/terminal/TerminalActivity.java64
-rw-r--r--src/com/android/terminal/TerminalSettingsActivity.java99
-rw-r--r--src/com/android/terminal/TerminalView.java56
10 files changed, 389 insertions, 4 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6e2c3e1..1b7823a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -30,6 +30,15 @@
</intent-filter>
</activity>
+ <activity
+ android:name=".TerminalSettingsActivity"
+ android:label="@string/settings"
+ android:excludeFromRecents="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
<service android:name=".TerminalService" />
</application>
diff --git a/jni/com_android_terminal_Terminal.cpp b/jni/com_android_terminal_Terminal.cpp
index 15e57a3..131912f 100644
--- a/jni/com_android_terminal_Terminal.cpp
+++ b/jni/com_android_terminal_Terminal.cpp
@@ -121,6 +121,7 @@ public:
bool flushInput();
status_t resize(dimen_t rows, dimen_t cols, dimen_t scrollRows);
+ status_t setColors(int fg, int bg);
status_t onPushline(dimen_t cols, const VTermScreenCell* cells);
status_t onPopline(dimen_t cols, VTermScreenCell* cells);
@@ -433,6 +434,24 @@ status_t Terminal::resize(dimen_t rows, dimen_t cols, dimen_t scrollRows) {
return 0;
}
+status_t Terminal::setColors(int fg, int bg) {
+ Mutex::Autolock lock(mLock);
+
+ ALOGD("setColors(%d, %d)", fg, bg);
+
+ VTermState* state = vterm_obtain_state(mVt);
+ VTermColor fg_color = { (uint8_t)((fg>>16)&0xff),
+ (uint8_t)((fg>>8)&0xff),
+ (uint8_t)(fg&0xff) };
+ VTermColor bg_color = { (uint8_t)((bg>>16)&0xff),
+ (uint8_t)((bg>>8)&0xff),
+ (uint8_t)(bg&0xff) };
+ vterm_state_set_default_colors(state, &fg_color, &bg_color);
+ vterm_state_reset(state, 0);
+
+ return 0;
+}
+
status_t Terminal::onPushline(dimen_t cols, const VTermScreenCell* cells) {
ScrollbackLine* line = NULL;
if (mScrollCur == mScrollSize) {
@@ -571,6 +590,12 @@ static jint com_android_terminal_Terminal_nativeResize(JNIEnv* env,
return term->resize(rows, cols, scrollRows);
}
+static jint com_android_terminal_Terminal_nativeSetColors(JNIEnv* env,
+ jclass clazz, jlong ptr, jint fg, jint bg) {
+ Terminal* term = reinterpret_cast<Terminal*>(ptr);
+ return term->setColors(fg, bg);
+}
+
static inline int toArgb(const VTermColor& color) {
return (0xff << 24 | color.red << 16 | color.green << 8 | color.blue);
}
@@ -684,6 +709,7 @@ static JNINativeMethod gMethods[] = {
{ "nativeDestroy", "(J)I", (void*)com_android_terminal_Terminal_nativeDestroy },
{ "nativeRun", "(J)I", (void*)com_android_terminal_Terminal_nativeRun },
{ "nativeResize", "(JIII)I", (void*)com_android_terminal_Terminal_nativeResize },
+ { "nativeSetColors", "(JII)I", (void*)com_android_terminal_Terminal_nativeSetColors },
{ "nativeGetCellRun", "(JIILcom/android/terminal/Terminal$CellRun;)I", (void*)com_android_terminal_Terminal_nativeGetCellRun },
{ "nativeGetRows", "(J)I", (void*)com_android_terminal_Terminal_nativeGetRows },
{ "nativeGetCols", "(J)I", (void*)com_android_terminal_Terminal_nativeGetCols },
diff --git a/res/menu/activity.xml b/res/menu/activity.xml
index d1be0ae..74abfd3 100644
--- a/res/menu/activity.xml
+++ b/res/menu/activity.xml
@@ -25,4 +25,7 @@
android:title="@string/menu_close_tab"
android:icon="@android:drawable/ic_menu_close_clear_cancel"
android:showAsAction="ifRoom" />
+ <item
+ android:id="@+id/menu_item_settings"
+ android:title="@string/menu_item_settings" />
</menu>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
new file mode 100644
index 0000000..1c83e9b
--- /dev/null
+++ b/res/values/arrays.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources>
+ <string-array name="screen_orientation_labels">
+ <item>Automatic</item>
+ <item>Landscape</item>
+ <item>Portrait</item>
+ </string-array>
+ <string-array name="screen_orientation_values" translatable="false">
+ <item>automatic</item>
+ <item>landscape</item>
+ <item>portrait</item>
+ </string-array>
+
+ <string-array name="font_size_labels">
+ <item>10 pt</item>
+ <item>12 pt</item>
+ <item>14 pt</item>
+ <item>16 pt</item>
+ <item>20 pt</item>
+ <item>24 pt</item>
+ </string-array>
+ <string-array name="font_size_values" translatable="false">
+ <item>10</item>
+ <item>12</item>
+ <item>14</item>
+ <item>16</item>
+ <item>20</item>
+ <item>24</item>
+ </string-array>
+
+ <string-array name="text_colors_labels">
+ <item>Black text on white</item>
+ <item>White text on black</item>
+ <item>Green text on black</item>
+ <item>Amber text on black</item>
+ <item>Red text on black</item>
+ </string-array>
+ <string-array name="text_colors_values" translatable="false">
+ <item>#000000/#ffffff</item>
+ <item>#f0f0f0/#000000</item>
+ <item>#00f000/#000000</item>
+ <item>#f0c000/#000000</item>
+ <item>#f00000/#000000</item>
+ </string-array>
+
+</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index cbcaef3..a5c8a5f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -21,4 +21,20 @@
<string name="menu_new_tab">New tab</string>
<string name="menu_close_tab">Close tab</string>
+ <string name="menu_item_settings">Settings</string>
+
+ <string name="settings">Settings</string>
+
+ <string name="screen_settings">Screen settings</string>
+ <string name="fullscreen_mode">Fullscreen mode</string>
+ <string name="fullscreen_mode_summary">Fullscreen mode</string>
+ <string name="screen_orientation">Screen orientation</string>
+ <string name="screen_orientation_title">Screen orientation</string>
+
+ <string name="text_settings">Text settings</string>
+ <string name="font_size">Font size</string>
+ <string name="font_size_title">Font size</string>
+ <string name="text_colors">Text colors</string>
+ <string name="text_colors_title">Text colors</string>
+
</resources>
diff --git a/res/xml/settings.xml b/res/xml/settings.xml
new file mode 100644
index 0000000..3bf1114
--- /dev/null
+++ b/res/xml/settings.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ Not a Contribution.
+
+ Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+ http://www.apache.org/licenses/LICENSE-2.0
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/settings">
+ <PreferenceCategory
+ android:title="@string/screen_settings">
+ <CheckBoxPreference
+ android:key="fullscreen_mode"
+ android:title="@string/fullscreen_mode"
+ android:summary="@string/fullscreen_mode_summary"
+ android:defaultValue="false" />
+ <ListPreference
+ android:key="screen_orientation"
+ android:title="@string/screen_orientation"
+ android:dialogTitle="@string/screen_orientation_title"
+ android:entries="@array/screen_orientation_labels"
+ android:entryValues="@array/screen_orientation_values" />
+ </PreferenceCategory>
+ <PreferenceCategory
+ android:title="@string/text_settings">
+ <ListPreference
+ android:key="font_size"
+ android:title="@string/font_size"
+ android:dialogTitle="@string/font_size_title"
+ android:entries="@array/font_size_labels"
+ android:entryValues="@array/font_size_values" />
+ <ListPreference
+ android:key="text_colors"
+ android:title="@string/text_colors"
+ android:dialogTitle="@string/text_colors_title"
+ android:entries="@array/text_colors_labels"
+ android:entryValues="@array/text_colors_values" />
+ </PreferenceCategory>
+ <!-- Keyboard category -->
+ <!-- Shell category -->
+</PreferenceScreen>
diff --git a/src/com/android/terminal/Terminal.java b/src/com/android/terminal/Terminal.java
index b6e981e..702e6f0 100644
--- a/src/com/android/terminal/Terminal.java
+++ b/src/com/android/terminal/Terminal.java
@@ -147,6 +147,12 @@ public class Terminal {
}
}
+ public void setColors(int fg, int bg) {
+ if (nativeSetColors(mNativePtr, fg, bg) != 0) {
+ throw new IllegalStateException("setColors failed");
+ }
+ }
+
public int getRows() {
return nativeGetRows(mNativePtr);
}
@@ -195,6 +201,7 @@ public class Terminal {
private static native int nativeRun(long ptr);
private static native int nativeResize(long ptr, int rows, int cols, int scrollRows);
+ private static native int nativeSetColors(long ptr, int fg, int bg);
private static native int nativeGetCellRun(long ptr, int row, int col, CellRun run);
private static native int nativeGetRows(long ptr);
private static native int nativeGetCols(long ptr);
diff --git a/src/com/android/terminal/TerminalActivity.java b/src/com/android/terminal/TerminalActivity.java
index 025a14a..475ce40 100644
--- a/src/com/android/terminal/TerminalActivity.java
+++ b/src/com/android/terminal/TerminalActivity.java
@@ -23,9 +23,12 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.SharedPreferences;
+import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
+import android.preference.PreferenceManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.PagerTitleStrip;
import android.support.v4.view.ViewPager;
@@ -142,6 +145,53 @@ public class TerminalActivity extends Activity {
}
};
+ private final View.OnSystemUiVisibilityChangeListener mUiVisibilityChangeListener = new View.OnSystemUiVisibilityChangeListener() {
+ @Override
+ public void onSystemUiVisibilityChange(int visibility) {
+ if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0) {
+ getActionBar().hide();
+ }
+ else {
+ getActionBar().show();
+ }
+ }
+ };
+
+ public void updatePreferences() {
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
+ boolean bval;
+ bval = sp.getBoolean(TerminalSettingsActivity.KEY_FULLSCREEN_MODE, false);
+ if (bval) {
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
+ getActionBar().hide();
+ }
+ else {
+ getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
+ getActionBar().show();
+ }
+
+ String sval;
+ sval = sp.getString(TerminalSettingsActivity.KEY_SCREEN_ORIENTATION, "automatic");
+ if (sval.equals("automatic")) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ }
+ if (sval.equals("portrait")) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+ if (sval.equals("landscape")) {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ }
+
+ for (int i = 0; i < mPager.getChildCount(); ++i) {
+ View v = mPager.getChildAt(i);
+ if (v instanceof TerminalView) {
+ TerminalView view = (TerminalView) v;
+ view.updatePreferences();
+ view.invalidateViews();
+ }
+ }
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -152,16 +202,26 @@ public class TerminalActivity extends Activity {
mTitles = (PagerTitleStrip) findViewById(R.id.titles);
mPager.setAdapter(mTermAdapter);
+
+ View decorView = getWindow().getDecorView();
+ decorView.setOnSystemUiVisibilityChangeListener(mUiVisibilityChangeListener);
}
@Override
protected void onStart() {
super.onStart();
+ updatePreferences();
bindService(
new Intent(this, TerminalService.class), mServiceConn, Context.BIND_AUTO_CREATE);
}
@Override
+ protected void onResume() {
+ super.onResume();
+ updatePreferences();
+ }
+
+ @Override
protected void onStop() {
super.onStop();
unbindService(mServiceConn);
@@ -199,6 +259,10 @@ public class TerminalActivity extends Activity {
invalidateOptionsMenu();
return true;
}
+ case R.id.menu_item_settings: {
+ startActivity(new Intent(TerminalActivity.this, TerminalSettingsActivity.class));
+ return true;
+ }
}
return false;
}
diff --git a/src/com/android/terminal/TerminalSettingsActivity.java b/src/com/android/terminal/TerminalSettingsActivity.java
new file mode 100644
index 0000000..6fd7b16
--- /dev/null
+++ b/src/com/android/terminal/TerminalSettingsActivity.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.terminal;
+
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+
+import static com.android.terminal.Terminal.TAG;
+
+/**
+ * Settings for Terminal.
+ */
+public class TerminalSettingsActivity extends PreferenceActivity
+ implements Preference.OnPreferenceChangeListener {
+
+ public static final String KEY_FULLSCREEN_MODE = "fullscreen_mode";
+ public static final String KEY_SCREEN_ORIENTATION = "screen_orientation";
+ public static final String KEY_FONT_SIZE = "font_size";
+ public static final String KEY_TEXT_COLORS = "text_colors";
+
+ private CheckBoxPreference mFullscreenModePref;
+ private ListPreference mScreenOrientationPref;
+ private ListPreference mFontSizePref;
+ private ListPreference mTextColorsPref;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.settings);
+
+ mFullscreenModePref = (CheckBoxPreference) findPreference(KEY_FULLSCREEN_MODE);
+ mScreenOrientationPref = (ListPreference) findPreference(KEY_SCREEN_ORIENTATION);
+ mScreenOrientationPref.setOnPreferenceChangeListener(this);
+ mFontSizePref = (ListPreference) findPreference(KEY_FONT_SIZE);
+ mFontSizePref.setOnPreferenceChangeListener(this);
+ mTextColorsPref = (ListPreference) findPreference(KEY_TEXT_COLORS);
+ mTextColorsPref.setOnPreferenceChangeListener(this);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
+ Preference preference) {
+ if (KEY_FULLSCREEN_MODE.equals(preference.getKey())) {
+ CheckBoxPreference pref = (CheckBoxPreference) preference;
+ }
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (KEY_SCREEN_ORIENTATION.equals(preference.getKey())) {
+ ListPreference pref = (ListPreference) preference;
+ String val = (String) newValue;
+ int idx = pref.findIndexOfValue(val);
+ }
+ if (KEY_FONT_SIZE.equals(preference.getKey())) {
+ ListPreference pref = (ListPreference) preference;
+ String val = (String) newValue;
+ int idx = pref.findIndexOfValue(val);
+ }
+ if (KEY_TEXT_COLORS.equals(preference.getKey())) {
+ ListPreference pref = (ListPreference) preference;
+ String val = (String) newValue;
+ int idx = pref.findIndexOfValue(val);
+ }
+ return true;
+ }
+}
diff --git a/src/com/android/terminal/TerminalView.java b/src/com/android/terminal/TerminalView.java
index 07d9e7b..c24bbfb 100644
--- a/src/com/android/terminal/TerminalView.java
+++ b/src/com/android/terminal/TerminalView.java
@@ -19,11 +19,15 @@ package com.android.terminal;
import static com.android.terminal.Terminal.TAG;
import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;
import android.graphics.Typeface;
import android.os.Parcelable;
+import android.preference.PreferenceManager;
import android.util.AttributeSet;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@@ -86,12 +90,11 @@ public class TerminalView extends ListView {
// Positions of each possible cell
// TODO: make sure this works with surrogate pairs
pos = new float[MAX_RUN_LENGTH * 2];
- setTextSize(20);
+ textPaint.setTypeface(Typeface.MONOSPACE);
+ textPaint.setAntiAlias(true);
}
public void setTextSize(float textSize) {
- textPaint.setTypeface(Typeface.MONOSPACE);
- textPaint.setAntiAlias(true);
textPaint.setTextSize(textSize);
// Read metrics to get exact pixel dimensions
@@ -111,9 +114,25 @@ public class TerminalView extends ListView {
}
}
+ private void toggleFullscreenMode() {
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
+ boolean oldVal = sp.getBoolean(TerminalSettingsActivity.KEY_FULLSCREEN_MODE, false);
+ SharedPreferences.Editor editor = sp.edit();
+ editor.putBoolean(TerminalSettingsActivity.KEY_FULLSCREEN_MODE, !oldVal);
+ editor.commit();
+ TerminalActivity activity = (TerminalActivity) getContext();
+ activity.updatePreferences();
+ }
+
private final AdapterView.OnItemClickListener mClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int pos, long id) {
+ // Clicking on top half of view toggles fullscreen mode
+ if (pos - mScrollRows < mRows / 2) {
+ toggleFullscreenMode();
+ return;
+ }
+ // Clicking on bottom half of view shows soft keyboard
if (parent.requestFocus()) {
InputMethodManager imm = (InputMethodManager) parent.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(parent, InputMethodManager.SHOW_IMPLICIT);
@@ -131,6 +150,11 @@ public class TerminalView extends ListView {
}
};
+ private final float PT_PER_INCH = 72.0f;
+ private float ptToDp(float pt) {
+ return (pt / PT_PER_INCH) * (float)DisplayMetrics.DENSITY_DEFAULT;
+ }
+
public TerminalView(Context context) {
this(context, null);
}
@@ -283,7 +307,7 @@ public class TerminalView extends ListView {
term.setClient(mClient);
mTermKeys.setTerminal(term);
- mMetrics.cursorPaint.setColor(0xf0f0f0);
+ updatePreferences();
// Populate any current settings
mRows = mTerm.getRows();
@@ -336,4 +360,28 @@ public class TerminalView extends ListView {
}
};
}
+
+ public void updatePreferences() {
+ SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
+ String val;
+
+ val = sp.getString(TerminalSettingsActivity.KEY_FONT_SIZE, "12");
+ mMetrics.setTextSize(ptToDp(Float.parseFloat(val)));
+
+ val = sp.getString(TerminalSettingsActivity.KEY_TEXT_COLORS, "black/white");
+ int fg = 0x000000;
+ int bg = 0xffffff;
+ int idx = val.indexOf('/');
+ if (idx != -1) {
+ try {
+ fg = Color.parseColor(val.substring(0, idx));
+ bg = Color.parseColor(val.substring(idx+1));
+ }
+ catch (IllegalArgumentException e) {
+ // Ignore
+ }
+ }
+ mTerm.setColors(fg, bg);
+ mMetrics.cursorPaint.setColor(fg);
+ }
}