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

get Accent color from OS, set on toolbar and StatusBar

parent 89fb3c79
Pipeline #71529 passed with stage
in 3 minutes and 37 seconds
......@@ -3,33 +3,41 @@ package foundation.e.notes.android.activity;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.AppCompatImageView;
......@@ -102,6 +110,8 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
private final static String login_account_eelo = "login_account_eelo";
private final static String key_email_address = "email_address";
public static int ACCENT_COLOR;
@BindView(R.id.notesListActivityActionBar)
Toolbar toolbar;
......@@ -236,6 +246,9 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
// dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.fg_default));
// dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.fg_default));
//}
ACCENT_COLOR= fetchAccentColor(this);
}
private void migrateUrl() {
......@@ -931,4 +944,40 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
adapter.notifyDataSetChanged();
}
}
/*
* 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);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment