Search in sources :

Example 31 with CompoundButton

use of android.widget.CompoundButton in project Hummingbird-for-Android by xiprox.

the class AnimeDetailsActivity method displayLibraryElements.

/* If Anime exist in user library, show library related elements... */
public void displayLibraryElements() {
    if (libraryEntry != null) {
        if (mRemove != null)
            mRemove.setVisible(true);
        final String animeEpisodeCount = anime.getEpisodeCount() != 0 ? anime.getEpisodeCount() + "" : "?";
        mEpisodes.setText(libraryEntry.getEpisodesWatched() + "/" + animeEpisodeCount);
        mRewatching.setChecked(libraryEntry.isRewatching());
        mRewatchedTimes.setText(libraryEntry.getNumberOfRewatches() + "");
        mPrivate.setChecked(libraryEntry.isPrivate());
        Rating rating = libraryEntry.getRating();
        if (rating.isAdvanced()) {
            if (rating.getAdvancedRating() != null)
                mRatingBar.setRating(Float.parseFloat(rating.getAdvancedRating()));
            else
                mRatingBar.setRating(0);
            mRatingBar.setVisibility(View.VISIBLE);
            mSimpleRatingView.setVisibility(View.GONE);
        } else {
            if (rating.getSimpleRating() != null)
                mSimpleRatingView.setSelectedRating(Utils.getRatingFromString(rating.getSimpleRating()));
            else
                mSimpleRatingView.setSelectedRating(SimpleRatingView.Rating.NEUTRAL);
            mRatingBar.setVisibility(View.GONE);
            mSimpleRatingView.setVisibility(View.VISIBLE);
        }
        newWatchStatus = libraryEntry.getStatus();
        newEpisodesWatched = libraryEntry.getEpisodesWatched();
        newIsRewatching = libraryEntry.isRewatching();
        newRewatchedTimes = libraryEntry.getNumberOfRewatches();
        newPrivate = libraryEntry.isPrivate();
        newRating = libraryEntry.getRating().getAdvancedRating() != null ? libraryEntry.getRating().getAdvancedRating() : "0";
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(AnimeDetailsActivity.this, R.array.library_watch_status_items, R.layout.item_spinner_library_status);
        adapter.setDropDownViewResource(R.layout.item_spinner_item_library_status);
        mStatusSpinner.setAdapter(adapter);
        String watchStatus = libraryEntry.getStatus();
        if (watchStatus.equals("currently-watching"))
            mStatusSpinner.setSelection(0);
        if (watchStatus.equals("plan-to-watch"))
            mStatusSpinner.setSelection(1);
        if (watchStatus.equals("completed"))
            mStatusSpinner.setSelection(2);
        if (watchStatus.equals("on-hold"))
            mStatusSpinner.setSelection(3);
        if (watchStatus.equals("dropped"))
            mStatusSpinner.setSelection(4);
        mEpisodesHolder.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                View dialogView = getLayoutInflater().inflate(R.layout.number_picker, null);
                final NumberPicker mNumberPicker = (NumberPicker) dialogView.findViewById(R.id.number_picker);
                mNumberPicker.setMaxValue(anime.getEpisodeCount() != 0 ? anime.getEpisodeCount() : 1000);
                mNumberPicker.setValue(newEpisodesWatched);
                mNumberPicker.setWrapSelectorWheel(false);
                new MaterialDialog.Builder(AnimeDetailsActivity.this).title(R.string.content_episodes).positiveText(R.string.ok).negativeText(R.string.cancel).positiveColor(vibrantColor).negativeColorRes(R.color.text_dialog_action).customView(dialogView, true).callback(new MaterialDialog.ButtonCallback() {

                    @Override
                    public void onPositive(MaterialDialog materialDialog) {
                        newEpisodesWatched = mNumberPicker.getValue();
                        mEpisodes.setText(newEpisodesWatched + "/" + animeEpisodeCount);
                        if ((newEpisodesWatched + "").equals(animeEpisodeCount))
                            // (completed)
                            mStatusSpinner.setSelection(2);
                        updateUpdateButtonStatus(libraryEntry);
                    }
                }).show();
            }
        });
        mRewatching.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                newIsRewatching = isChecked;
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mRewatchedTimesHolder.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                View dialogView = getLayoutInflater().inflate(R.layout.number_picker, null);
                final NumberPicker mNumberPicker = (NumberPicker) dialogView.findViewById(R.id.number_picker);
                mNumberPicker.setMaxValue(200);
                mNumberPicker.setValue(newRewatchedTimes);
                mNumberPicker.setWrapSelectorWheel(false);
                new MaterialDialog.Builder(AnimeDetailsActivity.this).title(R.string.content_rewatched).positiveText(R.string.ok).negativeText(R.string.cancel).positiveColor(vibrantColor).negativeColorRes(R.color.text_dialog_action).customView(dialogView, true).callback(new MaterialDialog.ButtonCallback() {

                    @Override
                    public void onPositive(MaterialDialog materialDialog) {
                        newRewatchedTimes = mNumberPicker.getValue();
                        mRewatchedTimes.setText(newRewatchedTimes + "");
                        updateUpdateButtonStatus(libraryEntry);
                    }
                }).show();
            }
        });
        mPrivate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                newPrivate = isChecked;
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mStatusSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
                switch(position) {
                    case 0:
                        newWatchStatus = "currently-watching";
                        break;
                    case 1:
                        newWatchStatus = "plan-to-watch";
                        break;
                    case 2:
                        newWatchStatus = "completed";
                        break;
                    case 3:
                        newWatchStatus = "on-hold";
                        break;
                    case 4:
                        newWatchStatus = "dropped";
                        break;
                }
                updateUpdateButtonStatus(libraryEntry);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {
            }
        });
        mRatingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {

            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                newRating = rating + "";
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mSimpleRatingView.setOnRatingChangedListener(new SimpleRatingView.OnRatingChangeListener() {

            @Override
            public void onRatingChanged(SimpleRatingView.Rating rating) {
                switch(rating) {
                    case POSITIVE:
                        newRating = "1";
                        break;
                    case NEUTRAL:
                        newRating = "3";
                        break;
                    case NEGATIVE:
                        newRating = "5";
                        break;
                }
                updateUpdateButtonStatus(libraryEntry);
            }
        });
        mActionButton.setImageResource(R.drawable.ic_upload_white_24dp);
        mActionButton.setOnClickListener(new OnLibraryUpdateClickListener());
        mLibraryProgressBar.setVisibility(View.GONE);
        mLibraryInfoHolder.setVisibility(View.VISIBLE);
    } else {
        enableFAB();
        mRemove.setVisible(false);
        mLibraryProgressBar.setVisibility(View.GONE);
        mLibraryInfoHolder.setVisibility(View.GONE);
    }
}
Also used : Rating(tr.bcxip.hummingbird.api.objects.Rating) NumberPicker(android.widget.NumberPicker) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ImageView(android.widget.ImageView) ObservableScrollView(tr.bcxip.hummingbird.widget.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) SimpleRatingView(tr.xip.widget.simpleratingview.SimpleRatingView) TextView(android.widget.TextView) RatingBar(android.widget.RatingBar) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SimpleRatingView(tr.xip.widget.simpleratingview.SimpleRatingView)

