Rework theming a bit to partially fix dark mode on dialogs

Dark mode is still not great, but at least it's a little less broken now
This commit is contained in:
Alexander Bakker 2018-05-11 15:12:36 +02:00
parent 3c2f62de26
commit 7be5d08a60
15 changed files with 79 additions and 132 deletions

View file

@ -15,7 +15,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
tools:replace="android:theme"
android:theme="@style/AppTheme.Default.NoActionBar">
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name=".ui.MainActivity"
android:label="@string/app_name"
@ -36,7 +36,7 @@
<activity
android:name=".ui.EditProfileActivity"
android:label="Edit profile"
android:theme="@style/AppTheme.Default.TransparentActionBar">
android:theme="@style/AppTheme.TransparentActionBar">
</activity>
<activity
android:name=".ui.IntroActivity"
@ -51,7 +51,8 @@
</activity>
<activity
android:name=".ui.SlotManagerActivity"
android:label="Manage key slots">
android:label="Manage key slots"
android:theme="@style/AppTheme.TransparentActionBar">
</activity>
</application>
</manifest>

View file

@ -8,6 +8,7 @@ import me.impy.aegis.AegisApplication;
public abstract class AegisActivity extends AppCompatActivity {
private AegisApplication _app;
private boolean _darkMode;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -18,13 +19,17 @@ public abstract class AegisActivity extends AppCompatActivity {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
// set the theme
boolean darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
setPreferredTheme(darkMode);
_darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
setPreferredTheme(_darkMode);
}
protected AegisApplication getApp() {
return _app;
}
protected boolean isDark() {
return _darkMode;
}
protected abstract void setPreferredTheme(boolean darkMode);
}

View file

@ -107,7 +107,7 @@ public class AuthActivity extends AegisActivity implements FingerprintUiHelper.C
if (darkMode) {
setTheme(R.style.AppTheme_Dark);
} else {
setTheme(R.style.AppTheme_Default);
setTheme(R.style.AppTheme);
}
}

View file

