Example usage for android.graphics.drawable LayerDrawable setBounds

List of usage examples for android.graphics.drawable LayerDrawable setBounds

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable setBounds.

Prototype

public void setBounds(@NonNull Rect bounds) 

Source Link

Document

Specify a bounding rectangle for the Drawable.

Usage

From source file:org.mythdroid.remote.TVRemote.java

private void setupProgressBar(int max, int progress, Program prog, float fps) {

    pBar.setMax(max);//w ww  . ja v  a2s .co  m
    pBar.setProgress(progress);

    pBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (!fromUser || seekBar.getMax() <= 0)
                return;
            if (mddMgr != null) {
                FrontendLocation loc = null;
                try {
                    synchronized (feLock) {
                        loc = feMgr.getLoc();
                    }
                } catch (IOException e) {
                    ErrUtil.err(ctx, e);
                    return;
                } catch (IllegalArgumentException e) {
                    return;
                }
                if (loc.end <= 0)
                    return;
                progress = (loc.end * progress) / 1000;
            }
            try {
                synchronized (feLock) {
                    feMgr.seekTo(progress);
                }
            } catch (IOException e) {
                ErrUtil.err(ctx, e);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

    });

    if (prog == null || endTime <= 0 || fps == 0)
        return;

    ArrayList<Commercial> cuts = prog.getCutList(feMgr.addr);
    if (cuts.isEmpty())
        return;

    Drawable[] layers = new Drawable[2];
    layers[0] = pBar.getProgressDrawable();
    Rect bounds = layers[0].getBounds();
    layers[1] = new CutListDrawable(cuts, fps, endTime, bounds);
    LayerDrawable lg = new LayerDrawable(layers);
    lg.setBounds(bounds);
    pBar.setProgressDrawable(lg);

}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void sortChannels() {
    ContentResolver cr = getContentResolver();

    StringBuilder where = new StringBuilder(TvBrowserContentProvider.CHANNEL_KEY_SELECTION);
    where.append("=1");

    LinearLayout main = (LinearLayout) getLayoutInflater().inflate(R.layout.channel_sort_list,
            getParentViewGroup(), false);

    Button sortAlphabetically = (Button) main.findViewById(R.id.channel_sort_alpabetically);

    final DynamicListView channelSort = (DynamicListView) main.findViewById(R.id.channel_sort);

    String[] projection = { TvBrowserContentProvider.KEY_ID, TvBrowserContentProvider.CHANNEL_KEY_NAME,
            TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER, TvBrowserContentProvider.CHANNEL_KEY_SELECTION,
            TvBrowserContentProvider.CHANNEL_KEY_LOGO };

    Cursor channels = cr.query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, projection, where.toString(),
            null, TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER);

    final ArrayList<SortInterface> channelSource = new ArrayList<SortInterface>();

    if (channels.moveToFirst()) {
        do {/*from  w w w . ja v a  2s.  co m*/
            int key = channels.getInt(0);
            String name = channels.getString(1);

            int order = 0;

            if (!channels.isNull(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER))) {
                order = channels
                        .getInt(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER));
            }

            Bitmap channelLogo = UiUtils.createBitmapFromByteArray(
                    channels.getBlob(channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_LOGO)));

            if (channelLogo != null) {
                BitmapDrawable l = new BitmapDrawable(getResources(), channelLogo);

                ColorDrawable background = new ColorDrawable(SettingConstants.LOGO_BACKGROUND_COLOR);
                background.setBounds(0, 0, channelLogo.getWidth() + 2, channelLogo.getHeight() + 2);

                LayerDrawable logoDrawable = new LayerDrawable(new Drawable[] { background, l });
                logoDrawable.setBounds(background.getBounds());

                l.setBounds(2, 2, channelLogo.getWidth(), channelLogo.getHeight());

                channelLogo = UiUtils.drawableToBitmap(logoDrawable);
            }

            channelSource.add(new ChannelSort(key, name, order, channelLogo));
        } while (channels.moveToNext());

        channels.close();

        final Comparator<SortInterface> sortComparator = new Comparator<SortInterface>() {
            @Override
            public int compare(SortInterface lhs, SortInterface rhs) {
                if (lhs.getSortNumber() < rhs.getSortNumber()) {
                    return -1;
                } else if (lhs.getSortNumber() > rhs.getSortNumber()) {
                    return 1;
                }

                return 0;
            }
        };

        Collections.sort(channelSource, sortComparator);

        // create default logo for channels without logo
        final Bitmap defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

        final StableArrayAdapter<SortInterface> aa = new StableArrayAdapter<SortInterface>(TvBrowser.this,
                R.layout.channel_sort_row, channelSource) {
            public View getView(int position, View convertView, ViewGroup parent) {
                ChannelSort value = (ChannelSort) getItem(position);
                ViewHolder holder = null;

                if (convertView == null) {
                    LayoutInflater mInflater = (LayoutInflater) getContext()
                            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                    holder = new ViewHolder();

                    convertView = mInflater.inflate(R.layout.channel_sort_row, getParentViewGroup(), false);

                    holder.mTextView = (TextView) convertView.findViewById(R.id.row_of_channel_sort_text);
                    holder.mSortNumber = (TextView) convertView.findViewById(R.id.row_of_channel_sort_number);
                    holder.mLogo = (ImageView) convertView.findViewById(R.id.row_of_channel_sort_icon);

                    convertView.setTag(holder);

                } else {
                    holder = (ViewHolder) convertView.getTag();
                }

                holder.mTextView.setText(value.getName());

                String sortNumber = String.valueOf(value.getSortNumber());

                if (value.getSortNumber() == 0) {
                    sortNumber = "-";
                }

                sortNumber += ".";

                holder.mSortNumber.setText(sortNumber);

                Bitmap logo = value.getLogo();

                if (logo != null) {
                    holder.mLogo.setImageBitmap(logo);
                } else {
                    holder.mLogo.setImageBitmap(defaultLogo);
                }

                return convertView;
            }
        };
        channelSort.setAdapter(aa);
        channelSort.setArrayList(channelSource);
        channelSort.setSortDropListener(new SortDropListener() {
            @Override
            public void dropped(int originalPosition, int position) {
                int startIndex = originalPosition;
                int endIndex = position;

                int droppedPos = position;

                if (originalPosition > position) {
                    startIndex = position;
                    endIndex = originalPosition;
                }

                int previousNumber = 0;

                if (startIndex > 0) {
                    previousNumber = aa.getItem(startIndex - 1).getSortNumber();
                }

                int firstVisible = channelSort.getFirstVisiblePosition();

                for (int i = startIndex; i <= endIndex; i++) {
                    if (i == droppedPos || aa.getItem(i).getSortNumber() != 0) {
                        aa.getItem(i).setSortNumber(++previousNumber);

                        if (i >= firstVisible) {
                            View line = channelSort.getChildAt(i - firstVisible);

                            if (line != null) {
                                ((TextView) line.findViewById(R.id.row_of_channel_sort_number))
                                        .setText(String.valueOf(previousNumber) + ".");
                            }
                        }
                    }
                }

            }
        });

        channelSort.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> adapterView, final View view, final int position,
                    long id) {
                AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

                LinearLayout numberSelection = (LinearLayout) getLayoutInflater()
                        .inflate(R.layout.sort_number_selection, getParentViewGroup(), false);

                mSelectionNumberChanged = false;

                final NumberPicker number = (NumberPicker) numberSelection.findViewById(R.id.sort_picker);
                number.setMinValue(1);
                number.setMaxValue(channelSource.size());
                number.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
                number.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
                    @Override
                    public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                        mSelectionNumberChanged = true;
                    }
                });

                final EditText numberAlternative = (EditText) numberSelection
                        .findViewById(R.id.sort_entered_number);

                builder.setView(numberSelection);

                final ChannelSort selection = (ChannelSort) channelSource.get(position);

                TextView name = (TextView) numberSelection.findViewById(R.id.sort_picker_channel_name);
                name.setText(selection.getName());

                if (selection.getSortNumber() > 0) {
                    if (selection.getSortNumber() < channelSource.size() + 1) {
                        number.setValue(selection.getSortNumber());
                    } else {
                        numberAlternative.setText(String.valueOf(selection.getSortNumber()));
                    }
                }

                builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        String test = numberAlternative.getText().toString().trim();

                        if (test.length() == 0 || mSelectionNumberChanged) {
                            selection.setSortNumber(number.getValue());
                        } else {
                            try {
                                selection.setSortNumber(Integer.parseInt(test));
                            } catch (NumberFormatException e1) {
                            }
                        }

                        Collections.sort(channelSource, sortComparator);
                        aa.notifyDataSetChanged();
                    }
                });

                builder.setNegativeButton(android.R.string.cancel, null);

                builder.show();
            }
        });

        sortAlphabetically.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Collections.sort(channelSource, new Comparator<SortInterface>() {
                    @Override
                    public int compare(SortInterface lhs, SortInterface rhs) {
                        return lhs.getName().compareToIgnoreCase(rhs.getName());
                    }
                });

                for (int i = 0; i < channelSource.size(); i++) {
                    channelSource.get(i).setSortNumber(i + 1);
                }

                aa.notifyDataSetChanged();
            }
        });

        AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

        builder.setTitle(R.string.action_sort_channels);
        builder.setView(main);

        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean somethingChanged = false;

                for (SortInterface selection : channelSource) {
                    if (((ChannelSort) selection).wasChanged()) {
                        somethingChanged = true;

                        ContentValues values = new ContentValues();
                        values.put(TvBrowserContentProvider.CHANNEL_KEY_ORDER_NUMBER,
                                selection.getSortNumber());

                        getContentResolver().update(
                                ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS,
                                        ((ChannelSort) selection).getKey()),
                                values, null, null);
                    }
                }

                if (somethingChanged) {
                    updateProgramListChannelBar();
                }
            }
        });
        builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        builder.show();
    }
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private void showChannelSelectionInternal(final String selection, final String title, final String help,
        final boolean delete) {
    String[] projection = {/*from w ww .  ja  va2 s .  co m*/
            TvBrowserContentProvider.CHANNEL_TABLE + "." + TvBrowserContentProvider.KEY_ID + " AS "
                    + TvBrowserContentProvider.KEY_ID,
            TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID, TvBrowserContentProvider.CHANNEL_KEY_NAME,
            TvBrowserContentProvider.CHANNEL_KEY_SELECTION, TvBrowserContentProvider.CHANNEL_KEY_CATEGORY,
            TvBrowserContentProvider.CHANNEL_KEY_LOGO, TvBrowserContentProvider.CHANNEL_KEY_ALL_COUNTRIES };

    ContentResolver cr = getContentResolver();
    Cursor channels = cr.query(TvBrowserContentProvider.CONTENT_URI_CHANNELS_WITH_GROUP, projection, selection,
            null, TvBrowserContentProvider.CHANNEL_KEY_NAME);
    channels.moveToPosition(-1);

    // populate array list with all available channels
    final ArrayListWrapper channelSelectionList = new ArrayListWrapper();
    ArrayList<Country> countryList = new ArrayList<Country>();

    int channelIdColumn = channels.getColumnIndex(TvBrowserContentProvider.KEY_ID);
    int categoryColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_CATEGORY);
    int logoColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_LOGO);
    int dataServiceColumn = channels.getColumnIndex(TvBrowserContentProvider.GROUP_KEY_DATA_SERVICE_ID);
    int nameColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_NAME);
    int countyColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_ALL_COUNTRIES);
    int selectionColumn = channels.getColumnIndex(TvBrowserContentProvider.CHANNEL_KEY_SELECTION);
    ;
    while (channels.moveToNext()) {
        int channelID = channels.getInt(channelIdColumn);
        int category = channels.getInt(categoryColumn);
        byte[] logo = channels.getBlob(logoColumn);
        String dataService = channels.getString(dataServiceColumn);
        String name = channels.getString(nameColumn);
        String countries = channels.getString(countyColumn);
        boolean isSelected = channels.getInt(selectionColumn) == 1 && !delete;

        if (countries.contains("$")) {
            String[] values = countries.split("\\$");

            for (String country : values) {
                Country test = new Country(new Locale(country, country));

                if (!countryList.contains(test) && test.mLocale.getDisplayCountry().trim().length() > 0) {
                    countryList.add(test);
                }
            }
        } else {
            Country test = new Country(new Locale(countries, countries));

            if (!countryList.contains(test) && test.mLocale.getDisplayCountry().trim().length() > 0) {
                countryList.add(test);
            }
        }

        Bitmap channelLogo = UiUtils.createBitmapFromByteArray(logo);

        if (channelLogo != null) {
            BitmapDrawable l = new BitmapDrawable(getResources(), channelLogo);

            ColorDrawable background = new ColorDrawable(SettingConstants.LOGO_BACKGROUND_COLOR);
            background.setBounds(0, 0, channelLogo.getWidth() + 2, channelLogo.getHeight() + 2);

            LayerDrawable logoDrawable = new LayerDrawable(new Drawable[] { background, l });
            logoDrawable.setBounds(background.getBounds());

            l.setBounds(2, 2, channelLogo.getWidth(), channelLogo.getHeight());

            channelLogo = UiUtils.drawableToBitmap(logoDrawable);
        }

        channelSelectionList.add(new ChannelSelection(channelID, name, category, countries, channelLogo,
                isSelected, SettingConstants.EPG_DONATE_KEY.equals(dataService)));
    }

    // sort countries for filtering
    Collections.sort(countryList, new Comparator<Country>() {
        @Override
        public int compare(Country lhs, Country rhs) {
            return lhs.toString().compareToIgnoreCase(rhs.toString());
        }
    });

    countryList.add(0, new Country(null));

    channels.close();

    // create filter for filtering of category and country
    final ChannelFilter filter = new ChannelFilter(SettingConstants.TV_CATEGORY, null);

    // create default logo for channels without logo
    final Bitmap defaultLogo = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

    final Set<String> firstDeletedChannels = PrefUtils.getStringSetValue(R.string.PREF_FIRST_DELETED_CHANNELS,
            new HashSet<String>());
    final Set<String> keptDeletedChannels = PrefUtils.getStringSetValue(R.string.PREF_KEPT_DELETED_CHANNELS,
            new HashSet<String>());

    final int firstDeletedColor = getResources().getColor(R.color.pref_first_deleted_channels);
    final int keptDeletedColor = getResources().getColor(R.color.pref_kept_deleted_channels);

    // Custom array adapter for channel selection
    final ArrayAdapter<ChannelSelection> channelSelectionAdapter = new ArrayAdapter<ChannelSelection>(
            TvBrowser.this, R.layout.channel_row, channelSelectionList) {
        public View getView(int position, View convertView, ViewGroup parent) {
            ChannelSelection value = getItem(position);
            ViewHolder holder = null;

            if (convertView == null) {
                LayoutInflater mInflater = (LayoutInflater) getContext()
                        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

                holder = new ViewHolder();

                convertView = mInflater.inflate(R.layout.channel_row, getParentViewGroup(), false);

                holder.mTextView = (TextView) convertView.findViewById(R.id.row_of_channel_text);
                holder.mCheckBox = (CheckBox) convertView.findViewById(R.id.row_of_channel_selection);
                holder.mLogo = (ImageView) convertView.findViewById(R.id.row_of_channel_icon);

                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            SpannableStringBuilder nameBuilder = new SpannableStringBuilder(value.toString());

            String channelID = String.valueOf(value.getChannelID());

            if (keptDeletedChannels.contains(channelID)) {
                nameBuilder.setSpan(new ForegroundColorSpan(keptDeletedColor), 0, value.toString().length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else if (firstDeletedChannels.contains(channelID)) {
                nameBuilder.setSpan(new ForegroundColorSpan(firstDeletedColor), 0, value.toString().length(),
                        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            if (value.isEpgDonateChannel()) {
                nameBuilder.append("\n(EPGdonate)");
                nameBuilder.setSpan(new RelativeSizeSpan(0.65f), value.toString().length(),
                        nameBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

            holder.mTextView.setText(nameBuilder);
            holder.mCheckBox.setChecked(value.isSelected());

            Bitmap logo = value.getLogo();

            if (logo != null) {
                holder.mLogo.setImageBitmap(logo);
            } else {
                holder.mLogo.setImageBitmap(defaultLogo);
            }

            return convertView;
        }
    };

    // inflate channel selection view
    View channelSelectionView = getLayoutInflater().inflate(R.layout.dialog_channel_selection_list,
            getParentViewGroup(), false);
    channelSelectionView.findViewById(R.id.channel_selection_selection_buttons).setVisibility(View.GONE);
    channelSelectionView.findViewById(R.id.channel_selection_input_id_name).setVisibility(View.GONE);

    TextView infoView = (TextView) channelSelectionView.findViewById(R.id.channel_selection_label_id_name);

    if (help != null) {
        infoView.setText(help);
        infoView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimension(R.dimen.epg_donate_info_font_size));
    } else {
        infoView.setVisibility(View.GONE);
    }

    // get spinner for country filtering and create array adapter with all available countries
    Spinner country = (Spinner) channelSelectionView.findViewById(R.id.channel_country_value);

    final ArrayAdapter<Country> countryListAdapter = new ArrayAdapter<Country>(this,
            android.R.layout.simple_spinner_item, countryList);
    countryListAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    country.setAdapter(countryListAdapter);

    // add item selection listener to react of user setting filter for country
    country.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Country country = countryListAdapter.getItem(position);

            filter.mCountry = country.getCountry();
            channelSelectionList.setFilter(filter);
            channelSelectionAdapter.notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    // get spinner for category selection and add listener to react to user category selection
    Spinner category = (Spinner) channelSelectionView.findViewById(R.id.channel_category_value);
    category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 1:
                filter.mCategory = SettingConstants.TV_CATEGORY;
                break;
            case 2:
                filter.mCategory = SettingConstants.RADIO_CATEGORY;
                break;
            case 3:
                filter.mCategory = SettingConstants.CINEMA_CATEGORY;
                break;

            default:
                filter.mCategory = SettingConstants.NO_CATEGORY;
                break;
            }

            channelSelectionList.setFilter(filter);
            channelSelectionAdapter.notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    if (delete) {
        channelSelectionView.findViewById(R.id.channel_country_label).setVisibility(View.GONE);
        channelSelectionView.findViewById(R.id.channel_category_label).setVisibility(View.GONE);

        country.setVisibility(View.GONE);
        category.setVisibility(View.GONE);
    }

    // get the list view of the layout and add adapter with available channels
    ListView list = (ListView) channelSelectionView.findViewById(R.id.channel_selection_list);
    list.setAdapter(channelSelectionAdapter);

    // add listener to react to user selection of channels
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CheckBox check = (CheckBox) view.findViewById(R.id.row_of_channel_selection);

            if (check != null) {
                check.setChecked(!check.isChecked());
                channelSelectionAdapter.getItem(position).setSelected(check.isChecked());
            }
        }
    });

    // show dialog only if channels are available
    if (!channelSelectionList.isEmpty()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this);

        if (title == null) {
            builder.setTitle(R.string.select_channels);
        } else {
            builder.setTitle(title);
        }

        builder.setView(channelSelectionView);

        builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                boolean somethingSelected = false;
                boolean somethingChanged = false;

                Iterator<ChannelSelection> it = channelSelectionList.superIterator();

                StringBuilder deleteWhere = new StringBuilder();
                HashSet<String> keep = new HashSet<String>();

                while (it.hasNext()) {
                    ChannelSelection sel = it.next();

                    if (sel.isSelected() && !sel.wasSelected()) {
                        somethingChanged = somethingSelected = true;

                        if (delete) {
                            if (deleteWhere.length() > 0) {
                                deleteWhere.append(", ");
                            }

                            deleteWhere.append(sel.getChannelID());
                        } else {
                            ContentValues values = new ContentValues();

                            values.put(TvBrowserContentProvider.CHANNEL_KEY_SELECTION, 1);

                            getContentResolver().update(
                                    ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS,
                                            sel.getChannelID()),
                                    values, null, null);
                        }
                    } else if (!sel.isSelected() && sel.wasSelected()) {
                        somethingChanged = true;

                        ContentValues values = new ContentValues();

                        values.put(TvBrowserContentProvider.CHANNEL_KEY_SELECTION, 0);

                        getContentResolver().update(
                                ContentUris.withAppendedId(TvBrowserContentProvider.CONTENT_URI_CHANNELS,
                                        sel.getChannelID()),
                                values, null, null);

                        getContentResolver().delete(TvBrowserContentProvider.CONTENT_URI_DATA_VERSION,
                                TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID + "=" + sel.getChannelID(),
                                null);
                        getContentResolver().delete(TvBrowserContentProvider.CONTENT_URI_DATA,
                                TvBrowserContentProvider.CHANNEL_KEY_CHANNEL_ID + "=" + sel.getChannelID(),
                                null);
                    } else if (delete && !sel.isSelected()) {
                        keep.add(String.valueOf(sel.getChannelID()));
                    }
                }

                if (delete) {
                    if (deleteWhere.length() > 0) {
                        deleteWhere.insert(0, TvBrowserContentProvider.KEY_ID + " IN ( ");
                        deleteWhere.append(" ) ");

                        Log.d("info2", "DELETE WHERE FOR REMOVED CHANNELS " + deleteWhere.toString());

                        int count = getContentResolver().delete(TvBrowserContentProvider.CONTENT_URI_CHANNELS,
                                deleteWhere.toString(), null);

                        Log.d("info2", "REMOVED CHANNELS COUNT " + count);
                    }

                    Editor edit = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit();
                    edit.putStringSet(getString(R.string.PREF_KEPT_DELETED_CHANNELS), keep);
                    edit.commit();
                }

                // if something was changed we need to update channel list bar in program list and the complete program table
                if (somethingChanged) {
                    SettingConstants.initializeLogoMap(TvBrowser.this, true);
                    updateProgramListChannelBar();
                }

                // if something was selected we need to download new data
                if (somethingSelected && !delete) {
                    checkTermsAccepted();
                }
            }
        });

        builder.setNegativeButton(android.R.string.cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (delete) {
                    HashSet<String> keep = new HashSet<String>();
                    Iterator<ChannelSelection> it = channelSelectionList.superIterator();

                    while (it.hasNext()) {
                        ChannelSelection sel = it.next();

                        keep.add(String.valueOf(sel.getChannelID()));
                    }

                    Editor edit = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit();
                    edit.putStringSet(getString(R.string.PREF_KEPT_DELETED_CHANNELS), keep);
                    edit.commit();
                }
            }
        });

        builder.show();
    }

    selectingChannels = false;
}