private void primaryColorPiker() { final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this, getDialogStyle()); final View dialogLayout = getLayoutInflater().inflate(R.layout.color_piker_primary, null); final LineColorPicker colorPicker = (LineColorPicker) dialogLayout.findViewById(R.id.color_picker_primary); final LineColorPicker colorPicker2 = (LineColorPicker) dialogLayout.findViewById(R.id.color_picker_primary_2); final TextView dialogTitle = (TextView) dialogLayout.findViewById(R.id.cp_primary_title); CardView dialogCardView = (CardView) dialogLayout.findViewById(R.id.cp_primary_card); dialogCardView.setCardBackgroundColor(getCardBackgroundColor()); colorPicker.setColors(ColorPalette.getBaseColors(getApplicationContext())); for (int i : colorPicker.getColors()) for (int i2 : ColorPalette.getColors(getBaseContext(), i)) if (i2 == getPrimaryColor()) { colorPicker.setSelectedColor(i); colorPicker2.setColors(ColorPalette.getColors(getBaseContext(), i)); colorPicker2.setSelectedColor(i2); break; } dialogTitle.setBackgroundColor(getPrimaryColor()); colorPicker.setOnColorChangedListener( new OnColorChangedListener() { @Override public void onColorChanged(int c) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (isTranslucentStatusBar()) { getWindow().setStatusBarColor(ColorPalette.getOscuredColor(getPrimaryColor())); } else getWindow().setStatusBarColor(c); } toolbar.setBackgroundColor(c); dialogTitle.setBackgroundColor(c); colorPicker2.setColors( ColorPalette.getColors(getApplicationContext(), colorPicker.getColor())); colorPicker2.setSelectedColor(colorPicker.getColor()); } }); colorPicker2.setOnColorChangedListener( new OnColorChangedListener() { @Override public void onColorChanged(int c) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (isTranslucentStatusBar()) { getWindow().setStatusBarColor(ColorPalette.getOscuredColor(c)); } else getWindow().setStatusBarColor(c); if (isNavigationBarColored()) getWindow().setNavigationBarColor(c); else getWindow() .setNavigationBarColor( ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000)); } toolbar.setBackgroundColor(c); dialogTitle.setBackgroundColor(c); } }); dialogBuilder.setView(dialogLayout); dialogBuilder.setNeutralButton( getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (isTranslucentStatusBar()) { getWindow().setStatusBarColor(ColorPalette.getOscuredColor(getPrimaryColor())); } else getWindow().setStatusBarColor(getPrimaryColor()); } toolbar.setBackgroundColor(getPrimaryColor()); dialog.cancel(); } }); dialogBuilder.setPositiveButton( getString(R.string.ok_action), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { SharedPreferences.Editor editor = SP.edit(); editor.putInt(getString(R.string.preference_primary_color), colorPicker2.getColor()); editor.apply(); updateTheme(); setNavBarColor(); setScrollViewColor(scr); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (isTranslucentStatusBar()) { getWindow().setStatusBarColor(ColorPalette.getOscuredColor(getPrimaryColor())); } else { getWindow().setStatusBarColor(getPrimaryColor()); } } } }); dialogBuilder.setOnDismissListener( new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (isTranslucentStatusBar()) { getWindow().setStatusBarColor(ColorPalette.getOscuredColor(getPrimaryColor())); } else getWindow().setStatusBarColor(getPrimaryColor()); if (isNavigationBarColored()) getWindow().setNavigationBarColor(getPrimaryColor()); else getWindow() .setNavigationBarColor( ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000)); } toolbar.setBackgroundColor(getPrimaryColor()); } }); dialogBuilder.show(); }