Search in sources :

Example 1 with Color

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();
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ProgressBar(android.widget.ProgressBar) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Drawable(android.graphics.drawable.Drawable) FileProvider(android.support.v4.content.FileProvider) Song(com.simplecity.amp_library.model.Song) FileObject(com.simplecity.amp_library.model.FileObject) Schedulers(rx.schedulers.Schedulers) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) BlacklistAdapter(com.simplecity.amp_library.ui.adapters.BlacklistAdapter) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) WhitelistAdapter(com.simplecity.amp_library.ui.adapters.WhitelistAdapter) R.id.album(com.simplecity.amp_library.R.id.album) MainActivity(com.simplecity.amp_library.ui.activities.MainActivity) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) R.id.artist(com.simplecity.amp_library.R.id.artist) WhitelistHelper(com.simplecity.amp_library.sql.databases.WhitelistHelper) FileNotFoundException(java.io.FileNotFoundException) CustomColorPicker(com.simplecity.amp_library.ui.views.CustomColorPicker) List(java.util.List) TextView(android.widget.TextView) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) Html(android.text.Html) LastFmArtist(com.simplecity.amp_library.lastfm.LastFmArtist) ListView(android.widget.ListView) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Call(retrofit2.Call) Subscription(rx.Subscription) NumberPicker(android.widget.NumberPicker) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity) Context(android.content.Context) LastFmAlbum(com.simplecity.amp_library.lastfm.LastFmAlbum) Stream(com.annimon.stream.Stream) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) HttpClient(com.simplecity.amp_library.http.HttpClient) Dialog(android.app.Dialog) Intent(android.content.Intent) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) Response(retrofit2.Response) SettingsFragment(com.simplecity.amp_library.ui.fragments.SettingsFragment) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BlacklistedSong(com.simplecity.amp_library.model.BlacklistedSong) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) IntentCompat(android.support.v4.content.IntentCompat) FileOutputStream(java.io.FileOutputStream) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) IOException(java.io.IOException) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Color(android.graphics.Color) RecyclerView(android.support.v7.widget.RecyclerView) ArrayAdapter(android.widget.ArrayAdapter) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) BlacklistHelper(com.simplecity.amp_library.sql.databases.BlacklistHelper) Glide(com.bumptech.glide.Glide) Callback(retrofit2.Callback) ScrollView(android.widget.ScrollView) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) ArrayList(java.util.ArrayList) AdaptableItem(com.simplecity.amp_library.model.AdaptableItem) View(android.view.View) BlacklistView(com.simplecity.amp_library.ui.modelviews.BlacklistView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) TextView(android.widget.TextView) ListView(android.widget.ListView) EmptyView(com.simplecity.amp_library.ui.modelviews.EmptyView) WhitelistView(com.simplecity.amp_library.ui.modelviews.WhitelistView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) ColorView(com.simplecity.amp_library.ui.modelviews.ColorView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) ColorAdapter(com.simplecity.amp_library.ui.adapters.ColorAdapter) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SettingsActivity(com.simplecity.amp_library.ui.activities.SettingsActivity)

Example 2 with Color

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;
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) GestureDetector(android.view.GestureDetector) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) ButterKnife(butterknife.ButterKnife) ImageView(android.widget.ImageView) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) BindView(butterknife.BindView) Inject(javax.inject.Inject) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) Priority(com.bumptech.glide.Priority) MotionEvent(android.view.MotionEvent) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) View(android.view.View) Unbinder(butterknife.Unbinder) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) PlayPauseView(com.simplecity.amp_library.ui.views.PlayPauseView) ViewGroup(android.view.ViewGroup) Color(android.graphics.Color) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) PlayerPresenter(com.simplecity.amp_library.ui.presenters.PlayerPresenter) Util(com.afollestad.aesthetic.Util) PlayerViewAdapter(com.simplecity.amp_library.ui.views.PlayerViewAdapter) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView)

