Search in sources :

Example 1 with ColorView

use of com.simplecity.amp_library.ui.modelviews.ColorView in project Shuttle by timusus.

the class ColorAdapter method setSelectedPosition.

public void setSelectedPosition(int position) {
    for (int i = 0, itemsSize = items.size(); i < itemsSize; i++) {
        ColorView item = (ColorView) items.get(i);
        if (item.selected) {
            item.selected = false;
            notifyItemChanged(i);
            break;
        }
    }
    ((ColorView) items.get(position)).selected = true;
    notifyItemChanged(position);
}
Also used : ColorView(com.simplecity.amp_library.ui.modelviews.ColorView)

Example 2 with ColorView

use of com.simplecity.amp_library.ui.modelviews.ColorView 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)

Aggregations

ColorView (com.simplecity.amp_library.ui.modelviews.ColorView)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 ComponentName (android.content.ComponentName)1 ContentProviderOperation (android.content.ContentProviderOperation)1 Context (android.content.Context)1 Intent (android.content.Intent)1 OperationApplicationException (android.content.OperationApplicationException)1 Bitmap (android.graphics.Bitmap)1 Color (android.graphics.Color)1 Drawable (android.graphics.drawable.Drawable)1 RemoteException (android.os.RemoteException)1 StringRes (android.support.annotation.StringRes)1 Snackbar (android.support.design.widget.Snackbar)1 FileProvider (android.support.v4.content.FileProvider)1 IntentCompat (android.support.v4.content.IntentCompat)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Html (android.text.Html)1