Example 32 with CompoundButton

use of android.widget.CompoundButton in project httpclient by pixmob.

the class ListMenuItemView method setCheckable.

public void setCheckable(boolean checkable) {
    if (!checkable && mRadioButton == null && mCheckBox == null) {
        return;
    }
    if (mRadioButton == null) {
        insertRadioButton();
    }
    if (mCheckBox == null) {
        insertCheckBox();
    }
    // Depending on whether its exclusive check or not, the checkbox or
    // radio button will be the one in use (and the other will be otherCompoundButton)
    final CompoundButton compoundButton;
    final CompoundButton otherCompoundButton;
    if (mItemData.isExclusiveCheckable()) {
        compoundButton = mRadioButton;
        otherCompoundButton = mCheckBox;
    } else {
        compoundButton = mCheckBox;
        otherCompoundButton = mRadioButton;
    }
    if (checkable) {
        compoundButton.setChecked(mItemData.isChecked());
        final int newVisibility = checkable ? VISIBLE : GONE;
        if (compoundButton.getVisibility() != newVisibility) {
            compoundButton.setVisibility(newVisibility);
        }
        // Make sure the other compound button isn't visible
        if (otherCompoundButton.getVisibility() != GONE) {
            otherCompoundButton.setVisibility(GONE);
        }
    } else {
        mCheckBox.setVisibility(GONE);
        mRadioButton.setVisibility(GONE);
    }
}
Also used : CompoundButton(android.widget.CompoundButton)

