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

Commit 11178279 authored by Narinder Rana's avatar Narinder Rana
Browse files

get Accent color and impl on Home screen, tabs, bottom view, Search Activity, Setting Activity

parent 774a2798
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
package org.lineageos.eleven.adapters;

import android.content.Context;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -25,6 +26,7 @@ import org.lineageos.eleven.cache.ImageFetcher;
import org.lineageos.eleven.model.Playlist;
import org.lineageos.eleven.ui.MusicHolder;
import org.lineageos.eleven.ui.MusicHolder.DataHolder;
import org.lineageos.eleven.ui.activities.HomeActivity;
import org.lineageos.eleven.ui.fragments.PlaylistFragment;
import org.lineageos.eleven.utils.MusicUtils;
import org.lineageos.eleven.widgets.IPopupMenuCallback;
@@ -127,7 +129,7 @@ public class PlaylistAdapter extends ArrayAdapter<Playlist> implements IPopupMen
                    dataHolder.mItemId, holder.mImage.get());
        }


        DrawableCompat.setTint(DrawableCompat.wrap(holder.mImage.get().getDrawable()), HomeActivity.accentColor);

        return convertView;
    }
+54 −5
Original line number Diff line number Diff line
@@ -25,13 +25,19 @@ import android.content.ServiceConnection;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.ColorInt;
import android.support.v4.app.FragmentActivity;
import android.support.v7.view.ContextThemeWrapper;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -72,7 +78,7 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo
    private Toolbar mToolBar;

    private int mActionBarHeight;

    private int accentColor;
    /**
     * The service token
     */
@@ -136,15 +142,19 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo
        setActionBar(mToolBar);

        setActionBarTitle(getString(R.string.app_name));

        mToolBar.setTitleTextColor(getResources().getColor(R.color.white));
        // set the background on the root view
        getWindow().getDecorView().getRootView().setBackgroundColor(
                getResources().getColor(R.color.background_color));
       // getWindow().getDecorView().getRootView().setBackgroundColor(
        //        getResources().getColor(R.color.background_color));
        // Initialze the bottom action bar
        initBottomActionBar();

        // listen to changes to the cache status
        ImageFetcher.getInstance(this).addCacheListener(this);
        accentColor=fetchAccentColor(this);

        mToolBar.setBackgroundColor(accentColor);

    }

    /**
@@ -283,7 +293,7 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo
        if (mActionBarBackground == null) {
            final int actionBarColor = getResources().getColor(R.color.header_action_bar_color);
            mActionBarBackground = new ColorDrawable(actionBarColor);
            mToolBar.setBackgroundDrawable(mActionBarBackground);
           // mToolBar.setBackgroundDrawable(mActionBarBackground);
        }
    }

@@ -488,4 +498,43 @@ public abstract class BaseActivity extends FragmentActivity implements ServiceCo
     * handle pending playback requests
     */
    public abstract void handlePendingPlaybackRequests();

    /*
     * 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);
    }

}
+46 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package org.lineageos.eleven.ui.activities;
import android.Manifest;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
@@ -28,13 +29,17 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.MediaStore;
import android.support.annotation.ColorInt;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.view.ContextThemeWrapper;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

import org.lineageos.eleven.Config;
import org.lineageos.eleven.R;
@@ -79,7 +84,7 @@ public class HomeActivity extends SlidingPanelActivity implements
    private boolean mHasPendingPlaybackRequest = false;
    private Handler mHandler = new Handler();
    private boolean mBrowsePanelActive = true;

    public static int accentColor;
    /**
     * Used by the up action to determine how to handle this
     */
@@ -94,6 +99,7 @@ public class HomeActivity extends SlidingPanelActivity implements
        if (!needRequestStoragePermission()) {
            init();
        }
        accentColor=fetchAccentColor(this);
    }

    private void init() {
@@ -133,7 +139,7 @@ public class HomeActivity extends SlidingPanelActivity implements

            // figure which panel we are on and update the status bar
            mBrowsePanelActive = (getCurrentPanel() == Panel.Browse);
            updateStatusBarColor();
           // updateStatusBarColor();
        }

        // if intent wasn't UI related, process it as a audio playback request
@@ -534,4 +540,42 @@ public class HomeActivity extends SlidingPanelActivity implements
        return true;
    }

    /*
     * 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);
    }

}
+41 −0
Original line number Diff line number Diff line
@@ -20,20 +20,28 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.support.annotation.ColorInt;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v7.view.ContextThemeWrapper;
import android.text.TextUtils;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
@@ -348,6 +356,8 @@ public class SearchActivity extends FragmentActivity implements
            // Start the loader for the search history
            getSupportLoaderManager().initLoader(HISTORY_LOADER, null, mSearchHistoryCallback);
        }

        actionBar.setBackgroundDrawable(new ColorDrawable(fetchAccentColor(this)));
    }

    /**
@@ -978,4 +988,35 @@ public class SearchActivity extends FragmentActivity implements
        hideInputManager();
        return false;
    }
    /*
     * 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 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);
    }

}
+41 −1
Original line number Diff line number Diff line
@@ -14,16 +14,25 @@
package org.lineageos.eleven.ui.activities;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.PackageManager;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.support.annotation.ColorInt;
import android.support.v7.view.ContextThemeWrapper;
import android.util.Log;
import android.util.TypedValue;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

import org.lineageos.eleven.R;
import org.lineageos.eleven.cache.ImageFetcher;
@@ -63,7 +72,7 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
            findPreference(BUILD_VERSION).setSummary(versionName);
        } catch (PackageManager.NameNotFoundException e) {
        }

        getActionBar().setBackgroundDrawable(new ColorDrawable(fetchAccentColor(this)));

    }

@@ -123,4 +132,35 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
            MusicUtils.setShowAlbumArtOnLockscreen(sharedPreferences.getBoolean(key, true));
        }
    }

    /*
     * 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 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);
    }
}
Loading