Example 3 with Color

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)));
            }
        });
    }
}
Also used : PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) ImageView(android.widget.ImageView) SeekBarStopChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStopChangeEvent) FavoriteActionBarView(com.simplecity.amp_library.ui.views.FavoriteActionBarView) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) RepeatingImageButton(com.simplecity.amp_library.ui.views.RepeatingImageButton) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Schedulers(io.reactivex.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) ShuffleButton(com.simplecity.amp_library.ui.views.ShuffleButton) Unbinder(butterknife.Unbinder) Log(android.util.Log) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) LogUtils(com.simplecity.amp_library.utils.LogUtils) PlayPauseView(com.simplecity.amp_library.ui.views.PlayPauseView) SeekBarProgressChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarProgressChangeEvent) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) SnowfallView(com.simplecity.amp_library.ui.views.SnowfallView) SeekBarStartChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStartChangeEvent) Util(com.afollestad.aesthetic.Util) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Palette(android.support.v7.graphics.Palette) ButterKnife(butterknife.ButterKnife) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SuppressLint(android.annotation.SuppressLint) SeekBarChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarChangeEvent) Flowable(io.reactivex.Flowable) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Observable(io.reactivex.Observable) UnsafeConsumer(com.simplecity.amp_library.rx.UnsafeConsumer) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) BackpressureStrategy(io.reactivex.BackpressureStrategy) LayoutInflater(android.view.LayoutInflater) Target(com.bumptech.glide.request.target.Target) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) TextUtils(android.text.TextUtils) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) PlayerView(com.simplecity.amp_library.ui.views.PlayerView) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap) Glide(com.bumptech.glide.Glide) MultiSheetSlideEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay) Toolbar(android.support.v7.widget.Toolbar) MusicService(com.simplecity.amp_library.playback.MusicService) PlayerPresenter(com.simplecity.amp_library.ui.presenters.PlayerPresenter) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) RepeatButton(com.simplecity.amp_library.ui.views.RepeatButton) Collections(java.util.Collections) RxSeekBar(com.jakewharton.rxbinding2.widget.RxSeekBar) ValueAnimator(android.animation.ValueAnimator) RxSharedPreferences(com.f2prateek.rx.preferences2.RxSharedPreferences) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Aesthetic(com.afollestad.aesthetic.Aesthetic) Drawable(android.graphics.drawable.Drawable) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap)