Example 33 with CompoundButton

use of android.widget.CompoundButton in project platform_frameworks_base by android.

the class ListMenuItemView method setCheckable.

public void setCheckable(boolean checkable) {
    if (!checkable && mRadioButton == null && mCheckBox == null) {
        return;
    }
    // Depending on whether its exclusive check or not, the checkbox or
    // radio button will be the one in use (and the other will be otherCompoundButton)
    final CompoundButton compoundButton;
    final CompoundButton otherCompoundButton;
    if (mItemData.isExclusiveCheckable()) {
        if (mRadioButton == null) {
            insertRadioButton();
        }
        compoundButton = mRadioButton;
        otherCompoundButton = mCheckBox;
    } else {
        if (mCheckBox == null) {
            insertCheckBox();
        }
        compoundButton = mCheckBox;
        otherCompoundButton = mRadioButton;
    }
    if (checkable) {
        compoundButton.setChecked(mItemData.isChecked());
        final int newVisibility = checkable ? VISIBLE : GONE;
        if (compoundButton.getVisibility() != newVisibility) {
            compoundButton.setVisibility(newVisibility);
        }
        // Make sure the other compound button isn't visible
        if (otherCompoundButton != null && otherCompoundButton.getVisibility() != GONE) {
            otherCompoundButton.setVisibility(GONE);
        }
    } else {
        if (mCheckBox != null)
            mCheckBox.setVisibility(GONE);
        if (mRadioButton != null)
            mRadioButton.setVisibility(GONE);
    }
}
Also used : CompoundButton(android.widget.CompoundButton)

Example 34 with CompoundButton

use of android.widget.CompoundButton in project JamsMusicPlayer by psaravan.

the class BlacklistedSongsMultiselectAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;
    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_songs_layout, parent, false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.songThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.songNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.songCheckboxMusicLibraryEditor);
        holder.subText = (TextView) convertView.findViewById(R.id.artistNameSongListView);
        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }
    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songTitle = c.getString(c.getColumnIndex(DBAccessHelper.SONG_TITLE));
    final String songFilePath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_FILE_PATH));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));
    String songBlacklistStatus = c.getString(c.getColumnIndex(DBAccessHelper.BLACKLIST_STATUS));
    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.subText.setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    //Set the songID as the view's tag.
    convertView.setTag(R.string.song_id, songId);
    convertView.setTag(R.string.song_file_path, songFilePath);
    //Set the song title.
    holder.title.setText(songTitle);
    holder.subText.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image, BlacklistManagerActivity.displayImageOptions);
    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (BlacklistManagerActivity.songIdBlacklistStatusPair.get(songId).equals("TRUE")) {
        convertView.setBackgroundColor(0xCCFF4444);
        holder.checkBox.setChecked(true);
    } else {
        convertView.setBackgroundColor(0x00000000);
        holder.checkBox.setChecked(false);
    }
    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {
            if (isChecked == true) {
                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCCFF4444);
                    BlacklistManagerActivity.songIdBlacklistStatusPair.put(songId, true);
                }
            } else if (isChecked == false) {
                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0x000000);
                    BlacklistManagerActivity.songIdBlacklistStatusPair.put(songId, false);
                }
            }
        }
    });
    return convertView;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Cursor(android.database.Cursor) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Example 35 with CompoundButton

