Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4cf011a9 authored by Gabor Keszthelyi's avatar Gabor Keszthelyi Committed by Marten Gajda
Browse files

Fix app bar colors when empty task fragment is shown in two pane mode. #353 (#520)

parent 556281db
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,3 +9,4 @@ ROBOLECTRIC_VERSION=3.1.4
JEMS_VERSION=1.13
ANDROID_TEST_RUNNER_VERSION=0.5
RFC5545_DATETIME_VERSION=0.2.4
BOLTS_VERSION=92914c5
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ dependencies {
    }
    implementation 'org.dmfs:jems:' + JEMS_VERSION
    implementation 'org.dmfs:rfc5545-datetime:' + RFC5545_DATETIME_VERSION
    implementation 'com.github.dmfs.bolts:color-bolts:' + BOLTS_VERSION

    testImplementation 'junit:junit:4.12'

+4 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="org.dmfs.tasks">

    <uses-permission android:name="org.dmfs.permission.READ_TASKS"/>
@@ -11,6 +12,9 @@
    <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

    <!--TODO Remove after https://github.com/dmfs/opentasks/issues/392-->
    <uses-sdk tools:overrideLibrary="org.dmfs.android.bolts"/>

    <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
+13 −0
Original line number Diff line number Diff line
@@ -16,11 +16,13 @@

package org.dmfs.tasks;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.dmfs.android.bolts.color.colors.AttributeColor;
import org.dmfs.android.retentionmagic.SupportFragment;


@@ -39,4 +41,15 @@ public class EmptyTaskFragment extends SupportFragment
        return inflater.inflate(R.layout.opentasks_fragment_empty_task, container, false);
    }


    @Override
    public void onAttach(Activity activity)
    {
        super.onAttach(activity);
        if (activity instanceof ViewTaskFragment.Callback)
        {
            ((ViewTaskFragment.Callback) activity)
                    .updateColor(new AttributeColor(getContext(), R.attr.colorPrimary));
        }
    }
}
+11 −9
Original line number Diff line number Diff line
@@ -21,13 +21,13 @@ import android.annotation.TargetApi;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.ColorInt;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
@@ -50,6 +50,7 @@ import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;

import org.dmfs.android.bolts.color.Color;
import org.dmfs.android.retentionmagic.annotations.Retain;
import org.dmfs.provider.tasks.AuthorityUtil;
import org.dmfs.tasks.contract.TaskContract.Tasks;
@@ -754,35 +755,36 @@ public class TaskListActivity extends BaseActivity implements TaskListFragment.C
    };


    private int darkenColor(int color)
    private int darkenColor(@ColorInt int color)
    {
        float[] hsv = new float[3];
        Color.colorToHSV(color, hsv);
        android.graphics.Color.colorToHSV(color, hsv);
        hsv[2] = hsv[2] * 0.75f;
        color = Color.HSVToColor(hsv);
        color = android.graphics.Color.HSVToColor(hsv);
        return color;
    }


    @SuppressLint("NewApi")
    @Override
    public void updateColor(int color)
    public void updateColor(Color color)
    {
        if (mTwoPane)
        {
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color));
            mTabs.setBackgroundColor(color);
            int colorInt = color.argb();
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(colorInt));
            mTabs.setBackgroundColor(colorInt);

            if (mAppBarLayout != null)
            {
                mAppBarLayout.setBackgroundColor(color);
                mAppBarLayout.setBackgroundColor(colorInt);
            }

            if (VERSION.SDK_INT >= 21)
            {
                Window window = getWindow();
                window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
                window.setStatusBarColor(darkenColor(color));
                window.setStatusBarColor(darkenColor(colorInt));
            }
        }
    }
Loading