Search in sources :

Example 16 with OnCheckedChangeListener

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

the class PlaylistEditorSongsMultiselectAdapter 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));
    String songAlbumArtPath = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ALBUM_ART_PATH));
    String songArtist = c.getString(c.getColumnIndex(DBAccessHelper.SONG_ARTIST));
    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);
    //Set the song title.
    holder.title.setText(songTitle);
    holder.subText.setText(songArtist);
    mApp.getImageLoader().displayImage(songAlbumArtPath, holder.image, PlaylistEditorActivity.displayImageOptions);
    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (PlaylistEditorActivity.songDBIdsList.contains(songId)) {
        convertView.setBackgroundColor(0xCC0099CC);
        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(0xCC0099CC);
                    PlaylistEditorActivity.songDBIdsList.add(songId);
                }
            } 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(0xCC0099CC);
                    PlaylistEditorActivity.songDBIdsList.remove(songId);
                }
            }
        }
    });
    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 17 with OnCheckedChangeListener

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

the class MusicLibraryEditorAlbumsMultiselectAdapter 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));
    //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, MusicLibraryEditorActivity.displayImageOptions);
    //Check if the song's DB ID exists in the HashSet and set the appropriate checkbox status.
    if (MusicLibraryEditorActivity.songDBIdsList.contains(songId)) {
        holder.checkBox.setChecked(true);
        convertView.setBackgroundColor(0xCC0099CC);
    } 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(0xCC0099CC);
                    AsyncGetAlbumSongIds task = new AsyncGetAlbumSongIds(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);
                    AsyncGetAlbumSongIds task = new AsyncGetAlbumSongIds(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)

Example 18 with OnCheckedChangeListener

use of android.widget.CompoundButton.OnCheckedChangeListener in project android-app by spark.

the class SmartConfigFragment method setUpCustomKeyCheckbox.

private void setUpCustomKeyCheckbox() {
    final ImageView aesCbImage = Ui.findView(this, R.id.custom_aes_key_checkbox_image);
    customKeyCheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            customKeyEntry.setVisibility((isChecked) ? View.VISIBLE : View.GONE);
            aesCbImage.setImageResource((isChecked) ? R.drawable.aes_checkbox_checked_temp : R.drawable.aes_checkbox_unchecked_temp);
            validateForm(buttonView.getId());
        }
    });
    View aesBoxParent = Ui.findView(this, R.id.aes_parent);
    aesBoxParent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            customKeyCheckbox.toggle();
        }
    });
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 19 with OnCheckedChangeListener

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

the class ZenModePanel method bind.

private void bind(final Condition condition, final View row, final int rowId) {
    if (condition == null)
        throw new IllegalArgumentException("condition must not be null");
    final boolean enabled = condition.state == Condition.STATE_TRUE;
    final ConditionTag tag = row.getTag() != null ? (ConditionTag) row.getTag() : new ConditionTag();
    row.setTag(tag);
    final boolean first = tag.rb == null;
    if (tag.rb == null) {
        tag.rb = (RadioButton) mZenRadioGroup.getChildAt(rowId);
    }
    tag.condition = condition;
    final Uri conditionId = getConditionId(tag.condition);
    if (DEBUG)
        Log.d(mTag, "bind i=" + mZenRadioGroupContent.indexOfChild(row) + " first=" + first + " condition=" + conditionId);
    tag.rb.setEnabled(enabled);
    tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mExpanded && isChecked) {
                tag.rb.setChecked(true);
                if (DEBUG)
                    Log.d(mTag, "onCheckedChanged " + conditionId);
                MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT);
                select(tag.condition);
                announceConditionSelection(tag);
            }
        }
    });
    if (tag.lines == null) {
        tag.lines = row.findViewById(android.R.id.content);
    }
    if (tag.line1 == null) {
        tag.line1 = (TextView) row.findViewById(android.R.id.text1);
        mSpTexts.add(tag.line1);
    }
    if (tag.line2 == null) {
        tag.line2 = (TextView) row.findViewById(android.R.id.text2);
        mSpTexts.add(tag.line2);
    }
    final String line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary;
    final String line2 = condition.line2;
    tag.line1.setText(line1);
    if (TextUtils.isEmpty(line2)) {
        tag.line2.setVisibility(GONE);
    } else {
        tag.line2.setVisibility(VISIBLE);
        tag.line2.setText(line2);
    }
    tag.lines.setEnabled(enabled);
    tag.lines.setAlpha(enabled ? 1 : .4f);
    final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, false, /*down*/
            rowId);
        }
    });
    final ImageView button2 = (ImageView) row.findViewById(android.R.id.button2);
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickTimeButton(row, tag, true, /*up*/
            rowId);
        }
    });
    tag.lines.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            tag.rb.setChecked(true);
        }
    });
    final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
    if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) {
        button1.setVisibility(VISIBLE);
        button2.setVisibility(VISIBLE);
        if (mBucketIndex > -1) {
            button1.setEnabled(mBucketIndex > 0);
            button2.setEnabled(mBucketIndex < MINUTE_BUCKETS.length - 1);
        } else {
            final long span = time - System.currentTimeMillis();
            button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS);
            final Condition maxCondition = ZenModeConfig.toTimeCondition(mContext, MAX_BUCKET_MINUTES, ActivityManager.getCurrentUser());
            button2.setEnabled(!Objects.equals(condition.summary, maxCondition.summary));
        }
        button1.setAlpha(button1.isEnabled() ? 1f : .5f);
        button2.setAlpha(button2.isEnabled() ? 1f : .5f);
    } else {
        button1.setVisibility(GONE);
        button2.setVisibility(GONE);
    }
    // wire up interaction callbacks for newly-added condition rows
    if (first) {
        Interaction.register(tag.rb, mInteractionCallback);
        Interaction.register(tag.lines, mInteractionCallback);
        Interaction.register(button1, mInteractionCallback);
        Interaction.register(button2, mInteractionCallback);
    }
    row.setVisibility(VISIBLE);
}
Also used : Condition(android.service.notification.Condition) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ImageView(android.widget.ImageView) CompoundButton(android.widget.CompoundButton)