use of android.widget.CompoundButton in project JamsMusicPlayer by psaravan.

the class BlacklistedAlbumsMultiselectAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final Cursor c = (Cursor) getItem(position);
    SongsListViewHolder holder = null;
    if (convertView == null) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.music_library_editor_albums_layout, parent, false);
        holder = new SongsListViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.albumThumbnailMusicLibraryEditor);
        holder.title = (TextView) convertView.findViewById(R.id.albumNameMusicLibraryEditor);
        holder.checkBox = (CheckBox) convertView.findViewById(R.id.albumCheckboxMusicLibraryEditor);
        holder.subText = (TextView) convertView.findViewById(R.id.albumArtistNameMusicLibraryEditor);
        convertView.setTag(holder);
    } else {
        holder = (SongsListViewHolder) convertView.getTag();
    }
    final View finalConvertView = convertView;
    final String songId = c.getString(c.getColumnIndex(DBAccessHelper._ID));
    final String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));
    final String songAlbum = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM));
    final String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    final String songBlacklistStatus = c.getString(c.getColumnIndex(DBAccessHelper.BLACKLIST_STATUS));
    //Set the album's name and artist as the row's tag.
    convertView.setTag(R.string.album, songAlbum);
    convertView.setTag(R.string.artist, songArtist);
    holder.title.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    holder.subText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    holder.subText.setPaintFlags(holder.subText.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
    //Set the song title.
    holder.title.setText(songAlbum);
    holder.subText.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image, BlacklistManagerActivity.displayImageOptions);
    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (BlacklistManagerActivity.songIdBlacklistStatusPair.get(songId).equals("TRUE")) {
        holder.checkBox.setChecked(true);
        convertView.setBackgroundColor(0xCCFF4444);
    } else {
        convertView.setBackgroundColor(0x00000000);
        holder.checkBox.setChecked(false);
    }
    holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {
            if (isChecked == true) {
                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0xCCFF4444);
                    AsyncBlacklistAlbumTask task = new AsyncBlacklistAlbumTask(songAlbum, songArtist);
                    task.execute(new String[] { "ADD" });
                }
            } else if (isChecked == false) {
                //Only receive inputs by the user and ignore any system-made changes to the checkbox state.
                if (checkbox.isPressed()) {
                    finalConvertView.setBackgroundColor(0x00000000);
                    AsyncBlacklistAlbumTask task = new AsyncBlacklistAlbumTask(songAlbum, songArtist);
                    task.execute(new String[] { "REMOVE" });
                }
            }
        }
    });
    return convertView;
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Cursor(android.database.Cursor) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Aggregations

CompoundButton (android.widget.CompoundButton)249 View (android.view.View)129 TextView (android.widget.TextView)102 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)63 ImageView (android.widget.ImageView)50 CheckBox (android.widget.CheckBox)45 AdapterView (android.widget.AdapterView)27 Intent (android.content.Intent)26 Button (android.widget.Button)24 DialogInterface (android.content.DialogInterface)23 LayoutInflater (android.view.LayoutInflater)23 OnClickListener (android.view.View.OnClickListener)20 Switch (android.widget.Switch)18 SeekBar (android.widget.SeekBar)17 SwitchCompat (android.support.v7.widget.SwitchCompat)15 AlertDialog (android.app.AlertDialog)14 RecyclerView (android.support.v7.widget.RecyclerView)13 ArrayList (java.util.ArrayList)13 LinearLayout (android.widget.LinearLayout)12 OnClickListener (android.content.DialogInterface.OnClickListener)11