@ -16,7 +16,6 @@ import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ExpandableListAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
@ -54,8 +53,6 @@ public class EditProfileActivity extends AegisActivity {
private RelativeLayout _advancedSettingsHeader;
private RelativeLayout _advancedSettings;
int _dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -122,12 +119,12 @@ public class EditProfileActivity extends AegisActivity {
});
_advancedSettingsHeader.setOnClickListener(v -> {
OpenAdvancedSettings();
openAdvancedSettings();
});
// Automatically open advanced settings since 'Secret' is required.
if(_isNew){
OpenAdvancedSettings();
openAdvancedSettings();
}
}
@ -158,15 +155,13 @@ public class EditProfileActivity extends AegisActivity {
@Override
protected void setPreferredTheme(boolean darkMode) {
if (darkMode) {
_dialogStyle = android.R.style.Theme_Material_Dialog_NoActionBar;
setTheme(R.style.AppTheme_Dark_TransparentActionBar);
} else {
_dialogStyle = android.R.style.Theme_Material_Light_Dialog_NoActionBar;
setTheme(R.style.AppTheme_Default_TransparentActionBar);
setTheme(R.style.AppTheme_TransparentActionBar);
}
}
private void OpenAdvancedSettings() {
private void openAdvancedSettings() {
Animation fadeOut = new AlphaAnimation(1, 0); // the 1, 0 here notifies that we want the opacity to go from opaque (1) to transparent (0)
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(220); // Fadeout duration should be 1000 milli seconds
@ -219,7 +214,7 @@ public class EditProfileActivity extends AegisActivity {
return;
}
new AlertDialog.Builder(this, _dialogStyle)
new AlertDialog.Builder(this)
.setTitle("Discard changes?")
.setMessage("Your changes have not been saved")
.setPositiveButton(R.string.save, (dialog, which) -> onSave())

View file

@ -12,6 +12,7 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
@ -47,7 +48,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
private DatabaseManager _db;
private KeyProfileView _keyProfileView;
private boolean _darkMode = false;
private Menu _menu;
private FloatingActionsMenu _fabMenu;
@ -59,7 +59,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
// set up the main view
setContentView(R.layout.activity_main);
setSupportActionBar(findViewById(R.id.toolbar));
// set up the key profile view
_keyProfileView = (KeyProfileView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
@ -140,11 +139,10 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
@Override
protected void setPreferredTheme(boolean darkMode) {
if (darkMode) {
setTheme(R.style.AppTheme_Dark_NoActionBar);
} else if (_darkMode) {
setTheme(R.style.AppTheme_Default_NoActionBar);
setTheme(R.style.AppTheme_Dark);
} else {
setTheme(R.style.AppTheme);
}
_darkMode = darkMode;
}
@Override
@ -346,7 +344,7 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
super.onResume();
boolean darkMode = _app.getPreferences().getBoolean("pref_dark_mode", false);
if (darkMode != _darkMode) {
if (darkMode != isDark()) {
setPreferredTheme(darkMode);
recreate();
}
@ -356,39 +354,34 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
}
private BottomSheetDialog createBottomSheet(final KeyProfile profile) {
View bottomSheetView = getLayoutInflater().inflate(R.layout.bottom_sheet_edit_profile, null);
LinearLayout copyLayout = bottomSheetView.findViewById(R.id.copy_button);
LinearLayout deleteLayout = bottomSheetView.findViewById(R.id.delete_button);
LinearLayout editLayout = bottomSheetView.findViewById(R.id.edit_button);
bottomSheetView.findViewById(R.id.edit_button);
BottomSheetDialog bottomDialog = new BottomSheetDialog(this);
bottomDialog.setContentView(bottomSheetView);
bottomDialog.setCancelable(true);
bottomDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
BottomSheetDialog dialog = new BottomSheetDialog(this);
dialog.setContentView(R.layout.bottom_sheet_edit_profile);
dialog.setCancelable(true);
dialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
bottomDialog.show();
dialog.show();
copyLayout.setOnClickListener(view -> {
bottomDialog.dismiss();
dialog.findViewById(R.id.copy_button).setOnClickListener(view -> {
dialog.dismiss();
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("text/plain", profile.getCode());
clipboard.setPrimaryClip(clip);
Toast.makeText(this.getApplicationContext(), "Code copied to the clipboard", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Code copied to the clipboard", Toast.LENGTH_SHORT).show();
});
deleteLayout.setOnClickListener(view -> {
bottomDialog.dismiss();
Dialogs.showDeleteEntryDialog(this, (dialog, which) -> {
dialog.findViewById(R.id.delete_button).setOnClickListener(view -> {
dialog.dismiss();
Dialogs.showDeleteEntryDialog(this, (d, which) -> {
deleteProfile(profile);
});
});
editLayout.setOnClickListener(view -> {
bottomDialog.dismiss();
dialog.findViewById(R.id.edit_button).setOnClickListener(view -> {
dialog.dismiss();
startEditProfileActivity(CODE_EDIT_KEYINFO, profile, false);
});
return bottomDialog;
return dialog;
}
private void deleteProfile(KeyProfile profile) {

View file

@ -21,7 +21,7 @@ public class PreferencesActivity extends AegisActivity {
if (darkMode) {
setTheme(R.style.AppTheme_Dark);
} else {
setTheme(R.style.AppTheme_Default);
setTheme(R.style.AppTheme);
}
}

View file

@ -36,10 +36,8 @@ public class SlotManagerActivity extends AegisActivity implements SlotAdapter.Li
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set up the view
setContentView(R.layout.activity_slots);
setSupportActionBar(findViewById(R.id.toolbar));
ActionBar bar = getSupportActionBar();
bar.setHomeAsUpIndicator(R.drawable.ic_close);
bar.setDisplayHomeAsUpEnabled(true);
@ -105,9 +103,9 @@ public class SlotManagerActivity extends AegisActivity implements SlotAdapter.Li
@Override
protected void setPreferredTheme(boolean darkMode) {
if (darkMode) {
setTheme(R.style.AppTheme_Dark_NoActionBar);
setTheme(R.style.AppTheme_Dark);
} else {
setTheme(R.style.AppTheme_Default_NoActionBar);
setTheme(R.style.AppTheme);
}
}

View file

@ -1,6 +1,6 @@
package me.impy.aegis.ui.dialogs;
import android.content.Context;
import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
@ -9,8 +9,8 @@ public class Dialogs {
}
public static AlertDialog showDeleteEntryDialog(Context context, DialogInterface.OnClickListener onDelete) {
return new AlertDialog.Builder(context)
public static AlertDialog showDeleteEntryDialog(Activity activity, DialogInterface.OnClickListener onDelete) {
return new AlertDialog.Builder(activity)
.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, onDelete)

View file

@ -88,7 +88,8 @@
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="14dp"
android:src="@drawable/ic_keyboard_arrow_down_black_24dp" />
android:src="@drawable/ic_keyboard_arrow_down_black_24dp"
android:tint="#7f7f7f"/>
<TextView
android:id="@+id/accordian_title"
@ -99,7 +100,6 @@
android:layout_toEndOf="@+id/down_btn"
android:padding="16dp"
android:text="Advanced"
android:textColor="#333"
android:textStyle="bold" />
</RelativeLayout>

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -7,20 +8,6 @@
android:fitsSystemWindows="true"
tools:context="me.impy.aegis.ui.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<fragment
android:name="me.impy.aegis.ui.views.KeyProfileView"
android:id="@+id/key_profiles"

View file

@ -7,19 +7,7 @@
android:fitsSystemWindows="true"
tools:context="me.impy.aegis.ui.SlotManagerActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"

View file

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
@ -8,12 +10,13 @@
android:padding="16dp"
android:id="@+id/copy_button"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_content_copy_black_24dp"/>
<TextView
android:layout_width="wrap_content"
@ -26,13 +29,14 @@
android:layout_height="wrap_content"
android:padding="16dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:id="@+id/edit_button"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_create_black_24dp"/>
<TextView
android:layout_width="wrap_content"
@ -46,12 +50,13 @@
android:padding="16dp"
android:id="@+id/delete_button"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:src="@drawable/ic_delete_black_24dp"/>
<TextView
android:layout_width="wrap_content"
@ -60,5 +65,4 @@
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -35,7 +35,7 @@
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Slot name"
android:id="@+id/text_slot_name"
android:textColor="@color/primary_text"/>
android:textColor="?android:attr/textColorPrimary"/>
<TextView
android:id="@+id/text_slot_used"

View file

@ -18,6 +18,8 @@
<color name="colorSwirlPrimary">#434343</color>
<color name="colorSwirlError">#FF5252</color>
<color name="colorSwirlPrimaryDark">#FFFFFF</color>
<color name="colorSwirlErrorDark">#FF5252</color>
<color name="code_primary_text">#0d47a1</color>
<color name="code_primary_text_dark">#ffffff</color>

View file

@ -1,29 +1,5 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="swirl_ridgeColor">?android:attr/textColorSecondary</item>
<item name="swirl_errorColor">?android:attr/colorAccent</item>
<!-- <item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>-->
</style>
<style name="AppTheme.TransparentActionBar">
<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="AppTheme.Fullscreen" parent="AppTheme.TransparentActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="ThemeActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:background">@null</item>
<!-- Support library compatibility -->
@ -37,23 +13,11 @@
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="EditTextTintTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<!--<item name="colorAccent">@color/</item>-->
</style>
<style name="AppTheme.Default">
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">@color/background</item>
<item name="swirl_ridgeColor">@color/colorSwirlPrimary</item>
<item name="swirl_errorColor">@color/colorSwirlError</item>
<item name="android:textColorPrimary">@color/primary_text</item>
<item name="android:textColorSecondary">@color/secondary_text</item>
@ -66,40 +30,50 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="swirl_ridgeColor">@color/colorSwirlPrimary</item>
<item name="swirl_errorColor">@color/colorSwirlError</item>
</style>
<style name="AppTheme.Default.NoActionBar" parent="AppTheme.Default">
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Default.TransparentActionBar" parent="AppTheme.Default">
<style name="AppTheme.TransparentActionBar">
<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/ThemeActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<style name="AppTheme.Fullscreen" parent="AppTheme.TransparentActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>
<style name="AppTheme.Dark">
<style name="AppTheme.Dark" parent="Theme.AppCompat">
<item name="android:windowBackground">@color/background_dark</item>
<item name="android:textColorPrimary">@color/primary_text_dark</item>
<item name="android:textColorSecondary">@color/secondary_text_dark</item>
<item name="primaryText">@color/primary_text_dark</item>
<item name="secondaryText">@color/secondary_text_dark</item>
<item name="background">@color/background_dark</item>
<item name="cardBackground">@color/card_background_dark</item>
<item name="codePrimaryText">@color/code_primary_text_dark</item>
<item name="android:textColorHint">@color/secondary_text</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorHint">@color/secondary_text</item>
<item name="swirl_ridgeColor">@color/colorSwirlPrimaryDark</item>
<item name="swirl_errorColor">@color/colorSwirlErrorDark</item>
</style>
<style name="AppTheme.Dark.NoActionBar" parent="AppTheme.Dark">
<style name="AppTheme.Dark.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.Dark.TransparentActionBar" parent="AppTheme.Dark">
<style name="AppTheme.Dark.TransparentActionBar">
<item name="android:actionBarStyle">@style/ThemeActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->