Example 4 with 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();
}
Also used : LinearLayout(android.widget.LinearLayout) PreferencesConstants(com.amaze.filemanager.fragments.preference_fragments.PreferencesConstants) ColorUsage(com.amaze.filemanager.utils.color.ColorUsage) ShellNotRunningException(com.amaze.filemanager.exceptions.ShellNotRunningException) Uri(android.net.Uri) WindowManager(android.view.WindowManager) TextInputLayout(android.support.design.widget.TextInputLayout) ThemedActivity(com.amaze.filemanager.activities.superclasses.ThemedActivity) AppTheme(com.amaze.filemanager.utils.theme.AppTheme) CompressedHelper(com.amaze.filemanager.filesystem.compressed.CompressedHelper) RootHelper(com.amaze.filemanager.filesystem.RootHelper) GeneralSecurityException(java.security.GeneralSecurityException) CheckBox(android.widget.CheckBox) View(android.view.View) Button(android.widget.Button) RootUtils(com.amaze.filemanager.utils.RootUtils) PreferenceManager(android.preference.PreferenceManager) PieChart(com.github.mikephil.charting.charts.PieChart) PieData(com.github.mikephil.charting.data.PieData) LoadFolderSpaceDataTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFolderSpaceDataTask) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) M(android.os.Build.VERSION_CODES.M) AsyncTask(android.os.AsyncTask) Entry(com.github.mikephil.charting.data.Entry) InputType(android.text.InputType) FingerprintManager(android.hardware.fingerprint.FingerprintManager) Executors(java.util.concurrent.Executors) CryptUtil(com.amaze.filemanager.utils.files.CryptUtil) List(java.util.List) TextView(android.widget.TextView) HiddenAdapter(com.amaze.filemanager.adapters.HiddenAdapter) R(com.amaze.filemanager.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CountItemsOrAndSizeTask(com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask) AppCompatEditText(android.support.v7.widget.AppCompatEditText) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) Context(android.content.Context) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) HybridFile(com.amaze.filemanager.filesystem.HybridFile) MainFragment(com.amaze.filemanager.fragments.MainFragment) FingerprintHandler(com.amaze.filemanager.utils.FingerprintHandler) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi) FileUtils.toHybridFileArrayList(com.amaze.filemanager.utils.files.FileUtils.toHybridFileArrayList) AppsListFragment(com.amaze.filemanager.fragments.AppsListFragment) Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) MainActivity(com.amaze.filemanager.activities.MainActivity) ArrayList(java.util.ArrayList) AppCompatButton(android.support.v7.widget.AppCompatButton) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) PieDataSet(com.github.mikephil.charting.data.PieDataSet) Toast(android.widget.Toast) DataUtils(com.amaze.filemanager.utils.DataUtils) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ExecutorService(java.util.concurrent.ExecutorService) Formatter(android.text.format.Formatter) GenerateHashesTask(com.amaze.filemanager.asynchronous.asynctasks.GenerateHashesTask) SpannableString(android.text.SpannableString) TextUtils(android.text.TextUtils) DialogAction(com.afollestad.materialdialogs.DialogAction) IOException(java.io.IOException) File(java.io.File) Theme(com.afollestad.materialdialogs.Theme) EncryptDecryptUtils(com.amaze.filemanager.utils.files.EncryptDecryptUtils) Color(android.graphics.Color) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) BasicActivity(com.amaze.filemanager.activities.superclasses.BasicActivity) ViewPortHandler(com.github.mikephil.charting.utils.ViewPortHandler) FileUtils(com.amaze.filemanager.utils.files.FileUtils) DialogUtils(com.afollestad.materialdialogs.util.DialogUtils) TextInputEditText(android.support.design.widget.TextInputEditText) PieEntry(com.github.mikephil.charting.data.PieEntry) OpenMode(com.amaze.filemanager.utils.OpenMode) EditText(android.widget.EditText) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FileUtils.toHybridFileArrayList(com.amaze.filemanager.utils.files.FileUtils.toHybridFileArrayList) ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) TextView(android.widget.TextView)

Example 5 with Color

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BuildConfig(com.farmerbb.taskbar.BuildConfig) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) R(com.farmerbb.taskbar.R) U(com.farmerbb.taskbar.util.U) Intent(android.content.Intent) AppCompatActivity(android.support.v7.app.AppCompatActivity) Color(android.graphics.Color) SeekBar(android.widget.SeekBar) SuppressLint(android.annotation.SuppressLint) IconPackActivity(com.farmerbb.taskbar.activity.IconPackActivity) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) ScrollView(android.widget.ScrollView) Preference(android.preference.Preference) IconPackActivityDark(com.farmerbb.taskbar.activity.dark.IconPackActivityDark) View(android.view.View) Activity(android.app.Activity) ActionBar(android.support.v7.app.ActionBar) SeekBar(android.widget.SeekBar) SharedPreferences(android.content.SharedPreferences) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) ScrollView(android.widget.ScrollView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Aggregations

Color (android.graphics.Color)10 View (android.view.View)10 TextView (android.widget.TextView)8 Context (android.content.Context)7 Bundle (android.os.Bundle)7 LayoutInflater (android.view.LayoutInflater)7 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)6 Intent (android.content.Intent)5 ViewGroup (android.view.ViewGroup)5 List (java.util.List)5 Drawable (android.graphics.drawable.Drawable)4 PreferenceManager (android.preference.PreferenceManager)4 Nullable (android.support.annotation.Nullable)4 Log (android.util.Log)4 ImageView (android.widget.ImageView)4 ButterKnife (butterknife.ButterKnife)4 SuppressLint (android.annotation.SuppressLint)3 SharedPreferences (android.content.SharedPreferences)3 Build (android.os.Build)3 Toast (android.widget.Toast)3