aboutsummaryrefslogtreecommitdiffstats
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml10
-rw-r--r--app/src/main/java/org/connectbot/HostEditorFragment.java95
-rw-r--r--app/src/main/java/org/connectbot/bean/HostBean.java4
-rw-r--r--app/src/main/res/layout/fragment_host_editor.xml341
4 files changed, 307 insertions, 143 deletions
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">
- <intent-filter android:label="@string/app_name">
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
- </intent-filter>
+
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT"/>
<category android:name="android.intent.category.DEFAULT"/>
@@ -87,7 +84,10 @@
<activity
android:name=".EditHostActivity"
android:label="@string/title_host_editor">
-
+ <intent-filter android:label="@string/app_name">
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.connectbot.HostListActivity"/>
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"
>
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_marginStart="4dp"
- android:layout_marginLeft="4dp"
- android:layout_marginBottom="4dp"
- >
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/protocol_spinner_label"
- android:textSize="12sp"
- />
-
- <Spinner
- android:id="@+id/transport_selector"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
-
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- tools:ignore="UnusedAttribute"
- >
-
- <android.support.design.widget.TextInputLayout
- android:id="@+id/quickconnect_field_container"
- android:layout_width="0dp"
- android:layout_weight ="1"
- android:layout_height="wrap_content"
- >
-
- <EditText
- android:id="@+id/quickconnect_field"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:maxLines="1"
- android:inputType="textNoSuggestions"
- />
-
- </android.support.design.widget.TextInputLayout>
-
- <ImageButton
- android:id="@+id/expand_collapse_button"
- android:layout_width="16dp"
- android:layout_height="16dp"
- android:layout_gravity="center"
- android:layout_margin="16dp"
- android:src="@drawable/ic_expand_more"
- android:contentDescription="@string/expand"
- android:background="#00000000"
- />
-
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/uri_parts_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:layout_marginLeft="56dp"
- android:layout_marginStart="56dp"
- android:visibility="gone"
- android:animateLayoutChanges="true"
- tools:ignore="UnusedAttribute"
- >
-
- <android.support.design.widget.TextInputLayout
- android:id="@+id/username_field_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
-
- <EditText
- android:id="@+id/username_edit_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/hostpref_username_title"
- android:maxLines="1"
- android:inputType="textNoSuggestions"
- />
-
- </android.support.design.widget.TextInputLayout>
-
- <android.support.design.widget.TextInputLayout
- android:id="@+id/hostname_field_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
-
- <EditText
- android:id="@+id/hostname_edit_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="@string/hostpref_hostname_title"
- android:maxLines="1"
- android:inputType="textNoSuggestions"
- />
-
- </android.support.design.widget.TextInputLayout>
-
- <android.support.design.widget.TextInputLayout
- android:id="@+id/port_field_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
-
- <EditText
- android:id="@+id/port_edit_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:inputType="number"
- android:hint="@string/hostpref_port_title"
- android:maxLines="1"
- />
-
- </android.support.design.widget.TextInputLayout>
-
- </LinearLayout>
-
- <View style="@style/Divider" />
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_marginStart="4dp"
+ android:layout_marginLeft="4dp"
+ android:layout_marginBottom="4dp"
+ >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/protocol_spinner_label"
+ android:textSize="12sp"
+ />
+
+ <Spinner
+ android:id="@+id/transport_selector"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
+ tools:ignore="UnusedAttribute"
+ >
+
+ <android.support.design.widget.TextInputLayout
+ android:id="@+id/quickconnect_field_container"
+ android:layout_width="0dp"
+ android:layout_weight ="1"
+ android:layout_height="wrap_content"
+ >
+
+ <EditText
+ android:id="@+id/quickconnect_field"
+ android:layout_width="match_parent"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:maxLines="1"
+ android:inputType="textNoSuggestions"
+ />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <ImageButton
+ android:id="@+id/expand_collapse_button"
+ android:layout_width="16dp"
+ android:layout_height="16dp"
+ android:layout_gravity="center"
+ android:layout_margin="16dp"
+ android:src="@drawable/ic_expand_more"
+ android:contentDescription="@string/expand"
+ android:background="#00000000"
+ />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/uri_parts_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_marginLeft="56dp"
+ android:layout_marginStart="56dp"
+ android:visibility="gone"
+ android:animateLayoutChanges="true"
+ tools:ignore="UnusedAttribute"
+ >
+
+ <android.support.design.widget.TextInputLayout
+ android:id="@+id/username_field_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ >
+
+ <EditText
+ android:id="@+id/username_edit_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/hostpref_username_title"
+ android:maxLines="1"
+ android:inputType="textNoSuggestions"
+ />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <android.support.design.widget.TextInputLayout
+ android:id="@+id/hostname_field_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ >
+
+ <EditText
+ android:id="@+id/hostname_edit_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/hostpref_hostname_title"
+ android:maxLines="1"
+ android:inputType="textNoSuggestions"
+ />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <android.support.design.widget.TextInputLayout
+ android:id="@+id/port_field_container"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ >
+
+ <EditText
+ android:id="@+id/port_edit_text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:inputType="number"
+ android:hint="@string/hostpref_port_title"
+ android:maxLines="1"
+ />
+
+ </android.support.design.widget.TextInputLayout>
+
+ </LinearLayout>
+
+ <View style="@style/Divider"
+ />
+
+ <android.support.design.widget.TextInputLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ >
+
+ <EditText
+ android:id="@+id/nickname_field"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:maxLines="1"
+ android:inputType="text"
+ android:hint="@string/hostpref_nickname_title"
+ />
+
+ </android.support.design.widget.TextInputLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_marginStart="4dp"
+ android:layout_marginLeft="4dp"
+ android:layout_marginBottom="4dp"
+ >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/hostpref_color_title"
+ android:textSize="12sp"
+ />
+
+ <Spinner
+ android:id="@+id/color_selector"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:entries="@array/list_colors"
+ android:entryValues="@array/list_color_values"
+ />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:layout_marginStart="4dp"
+ android:layout_marginLeft="4dp"
+ android:layout_marginBottom="4dp"
+ >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/hostpref_fontsize_title"
+ android:textSize="12sp"
+ />
+
+ <TextView
+ android:id="@+id/font_size_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="12sp"
+ />
+
+ </LinearLayout>
+
+ <SeekBar
+ android:id="@+id/font_size_bar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:max="32"
+ />
+
+ </LinearLayout>
+
+ <View style="@style/Divider"
+ />
</LinearLayout>