introduce SettingsActivity

This commit is contained in:
Peter Cai 2018-08-24 16:25:25 +08:00
parent 6d17405dbe
commit a2d838f470
No known key found for this signature in database
GPG key ID: 71F5FB4E4F3FD54F
10 changed files with 153 additions and 0 deletions

View file

@ -27,6 +27,7 @@ dependencies {
implementation 'com.android.support:support-core-ui:28.0.0-rc01'
implementation 'com.android.support:support-fragment:28.0.0-rc01'
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support:preference-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support:localbroadcastmanager:28.0.0-rc01'

View file

@ -28,6 +28,10 @@
</intent-filter>
</activity>
<!-- The Settings activity -->
<activity android:name=".ui.SettingsActivity"
android:label="@string/settings" />
<!-- An activity that wraps intents that cross the profile boundary -->
<!-- Needed because only cross-profile Activity intents are supported -->
<activity android:name=".ui.DummyActivity"

View file

@ -236,6 +236,9 @@ public class MainActivity extends AppCompatActivity {
intent.setComponent(new ComponentName(this, DummyActivity.class));
startActivity(intent);
return true;
case R.id.main_menu_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
case R.id.main_menu_create_freeze_all_shortcut:
Intent launchIntent = new Intent(DummyActivity.PUBLIC_FREEZE_ALL);
launchIntent.setComponent(new ComponentName(this, DummyActivity.class));

View file

@ -0,0 +1,23 @@
package net.typeblog.shelter.ui;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import net.typeblog.shelter.R;
public class SettingsActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
setSupportActionBar(findViewById(R.id.settings_toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onSupportNavigateUp() {
finish();
return true;
}
}

View file

@ -0,0 +1,43 @@
package net.typeblog.shelter.ui;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
import net.typeblog.shelter.R;
public class SettingsFragment extends PreferenceFragmentCompat {
private static final String SETTINGS_VERSION = "settings_version";
private static final String SETTINGS_SOURCE_CODE = "settings_source_code";
private static final String SETTINGS_BUG_REPORT = "settings_bug_report";
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences_settings);
// Set the displayed version
try {
findPreference(SETTINGS_VERSION).setSummary(
getContext().getPackageManager().getPackageInfo(
getContext().getPackageName(), 0).versionName);
} catch (PackageManager.NameNotFoundException e) {
// WTF?
}
// Open source code url on click
findPreference(SETTINGS_SOURCE_CODE)
.setOnPreferenceClickListener(this::openSummaryUrl);
findPreference(SETTINGS_BUG_REPORT)
.setOnPreferenceClickListener(this::openSummaryUrl);
}
private boolean openSummaryUrl(Preference pref) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pref.getSummary().toString()));
startActivity(intent);
return true;
}
}

View file

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/colorAccent"
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/>
</vector>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/settings_appbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<android.support.v7.widget.Toolbar
android:id="@+id/settings_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ToolbarTheme"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<fragment
android:name="net.typeblog.shelter.ui.SettingsFragment"
android:tag="net.typeblog.shelter.ui.SettingsFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/settings_appbar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>

View file

@ -7,6 +7,12 @@
android:title="@string/freeze_all"
app:showAsAction="ifRoom" />
<item
android:id="@+id/main_menu_settings"
android:icon="@drawable/ic_settings_tinted_24dp"
android:title="@string/settings"
app:showAsAction="ifRoom" />
<item
android:id="@+id/main_menu_create_freeze_all_shortcut"
android:title="@string/create_freeze_all_shortcut" />

View file

@ -36,4 +36,11 @@
<string name="unsupported_launcher">Cannot add shortcuts to your launcher. Please contact the developer for more information.</string>
<string name="app_context_menu_title">Operations for %s</string>
<string name="freeze_all_success">All apps in \"Auto Freeze\" list have been frozen successfully.</string>
<string name="settings">Settings</string>
<string name="settings_about">About</string>
<string name="settings_version">Version</string>
<string name="settings_source_code">Source Code</string>
<string name="settings_source_code_url" translatable="false">https://git.angry.im/PeterCxy/Shelter</string>
<string name="settings_bug_report">Bug Report / Issue Tracker</string>
<string name="settings_bug_report_url" translatable="false">https://git.angry.im/PeterCxy/Shelter/issues</string>
</resources>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.preference.PreferenceCategory
android:title="@string/settings_about">
<android.support.v7.preference.Preference
android:key="settings_version"
android:title="@string/settings_version" />
<android.support.v7.preference.Preference
android:key="settings_source_code"
android:title="@string/settings_source_code"
android:summary="@string/settings_source_code_url" />
<android.support.v7.preference.Preference
android:key="settings_bug_report"
android:title="@string/settings_bug_report"
android:summary="@string/settings_bug_report_url" />
</android.support.v7.preference.PreferenceCategory>
</android.support.v7.preference.PreferenceScreen>