commit 18f453de453981d3f5105d661efe40905aca5cc9 Author: Hashik Donthineni HashikDonthineni@gmail.com Date: Sun Jun 28 16:05:44 2020 +0530
Added settings UI and handled button click --- .../torproject/snowflake/AppSettingsFragment.java | 18 +++++++++ .../org/torproject/snowflake/MainActivity.java | 13 ++++++ .../org/torproject/snowflake/MainFragment.java | 1 - app/src/main/res/layout/activity_main.xml | 9 +++-- app/src/main/res/values/arrays.xml | 12 ++++++ app/src/main/res/xml/app_settings.xml | 47 ++++++++++++++++------ 6 files changed, 83 insertions(+), 17 deletions(-)
diff --git a/app/src/main/java/org/torproject/snowflake/AppSettingsFragment.java b/app/src/main/java/org/torproject/snowflake/AppSettingsFragment.java new file mode 100644 index 0000000..33bc456 --- /dev/null +++ b/app/src/main/java/org/torproject/snowflake/AppSettingsFragment.java @@ -0,0 +1,18 @@ +package org.torproject.snowflake; + +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; + +public class AppSettingsFragment extends PreferenceFragmentCompat { + + public static AppSettingsFragment newInstance() { + AppSettingsFragment fragment = new AppSettingsFragment(); + return fragment; + } + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.app_settings, rootKey); + } +} diff --git a/app/src/main/java/org/torproject/snowflake/MainActivity.java b/app/src/main/java/org/torproject/snowflake/MainActivity.java index 642fe21..a1eb34d 100644 --- a/app/src/main/java/org/torproject/snowflake/MainActivity.java +++ b/app/src/main/java/org/torproject/snowflake/MainActivity.java @@ -8,6 +8,8 @@ import android.content.SharedPreferences; import android.graphics.Color; import android.os.Build; import android.os.Bundle; +import android.view.View; +import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; @@ -21,12 +23,15 @@ import org.torproject.snowflake.interfaces.MainFragmentCallback; public class MainActivity extends AppCompatActivity implements MainFragmentCallback { private static final String TAG = "MainActivity"; private SharedPreferences sharedPreferences; + private Button settingsButton;
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setSupportActionBar(findViewById(R.id.toolbar)); + settingsButton = findViewById(R.id.settings_button); + sharedPreferences = getSharedPreferences(getString(R.string.sharedpreference_file), MODE_PRIVATE);
//Creating notification channel if app is being run for the first time @@ -36,6 +41,14 @@ public class MainActivity extends AppCompatActivity implements MainFragmentCallb sharedPreferences.edit().putBoolean(getString(R.string.initial_run_boolean), false).apply(); }
+ settingsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //Starting Settings Activity. + startFragment(AppSettingsFragment.newInstance()); + } + }); + //Starting the MainFragment. startFragment(MainFragment.newInstance()); } diff --git a/app/src/main/java/org/torproject/snowflake/MainFragment.java b/app/src/main/java/org/torproject/snowflake/MainFragment.java index e30923b..520436c 100644 --- a/app/src/main/java/org/torproject/snowflake/MainFragment.java +++ b/app/src/main/java/org/torproject/snowflake/MainFragment.java @@ -34,7 +34,6 @@ public class MainFragment extends Fragment {
public static MainFragment newInstance() { MainFragment fragment = new MainFragment(); - Bundle bundle = new Bundle(); return fragment; }
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index c9f27a2..d095c62 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" @@ -29,6 +29,7 @@ android:textSize="16sp" />
<androidx.appcompat.widget.AppCompatButton + android:id="@+id/settings_button" android:layout_width="25dp" android:layout_height="25dp" android:layout_alignParentEnd="true" @@ -40,8 +41,8 @@ </androidx.appcompat.widget.Toolbar>
<FrameLayout + android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" - android:id="@+id/fragment_container" - app:layout_constraintTop_toBottomOf="@+id/toolbar" /> -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file + android:layout_below="@id/toolbar" /> +</RelativeLayout> \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..6cf9ed4 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,12 @@ +<resources> + <!-- Reply Preference --> + <string-array name="reply_entries"> + <item>Reply</item> + <item>Reply to all</item> + </string-array> + + <string-array name="reply_values"> + <item>reply</item> + <item>reply_all</item> + </string-array> +</resources> \ No newline at end of file diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 6685708..ae85095 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -1,25 +1,48 @@ <?xml version="1.0" encoding="utf-8"?> -<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> - - <PreferenceCategory android:title="Snowflake Settings"> +<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto%22%3E
+ <PreferenceCategory + android:title="Snowflake Settings" + app:iconSpaceReserved="false"> + <SwitchPreference + android:key="stun_switch" + android:title="Set STUN server" + app:iconSpaceReserved="false" /> <EditTextPreference - android:defaultValue="Default value" - android:key="edit_text_preference_1" + android:enabled="false" + android:key="stun_edit_text" android:selectAllOnFocus="true" android:singleLine="true" - android:title="Custom STUN Server" /> + android:summary="Using Default" + android:title="Set STUN server" + app:iconSpaceReserved="false" /> + + <SwitchPreference + android:key="broker_switch" + android:title="Set broker URL" + app:iconSpaceReserved="false" /> <EditTextPreference - android:defaultValue="Default value" - android:key="edit_text_preference_1" + android:enabled="false" + android:key="broker_switch_edit_text" android:selectAllOnFocus="true" android:singleLine="true" - android:title="Custom Broker URL" /> + android:summary="Using Default" + android:title="Set broker URL" + app:iconSpaceReserved="false" /> + + <SwitchPreference + android:key="relay_switch" + android:title="Set relay URL" + app:iconSpaceReserved="false" /> <EditTextPreference - android:defaultValue="Default value" - android:key="edit_text_preference_2" + android:enabled="false" + android:key="relay_switch_edit_text" android:selectAllOnFocus="true" android:singleLine="true" - android:title="Custom Relay URL" /> + android:summary="Using Default" + android:title="Custom relay URL" + app:iconSpaceReserved="false" /> + </PreferenceCategory> </PreferenceScreen> \ No newline at end of file
tor-commits@lists.torproject.org