use of android.graphics.Color in project Shuttle by timusus.
the class DialogUtils method showColorPickerDialog.
public static void showColorPickerDialog(SettingsFragment fragment, int selectedColor, int[] mainColors, int[][] subColors, ColorSelectionListener listener) {
View customView = LayoutInflater.from(fragment.getActivity()).inflate(R.layout.dialog_color_picker, null);
RecyclerView recyclerView = (RecyclerView) customView.findViewById(R.id.recyclerView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(fragment.getActivity(), 5);
recyclerView.setLayoutManager(gridLayoutManager);
ThemeUtils.themeRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
ThemeUtils.themeRecyclerView(recyclerView);
super.onScrollStateChanged(recyclerView, newState);
}
});
ColorAdapter colorAdapter = new ColorAdapter();
List<AdaptableItem> colorViews = new ArrayList<>();
for (int i = 0, length = mainColors.length; i < length; i++) {
ColorView colorView = new ColorView(mainColors[i]);
boolean selected = false;
//If the sub colors array contains our selected color, then we set this colorView to selected.
for (int j = 0, jLength = subColors[i].length; j < jLength; j++) {
if (subColors[i][j] == selectedColor) {
selected = true;
}
}
colorView.selected = selected;
colorViews.add(colorView);
}
colorAdapter.setItems(colorViews);
recyclerView.setAdapter(colorAdapter);
colorAdapter.setColorListener((position, color, isSubColor) -> {
if (isSubColor) {
colorAdapter.setSelectedPosition(position);
} else {
List<AdaptableItem> subColorViews = new ArrayList<>();
for (int i = 0, length = subColors[position].length; i < length; i++) {
ColorView colorView = new ColorView(subColors[position][i]);
colorView.selected = colorView.color == selectedColor;
subColorViews.add(colorView);
colorAdapter.isSubColor = true;
}
colorAdapter.setItems(subColorViews);
}
});
int neutralTextResId;
TextView textView = (TextView) customView.findViewById(R.id.text1);
if (ShuttleUtils.isUpgraded()) {
textView.setVisibility(View.GONE);
neutralTextResId = R.string.dialog_custom;
} else {
textView.setVisibility(View.VISIBLE);
if (ShuttleUtils.isAmazonBuild()) {
neutralTextResId = R.string.get_pro_button_amazon;
} else {
neutralTextResId = R.string.btn_upgrade;
}
}
getBuilder(fragment.getActivity()).title(fragment.getActivity().getString(R.string.color_pick)).negativeText(R.string.cancel).onNegative((dialog, which) -> dialog.dismiss()).positiveText(R.string.button_done).onPositive((dialog, which) -> {
int color = selectedColor;
for (AdaptableItem item : colorAdapter.items) {
if (((ColorView) item).selected) {
color = ((ColorView) item).color;
break;
}
}
listener.colorSelected(color);
dialog.dismiss();
}).neutralText(neutralTextResId).autoDismiss(false).onNeutral((dialog, which) -> {
if (ShuttleUtils.isUpgraded()) {
showCustomColorPickerDialog(fragment.getActivity(), selectedColor, listener);
dialog.dismiss();
} else {
showUpgradeDialog(fragment.getActivity(), (upgradeDialog, which1) -> {
if (ShuttleUtils.isAmazonBuild()) {
ShuttleUtils.openShuttleLink(fragment.getActivity(), "com.simplecity.amp_pro");
} else {
AnalyticsManager.logUpgrade(AnalyticsManager.UpgradeType.COLORS);
((SettingsActivity) fragment.getActivity()).purchasePremiumUpgrade();
}
});
}
}).customView(customView, false).show();
}
use of android.graphics.Color in project Shuttle by timusus.
the class MiniPlayerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_mini_player, container, false);
unbinder = ButterKnife.bind(this, rootView);
rootView.setOnClickListener(v -> {
MultiSheetView multiSheetView = MultiSheetView.getParentMultiSheetView(rootView);
if (multiSheetView != null) {
multiSheetView.expandSheet(MultiSheetView.Sheet.FIRST);
}
});
rootView.setOnTouchListener(new OnSwipeTouchListener(getActivity()));
playPauseView.setOnClickListener(v -> {
playPauseView.toggle();
playPauseView.postDelayed(() -> presenter.togglePlayback(), 200);
});
progressBar.setMax(1000);
disposable.add(Aesthetic.get(getContext()).colorPrimary().compose(distinctToMainThread()).subscribe(color -> {
boolean isDark = !Util.isColorLight(color);
trackName.setTextColor(isDark ? Color.WHITE : Color.BLACK);
artistName.setTextColor(isDark ? Color.WHITE : Color.BLACK);
ViewBackgroundAction.create(rootView).accept(color);
}, onErrorLogAndRethrow()));
return rootView;
}
use of android.graphics.Color in project Shuttle by timusus.
the class PlayerFragment method trackInfoChanged.
@Override
public void trackInfoChanged(@Nullable Song song) {
if (song == null)
return;
if (isExpanded && !snowfallView.isSnowing()) {
snowfallView.letItSnow();
} else {
snowfallView.removeSnow();
}
String totalTimeString = StringUtils.makeTimeString(this.getActivity(), song.duration / 1000);
if (!TextUtils.isEmpty(totalTimeString)) {
if (totalTime != null) {
totalTime.setText(totalTimeString);
}
}
if (track != null) {
track.setText(song.name);
track.setSelected(true);
}
if (album != null) {
album.setText(String.format("%s | %s", song.artistName, song.albumName));
}
if (isLandscape) {
toolbar.setTitle(song.name);
toolbar.setSubtitle(String.format("%s | %s", song.artistName, song.albumName));
target = Glide.with(this).load(song).diskCacheStrategy(DiskCacheStrategy.SOURCE).bitmapTransform(new BlurTransformation(getContext(), 15, 4)).error(PlaceholderProvider.getInstance().getPlaceHolderDrawable(song.name, true)).thumbnail(Glide.with(this).load(this.song).bitmapTransform(new BlurTransformation(getContext(), 15, 4))).crossFade(600).into(backgroundView);
this.song = song;
} else {
backgroundView.setImageDrawable(null);
toolbar.setTitle(null);
toolbar.setSubtitle(null);
}
if (SettingsManager.getInstance().getUsePalette()) {
// noinspection unchecked
Glide.with(this).load(song).asBitmap().transcode(new PaletteBitmapTranscoder(getContext()), PaletteBitmap.class).override(250, 250).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<PaletteBitmap>() {
@Override
public void onResourceReady(PaletteBitmap resource, GlideAnimation<? super PaletteBitmap> glideAnimation) {
if (!isAdded() || getContext() == null) {
return;
}
Palette.Swatch swatch = resource.palette.getDarkMutedSwatch();
if (swatch != null) {
if (SettingsManager.getInstance().getUsePalette()) {
if (SettingsManager.getInstance().getUsePaletteNowPlayingOnly()) {
animateColors(currentColor, swatch.getRgb(), color -> invalidateColors(color));
} else {
// Set Aesthetic colors globally, based on the current Palette swatch
disposables.add(Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(integer -> animateColors(integer, swatch.getRgb(), color -> {
if (getContext() != null && isAdded()) {
Aesthetic aesthetic = Aesthetic.get(getContext()).colorPrimary(color).colorStatusBarAuto();
if (SettingsManager.getInstance().getTintNavBar()) {
aesthetic = aesthetic.colorNavigationBar(color);
}
aesthetic.apply();
}
})));
}
}
} else {
// Failed to generate the dark muted swatch, fall back to the primary theme colour.
Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
}
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
}
});
}
}
use of android.graphics.Color in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method deleteFilesDialog.
@SuppressWarnings("ConstantConditions")
public static void deleteFilesDialog(final Context c, final ArrayList<LayoutElementParcelable> layoutElements, final MainActivity mainActivity, final List<LayoutElementParcelable> positions, AppTheme appTheme) {
final ArrayList<HybridFileParcelable> itemsToDelete = new ArrayList<>();
int accentColor = mainActivity.getColorPreference().getColor(ColorUsage.ACCENT);
// Build dialog with custom view layout and accent color.
MaterialDialog dialog = new MaterialDialog.Builder(c).title(c.getString(R.string.dialog_delete_title)).customView(R.layout.dialog_delete, true).theme(appTheme.getMaterialDialogTheme()).negativeText(c.getString(R.string.cancel).toUpperCase()).positiveText(c.getString(R.string.delete).toUpperCase()).positiveColor(accentColor).negativeColor(accentColor).onPositive((dialog1, which) -> {
Toast.makeText(c, c.getString(R.string.deleting), Toast.LENGTH_SHORT).show();
mainActivity.mainActivityHelper.deleteFiles(itemsToDelete);
}).build();
// Get views from custom layout to set text values.
final TextView categoryDirectories = (TextView) dialog.getCustomView().findViewById(R.id.category_directories);
final TextView categoryFiles = (TextView) dialog.getCustomView().findViewById(R.id.category_files);
final TextView listDirectories = (TextView) dialog.getCustomView().findViewById(R.id.list_directories);
final TextView listFiles = (TextView) dialog.getCustomView().findViewById(R.id.list_files);
final TextView total = (TextView) dialog.getCustomView().findViewById(R.id.total);
// Parse items to delete.
new AsyncTask<Void, Object, Void>() {
long sizeTotal = 0;
StringBuilder files = new StringBuilder();
StringBuilder directories = new StringBuilder();
int counterDirectories = 0;
int counterFiles = 0;
@Override
protected void onPreExecute() {
super.onPreExecute();
listFiles.setText(c.getString(R.string.loading));
listDirectories.setText(c.getString(R.string.loading));
total.setText(c.getString(R.string.loading));
}
@Override
protected Void doInBackground(Void... params) {
for (int i = 0; i < positions.size(); i++) {
final LayoutElementParcelable layoutElement = positions.get(i);
itemsToDelete.add(layoutElement.generateBaseFile());
// Build list of directories to delete.
if (layoutElement.isDirectory) {
// Don't add newline between category and list.
if (counterDirectories != 0) {
directories.append("\n");
}
long sizeDirectory = layoutElement.generateBaseFile().folderSize(c);
directories.append(++counterDirectories).append(". ").append(layoutElement.title).append(" (").append(Formatter.formatFileSize(c, sizeDirectory)).append(")");
sizeTotal += sizeDirectory;
// Build list of files to delete.
} else {
// Don't add newline between category and list.
if (counterFiles != 0) {
files.append("\n");
}
files.append(++counterFiles).append(". ").append(layoutElement.title).append(" (").append(layoutElement.size).append(")");
sizeTotal += layoutElement.longSize;
}
publishProgress(sizeTotal, counterFiles, counterDirectories, files, directories);
}
return null;
}
@Override
protected void onProgressUpdate(Object... result) {
super.onProgressUpdate(result);
int tempCounterFiles = (int) result[1];
int tempCounterDirectories = (int) result[2];
long tempSizeTotal = (long) result[0];
StringBuilder tempFilesStringBuilder = (StringBuilder) result[3];
StringBuilder tempDirectoriesStringBuilder = (StringBuilder) result[4];
updateViews(tempSizeTotal, tempFilesStringBuilder, tempDirectoriesStringBuilder, tempCounterFiles, tempCounterDirectories);
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
updateViews(sizeTotal, files, directories, counterFiles, counterDirectories);
}
private void updateViews(long tempSizeTotal, StringBuilder filesStringBuilder, StringBuilder directoriesStringBuilder, int... values) {
int tempCounterFiles = values[0];
int tempCounterDirectories = values[1];
// Hide category and list for directories when zero.
if (tempCounterDirectories == 0) {
if (tempCounterDirectories == 0) {
categoryDirectories.setVisibility(View.GONE);
listDirectories.setVisibility(View.GONE);
}
// Hide category and list for files when zero.
}
if (tempCounterFiles == 0) {
categoryFiles.setVisibility(View.GONE);
listFiles.setVisibility(View.GONE);
}
if (tempCounterDirectories != 0 || tempCounterFiles != 0) {
listDirectories.setText(directoriesStringBuilder);
if (listDirectories.getVisibility() != View.VISIBLE && tempCounterDirectories != 0)
listDirectories.setVisibility(View.VISIBLE);
listFiles.setText(filesStringBuilder);
if (listFiles.getVisibility() != View.VISIBLE && tempCounterFiles != 0)
listFiles.setVisibility(View.VISIBLE);
if (categoryDirectories.getVisibility() != View.VISIBLE && tempCounterDirectories != 0)
categoryDirectories.setVisibility(View.VISIBLE);
if (categoryFiles.getVisibility() != View.VISIBLE && tempCounterFiles != 0)
categoryFiles.setVisibility(View.VISIBLE);
}
// Show total size with at least one directory or file and size is not zero.
if (tempCounterFiles + tempCounterDirectories > 1 && tempSizeTotal > 0) {
StringBuilder builderTotal = new StringBuilder().append(c.getString(R.string.total)).append(" ").append(Formatter.formatFileSize(c, tempSizeTotal));
total.setText(builderTotal);
if (total.getVisibility() != View.VISIBLE)
total.setVisibility(View.VISIBLE);
} else {
total.setVisibility(View.GONE);
}
}
}.execute();
// Set category text color for Jelly Bean (API 16) and later.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
categoryDirectories.setTextColor(accentColor);
categoryFiles.setTextColor(accentColor);
}
// Show dialog on screen.
dialog.show();
}
use of android.graphics.Color in project Taskbar by farmerbb.
the class AppearanceFragment method showColorPicker.
@SuppressLint("SetTextI18n")
private void showColorPicker(ColorPickerType type) {
int color = -1;
int dialogTitle = -1;
switch(type) {
case BACKGROUND_TINT:
color = U.getBackgroundTint(getActivity());
dialogTitle = R.string.pref_title_background_tint;
break;
case ACCENT_COLOR:
color = U.getAccentColor(getActivity());
dialogTitle = R.string.pref_title_accent_color;
break;
}
alpha = Color.alpha(color);
red = Color.red(color);
green = Color.green(color);
blue = Color.blue(color);
ScrollView dialogLayout = (ScrollView) View.inflate(getActivity(), R.layout.color_picker_pref, null);
View colorPreview = dialogLayout.findViewById(R.id.color_preview);
colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
TextView hexPreview = U.findViewById(dialogLayout, R.id.hex_preview);
hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
final TextView alphaValue = U.findViewById(dialogLayout, R.id.alpha_value);
alphaValue.setText("0");
final SeekBar alphaSeekBar = U.findViewById(dialogLayout, R.id.alpha_seekbar);
alphaSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
alpha = progress;
alphaValue.setText(Integer.toString(alpha));
colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
alphaSeekBar.setProgress(Color.alpha(color));
final TextView redValue = U.findViewById(dialogLayout, R.id.red_value);
redValue.setText("0");
final SeekBar redSeekBar = U.findViewById(dialogLayout, R.id.red_seekbar);
redSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
red = progress;
redValue.setText(Integer.toString(red));
colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
redSeekBar.setProgress(Color.red(color));
final TextView greenValue = U.findViewById(dialogLayout, R.id.green_value);
greenValue.setText("0");
final SeekBar greenSeekBar = U.findViewById(dialogLayout, R.id.green_seekbar);
greenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
green = progress;
greenValue.setText(Integer.toString(green));
colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
greenSeekBar.setProgress(Color.green(color));
final TextView blueValue = U.findViewById(dialogLayout, R.id.blue_value);
blueValue.setText("0");
final SeekBar blueSeekBar = U.findViewById(dialogLayout, R.id.blue_seekbar);
blueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
blue = progress;
blueValue.setText(Integer.toString(blue));
colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
blueSeekBar.setProgress(Color.blue(color));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(dialogLayout).setTitle(dialogTitle).setPositiveButton(R.string.action_ok, (dialog, which) -> {
String preferenceId = null;
switch(type) {
case BACKGROUND_TINT:
preferenceId = "background_tint";
break;
case ACCENT_COLOR:
preferenceId = "accent_color";
break;
}
SharedPreferences pref = U.getSharedPreferences(getActivity());
pref.edit().putInt(preferenceId, Color.argb(alpha, red, green, blue)).apply();
findPreference(preferenceId + "_pref").setSummary("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
U.restartTaskbar(getActivity());
}).setNegativeButton(R.string.action_cancel, null);
AlertDialog dialog = builder.create();
dialog.show();
}
Aggregations