android: enable dark mode in documents
Signed-off-by: Rash419 <rashesh.padia@collabora.com> Change-Id: I108601f78f4d7bbf704b5f5f89b20c8f8a597355
This commit is contained in:
parent
c2192b4a67
commit
5dcce1965e
3 changed files with 29 additions and 0 deletions
|
@ -17,6 +17,7 @@ import androidx.appcompat.app.AppCompatDelegate;
|
|||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import org.libreoffice.androidapp.ui.LibreOfficeUIActivity;
|
||||
import org.libreoffice.androidlib.LOActivity;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
|
@ -86,6 +87,7 @@ public class SettingsActivity extends AppCompatActivity {
|
|||
}
|
||||
AppCompatDelegate.setDefaultNightMode(dayNightMode);
|
||||
prefs.edit().putInt(LibreOfficeUIActivity.NIGHT_MODE_KEY, dayNightMode).commit();
|
||||
prefs.edit().putInt(LOActivity.NIGHT_MODE_KEY, dayNightMode).commit();
|
||||
getActivity().recreate();
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import android.content.pm.ApplicationInfo;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
|
@ -74,6 +75,7 @@ import java.util.Map;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
@ -96,6 +98,7 @@ public class LOActivity extends AppCompatActivity {
|
|||
private static final String CLIPBOARD_COOL_SIGNATURE = "cool-clip-magic-4a22437e49a8-";
|
||||
public static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENTS_LIST";
|
||||
private static String USER_NAME_KEY = "USER_NAME";
|
||||
public static final String NIGHT_MODE_KEY = "NIGHT_MODE";
|
||||
|
||||
private File mTempFile = null;
|
||||
|
||||
|
@ -858,6 +861,11 @@ public class LOActivity extends AppCompatActivity {
|
|||
|
||||
if (isLargeScreen() && !isChromeOS())
|
||||
finalUrlToLoad += "&userinterfacemode=notebookbar";
|
||||
|
||||
if(isDarkMode()) {
|
||||
finalUrlToLoad += "&darkTheme=true";
|
||||
}
|
||||
|
||||
// load the page
|
||||
mWebView.loadUrl(finalUrlToLoad);
|
||||
|
||||
|
@ -866,6 +874,21 @@ public class LOActivity extends AppCompatActivity {
|
|||
loadDocumentMillis = android.os.SystemClock.uptimeMillis();
|
||||
}
|
||||
|
||||
private boolean isDarkMode() {
|
||||
SharedPreferences recentPrefs = getSharedPreferences(EXPLORER_PREFS_KEY, MODE_PRIVATE);
|
||||
int mode = recentPrefs.getInt(NIGHT_MODE_KEY, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
||||
switch (mode) {
|
||||
case -1:
|
||||
int darkModeFlag = getBaseContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
return darkModeFlag == Configuration.UI_MODE_NIGHT_YES;
|
||||
case 1:
|
||||
return false;
|
||||
case 2:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("androidapp");
|
||||
}
|
||||
|
|
|
@ -396,6 +396,10 @@ m4_ifelse(IOSAPP,[true],
|
|||
m4_ifelse(ANDROIDAPP,[true],
|
||||
[window.userInterfaceMode = window.getParameterByName('userinterfacemode');])
|
||||
|
||||
m4_ifelse(ANDROIDAPP,[true],
|
||||
[var darkTheme = window.getParameterByName('darkTheme');
|
||||
if (darkTheme) {window.uiDefaults = {'darkTheme': true};}])
|
||||
|
||||
m4_ifelse(EMSCRIPTENAPP,[true],
|
||||
[window.userInterfaceMode = 'notebookbar';])
|
||||
|
||||
|
|
Loading…
Reference in a new issue