mirror of
https://github.com/sismics/docs.git
synced 2024-11-26 07:34:55 +01:00
Android: settings activity
This commit is contained in:
parent
5662c080d6
commit
a181eac9a5
@ -38,6 +38,10 @@
|
|||||||
android:name=".activity.DocumentEditActivity"
|
android:name=".activity.DocumentEditActivity"
|
||||||
android:label="@string/new_document">
|
android:label="@string/new_document">
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".activity.SettingsActivity"
|
||||||
|
android:label="@string/settings">
|
||||||
|
</activity>
|
||||||
<provider android:name=".provider.RecentSuggestionsProvider"
|
<provider android:name=".provider.RecentSuggestionsProvider"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:authorities="com.sismics.docs.provider.RecentSuggestionsProvider" />
|
android:authorities="com.sismics.docs.provider.RecentSuggestionsProvider" />
|
||||||
|
@ -21,7 +21,6 @@ public class MainApplication extends Application {
|
|||||||
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
|
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), json);
|
||||||
|
|
||||||
// TODO Fullscreen preview
|
// TODO Fullscreen preview
|
||||||
// TODO Caching preferences
|
|
||||||
// TODO Documents adding/editing
|
// TODO Documents adding/editing
|
||||||
// TODO Files adding/deleting
|
// TODO Files adding/deleting
|
||||||
|
|
||||||
|
@ -27,10 +27,8 @@ public class DocumentEditActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
// Setup the activity
|
// Setup the activity
|
||||||
setContentView(R.layout.document_edit_activity);
|
setContentView(R.layout.document_edit_activity);
|
||||||
if (getSupportActionBar() != null) {
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
}
|
|
||||||
|
|
||||||
Spinner languageSpinner = (Spinner) findViewById(R.id.languageSpinner);
|
Spinner languageSpinner = (Spinner) findViewById(R.id.languageSpinner);
|
||||||
languageSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item,
|
languageSpinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item,
|
||||||
|
@ -92,10 +92,8 @@ public class DocumentViewActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
// Setup the activity
|
// Setup the activity
|
||||||
setContentView(R.layout.document_view_activity);
|
setContentView(R.layout.document_view_activity);
|
||||||
if (getSupportActionBar() != null) {
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
}
|
|
||||||
|
|
||||||
// Grab the document
|
// Grab the document
|
||||||
refreshDocument(document);
|
refreshDocument(document);
|
||||||
|
@ -18,6 +18,7 @@ import android.widget.AdapterView;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.androidquery.util.AQUtility;
|
||||||
import com.sismics.docs.R;
|
import com.sismics.docs.R;
|
||||||
import com.sismics.docs.adapter.TagListAdapter;
|
import com.sismics.docs.adapter.TagListAdapter;
|
||||||
import com.sismics.docs.event.SearchEvent;
|
import com.sismics.docs.event.SearchEvent;
|
||||||
@ -25,6 +26,7 @@ import com.sismics.docs.listener.JsonHttpResponseHandler;
|
|||||||
import com.sismics.docs.model.application.ApplicationContext;
|
import com.sismics.docs.model.application.ApplicationContext;
|
||||||
import com.sismics.docs.provider.RecentSuggestionsProvider;
|
import com.sismics.docs.provider.RecentSuggestionsProvider;
|
||||||
import com.sismics.docs.resource.TagResource;
|
import com.sismics.docs.resource.TagResource;
|
||||||
|
import com.sismics.docs.resource.UserResource;
|
||||||
import com.sismics.docs.util.PreferenceUtil;
|
import com.sismics.docs.util.PreferenceUtil;
|
||||||
|
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
@ -59,10 +61,8 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
// Enable ActionBar app icon to behave as action to toggle nav drawer
|
// Enable ActionBar app icon to behave as action to toggle nav drawer
|
||||||
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
if (getSupportActionBar() != null) {
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
}
|
|
||||||
|
|
||||||
// ActionBarDrawerToggle ties together the the proper interactions
|
// ActionBarDrawerToggle ties together the the proper interactions
|
||||||
// between the sliding drawer and the action bar app icon
|
// between the sliding drawer and the action bar app icon
|
||||||
@ -139,6 +139,22 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
case R.id.logout:
|
||||||
|
UserResource.logout(getApplicationContext(), new JsonHttpResponseHandler() {
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
// Force logout in all cases, so the user is not stuck in case of network error
|
||||||
|
ApplicationContext.getInstance().setUserInfo(getApplicationContext(), null);
|
||||||
|
startActivity(new Intent(MainActivity.this, LoginActivity.class));
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.settings:
|
||||||
|
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
|
||||||
|
return true;
|
||||||
|
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
// The action bar home/up action should open or close the drawer.
|
// The action bar home/up action should open or close the drawer.
|
||||||
// ActionBarDrawerToggle will take care of this.
|
// ActionBarDrawerToggle will take care of this.
|
||||||
@ -233,4 +249,13 @@ public class MainActivity extends ActionBarActivity {
|
|||||||
searchView.clearFocus();
|
searchView.clearFocus();
|
||||||
drawerLayout.closeDrawers();
|
drawerLayout.closeDrawers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if(isTaskRoot()) {
|
||||||
|
int cacheSizeMb = PreferenceUtil.getIntegerPreference(this, PreferenceUtil.PREF_CACHE_SIZE, 10);
|
||||||
|
AQUtility.cleanCacheAsync(this, cacheSizeMb * 1000000, cacheSizeMb * 1000000);
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.sismics.docs.activity;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.app.ActionBarActivity;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import com.sismics.docs.fragment.SettingsFragment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings activity.
|
||||||
|
*
|
||||||
|
* @author bgamard.
|
||||||
|
*/
|
||||||
|
public class SettingsActivity extends ActionBarActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
|
|
||||||
|
// Display the fragment as the main content.
|
||||||
|
getFragmentManager().beginTransaction()
|
||||||
|
.replace(android.R.id.content, new SettingsFragment())
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package com.sismics.docs.fragment;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.SearchRecentSuggestions;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.androidquery.util.AQUtility;
|
||||||
|
import com.sismics.docs.R;
|
||||||
|
import com.sismics.docs.provider.RecentSuggestionsProvider;
|
||||||
|
import com.sismics.docs.util.ApplicationUtil;
|
||||||
|
import com.sismics.docs.util.PreferenceUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings fragment.
|
||||||
|
*
|
||||||
|
* @author bgamard.
|
||||||
|
*/
|
||||||
|
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Load the preferences from an XML resource
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
|
// Initialize summaries
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
|
onSharedPreferenceChanged(sharedPreferences, PreferenceUtil.PREF_CACHE_SIZE);
|
||||||
|
|
||||||
|
|
||||||
|
// Handle clearing the recent search history
|
||||||
|
Preference clearHistoryPref = findPreference("pref_clearHistory");
|
||||||
|
clearHistoryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
SearchRecentSuggestions suggestions = new SearchRecentSuggestions(getActivity(),
|
||||||
|
RecentSuggestionsProvider.AUTHORITY, RecentSuggestionsProvider.MODE);
|
||||||
|
suggestions.clearHistory();
|
||||||
|
Toast.makeText(getActivity(), R.string.pref_clear_history_success, Toast.LENGTH_LONG).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle clearing the cache
|
||||||
|
Preference clearCachePref = findPreference("pref_clearCache");
|
||||||
|
clearCachePref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
AQUtility.cleanCacheAsync(getActivity());
|
||||||
|
Toast.makeText(getActivity(), R.string.pref_clear_cache_success, Toast.LENGTH_LONG).show();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize static text preferences
|
||||||
|
Preference versionPref = findPreference("pref_version");
|
||||||
|
versionPref.setSummary(getString(R.string.version) + " " + ApplicationUtil.getVersionName(getActivity())
|
||||||
|
+ " | " + getString(R.string.build) + " " + ApplicationUtil.getVersionCode(getActivity()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
Preference pref = findPreference(key);
|
||||||
|
if (pref instanceof ListPreference) {
|
||||||
|
ListPreference listPref = (ListPreference) pref;
|
||||||
|
pref.setSummary(listPref.getEntry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ public class PreferenceUtil {
|
|||||||
public static final String PREF_CACHED_USER_INFO_JSON = "pref_cachedUserInfoJson";
|
public static final String PREF_CACHED_USER_INFO_JSON = "pref_cachedUserInfoJson";
|
||||||
public static final String PREF_CACHED_TAGS_JSON = "pref_cachedTagsJson";
|
public static final String PREF_CACHED_TAGS_JSON = "pref_cachedTagsJson";
|
||||||
public static final String PREF_SERVER_URL = "pref_ServerUrl";
|
public static final String PREF_SERVER_URL = "pref_ServerUrl";
|
||||||
|
public static final String PREF_CACHE_SIZE = "pref_cacheSize";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a preference of boolean type.
|
* Returns a preference of boolean type.
|
||||||
|
@ -1,8 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<item android:id="@+id/action_search"
|
<item android:id="@+id/action_search"
|
||||||
android:title="@string/action_search"
|
android:title="@string/action_search"
|
||||||
app:showAsAction="ifRoom"
|
app:showAsAction="ifRoom"
|
||||||
app:actionViewClass="android.support.v7.widget.SearchView" />
|
app:actionViewClass="android.support.v7.widget.SearchView" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/settings"
|
||||||
|
app:showAsAction="collapseActionView"
|
||||||
|
android:title="@string/settings">
|
||||||
|
</item>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/logout"
|
||||||
|
app:showAsAction="collapseActionView"
|
||||||
|
android:title="@string/logout">
|
||||||
|
</item>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
18
docs-android/app/src/main/res/values/arrays.xml
Normal file
18
docs-android/app/src/main/res/values/arrays.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
|
||||||
|
<string-array name="cacheSizes">
|
||||||
|
<item>5MB</item>
|
||||||
|
<item>10MB</item>
|
||||||
|
<item>30MB</item>
|
||||||
|
<item>100MB</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="cacheSizesValues">
|
||||||
|
<item>5</item>
|
||||||
|
<item>10</item>
|
||||||
|
<item>30</item>
|
||||||
|
<item>100</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
</resources>
|
@ -56,5 +56,21 @@
|
|||||||
<string name="send_share_to">Send share link to</string>
|
<string name="send_share_to">Send share link to</string>
|
||||||
<string name="upload_file">Upload a file</string>
|
<string name="upload_file">Upload a file</string>
|
||||||
<string name="upload_from">Upload a file from</string>
|
<string name="upload_from">Upload a file from</string>
|
||||||
|
<string name="settings">Settings</string>
|
||||||
|
<string name="logout">Sign Out</string>
|
||||||
|
<string name="version">Version</string>
|
||||||
|
<string name="build">Build</string>
|
||||||
|
<string name="pref_advanced_category">Advanced settings</string>
|
||||||
|
<string name="pref_about_category">About</string>
|
||||||
|
<string name="pref_github">GitHub</string>
|
||||||
|
<string name="pref_issue">Report a bug</string>
|
||||||
|
<string name="pref_clear_cache_title">Clear cache</string>
|
||||||
|
<string name="pref_clear_cache_summary">Cleanup cached files</string>
|
||||||
|
<string name="pref_clear_cache_success">Cache cleared</string>
|
||||||
|
<string name="pref_clear_history_title">Clear search history</string>
|
||||||
|
<string name="pref_clear_history_summary">Wipe the recent search suggestions</string>
|
||||||
|
<string name="pref_clear_history_success">Search history cleared</string>
|
||||||
|
<string name="pref_cache_size">Cache size</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -1,3 +1,58 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen>
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_advanced_category"
|
||||||
|
android:title="@string/pref_advanced_category">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="pref_cacheSize"
|
||||||
|
android:title="@string/pref_cache_size"
|
||||||
|
android:dialogTitle="@string/pref_cache_size"
|
||||||
|
android:entries="@array/cacheSizes"
|
||||||
|
android:entryValues="@array/cacheSizesValues"
|
||||||
|
android:defaultValue="10"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_clearCache"
|
||||||
|
android:title="@string/pref_clear_cache_title"
|
||||||
|
android:summary="@string/pref_clear_cache_summary">
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_clearHistory"
|
||||||
|
android:title="@string/pref_clear_history_title"
|
||||||
|
android:summary="@string/pref_clear_history_summary">
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_about_category"
|
||||||
|
android:title="@string/pref_about_category">
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_github"
|
||||||
|
android:title="@string/pref_github"
|
||||||
|
android:summary="github.com/sismics/docs">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:data="https://github.com/sismics/docs"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_issue"
|
||||||
|
android:title="@string/pref_issue"
|
||||||
|
android:summary="github.com/sismics/docs/issues">
|
||||||
|
<intent
|
||||||
|
android:action="android.intent.action.VIEW"
|
||||||
|
android:data="https://github.com/sismics/docs/issues"/>
|
||||||
|
</Preference>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_version"
|
||||||
|
android:title="@string/app_name"/>
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user