Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Commit 17747f0

Browse files
committed
Redo key edit UI, improve colours, attempt to disable spellcheck
1 parent b8baf6c commit 17747f0

17 files changed

+169
-119
lines changed

app/src/main/java/link/infra/sslsocks/gui/AdvancedSettingsActivity.java

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package link.infra.sslsocks.gui;
22

33
import android.os.Bundle;
4+
import android.view.MenuItem;
45

56
import androidx.appcompat.app.AppCompatActivity;
67
import androidx.appcompat.widget.Toolbar;
@@ -28,4 +29,19 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
2829
setPreferencesFromResource(R.xml.advanced_settings, rootKey);
2930
}
3031
}
32+
33+
@Override
34+
public boolean onOptionsItemSelected(MenuItem item) {
35+
// Handle action bar item clicks here. The action bar will
36+
// automatically handle clicks on the Home/Up button, so long
37+
// as you specify a parent activity in AndroidManifest.xml.
38+
int id = item.getItemId();
39+
40+
if (id == android.R.id.home) {
41+
finish();
42+
return true;
43+
}
44+
45+
return super.onOptionsItemSelected(item);
46+
}
3147
}

app/src/main/java/link/infra/sslsocks/gui/keymgmt/KeyEditActivity.java

+39-24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.os.Bundle;
77
import android.provider.OpenableColumns;
88
import android.util.Log;
9+
import android.view.Menu;
10+
import android.view.MenuItem;
911
import android.view.View;
1012
import android.widget.EditText;
1113
import android.widget.Toast;
@@ -33,6 +35,7 @@ public class KeyEditActivity extends AppCompatActivity {
3335
public static final String ARG_EXISTING_FILE_NAME = "EXISTING_FILE_NAME";
3436

3537
private static final String TAG = KeyEditActivity.class.getSimpleName();
38+
private boolean showDelete = true;
3639

3740
@Override
3841
protected void onCreate(Bundle savedInstanceState) {
@@ -41,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
4144
Toolbar toolbar = findViewById(R.id.toolbar);
4245
setSupportActionBar(toolbar);
4346
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
47+
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_close_black_24dp);
4448

4549
fileContents = findViewById(R.id.file_contents);
4650
fileName = findViewById(R.id.file_name);
@@ -52,7 +56,8 @@ protected void onCreate(Bundle savedInstanceState) {
5256
if (existingFileName == null) {
5357
getSupportActionBar().setTitle(R.string.title_activity_key_create);
5458
findViewById(R.id.import_button).setVisibility(View.VISIBLE);
55-
findViewById(R.id.delete_button).setVisibility(View.GONE);
59+
showDelete = false;
60+
invalidateOptionsMenu();
5661
} else {
5762
fileName.setText(existingFileName);
5863
openFile();
@@ -66,26 +71,41 @@ public void onClick(View view) {
6671
importExternalFile();
6772
}
6873
});
69-
findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() {
70-
@Override
71-
public void onClick(View view) {
72-
deleteFile();
73-
}
74-
});
75-
findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
76-
@Override
77-
public void onClick(View view) {
78-
cancel();
79-
}
80-
});
81-
findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() {
82-
@Override
83-
public void onClick(View view) {
84-
saveFile();
85-
}
86-
});
8774
}
8875

76+
@Override
77+
public boolean onCreateOptionsMenu(Menu menu) {
78+
// Inflate the menu; this adds items to the action bar if it is present.
79+
getMenuInflater().inflate(R.menu.menu_key_edit, menu);
80+
if (!showDelete) {
81+
menu.findItem(R.id.action_delete).setVisible(false);
82+
}
83+
return true;
84+
}
85+
86+
@Override
87+
public boolean onOptionsItemSelected(MenuItem item) {
88+
// Handle action bar item clicks here. The action bar will
89+
// automatically handle clicks on the Home/Up button, so long
90+
// as you specify a parent activity in AndroidManifest.xml.
91+
int id = item.getItemId();
92+
93+
if (id == R.id.action_save) {
94+
saveFile();
95+
return true;
96+
}
97+
if (id == android.R.id.home) {
98+
setResult(RESULT_CANCELED);
99+
finish();
100+
return true;
101+
}
102+
if (id == R.id.action_delete) {
103+
deleteFile();
104+
return true;
105+
}
106+
107+
return super.onOptionsItemSelected(item);
108+
}
89109

