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

Commit b1d9da78 authored by Narinder Rana's avatar Narinder Rana Committed by Fahim Salam Chowdhury
Browse files

get Accent color from OS, set on toolbar and StatusBar

parent a3945fd2
Loading
Loading
Loading
Loading
+48 −0
Original line number Diff line number Diff line
@@ -17,19 +17,27 @@ import static it.niedermann.owncloud.notes.shared.util.SSOUtil.askForNewAccount;
import android.accounts.NetworkErrorException;
import android.animation.AnimatorInflater;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.SearchView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
@@ -136,6 +144,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A

    boolean canMoveNoteToAnotherAccounts = false;

    public static int ACCENT_COLOR;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.installSplashScreen(this);
@@ -357,6 +367,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
                menuAdapter.updateAccount(this, nextAccount);
            }
        });

        ACCENT_COLOR= fetchAccentColor(this);
    }

    @Override
@@ -820,4 +832,40 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
        categoryLiveData.observe(this, (next) -> categoryLiveData.removeObservers(this));
        tracker.clearSelection();
    }

    /*
     * get Accent color from OS
     * */
    private int fetchAccentColor(Context context) {

        TypedValue typedValue = new TypedValue();
        ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(this,
                android.R.style.Theme_DeviceDefault);
        contextThemeWrapper.getTheme().resolveAttribute(android.R.attr.colorAccent,
                typedValue, true);
        int color_accent = typedValue.data;
        Log.e("TAG", "accent Colour  #"+Integer.toHexString(color_accent));

        //change toolbar color
        getSupportActionBar().setBackgroundDrawable(
                new ColorDrawable(color_accent));

        //change status bar color
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(darkenColor(color_accent));
        }

        return color_accent;
    }


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