From 8f03cfeb51904905f351a9e1894b8a64a087b097 Mon Sep 17 00:00:00 2001 From: Kyle Horimoto Date: Thu, 1 Oct 2015 10:37:57 -0700 Subject: Add host display editing UI. --- app/src/main/AndroidManifest.xml | 10 +- .../java/org/connectbot/HostEditorFragment.java | 95 +++++- .../main/java/org/connectbot/bean/HostBean.java | 4 +- app/src/main/res/layout/fragment_host_editor.xml | 341 +++++++++++++-------- 4 files changed, 307 insertions(+), 143 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e863b21..b528acd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,10 +46,7 @@ android:name=".HostListActivity" android:label="@string/title_hosts_list" android:launchMode="singleTop"> - - - - + @@ -87,7 +84,10 @@ - + + + + diff --git a/app/src/main/java/org/connectbot/HostEditorFragment.java b/app/src/main/java/org/connectbot/HostEditorFragment.java index ea9d65f..4223907 100644 --- a/app/src/main/java/org/connectbot/HostEditorFragment.java +++ b/app/src/main/java/org/connectbot/HostEditorFragment.java @@ -19,6 +19,7 @@ package org.connectbot; import android.content.ContentValues; import android.content.Context; +import android.content.res.TypedArray; import android.net.Uri; import android.os.Bundle; import android.os.Parcelable; @@ -33,7 +34,9 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ImageButton; +import android.widget.SeekBar; import android.widget.Spinner; +import android.widget.TextView; import org.connectbot.bean.HostBean; import org.connectbot.transport.SSH; @@ -47,6 +50,8 @@ public class HostEditorFragment extends Fragment { private static final String ARG_IS_EXPANDED = "isExpanded"; private static final String ARG_QUICKCONNECT_STRING = "quickConnectString"; + private static final int MINIMUM_FONT_SIZE = 8; + // The host being edited. private HostBean mHost; @@ -67,6 +72,10 @@ public class HostEditorFragment extends Fragment { // first field, etc. private boolean mUriFieldEditInProgress = false; + // Values for the colors displayed in the color Spinner. These are not necessarily the same as + // the text in the Spinner because the text is localized while these values are not. + private TypedArray mColorValues; + private Spinner mTransportSpinner; private TextInputLayout mQuickConnectContainer; private EditText mQuickConnectField; @@ -78,6 +87,10 @@ public class HostEditorFragment extends Fragment { private EditText mHostnameField; private View mPortContainer; private EditText mPortField; + private EditText mNicknameField; + private Spinner mColorSelector; + private TextView mFontSizeText; + private SeekBar mFontSizeSeekBar; public static HostEditorFragment newInstance(HostBean existingHost) { HostEditorFragment fragment = new HostEditorFragment(); @@ -209,17 +222,64 @@ public class HostEditorFragment extends Fragment { mUsernameContainer = view.findViewById(R.id.username_field_container); mUsernameField = (EditText) view.findViewById(R.id.username_edit_text); mUsernameField.setText(mHost.getUsername()); - mUsernameField.addTextChangedListener(new UriDataUpdater(HostDatabase.FIELD_HOST_USERNAME)); + mUsernameField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_USERNAME)); mHostnameContainer = view.findViewById(R.id.hostname_field_container); mHostnameField = (EditText) view.findViewById(R.id.hostname_edit_text); mHostnameField.setText(mHost.getHostname()); - mHostnameField.addTextChangedListener(new UriDataUpdater(HostDatabase.FIELD_HOST_HOSTNAME)); + mHostnameField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_HOSTNAME)); mPortContainer = view.findViewById(R.id.port_field_container); mPortField = (EditText) view.findViewById(R.id.port_edit_text); mPortField.setText(Integer.toString(mHost.getPort())); - mPortField.addTextChangedListener(new UriDataUpdater(HostDatabase.FIELD_HOST_PORT)); + mPortField.addTextChangedListener(new HostTextFieldWatcher(HostDatabase.FIELD_HOST_PORT)); + + mNicknameField = (EditText) view.findViewById(R.id.nickname_field); + mNicknameField.setText(mHost.getNickname()); + mNicknameField.addTextChangedListener( + new HostTextFieldWatcher(HostDatabase.FIELD_HOST_NICKNAME)); + + mColorSelector = (Spinner) view.findViewById(R.id.color_selector); + if (mHost.getColor() != null) { + // Unfortunately, TypedArray doesn't have an indexOf(String) function, so search through + // the array for the saved color. + for (int i = 0; i < mColorValues.getIndexCount(); i++) { + if (mHost.getColor().equals(mColorValues.getString(i))) { + mColorSelector.setSelection(i); + break; + } + } + } + mColorSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + mHost.setColor(mColorValues.getString(position)); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + + mFontSizeText = (TextView) view.findViewById(R.id.font_size_text); + mFontSizeSeekBar = (SeekBar) view.findViewById(R.id.font_size_bar); + mFontSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + int fontSize = MINIMUM_FONT_SIZE + progress; + mHost.setFontSize(fontSize); + mFontSizeText.setText(Integer.toString(fontSize)); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + }); + mFontSizeSeekBar.setProgress(mHost.getFontSize() - MINIMUM_FONT_SIZE); setUriPartsContainerExpanded(mIsUriEditorExpanded); @@ -234,6 +294,10 @@ public class HostEditorFragment extends Fragment { } catch (ClassCastException e) { throw new ClassCastException(context.toString() + " must implement Listener"); } + + // Now that the fragment is attached to an Activity, fetch the array from the attached + // Activity's resources. + mColorValues = getResources().obtainTypedArray(R.array.list_color_values); } @Override @@ -297,11 +361,11 @@ public class HostEditorFragment extends Fragment { public void onHostUpdated(HostBean host); } - private class UriDataUpdater implements TextWatcher { + private class HostTextFieldWatcher implements TextWatcher { private final String mFieldType; - public UriDataUpdater(String fieldType) { + public HostTextFieldWatcher(String fieldType) { mFieldType = fieldType; } @@ -325,15 +389,28 @@ public class HostEditorFragment extends Fragment { } catch (NumberFormatException e) { return; } + } else if (HostDatabase.FIELD_HOST_NICKNAME.equals(mFieldType)) { + mHost.setNickname(text); } else { throw new RuntimeException("Invalid field type."); } - if (!mUriFieldEditInProgress) { - mUriFieldEditInProgress = true; - mQuickConnectField.setText(mHost.toString()); - mUriFieldEditInProgress = false; + if (isUriRelatedField(mFieldType)) { + mNicknameField.setText(mHost.toString()); + mHost.setNickname(mHost.toString()); + + if (!mUriFieldEditInProgress) { + mUriFieldEditInProgress = true; + mQuickConnectField.setText(mHost.toString()); + mUriFieldEditInProgress = false; + } } } + + private boolean isUriRelatedField(String fieldType) { + return HostDatabase.FIELD_HOST_USERNAME.equals(fieldType) || + HostDatabase.FIELD_HOST_HOSTNAME.equals(fieldType) || + HostDatabase.FIELD_HOST_PORT.equals(fieldType); + } } } diff --git a/app/src/main/java/org/connectbot/bean/HostBean.java b/app/src/main/java/org/connectbot/bean/HostBean.java index 1fbb9be..d6cf8f4 100644 --- a/app/src/main/java/org/connectbot/bean/HostBean.java +++ b/app/src/main/java/org/connectbot/bean/HostBean.java @@ -31,7 +31,9 @@ import android.net.Uri; * */ public class HostBean extends AbstractBean { + public static final String BEAN_NAME = "host"; + private static final int DEFAULT_FONT_SIZE = 10; /* Database fields */ private long id = -1; @@ -48,7 +50,7 @@ public class HostBean extends AbstractBean { private long pubkeyId = -1; private boolean wantSession = true; private String delKey = HostDatabase.DELKEY_DEL; - private int fontSize = -1; + private int fontSize = DEFAULT_FONT_SIZE; private boolean compression = false; private String encoding = HostDatabase.ENCODING_DEFAULT; private boolean stayConnected = false; diff --git a/app/src/main/res/layout/fragment_host_editor.xml b/app/src/main/res/layout/fragment_host_editor.xml index b2dc0fe..6f429ac 100644 --- a/app/src/main/res/layout/fragment_host_editor.xml +++ b/app/src/main/res/layout/fragment_host_editor.xml @@ -23,133 +23,218 @@ tools:context="org.connectbot.HostEditorFragment" > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From a6c1a06578694fce6ee7e2460e3ab0df88d35276 Mon Sep 17 00:00:00 2001 From: Kyle Horimoto Date: Thu, 1 Oct 2015 10:48:56 -0700 Subject: Remove launcher intent-filter. --- app/src/main/AndroidManifest.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b528acd..e863b21 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,7 +46,10 @@ android:name=".HostListActivity" android:label="@string/title_hosts_list" android:launchMode="singleTop"> - + + + + @@ -84,10 +87,7 @@ - - - - + -- cgit v1.2.3 From 0407b261fc98d0cf4f8fbee7c7a889db2b52266a Mon Sep 17 00:00:00 2001 From: Kyle Horimoto Date: Thu, 1 Oct 2015 12:05:17 -0700 Subject: jlklein comment. --- app/src/main/java/org/connectbot/HostEditorFragment.java | 1 + 1 file changed, 1 insertion(+) (limited to 'app/src/main') diff --git a/app/src/main/java/org/connectbot/HostEditorFragment.java b/app/src/main/java/org/connectbot/HostEditorFragment.java index 4223907..f0a8c4f 100644 --- a/app/src/main/java/org/connectbot/HostEditorFragment.java +++ b/app/src/main/java/org/connectbot/HostEditorFragment.java @@ -304,6 +304,7 @@ public class HostEditorFragment extends Fragment { public void onDetach() { super.onDetach(); mListener = null; + mColorValues.recycle(); } @Override -- cgit v1.2.3