Example 20 with OnCheckedChangeListener

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

the class InputMethodManagerService method showInputMethodMenu.

private void showInputMethodMenu(boolean showAuxSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu. showAuxSubtypes=" + showAuxSubtypes);
    final Context context = mContext;
    final boolean isScreenLocked = isScreenLocked();
    final String lastInputMethodId = mSettings.getSelectedInputMethod();
    int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
    if (DEBUG)
        Slog.v(TAG, "Current IME: " + lastInputMethodId);
    synchronized (mMethodMap) {
        final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = mSettings.getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked(mContext);
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mSwitchingController.getSortedInputMethodAndSubtypeListLocked(showAuxSubtypes, isScreenLocked);
        if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
                lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
            }
        }
        final int N = imList.size();
        mIms = new InputMethodInfo[N];
        mSubtypeIds = new int[N];
        int checkedItem = 0;
        for (int i = 0; i < N; ++i) {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
            if (mIms[i].getId().equals(lastInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
        }
        final Context settingsContext = new ContextThemeWrapper(context, com.android.internal.R.style.Theme_DeviceDefault_Settings);
        mDialogBuilder = new AlertDialog.Builder(settingsContext);
        mDialogBuilder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        });
        final Context dialogContext = mDialogBuilder.getContext();
        final TypedArray a = dialogContext.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        final Drawable dialogIcon = a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogIcon);
        a.recycle();
        mDialogBuilder.setIcon(dialogIcon);
        final LayoutInflater inflater = dialogContext.getSystemService(LayoutInflater.class);
        final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
        mDialogBuilder.setCustomTitle(tv);
        // Setup layout for a toggle switch of the hardware keyboard
        mSwitchingDialogTitleView = tv;
        mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerInternal.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = (Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch);
        hardKeySwitch.setChecked(mShowImeWithHardKeyboard);
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mSettings.setShowImeWithHardKeyboard(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(dialogContext, com.android.internal.R.layout.input_method_switch_item, imList, checkedItem);
        final OnClickListener choiceListener = new OnClickListener() {

            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    final InputMethodInfo im = mIms[which];
                    int subtypeId = mSubtypeIds[which];
                    adapter.mCheckedItem = which;
                    adapter.notifyDataSetChanged();
                    hideInputMethodMenu();
                    if (im != null) {
                        if (subtypeId < 0 || subtypeId >= im.getSubtypeCount()) {
                            subtypeId = NOT_A_SUBTYPE_ID;
                        }
                        setInputMethodLocked(im.getId(), subtypeId);
                    }
                }
            }
        };
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, choiceListener);
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
        updateSystemUi(mCurToken, mImeWindowVis, mBackDisposition);
        mSwitchingDialog.show();
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) InputMethodInfo(android.view.inputmethod.InputMethodInfo) TypedArray(android.content.res.TypedArray) ArrayList(java.util.ArrayList) List(java.util.List) LocaleList(android.os.LocaleList) OnCancelListener(android.content.DialogInterface.OnCancelListener) IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) Drawable(android.graphics.drawable.Drawable) View(android.view.View) TextView(android.widget.TextView) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem) ContextThemeWrapper(android.view.ContextThemeWrapper) Switch(android.widget.Switch) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener) CompoundButton(android.widget.CompoundButton)

Aggregations

OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)60 CompoundButton (android.widget.CompoundButton)59 View (android.view.View)44 TextView (android.widget.TextView)37 ImageView (android.widget.ImageView)24 OnClickListener (android.view.View.OnClickListener)15 DialogInterface (android.content.DialogInterface)13 AlertDialog (android.app.AlertDialog)12 OnClickListener (android.content.DialogInterface.OnClickListener)11 Button (android.widget.Button)11 Cursor (android.database.Cursor)9 CheckBox (android.widget.CheckBox)8 Context (android.content.Context)7 LayoutInflater (android.view.LayoutInflater)7 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 TypedArray (android.content.res.TypedArray)6 Paint (android.graphics.Paint)6 AdapterView (android.widget.AdapterView)6 Intent (android.content.Intent)5 Drawable (android.graphics.drawable.Drawable)5