90110
private void importExternalFile() {
91111
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
@@ -181,11 +201,6 @@ private void saveFile() {
181201
}
182202
}
183203

184-
private void cancel() {
185-
setResult(RESULT_CANCELED);
186-
finish();
187-
}
188-
189204
private void deleteFile() {
190205
if (existingFileName != null) {
191206
File existingFile = new File(getFilesDir().getPath() + "/" + existingFileName);

app/src/main/java/link/infra/sslsocks/gui/main/MainActivity.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
108108

109109
//noinspection SimplifiableIfStatement
110110
if (id == R.id.action_settings) {
111+
Intent intent = new Intent(this, AdvancedSettingsActivity.class);
112+
startActivity(intent);
111113
return true;
112114
}
113115

@@ -199,11 +201,6 @@ public void onPageSelected(int position) {
199201
public void onPageScrollStateChanged(int state) {} // nothing needed here
200202
};
201203

202-
public void openSettings(MenuItem item) {
203-
Intent intent = new Intent(this, AdvancedSettingsActivity.class);
204-
startActivity(intent);
205-
}
206-
207204
private void stopStunnelService() {
208205
Intent intent = new Intent(this, StunnelIntentService.class);
209206
stopService(intent);

app/src/main/res/drawable/ic_add_white_24dp.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
android:viewportWidth="24.0"
55
android:viewportHeight="24.0">
66
<path
7-
android:fillColor="#FFFFFFFF"
7+
android:fillColor="@color/overColor"
88
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
99
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="@color/overColor"
8+
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
9+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="@color/overColor"
8+
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
9+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24.0"
5+
android:viewportHeight="24.0">
6+
<path
7+
android:fillColor="@color/overColor"
8+
android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
9+
</vector>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24">
6+
<path
7+
android:fillColor="@color/overColor"
8+
android:pathData="M19.1,12.9a2.8,2.8 0,0 0,0.1 -0.9,2.8 2.8,0 0,0 -0.1,-0.9l2.1,-1.6a0.7,0.7 0,0 0,0.1 -0.6L19.4,5.5a0.7,0.7 0,0 0,-0.6 -0.2l-2.4,1a6.5,6.5 0,0 0,-1.6 -0.9l-0.4,-2.6a0.5,0.5 0,0 0,-0.5 -0.4H10.1a0.5,0.5 0,0 0,-0.5 0.4L9.3,5.4a5.6,5.6 0,0 0,-1.7 0.9l-2.4,-1a0.4,0.4 0,0 0,-0.5 0.2l-2,3.4c-0.1,0.2 0,0.4 0.2,0.6l2,1.6a2.8,2.8 0,0 0,-0.1 0.9,2.8 2.8,0 0,0 0.1,0.9L2.8,14.5a0.7,0.7 0,0 0,-0.1 0.6l1.9,3.4a0.7,0.7 0,0 0,0.6 0.2l2.4,-1a6.5,6.5 0,0 0,1.6 0.9l0.4,2.6a0.5,0.5 0,0 0,0.5 0.4h3.8a0.5,0.5 0,0 0,0.5 -0.4l0.3,-2.6a5.6,5.6 0,0 0,1.7 -0.9l2.4,1a0.4,0.4 0,0 0,0.5 -0.2l2,-3.4c0.1,-0.2 0,-0.4 -0.2,-0.6ZM12,15.6A3.6,3.6 0,1 1,15.6 12,3.6 3.6,0 0,1 12,15.6Z"/>
9+
</vector>

app/src/main/res/layout/activity_advanced_settings.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
android:id="@+id/toolbar"
1515
android:layout_width="match_parent"
1616
android:layout_height="?attr/actionBarSize"
17-
android:background="?attr/colorPrimary"/>
17+
android:background="?attr/colorPrimary"
18+
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
1819

1920
</com.google.android.material.appbar.AppBarLayout>
2021

app/src/main/res/layout/activity_key_edit.xml

+25-63
Original file line numberDiff line numberDiff line change
@@ -14,89 +14,51 @@
1414
android:id="@+id/toolbar"
1515
android:layout_width="match_parent"
1616
android:layout_height="?attr/actionBarSize"
17-
android:background="?attr/colorPrimary"/>
17+
android:background="?attr/colorPrimary"
18+
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
1819

1920
</com.google.android.material.appbar.AppBarLayout>
2021

2122
<LinearLayout
2223
android:layout_width="match_parent"
2324
android:layout_height="match_parent"
25+
android:padding="4dp"
2426
app:layout_behavior="@string/appbar_scrolling_view_behavior"
2527
android:orientation="vertical">
26-
<GridLayout
27-
android:layout_width="match_parent"
28-
android:layout_height="0dp"
29-
android:columnCount="2"
30-
android:layout_weight="1">
3128
<com.google.android.material.button.MaterialButton
3229
android:id="@+id/import_button"
3330
android:layout_width="match_parent"
3431
android:layout_height="wrap_content"
3532
android:text="@string/import_pem"
36-
android:layout_columnSpan="2"
3733
android:insetLeft="4dp"
3834
android:insetRight="4dp"
3935
android:visibility="gone"/>
40-
<TextView
41-
android:layout_width="wrap_content"
42-
android:layout_height="wrap_content"
43-
android:text="@string/file_name"
44-
android:labelFor="@id/file_name"/>
45-
<EditText
46-
android:id="@+id/file_name"
36+
<com.google.android.material.textfield.TextInputLayout
4737
android:layout_width="match_parent"
48-
android:inputType="text"
49-
android:importantForAutofill="no"
50-
tools:ignore="UnusedAttribute" />
51-
<TextView
52-
android:layout_width="wrap_content"
5338
android:layout_height="wrap_content"
54-
android:text="@string/file_contents"
55-
android:labelFor="@id/file_contents"
56-
android:layout_columnSpan="2"/>
57-
<EditText
58-
android:id="@+id/file_contents"
59-
android:layout_height="0dp"
60-
android:layout_rowWeight="1"
39+
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
40+
android:hint="@string/file_name">
41+
<com.google.android.material.textfield.TextInputEditText
42+
android:id="@+id/file_name"
43+
android:layout_width="match_parent"
44+
android:inputType="textNoSuggestions"
45+
android:importantForAutofill="no"
46+
android:layout_height="wrap_content"
47+
tools:ignore="UnusedAttribute" />
48+
</com.google.android.material.textfield.TextInputLayout>
49+
<com.google.android.material.textfield.TextInputLayout
6150
android:layout_width="match_parent"
62-
android:layout_columnSpan="2"
63-
android:ems="10"
64-
android:gravity="top|start"
65-
android:inputType="textMultiLine"
66-
android:background="@android:color/transparent"
67-
android:textCursorDrawable="@null"
68-
android:padding="5dp"
69-
android:importantForAutofill="no"
70-
tools:ignore="UnusedAttribute" />
71-
</GridLayout>
72-
<LinearLayout
73-
android:layout_width="match_parent"
74-
android:layout_height="wrap_content"
75-
android:gravity="center|bottom"
76-
style="?android:attr/buttonBarStyle"
77-
android:layout_weight="0">
78-
<com.google.android.material.button.MaterialButton
79-
android:id="@+id/cancel_button"
80-
android:layout_width="wrap_content"
81-
android:layout_height="wrap_content"
82-
android:insetLeft="4dp"
83-
android:insetRight="4dp"
84-
android:text="@android:string/cancel"/>
85-
<com.google.android.material.button.MaterialButton
86-
android:id="@+id/delete_button"
87-
android:layout_width="wrap_content"
8851
android:layout_height="wrap_content"
89-
android:insetLeft="4dp"
90-
android:insetRight="4dp"
91-
android:text="@string/delete"/>
92-
<com.google.android.material.button.MaterialButton
93-
android:id="@+id/save_button"
94-
android:layout_width="wrap_content"
95-
android:layout_height="wrap_content"
96-
android:insetLeft="4dp"
97-
android:insetRight="4dp"
98-
android:text="@android:string/ok"/>
99-
</LinearLayout>
52+
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
53+
android:hint="@string/file_contents">
54+
<com.google.android.material.textfield.TextInputEditText
55+
android:id="@+id/file_contents"
56+
android:layout_width="match_parent"
57+
android:inputType="textMultiLine|textNoSuggestions"
58+
android:importantForAutofill="no"
59+
android:layout_height="match_parent"
60+
tools:ignore="UnusedAttribute"/>
61+
</com.google.android.material.textfield.TextInputLayout>
10062
</LinearLayout>
10163

10264

app/src/main/res/layout/activity_main.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
android:id="@+id/toolbar"
1818
android:layout_width="match_parent"
1919
android:layout_height="?attr/actionBarSize"
20-
android:background="?attr/colorPrimary">
20+
android:background="?attr/colorPrimary"
21+
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
2122

2223
</androidx.appcompat.widget.Toolbar>
2324

@@ -39,10 +40,10 @@
3940
style="@style/Widget.MaterialComponents.FloatingActionButton"
4041
android:layout_width="wrap_content"
4142
android:layout_height="wrap_content"
42-
android:layout_gravity="end|bottom"
43+
android:layout_gravity="bottom|end"
4344
android:layout_margin="@dimen/fab_margin"
4445
android:visibility="gone"
4546
app:backgroundTint="@color/colorPrimary"
46-
app:srcCompat="@drawable/ic_add_white_24dp" />
47+
app:srcCompat="@drawable/ic_add_white_24dp"/>
4748

4849
</androidx.coordinatorlayout.widget.CoordinatorLayout>

app/src/main/res/layout/fragment_config_editor.xml

+18-18
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
tools:context=".gui.main.ConfigEditorFragment"
77
android:orientation="vertical">
88

9-
<Spinner
10-
android:id="@+id/spinner"
11-
android:layout_width="match_parent"
12-
android:layout_height="wrap_content"
13-
android:layout_margin="5dp"/>
14-
<EditText
15-
android:id="@+id/editText"
16-
android:layout_height="match_parent"
17-
android:layout_width="match_parent"
18-
android:ems="10"
19-
android:gravity="top|start"
20-
android:inputType="textMultiLine"
21-
android:background="@android:color/transparent"
22-
android:textCursorDrawable="@null"
23-
android:padding="5dp"
24-
android:importantForAutofill="no"
25-
android:hint="@string/config_editor_hint"
26-
tools:ignore="UnusedAttribute" />
9+
<Spinner
10+
android:id="@+id/spinner"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:layout_margin="5dp"/>
14+
<EditText
15+
android:id="@+id/editText"
16+
android:layout_height="match_parent"
17+
android:layout_width="match_parent"
18+
android:ems="10"
19+
android:gravity="top|start"
20+
android:inputType="textMultiLine|textNoSuggestions"
21+
android:background="@android:color/transparent"
22+
android:textCursorDrawable="@null"
23+
android:padding="5dp"
24+
android:importantForAutofill="no"
25+
android:hint="@string/config_editor_hint"
26+
tools:ignore="UnusedAttribute" />
2727

2828
</LinearLayout>

0 commit comments

Comments
 (0)