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

Commit 71d060da authored by Narinder Rana's avatar Narinder Rana
Browse files

impl on Setting Activity

parent 4a3d7b37
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ public class HeaderBar extends LinearLayout {
        mBackButton = (ImageView)findViewById(R.id.header_bar_up);

        mTitleText = (TextView)findViewById(R.id.header_bar_title);

    }

    /**
+48 −0
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;
@@ -64,6 +73,7 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
        } catch (PackageManager.NameNotFoundException e) {
        }

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

    /**
@@ -122,4 +132,42 @@ 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 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);
    }
}