Fix Terminal Preferences, Resolution

The terminal app was using the preferences framework incorrectly: it was
trying to keep its own authoritative copies of the preferences, instead
of relying in the preference framework to store the preferences. This
lead to some race conditions, and made terminal's preferences not work
correctly in Donut or Eclair.

Terminal now uses preferences in a more straightforward way.

As long as I was editing terminal, I made two additional changes:

Term now honors the display density. This makes the text more readable on
high-density devices.

An I put in some error checks for empty shell and first-command strings.

Fixes bug 2177356	Term program on Sholes: preferences doesn't work
This commit is contained in:
Jack Palevich
2009-10-09 20:16:26 -07:00
parent 5e04446cb1
commit edb55982e1
2 changed files with 11 additions and 23 deletions

View File

@@ -25,7 +25,7 @@
<string name="text_preferences">Text</string> <string name="text_preferences">Text</string>
<string name="title_fontsize_preference">Font size</string> <string name="title_fontsize_preference">Font size</string>
<string name="summary_fontsize_preference">Choose character height in pixels.</string> <string name="summary_fontsize_preference">Choose character height in points.</string>
<string name="dialog_title_fontsize_preference">Font size</string> <string name="dialog_title_fontsize_preference">Font size</string>
<string name="title_color_preference">Colors</string> <string name="title_color_preference">Colors</string>

View File

@@ -45,6 +45,7 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.KeyEvent; import android.view.KeyEvent;
@@ -158,14 +159,6 @@ public class Term extends Activity {
super.onCreate(icicle); super.onCreate(icicle);
Log.e(Term.LOG_TAG, "onCreate"); Log.e(Term.LOG_TAG, "onCreate");
mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mPrefs.registerOnSharedPreferenceChangeListener(
new SharedPreferences.OnSharedPreferenceChangeListener(){
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
readPrefs();
updatePrefs();
}});
readPrefs(); readPrefs();
setContentView(R.layout.term_activity); setContentView(R.layout.term_activity);
@@ -227,7 +220,7 @@ public class Term extends Activity {
private void sendInitialCommand() { private void sendInitialCommand() {
String initialCommand = mInitialCommand; String initialCommand = mInitialCommand;
if (initialCommand == null) { if (initialCommand == null || initialCommand.equals("")) {
initialCommand = DEFAULT_INITIAL_COMMAND; initialCommand = DEFAULT_INITIAL_COMMAND;
} }
if (initialCommand.length() > 0) { if (initialCommand.length() > 0) {
@@ -253,7 +246,7 @@ public class Term extends Activity {
private void createSubprocess(int[] processId) { private void createSubprocess(int[] processId) {
String shell = mShell; String shell = mShell;
if (shell == null) { if (shell == null || shell.equals("")) {
shell = DEFAULT_SHELL; shell = DEFAULT_SHELL;
} }
ArrayList<String> args = parse(shell); ArrayList<String> args = parse(shell);
@@ -347,7 +340,9 @@ public class Term extends Activity {
} }
private void updatePrefs() { private void updatePrefs() {
mEmulatorView.setTextSize(mFontSize); DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mEmulatorView.setTextSize((int) (mFontSize * metrics.density));
setColors(); setColors();
mControlKeyCode = CONTROL_KEY_SCHEMES[mControlKeyId]; mControlKeyCode = CONTROL_KEY_SCHEMES[mControlKeyId];
} }
@@ -369,17 +364,10 @@ public class Term extends Activity {
} }
@Override @Override
public void onPause() { public void onResume() {
SharedPreferences.Editor e = mPrefs.edit(); super.onResume();
e.clear(); readPrefs();
e.putString(FONTSIZE_KEY, Integer.toString(mFontSize)); updatePrefs();
e.putString(COLOR_KEY, Integer.toString(mColorId));
e.putString(CONTROLKEY_KEY, Integer.toString(mControlKeyId));
e.putString(SHELL_KEY, mShell);
e.putString(INITIALCOMMAND_KEY, mInitialCommand);
e.commit();
super.onPause();
} }
@Override @Override