@Override public View getView(int position, View convertView, final ViewGroup parent) { final Item item = getItem(position); final View view; if (convertView != null && item.getClass().equals(convertView.getTag())) { view = convertView; } else { view = getLayoutInflater() .inflate( item instanceof SectionItem ? R.layout.catalog_manager_section_head : R.layout.catalog_manager_item, null); view.setTag(item.getClass()); } if (item instanceof SectionItem) { ((TextView) view.findViewById(R.id.catalog_manager_section_head_title)) .setText(((SectionItem) item).Title); } else /* if (item instanceof CatalogItem) */ { final CatalogItem catalogItem = (CatalogItem) item; if (myCoverManager == null) { view.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final int coverHeight = view.getMeasuredHeight(); myCoverManager = new CoverManager(CatalogManagerActivity.this, coverHeight * 15 / 22, coverHeight); view.requestLayout(); } final INetworkLink link = catalogItem.Tree.getLink(); ((TextView) view.findViewById(R.id.catalog_manager_item_title)).setText(link.getTitle()); ((TextView) view.findViewById(R.id.catalog_manager_item_subtitle)) .setText(link.getSummary()); final ImageView coverView = (ImageView) view.findViewById(R.id.catalog_manager_item_icon); if (!myCoverManager.trySetCoverImage(coverView, catalogItem.Tree)) { coverView.setImageResource(R.drawable.ic_list_library_books); } final CheckBox checkBox = (CheckBox) view.findViewById(R.id.catalog_manager_item_checkbox); checkBox.setChecked(catalogItem.IsChecked); checkBox.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { catalogItem.IsChecked = checkBox.isChecked(); setResultIds(catalogItem, 0); } }); } return view; }
private Item createItem(String label, float percent, int sliceColor, int itemColor) { Item it = new Item(); it.mLabel = label; it.mItemColor = itemColor; it.cSliceColor = sliceColor; it.cPercent = percent; // Log.d(TAG, "Percent for "+it.mLabel+": "+it.cPercent); // Calculate the highlight color. Saturate at 0xff to make sure that high values // don't result in aliasing. it.mItemHighlight = Color.argb( 0xff, Math.min((int) (mHighlightStrength * (float) Color.red(itemColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.green(itemColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.blue(itemColor)), 0xff)); it.cSliceHighlight = Color.argb( 0xff, Math.min((int) (mHighlightStrength * (float) Color.red(sliceColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.green(sliceColor)), 0xff), Math.min((int) (mHighlightStrength * (float) Color.blue(sliceColor)), 0xff)); float centerX = mPieBounds.width() / 2; float centerY = mPieBounds.height() / 2; float itemW = (mPieBounds.width() / 2) * it.cPercent; float itemH = (mPieBounds.height() / 2) * it.cPercent; it.cSliceBounds = new RectF(centerX - itemW, centerY - itemH, centerX + itemW, centerY + itemH); return it; }
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; Holder holder = null; if (view == null) { view = View.inflate(RssfeedActivity.this, R.layout.list_item_simple, null); holder = new Holder(); holder.cityTextView = (TextView) view.findViewById(R.id.item); view.setTag(holder); } else { holder = (Holder) view.getTag(); } // Set properties Item item = items.get(position); holder.cityTextView.setText(item.getTitle()); return view; }
/** Do all of the recalculations needed when the data array changes. */ private void onDataChanged() { int angle = 360 / mData.size(); // This is the extra degrees that cannot be equally divided by the number of sides int extra = 360 % mData.size(); // When the data changes, we have to recalculate // all of the angles. int currentAngle = 0; for (Item it : mData) { // Adds the extra degrees to the last slice to ensue no gaps if (mData.get(mData.size() - 1).mLabel.equals(it.mLabel)) { it.mEndAngle = currentAngle + angle + extra; } else { it.mEndAngle = currentAngle + angle; } it.mStartAngle = currentAngle; currentAngle = it.mEndAngle; // Recalculate the gradient shaders. There are // three values in this gradient, even though only // two are necessary, in order to work around // a bug in certain versions of the graphics engine // that expects at least three values if the // positions array is non-null. // it.mItemShader = new SweepGradient( mPieBounds.width() / 2.0f, mPieBounds.height() / 2.0f, new int[] { it.mItemHighlight, it.mItemHighlight, it.mItemColor, it.mItemColor, }, new float[] { 0, (float) (360 - it.mEndAngle) / 360.0f, (float) (360 - it.mStartAngle) / 360.0f, 1.0f }); it.cSliceShader = new SweepGradient( mPieBounds.width() / 2.0f, mPieBounds.height() / 2.0f, new int[] { it.cSliceHighlight, it.cSliceHighlight, it.cSliceColor, it.cSliceColor, }, new float[] { 0, (float) (360 - it.mEndAngle) / 360.0f, (float) (360 - it.mStartAngle) / 360.0f, 1.0f }); } calcCurrentItem(); onScrollFinished(); }
@Override public String getSectionTitleForItem(Item item) { String sectionTitle = "Unknown"; return item.getHeader(); }