Skip to content

Commit

Permalink
Refactor Light Theme Capter I, implements #879 (#971)
Browse files Browse the repository at this point in the history
This is an initial redesign and refactoring of the light theme. This also prepares for a future dark theme.
The new theme was separated into a new module so we can share it among modules.
  • Loading branch information
dmfs committed Feb 6, 2021
1 parent 4e96efe commit bcc8a32
Show file tree
Hide file tree
Showing 56 changed files with 727 additions and 782 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -14,7 +14,7 @@ android:
- platform-tools
- tools
- build-tools-28.0.3
- build-tools-29.0.2
- build-tools-29.0.3
- android-24
- android-28
- android-29
Expand Down
6 changes: 3 additions & 3 deletions dependencies.gradle
Expand Up @@ -4,9 +4,9 @@ def androidx_test_runner_version = '1.1.1'

ext.deps = [
// Support & Google libraries
support_appcompat : 'androidx.appcompat:appcompat:1.0.2',
support_annotations: 'androidx.annotation:annotation:1.0.0',
support_design : 'com.google.android.material:material:1.0.0',
support_appcompat : 'androidx.appcompat:appcompat:1.2.0',
support_annotations: 'androidx.annotation:annotation:1.1.0',
support_design : 'com.google.android.material:material:1.2.1',
android_dashclock : 'com.google.android.apps.dashclock:dashclock-api:2.0.0',

// dmfs
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,5 +1,5 @@
COMPILE_SDK_VERSION=29
MIN_SDK_VERSION=19
MIN_SDK_VERSION=21
TARGET_SDK_VERSION=29
VERSION_OVERRIDE=0
android.enableJetifier=true
Expand Down
1 change: 1 addition & 0 deletions opentasks-theme/.gitignore
@@ -0,0 +1 @@
/build
49 changes: 49 additions & 0 deletions opentasks-theme/build.gradle
@@ -0,0 +1,49 @@
/*
* Copyright 2021 dmfs GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id 'com.android.library'
}

android {
compileSdkVersion COMPILE_SDK_VERSION.toInteger()
buildToolsVersion "29.0.3"

defaultConfig {
minSdkVersion MIN_SDK_VERSION
targetSdkVersion TARGET_SDK_VERSION

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
}
4 changes: 4 additions & 0 deletions opentasks-theme/src/main/AndroidManifest.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.dmfs.android.sync.opentasks_theme">

</manifest>
13 changes: 13 additions & 0 deletions opentasks-theme/src/main/res/values-v23/theme_light.xml
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>

<style name="OpenTasks_BaseTheme.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:statusBarColor">#ffffffff</item>
</style>

</resources>
17 changes: 17 additions & 0 deletions opentasks-theme/src/main/res/values/attrs.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<attr name="colorHighPriority"
format="color" />
<attr name="colorMediumPriority"
format="color" />
<attr name="colorLowPriority"
format="color" />

<attr name="colorError"
format="color" />

<attr name="colorWarning"
format="color" />

</resources>
31 changes: 31 additions & 0 deletions opentasks-theme/src/main/res/values/colors.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Our primary color - a nice shade of teal -->
<color name="primary">#009688</color>
<color name="primary_dark">#00796B</color>
<color name="secondary">#ff5722</color>
<color name="secondary_variant">#ff5722</color>

<!-- material colors -->

<!-- green -->
<color name="material_green_500">#4caf50</color>

<!-- red -->
<color name="material_red_500">#f44336</color>
<color name="material_red_700">#d32f2f</color>
<color name="material_red_900">#b71c1c</color>

<!-- teal -->
<color name="material_teal_500">#009688</color>
<color name="material_teal_700">#00796B</color>

<!-- amber -->
<color name="material_amber_500">#ffc107</color>

<!-- deep orange -->
<color name="material_deep_orange_500">#ff5722</color>
<color name="material_deep_orange_900">#bf360c</color>

</resources>
14 changes: 14 additions & 0 deletions opentasks-theme/src/main/res/values/theme.xml
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>

<!-- This sets the default theme to light -->

<style name="OpenTasks_Theme.Default"
parent="OpenTasks_Theme.Light" />


<style name="OpenTasks_Theme.Default.Dialog"
parent="OpenTasks_BaseTheme.Light.Dialog" />

</resources>
62 changes: 62 additions & 0 deletions opentasks-theme/src/main/res/values/theme_light.xml
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>

<!-- The default Light theme. Use this as the parent of your theme to customize it. -->
<style name="OpenTasks_Theme.Light"
parent="OpenTasks_BaseTheme.Light.NoActionBar" />

<style name="OpenTasks_BaseTheme.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#ffd0d0d0</item>
</style>

<style name="OpenTasks_BaseTheme.Light"
parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">?attr/colorSecondary</item>
<item name="colorSecondary">@color/secondary</item>
<item name="colorSecondaryVariant">@color/secondary_variant</item>

<item name="colorHighPriority">@color/material_red_700</item>
<item name="colorMediumPriority">@color/material_amber_500</item>
<item name="colorLowPriority">@color/material_green_500</item>

<item name="colorError">@color/material_red_900</item>
<item name="colorWarning">@color/material_deep_orange_900</item>

<item name="tabIconTint">?attr/colorPrimary</item>
<item name="tabIndicatorColor">?attr/colorPrimary</item>

<item name="android:scrollbarTrackVertical">@null</item>
<item name="android:scrollbarSize">2dp</item>

</style>

<!-- TODO: what's the correct way of sharing the details of the themes? -->
<style name="OpenTasks_BaseTheme.Light.Dialog"
parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimary">@color/material_teal_500</item>
<item name="colorPrimaryDark">@color/material_teal_700</item>
<item name="colorAccent">?attr/colorSecondary</item>
<item name="colorSecondary">@color/material_deep_orange_500</item>
<item name="colorSecondaryVariant">@color/material_deep_orange_500</item>

<item name="colorHighPriority">@color/material_red_700</item>
<item name="colorMediumPriority">@color/material_amber_500</item>
<item name="colorLowPriority">@color/material_green_500</item>

<item name="colorError">@color/material_red_900</item>
<item name="colorWarning">@color/material_deep_orange_900</item>

<item name="tabIconTint">?attr/colorPrimary</item>
<item name="tabIndicatorColor">?attr/colorPrimary</item>

<item name="android:scrollbarTrackVertical">@null</item>
<item name="android:scrollbarSize">2dp</item>
</style>

</resources>
1 change: 1 addition & 0 deletions opentasks/build.gradle
Expand Up @@ -60,6 +60,7 @@ android {
}

dependencies {
implementation project(':opentasks-theme')
implementation project(':opentasks-provider')
implementation deps.support_appcompat
implementation deps.support_design
Expand Down
10 changes: 5 additions & 5 deletions opentasks/src/main/AndroidManifest.xml
Expand Up @@ -24,7 +24,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:taskAffinity="org.dmfs.tasks.TaskListActivity"
android:theme="@style/OpenTasksAppTheme">
android:theme="@style/OpenTasks_Theme.Default">

<!-- TaskListActivity listens for MAIN intents -->
<activity
Expand Down Expand Up @@ -145,8 +145,8 @@
<activity
android:name=".SyncSettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".TaskListActivity"
android:theme="@style/AppTheme">
android:theme="@style/OpenTasksAppTheme"
android:parentActivityName=".TaskListActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.dmfs.tasks.TaskListActivity"/>
Expand All @@ -156,7 +156,7 @@
<activity
android:name=".homescreen.TaskListWidgetSettingsActivity"
android:label="@string/task_list_selection_title"
android:theme="@style/Theme.MaterialDialog">
android:theme="@style/OpenTasks_BaseTheme.Light.Dialog">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
Expand Down Expand Up @@ -260,7 +260,7 @@
<!-- Manage List -->
<activity
android:name=".ManageListActivity"
android:theme="@style/AppThemeDialog">
android:theme="@style/OpenTasks_Theme.Default.Dialog">
<intent-filter>
<action android:name="android.intent.action.INSERT"/>

Expand Down
12 changes: 4 additions & 8 deletions opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java
Expand Up @@ -24,7 +24,6 @@
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
Expand Down Expand Up @@ -643,13 +642,10 @@ private void updateColor(float percentage)
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);

if (VERSION.SDK_INT >= 21)
{
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(new Mixed(newColor, mListColor).argb());
// window.setNavigationBarColor(mixColors(newColor, mListColor));
}
Window window = getActivity().getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(new Mixed(newColor, mListColor).argb());

mTaskListBar.setBackgroundColor(mListColor);
if (mColorBar != null)
{
Expand Down
Expand Up @@ -23,9 +23,6 @@
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
Expand Down Expand Up @@ -58,6 +55,10 @@
import org.dmfs.tasks.utils.SafeFragmentUiRunnable;
import org.dmfs.tasks.utils.TasksListCursorSpinnerAdapter;

import androidx.loader.app.LoaderManager;
import androidx.loader.content.CursorLoader;
import androidx.loader.content.Loader;


/**
* A quick add dialog. It allows the user to enter a new task without having to deal with the full blown editor interface. At present it support task with a
Expand Down Expand Up @@ -200,16 +201,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{

// create ContextThemeWrapper from the original Activity Context with the custom theme
final Context contextThemeWrapperLight = new ContextThemeWrapper(getActivity(), R.style.ThemeOverlay_AppCompat_Light);
final Context contextThemeWrapperDark = new ContextThemeWrapper(getActivity(), R.style.Base_Theme_AppCompat);

LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapperLight);
View view = localInflater.inflate(R.layout.fragment_quick_add_dialog, container);
View view = inflater.inflate(R.layout.fragment_quick_add_dialog, container);

ViewGroup headerContainer = (ViewGroup) view.findViewById(R.id.header_container);
localInflater = inflater.cloneInContext(contextThemeWrapperDark);
LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapperDark);
localInflater.inflate(R.layout.fragment_quick_add_dialog_header, headerContainer);

if (savedInstanceState == null)
Expand Down

0 comments on commit bcc8a32

Please sign in to comment.