mirror of
https://github.com/etesync/android
synced 2025-01-11 00:01:12 +00:00
App settings UI
This commit is contained in:
parent
f73f6ca43c
commit
5723225475
@ -42,6 +42,7 @@
|
||||
<uses-permission android:name="android.permission.WRITE_CALENDAR"/>
|
||||
|
||||
<!-- ical4android declares task access permissions -->
|
||||
|
||||
<application
|
||||
android:name=".App"
|
||||
android:allowBackup="true"
|
||||
@ -125,6 +126,21 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.AppSettingsActivity"
|
||||
android:label="@string/app_settings"
|
||||
android:parentActivityName=".ui.AccountsActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.setup.LoginActivity"
|
||||
android:label="@string/login_title"
|
||||
android:parentActivityName=".ui.AccountsActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ui.AccountActivity"
|
||||
android:parentActivityName=".ui.AccountsActivity">
|
||||
@ -134,19 +150,12 @@
|
||||
android:label="@string/create_addressbook"/>
|
||||
<activity android:name=".ui.CreateCalendarActivity"
|
||||
android:label="@string/create_calendar"/>
|
||||
|
||||
<activity
|
||||
android:name=".ui.DebugInfoActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/debug_info_title">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.setup.LoginActivity"
|
||||
android:label="@string/login_title"
|
||||
android:parentActivityName=".ui.AccountsActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- MemorizingTrustManager -->
|
||||
<activity
|
||||
|
@ -29,11 +29,14 @@ import de.duenndns.ssl.MemorizingTrustManager;
|
||||
import lombok.Getter;
|
||||
import okhttp3.internal.tls.OkHostnameVerifier;
|
||||
|
||||
public class App extends Application {
|
||||
public class App extends Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public static final String
|
||||
PREF_FILE = "global",
|
||||
PREF_FILE = "davdroid_preferences",
|
||||
PREF_LOG_TO_FILE = "log_to_file";
|
||||
|
||||
@Getter
|
||||
private static MemorizingTrustManager memorizingTrustManager;
|
||||
|
||||
@Getter
|
||||
private static SSLSocketFactoryCompat sslSocketFactoryCompat;
|
||||
|
||||
@ -50,17 +53,32 @@ public class App extends Application {
|
||||
super.onCreate();
|
||||
|
||||
preferences = getSharedPreferences(PREF_FILE, MODE_PRIVATE);
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
// initialize MemorizingTrustManager
|
||||
MemorizingTrustManager mtm = new MemorizingTrustManager(this);
|
||||
sslSocketFactoryCompat = new SSLSocketFactoryCompat(mtm);
|
||||
hostnameVerifier = mtm.wrapHostnameVerifier(OkHostnameVerifier.INSTANCE);
|
||||
memorizingTrustManager = new MemorizingTrustManager(this);
|
||||
sslSocketFactoryCompat = new SSLSocketFactoryCompat(memorizingTrustManager);
|
||||
hostnameVerifier = memorizingTrustManager.wrapHostnameVerifier(OkHostnameVerifier.INSTANCE);
|
||||
|
||||
reinitLogger();
|
||||
}
|
||||
|
||||
// won't be called in production
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
preferences.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void reinitLogger() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (PREF_LOG_TO_FILE.equals(key)) {
|
||||
log.info("Logging preferences changed, initializing logger again");
|
||||
reinitLogger();
|
||||
}
|
||||
}
|
||||
|
||||
private void reinitLogger() {
|
||||
// don't use Android default logging, we have our own handlers
|
||||
log.setUseParentHandlers(false);
|
||||
|
||||
|
@ -72,7 +72,8 @@ public class AccountsActivity extends AppCompatActivity implements NavigationVie
|
||||
case R.id.nav_donate:
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Constants.webUri.buildUpon().appendEncodedPath("donate/").build()));
|
||||
break;
|
||||
case R.id.nav_preferences:
|
||||
case R.id.nav_app_settings:
|
||||
startActivity(new Intent(this, AppSettingsActivity.class));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
|
||||
package at.bitfire.davdroid.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.security.KeyStoreException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import at.bitfire.davdroid.App;
|
||||
import at.bitfire.davdroid.R;
|
||||
import de.duenndns.ssl.MemorizingTrustManager;
|
||||
|
||||
public class AppSettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
Preference prefResetHints,
|
||||
prefResetCertificates;
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.settings_app);
|
||||
prefResetHints = findPreference("reset_hints");
|
||||
prefResetCertificates = findPreference("reset_certificates");
|
||||
|
||||
getPreferenceManager().setSharedPreferencesName(App.PREF_FILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference == prefResetHints)
|
||||
resetHints();
|
||||
else if (preference == prefResetCertificates)
|
||||
resetCertificates();
|
||||
else
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private void resetHints() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
private void resetCertificates() {
|
||||
MemorizingTrustManager mtm = App.getMemorizingTrustManager();
|
||||
|
||||
int deleted = 0;
|
||||
Enumeration<String> iterator = mtm.getCertificates();
|
||||
while (iterator.hasMoreElements())
|
||||
try {
|
||||
mtm.deleteCertificate(iterator.nextElement());
|
||||
deleted++;
|
||||
} catch (KeyStoreException e) {
|
||||
App.log.log(Level.SEVERE, "Couldn't distrust certificate", e);
|
||||
}
|
||||
Snackbar.make(getView(), getString(R.string.app_settings_reset_trusted_certificates_success, deleted), Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -22,8 +22,8 @@
|
||||
android:icon="@drawable/ic_attach_money_dark"
|
||||
android:title="@string/navigation_drawer_donate"/>
|
||||
<item
|
||||
android:id="@+id/nav_preferences"
|
||||
android:id="@+id/nav_app_settings"
|
||||
android:icon="@drawable/ic_settings_dark"
|
||||
android:title="@string/navigation_drawer_preferences"/>
|
||||
android:title="@string/navigation_drawer_app_settings"/>
|
||||
|
||||
</menu>
|
||||
|
@ -17,13 +17,27 @@
|
||||
<string name="send">Send</string>
|
||||
<string name="skip">Skip</string>
|
||||
|
||||
<!-- AppSettingsActivity -->
|
||||
<string name="app_settings">Settings</string>
|
||||
<string name="app_settings_user_interface">User interface</string>
|
||||
<string name="app_settings_reset_hints">Reset hints</string>
|
||||
<string name="app_settings_reset_hints_summary">Re-enables hints which have been dismissed previously</string>
|
||||
<string name="app_settings_security">Security</string>
|
||||
<string name="app_settings_reset_trusted_certificates">Reset trusted certificates</string>
|
||||
<string name="app_settings_reset_trusted_certificates_summary">Forgets all certificates which have been accepted previously</string>
|
||||
<string name="app_settings_reset_trusted_certificates_success">Distrusted %d certificate(s)</string>
|
||||
<string name="app_settings_debug">Debugging</string>
|
||||
<string name="app_settings_log_to_file">Log to external file</string>
|
||||
<string name="app_settings_log_to_file_on">Logging to external storage (if available)</string>
|
||||
<string name="app_settings_log_to_file_off">External file logging is disabled</string>
|
||||
|
||||
<!-- AccountsActivity -->
|
||||
<string name="navigation_drawer_open">Open navigation drawer</string>
|
||||
<string name="navigation_drawer_close">Close navigation drawer</string>
|
||||
<string name="navigation_drawer_subtitle">CalDAV/CardDAV Sync Adapter</string>
|
||||
<string name="navigation_drawer_about">About / License</string>
|
||||
<string name="navigation_drawer_donate">Donate</string>
|
||||
<string name="navigation_drawer_preferences">Preferences</string>
|
||||
<string name="navigation_drawer_app_settings">Settings</string>
|
||||
<string name="navigation_drawer_website">Web site</string>
|
||||
|
||||
<string name="account_list_empty">Welcome to DAVdroid!\n\nYou can add a CalDAV/CardDAV account now.</string>
|
||||
@ -190,7 +204,7 @@
|
||||
<string name="create_collection_color">Set a collection color</string>
|
||||
<string name="create_collection_creating">Creating collection</string>
|
||||
<string name="create_collection_display_name">Display name (title) of this collection:</string>
|
||||
<string name="create_collection_display_name_required">A title is required</string>
|
||||
<string name="create_collection_display_name_required">Title is required</string>
|
||||
<string name="create_collection_description">Description (optional):</string>
|
||||
<string name="create_collection_home_set">Home set:</string>
|
||||
<string name="delete_collection">Delete collection</string>
|
||||
|
34
app/src/main/res/xml/settings_app.xml
Normal file
34
app/src/main/res/xml/settings_app.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
||||
~ All rights reserved. This program and the accompanying materials
|
||||
~ are made available under the terms of the GNU Public License v3.0
|
||||
~ which accompanies this distribution, and is available at
|
||||
~ http://www.gnu.org/licenses/gpl.html
|
||||
-->
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory android:title="@string/app_settings_user_interface">
|
||||
<Preference
|
||||
android:key="reset_hints"
|
||||
android:title="@string/app_settings_reset_hints"
|
||||
android:summary="@string/app_settings_reset_hints_summary"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/app_settings_security">
|
||||
<Preference
|
||||
android:key="reset_certificates"
|
||||
android:title="@string/app_settings_reset_trusted_certificates"
|
||||
android:summary="@string/app_settings_reset_trusted_certificates_summary"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/app_settings_debug">
|
||||
<SwitchPreferenceCompat
|
||||
android:key="log_to_file"
|
||||
android:title="@string/app_settings_log_to_file"
|
||||
android:summaryOn="@string/app_settings_log_to_file_on"
|
||||
android:summaryOff="@string/app_settings_log_to_file_off"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user