[Libreoffice-commits] online.git: android/app
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Apr 16 06:53:08 UTC 2019
android/app/src/main/AndroidManifest.xml | 5
android/app/src/main/java/org/libreoffice/androidapp/SettingsActivity.java | 57 ++++++++++
android/app/src/main/java/org/libreoffice/androidapp/SettingsListenerModel.java | 56 +++++++++
android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java | 42 +++----
android/app/src/main/res/values/arrays.xml | 53 +++++++++
android/app/src/main/res/values/integers.xml | 4
android/app/src/main/res/values/strings.xml | 21 +++
android/app/src/main/res/xml/libreoffice_preferences.xml | 41 +++++++
8 files changed, 256 insertions(+), 23 deletions(-)
New commits:
commit 7705d5893d10b148716efe4b7bd1bb17d44ee2be
Author: Florin Ciornei <florin.ciornei at collabora.com>
AuthorDate: Mon Apr 15 16:50:07 2019 +0200
Commit: Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Apr 16 08:52:48 2019 +0200
android: Port Settings from the old app
Change-Id: I283040c518f9a7deb3bd302bc9ed2d11ac560775
Reviewed-on: https://gerrit.libreoffice.org/70790
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index d13a27cd7..cb302929c 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -119,6 +119,11 @@
<activity
android:name=".ShowHTMLActivity"
android:label="@string/title_activity_show_html"></activity>
+ <activity
+ android:name=".SettingsActivity"
+ android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
+ android:label="@string/app_name_settings">
+ </activity>
</application>
</manifest>
\ No newline at end of file
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/SettingsActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/SettingsActivity.java
new file mode 100644
index 000000000..83701f194
--- /dev/null
+++ b/android/app/src/main/java/org/libreoffice/androidapp/SettingsActivity.java
@@ -0,0 +1,57 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.libreoffice.androidapp;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+
+public class SettingsActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Display the fragment as the main content.
+ getFragmentManager().beginTransaction()
+ .replace(android.R.id.content, new SettingsFragment())
+ .commit();
+ }
+
+ public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.libreoffice_preferences);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ getPreferenceScreen().getSharedPreferences()
+ .registerOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ getPreferenceScreen().getSharedPreferences()
+ .unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ SettingsListenerModel.getInstance().changePreferenceState(sharedPreferences, key);
+ if (key.equals("DISPLAY_LANGUAGE")) {
+ getActivity().recreate();
+ }
+ }
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/SettingsListenerModel.java b/android/app/src/main/java/org/libreoffice/androidapp/SettingsListenerModel.java
new file mode 100644
index 000000000..89bf93f91
--- /dev/null
+++ b/android/app/src/main/java/org/libreoffice/androidapp/SettingsListenerModel.java
@@ -0,0 +1,56 @@
+/*
+ *
+ * * This file is part of the LibreOffice project.
+ * * This Source Code Form is subject to the terms of the Mozilla Public
+ * * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+package org.libreoffice.androidapp;
+
+import android.content.SharedPreferences;
+
+public class SettingsListenerModel {
+
+ public interface OnSettingsPreferenceChangedListener {
+ void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key);
+ }
+
+ private static SettingsListenerModel mInstance;
+ private OnSettingsPreferenceChangedListener mListener;
+ private SharedPreferences sharedPreferences;
+ private String key;
+
+ private SettingsListenerModel() {}
+
+ public static SettingsListenerModel getInstance() {
+ if(mInstance == null) {
+ mInstance = new SettingsListenerModel();
+ }
+ return mInstance;
+ }
+
+ public void setListener(OnSettingsPreferenceChangedListener listener) {
+ mListener = listener;
+ }
+
+ public void changePreferenceState(SharedPreferences sharedPreferences, String key) {
+ if(mListener != null) {
+ this.sharedPreferences = sharedPreferences;
+ this.key = key;
+ notifyPreferenceChange(sharedPreferences, key);
+ }
+ }
+
+ public SharedPreferences getSharedPreferences() {
+ return sharedPreferences;
+ }
+
+ public String getKey(){
+ return key;
+ }
+
+ private void notifyPreferenceChange(SharedPreferences preferences, String key) {
+ mListener.settingsPreferenceChanged(preferences, key);
+ }
+}
diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 5c23799f8..0d9c65b46 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -60,6 +60,8 @@ import org.libreoffice.androidapp.LibreOfficeApplication;
import org.libreoffice.androidapp.LocaleHelper;
import org.libreoffice.androidapp.MainActivity;
import org.libreoffice.androidapp.R;
+import org.libreoffice.androidapp.SettingsActivity;
+import org.libreoffice.androidapp.SettingsListenerModel;
import org.libreoffice.androidapp.storage.DocumentProviderFactory;
import org.libreoffice.androidapp.storage.DocumentProviderSettingsActivity;
import org.libreoffice.androidapp.storage.IDocumentProvider;
@@ -98,7 +100,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
-public class LibreOfficeUIActivity extends AppCompatActivity implements /*SettingsListenerModel.OnSettingsPreferenceChangedListener,*/ View.OnClickListener {
+public class LibreOfficeUIActivity extends AppCompatActivity implements SettingsListenerModel.OnSettingsPreferenceChangedListener, View.OnClickListener {
private String LOGTAG = LibreOfficeUIActivity.class.getSimpleName();
private SharedPreferences prefs;
private int filterMode = FileUtilities.ALL;
@@ -176,8 +178,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
PreferenceManager.setDefaultValues(this, R.xml.documentprovider_preferences, false);
readPreferences();
- //TODO finish importing settings
-// SettingsListenerModel.getInstance().setListener(this);
+ SettingsListenerModel.getInstance().setListener(this);
// Registering the USB detect broadcast receiver
IntentFilter filter = new IntentFilter();
@@ -563,8 +564,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
// a different thread
try {
return document[0].getDocument();
- }
- catch (final RuntimeException e) {
+ } catch (final RuntimeException e) {
final Activity activity = LibreOfficeUIActivity.this;
activity.runOnUiThread(new Runnable() {
@Override
@@ -619,7 +619,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
layout.addView(warningText);
//check if the file exists when showing the create dialog
File tempFile = new File(currentDirectory.getUri().getPath() + input.getText().toString());
- warningText.setVisibility(tempFile.exists()?View.VISIBLE:View.GONE);
+ warningText.setVisibility(tempFile.exists() ? View.VISIBLE : View.GONE);
builder.setView(layout);
@@ -657,12 +657,16 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
@Override
public void onTextChanged(CharSequence c, int start, int before, int count) {
File tempFile = new File(currentDirectory.getUri().getPath() + input.getText().toString());
- warningText.setVisibility(tempFile.exists()?View.VISIBLE:View.GONE);
+ warningText.setVisibility(tempFile.exists() ? View.VISIBLE : View.GONE);
}
+
@Override
- public void afterTextChanged(Editable s) {}
+ public void afterTextChanged(Editable s) {
+ }
+
@Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
});
builder.show();
@@ -671,9 +675,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
/**
* Creates a new file at the specified path, by copying an empty template to that location.
- * @param path the complete path (including the file name) where the file will be created
- * @param extension is required to know what template should be used when creating the document
*
+ * @param path the complete path (including the file name) where the file will be created
+ * @param extension is required to know what template should be used when creating the document
* @return Uri of newFile if newFile is successfully created else null
*/
private Uri createNewFile(final String path, final String extension) {
@@ -683,7 +687,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
OutputStream newFileStream = null;
try {
//read the template and copy it to the new file
- templateFileStream = getAssets().open("templates/untitled"+extension);
+ templateFileStream = getAssets().open("templates/untitled" + extension);
newFileStream = new FileOutputStream(newFile);
byte[] buffer = new byte[1024];
int length;
@@ -918,8 +922,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
}
return true;
case R.id.action_settings:
- //TODO import the settings activity
-// startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
+ startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
return true;
default:
@@ -962,12 +965,11 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
}
- //TODO finish importing settings
-// @Override
-// public void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key) {
-// readPreferences();
-// refreshView();
-// }
+ @Override
+ public void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ readPreferences();
+ refreshView();
+ }
@Override
protected void onSaveInstanceState(Bundle outState) {
diff --git a/android/app/src/main/res/values/arrays.xml b/android/app/src/main/res/values/arrays.xml
index 365171568..f7bae3b3e 100644
--- a/android/app/src/main/res/values/arrays.xml
+++ b/android/app/src/main/res/values/arrays.xml
@@ -1,6 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- View Mode names,values -->
-
+<integer-array name="FilterTypeValues">
+ <item >-1</item>
+ <item >0</item>
+ <item >1</item>
+ <item >2</item>
+ </integer-array>
+ <string-array name="FilterTypeStringValues">
+ <item >-1</item>
+ <item >0</item>
+ <item >1</item>
+ <item >2</item>
+ </string-array>
+ <string-array name="SupportedLanguagesValues">
+ <item >en</item>
+ <item >tr</item>
+ </string-array>
+ <string-array name="SortModeStringValues">
+ <item >0</item>
+ <item >1</item>
+ <item >2</item>
+ <item >3</item>
+ <item >4</item>
+ <item >5</item>
+ </string-array>
+ <!-- View Mode names,values -->
+ <string-array name="ViewModeNames">
+ <item >@string/grid_view</item>
+ <item >@string/list_view</item>
+ </string-array>
+ <string-array name="ViewModeStringValues">
+ <item >0</item>
+ <item >1</item>
+ </string-array>
+ <string-array name="FilterTypeNames">
+ <item>@string/filter_everything</item>
+ <item>@string/filter_documents</item>
+ <item>@string/filter_spreadsheets</item>
+ <item>@string/filter_presentations</item>
+ <item>@string/filter_drawings</item>
+ </string-array>
+ <string-array name="SupportedLanguages">
+ <item>English</item>
+ <item>Turkçe</item>
+ </string-array>
+ <string-array name="SortModeNames">
+ <item >@string/sort_az</item>
+ <item >@string/sort_za</item>
+ <item >@string/sort_oldest</item>
+ <item >@string/sort_newest</item>
+ <item >@string/sort_largest</item>
+ <item >@string/sort_smallest</item>
+ </string-array>
</resources>
diff --git a/android/app/src/main/res/values/integers.xml b/android/app/src/main/res/values/integers.xml
index 0d2c4cc40..5f7fc625e 100644
--- a/android/app/src/main/res/values/integers.xml
+++ b/android/app/src/main/res/values/integers.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
-
-</resources>
\ No newline at end of file
+ <integer name="grid_view_integer">0</integer>
+</resources>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 5b94ca5c6..d371bece6 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -1,6 +1,8 @@
<resources>
<!--string name="app_name" definition is deliberately missing here, it is filled in in build.gradle.-->
+ <string name="app_name_settings">LibreOffice Viewer Settings</string>
+ <string name="app_about_name"><b>LibreOffice Viewer \'Beta\'</b></string>
<string name="app_version">Version: %1$s\nBuild ID: %2$s</string>
<string name="app_description">LibreOffice Viewer is a document viewer based on LibreOffice.</string>
<string name="app_credits">https://www.libreoffice.org</string>
@@ -12,6 +14,25 @@
<string name="file_creation_failed">File creation failed</string>
<string name="storage_permission_required">Storage permission is required</string>
+ <string name="list_view">List</string>
+ <string name="grid_view">Grid</string>
+ <string name="pref_category_explorer">File Explorer Settings</string>
+ <string name="pref_category_general">General</string>
+ <string name="pref_experimental_editing">Experimental Mode</string>
+ <string name="pref_experimental_editing_summary">Enable the experimental editing mode. Use at your own risk.</string>
+ <string name="pref_show_hidden_files">Hidden Files/Folders</string>
+ <string name="pref_show_hidden_files_summary">Enable to show hidden files/folders</string>
+ <string name="pref_developer_mode">Developer Mode</string>
+ <string name="pref_developer_mode_summary">Enable developer mode where you can send UNO commands within app. Use at your own risk.</string>
+ <string name="pref_sort_summary">Select how to order files: A-Z, by size or by date.</string>
+ <string name="pref_viewmode_summary">View files as a grid or in a list.</string>
+ <string name="pref_file_explorer_title">File explorer layout</string>
+ <string name="pref_sort_title">File Order</string>
+ <string name="pref_filter_title">Default File Filter</string>
+ <string name="pref_filter_summary">Set which file filter should be used by default.</string>
+ <string name="display_language">Display Language</string>
+ <string name="display_language_summary">Set the default display language</string>
+
<string name="about_license">Show License</string>
<string name="about_notice">Show Notice</string>
<string name="about_moreinfo">More Info</string>
diff --git a/android/app/src/main/res/xml/libreoffice_preferences.xml b/android/app/src/main/res/xml/libreoffice_preferences.xml
new file mode 100644
index 000000000..cd9104a93
--- /dev/null
+++ b/android/app/src/main/res/xml/libreoffice_preferences.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
+ <PreferenceCategory
+ android:title="@string/pref_category_explorer"
+ android:key="PREF_CATEGORY_EXPLORER">
+ <ListPreference
+ android:title="@string/pref_filter_title"
+ android:summary="@string/pref_filter_summary"
+ android:entries="@array/FilterTypeNames"
+ android:entryValues="@array/FilterTypeStringValues"
+ android:key="FILTER_MODE"/>
+ <ListPreference
+ android:summary="@string/pref_sort_summary"
+ android:key="SORT_MODE"
+ android:title="@string/pref_sort_title"
+ android:entries="@array/SortModeNames"
+ android:entryValues="@array/SortModeStringValues"/>
+ <ListPreference
+ android:entries="@array/ViewModeNames"
+ android:entryValues="@array/ViewModeStringValues"
+ android:defaultValue="@integer/grid_view_integer"
+ android:title="@string/pref_file_explorer_title"
+ android:key="EXPLORER_VIEW_TYPE"
+ android:summary="@string/pref_viewmode_summary" />
+
+ <ListPreference
+ android:title="@string/display_language"
+ android:summary="@string/display_language_summary"
+ android:entries="@array/SupportedLanguages"
+ android:entryValues="@array/SupportedLanguagesValues"
+ android:key="DISPLAY_LANGUAGE"
+ />
+
+ <CheckBoxPreference
+ android:title="@string/pref_show_hidden_files"
+ android:key="ENABLE_SHOW_HIDDEN_FILES"
+ android:summary="@string/pref_show_hidden_files_summary"
+ android:defaultValue="false" />
+ </PreferenceCategory>
+
+</PreferenceScreen>
More information about the Libreoffice-commits
mailing list