@TestTargetNew( level = TestLevel.COMPLETE, notes = "Test {@link ImageView#setMaxHeight(int)}", method = "setMaxHeight", args = {int.class} ) @ToBeFixed(bug="1400249", explanation="It will be tested by functional test.") public void testSetMaxHeight() { ImageView imageView = new ImageView(mActivity); imageView.setMaxHeight(120); imageView.setMaxHeight(-1); }
@Override protected ImageView getImageView(Context context, List<String> imageURLs) { ImageView imgView = new ImageView(context); imgView.setMaxHeight(ViewGroup.LayoutParams.MATCH_PARENT); imgView.setMaxWidth(ViewGroup.LayoutParams.MATCH_PARENT); return imgView; }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.comment); final EditText edt = (EditText) findViewById(R.id.editText1); TextView t = (TextView) findViewById(R.id.textView1); Button b = (Button) findViewById(R.id.button1); Bundle extra = getIntent().getExtras(); t.setText((extra.getString("user") + ":\n" + extra.getString("update"))); ImageView iv = (ImageView) findViewById(R.id.imageView1); final Main imageGetter = new Main(); Bitmap bmp = imageGetter.getImageFromWeb(imageGetter.webRoot + extra.getString("pic")); iv.setImageBitmap(bmp); iv.setAdjustViewBounds(true); iv.setMaxHeight(120); iv.setMaxWidth(120); b.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), edt.getText(), Toast.LENGTH_LONG).show(); } }); }
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; String pkg_name = display_process.get(position).processName; if (view == null) { LayoutInflater inflater = getLayoutInflater(); view = inflater.inflate(R.layout.tablerow, parent, false); } TextView bottom_label = (TextView) view.findViewById(R.id.bottom_view); TextView top_label = (TextView) view.findViewById(R.id.top_view); ImageView icon = (ImageView) view.findViewById(R.id.row_image); icon.setAdjustViewBounds(true); icon.setMaxHeight(40); top_label.setText(parse_name(pkg_name)); bottom_label.setText( String.format( "%s, pid: %d", display_process.get(position).processName, display_process.get(position).pid)); try { icon.setImageDrawable(pk.getApplicationIcon(pkg_name)); } catch (NameNotFoundException e) { icon.setImageResource(R.drawable.processinfo); } return view; }
@Override public View getView(final int position, View view, ViewGroup arg2) { ViewHolder viewHolder = null; final ContactSortModel item = (ContactSortModel) getItem(position); if (view == null) { viewHolder = new ViewHolder(); view = LayoutInflater.from(mContext).inflate(R.layout.contact_item, null); viewHolder.tvTitle = (TextView) view.findViewById(R.id.title); viewHolder.tvLetter = (TextView) view.findViewById(R.id.catalog); view.setTag(viewHolder); } else { viewHolder = (ViewHolder) view.getTag(); } // 根据position获取分类的首字母的Char ascii值 int section = getSectionForPosition(position); // 如果当前位置等于该分类首字母的Char的位置 ,则认为是第一次出现 if ("添加好友".equals(item.getRoster().getAlias()) || "新朋友".equals(item.getRoster().getAlias())) { viewHolder.tvLetter.setVisibility(View.GONE); } else if (position == getPositionForSection(section)) { viewHolder.tvLetter.setVisibility(View.VISIBLE); viewHolder.tvLetter.setText(item.getSortLetters()); } else { viewHolder.tvLetter.setVisibility(View.GONE); } viewHolder.tvTitle.setText(item.getRoster().getAlias()); ImageView image = (ImageView) view.findViewById(R.id.iv_icon); // 获得ImageView对象 viewHolder.tvImage = image; if ("添加好友".equals(item.getRoster().getAlias())) { viewHolder.tvImage.setBackgroundResource(R.drawable.contact_add_friends); } else if ("新朋友".equals(item.getRoster().getAlias())) { viewHolder.tvImage.setBackgroundResource(R.drawable.contact_new_friends); } else { viewHolder.tvImage.setBackgroundResource(R.drawable.default_mobile_avatar); File file = new File("mnt/sdcard/Wanglai/Avatar/" + item.getRoster().getJid() + ".png"); if (file.exists()) { Bitmap bitmap = getLoacalBitmap( "mnt/sdcard/Wanglai/Avatar/" + item.getRoster().getJid() + ".png"); // 从本地取图片vcard // 设置Bitmap image.setImageBitmap(bitmap); // 设置Imageview image.setAdjustViewBounds(true); image.setMaxHeight(60); image.setMaxWidth(60); viewHolder.tvImage = image; viewHolder.tvImage.setBackgroundResource(0); } } return view; }
public void run() { titleIcon.setAdjustViewBounds(true); titleIcon.setMaxHeight(viewSize); titleIcon.setMaxWidth(viewSize); titleIcon.setMinimumHeight(viewSize); titleIcon.setMinimumWidth(viewSize); titleIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); titleIcon.setImageBitmap(bitmap); menuIconAnimation(titleIcon); }
@Override public void onHandleScreenshot(Bitmap screenshot) { if (screenshot != null) { mScreenshot.setImageBitmap(screenshot); mScreenshot.setAdjustViewBounds(true); mScreenshot.setMaxWidth(screenshot.getWidth() / 3); mScreenshot.setMaxHeight(screenshot.getHeight() / 3); mFullScreenshot.setImageBitmap(screenshot); } else { mScreenshot.setImageDrawable(null); mFullScreenshot.setImageDrawable(null); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.movie_detail_view); // Get intent data Intent i = getIntent(); // Selected image id // int position = i.getExtras().getInt("id"); String InstanceTagLocal = getApplicationContext().getResources().getString(R.string.InstanceTag2); Film recdFilm = i.getParcelableExtra(InstanceTagLocal); /* decide the heights of the controls on the basis of the displayMetrics */ final DisplayMetrics displayMetrics = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); final int HeightLocal = displayMetrics.heightPixels; // final int WidthLocal = displayMetrics.widthPixels; ImageView imageView = (ImageView) findViewById(R.id.MovieDetailView); imageView.setMaxHeight((int) Math.round(HeightLocal * 0.30)); // Film film = imageAdapter.getInstance().films.get(position); // imageView.setImageResource(film.getPosterPath()); Glide.with(this) .load(baseImgURL + recdFilm.getPosterPath()) .error(R.drawable.big_problem) .into(imageView); TextView title = (TextView) findViewById(R.id.MovieTitle); title.setHeight((int) Math.round(HeightLocal * 0.20)); title.setText(recdFilm.getTitle()); RatingBar rating = (RatingBar) findViewById(R.id.UserRating); // float f = Float.parseFloat( film.getRating().trim() ); rating.setRating(recdFilm.getRating()); TextView releaseDate = (TextView) findViewById(R.id.ReleaseDate); releaseDate.setText( getApplicationContext().getResources().getString(R.string.ReleaseDateLabel) + recdFilm.getFormattedDate()); TextView overView = (TextView) findViewById(R.id.OverView); overView.setHeight((int) Math.round(HeightLocal * 0.30)); overView.setText(recdFilm.getOverview()); }
public ViewHolder(View view) { super(view); ButterKnife.bind(this, view); this.view = (FrameLayout) view; // optimization to preset the correct height for our device int screenWidth = view.getContext().getResources().getDisplayMetrics().widthPixels; int finalHeight = (int) (screenWidth / 1.5) / 2; imageView.setMinimumHeight(finalHeight); imageView.setMaxHeight(finalHeight); imageView.setAdjustViewBounds(false); // set height as layoutParameter too FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) imageView.getLayoutParams(); lp.height = finalHeight; imageView.setLayoutParams(lp); }
public ImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); initImageView(); TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.ImageView, defStyle, 0); Drawable d = a.getDrawable(com.android.internal.R.styleable.ImageView_src); if (d != null) { setImageDrawable(d); } mBaselineAligned = a.getBoolean(com.android.internal.R.styleable.ImageView_baselineAlignBottom, false); setAdjustViewBounds( a.getBoolean(com.android.internal.R.styleable.ImageView_adjustViewBounds, false)); setMaxWidth( a.getDimensionPixelSize( com.android.internal.R.styleable.ImageView_maxWidth, Integer.MAX_VALUE)); setMaxHeight( a.getDimensionPixelSize( com.android.internal.R.styleable.ImageView_maxHeight, Integer.MAX_VALUE)); int index = a.getInt(com.android.internal.R.styleable.ImageView_scaleType, -1); if (index >= 0) { setScaleType(sScaleTypeArray[index]); } int tint = a.getInt(com.android.internal.R.styleable.ImageView_tint, 0); if (tint != 0) { setColorFilter(tint, PorterDuff.Mode.SRC_ATOP); } mCropToPadding = a.getBoolean(com.android.internal.R.styleable.ImageView_cropToPadding, false); a.recycle(); // need inflate syntax/reader for matrix }
// ---returns an ImageView view--- public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView; if (convertView == null) { imageView = new ImageView(context); imageView.setLayoutParams(new GridView.LayoutParams(185, 185)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(5, 5, 5, 5); Point size = new Point(); ProfilePageChooseProfileImageActivity.this .getWindowManager() .getDefaultDisplay() .getSize(size); int imageMaxSize = size.y / 13; imageView.setMaxHeight(imageMaxSize); imageView.setMaxWidth(imageMaxSize); } else { imageView = (ImageView) convertView; } imageView.setImageResource(imageIDs[position]); return imageView; }
private Bitmap getMarkerBitmapFromView( View view, ImageView mMarkerImageView, @DrawableRes int resId, String nazwaAlbumu) { // View customMarkerView = ((LayoutInflater) // context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.element_marker, // null); // ImageView markerImageView = (ImageView) // customMarkerView.findViewById(R.id.miniaturka_marker); if (nazwaAlbumu != "") { Bitmap bitmap = dekodowanieBitmapy(sciezkaDoZdjecia, 40, 40); // Bitmap bitmap = BitmapFactory.decodeFile(sciezkaDoZdjecia); // try { ExifInterface exif = new ExifInterface(sciezkaDoZdjecia); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); } else if (orientation == 3) { matrix.postRotate(180); } else if (orientation == 8) { matrix.postRotate(270); } // Bitmap bitmap = BitmapFactory.decodeFile(sciezka[obecneZdjecie]); bitmap = Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); // rotating bitmap mMarkerImageView.setImageBitmap(bitmap); mMarkerImageView.setMaxWidth(60); mMarkerImageView.setMaxHeight(60); mMarkerImageView.setMinimumWidth(57); mMarkerImageView.setMinimumHeight(57); // markerImageView.setImageBitmap(bitmap); // Toast.makeText(context, "bitmapa wgrana", Toast.LENGTH_SHORT).show(); } catch (Exception e) { } } // markerImageView.setImageResource(R.drawable.folder_multiple_image); // markerImageView.setImageResource(context.getResources().getIdentifier("folder_multiple_image", "drawable", context.getPackageName())); // markerImageView.setImageResource(context.getResources().getIdentifier("folder_multiple_image", "drawable", context.getPackageName())); view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight()); view.buildDrawingCache(); Bitmap returnedBitmap = Bitmap.createBitmap( view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(returnedBitmap); canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC_IN); Drawable drawable = view.getBackground(); if (drawable != null) drawable.draw(canvas); view.draw(canvas); return returnedBitmap; }
public BottomBar(Context context, AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.BottomBar); image1 = ta.getDrawable(R.styleable.BottomBar_ImageView1); image2 = ta.getDrawable(R.styleable.BottomBar_ImageView2); image3 = ta.getDrawable(R.styleable.BottomBar_ImageView3); image4 = ta.getDrawable(R.styleable.BottomBar_ImageView4); image1Height = ta.getDimension(R.styleable.BottomBar_ImageView1Height, 50); image2Height = ta.getDimension(R.styleable.BottomBar_ImageView2Height, 0); image3Height = ta.getDimension(R.styleable.BottomBar_ImageView3Height, 0); image4Height = ta.getDimension(R.styleable.BottomBar_ImageView4Height, 0); image1Width = ta.getDimension(R.styleable.BottomBar_ImageView1Width, 50); image2Width = ta.getDimension(R.styleable.BottomBar_ImageView2Width, 0); image3Width = ta.getDimension(R.styleable.BottomBar_ImageView3Width, 0); image4Width = ta.getDimension(R.styleable.BottomBar_ImageView4Width, 0); ta.recycle(); imageView1 = new ImageView(context); imageView2 = new ImageView(context); imageView3 = new ImageView(context); imageView4 = new ImageView(context); imageView1.setImageDrawable(image1); imageView1.setAdjustViewBounds(true); imageView1.setMaxHeight((int) image1Height); imageView1.setMaxWidth((int) image1Width); imageView2.setImageDrawable(image2); imageView2.setAdjustViewBounds(true); imageView2.setMaxHeight((int) image2Height); imageView2.setMaxWidth((int) image2Width); imageView3.setImageDrawable(image3); imageView3.setAdjustViewBounds(true); imageView3.setMaxHeight((int) image3Height); imageView3.setMaxWidth((int) image3Width); imageView4.setImageDrawable(image4); imageView4.setAdjustViewBounds(true); imageView4.setMaxHeight((int) image4Height); imageView4.setMaxWidth((int) image4Width); setOrientation(LinearLayout.HORIZONTAL); setBackgroundColor(0x8800CCCC); param1 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); param1.gravity = Gravity.CENTER_VERTICAL; param1.weight = 1; addView(imageView1, param1); param2 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); param2.gravity = Gravity.CENTER_VERTICAL; param2.weight = 1; addView(imageView2, param2); param3 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); param3.gravity = Gravity.CENTER_VERTICAL; param3.weight = 1; addView(imageView3, param3); param4 = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); param4.gravity = Gravity.CENTER_VERTICAL; param4.weight = 1; addView(imageView4, param4); imageView1.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { listener.Click1(); } }); imageView2.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { listener.Click2(); } }); imageView3.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { listener.Click3(); } }); imageView4.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { listener.Click4(); } }); }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub String rich = Constants.RICH_TEXTS[position]; // 通过迭代装饰方式构造解析器。 IParser parser = new SmileyParser(mContext); parser = new ImageParser(mContext, parser); parser = new HyperlinkParser(mContext, parser); parser = new WeburlParser(mContext, parser); // 执行解析并返回解析文本段队列。 ParseManager manager = new ParseManager(); ArrayList<ParsedSegment> segments = manager.parse(parser, rich); // 用 Holder 模式更新列表数据。 CustomLayout layout = null; ViewHolder holder = null; if (null == convertView) { layout = new CustomLayout(mContext); AbsListView.LayoutParams params = new AbsListView.LayoutParams( AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT); layout.setLayoutParams(params); layout.setOrientation(LinearLayout.VERTICAL); layout.setBackgroundResource(R.drawable.list_item_background); holder = new ViewHolder(); holder.views = new ArrayList<View>(); layout.setTag(holder); } else { layout = (CustomLayout) convertView; holder = (ViewHolder) convertView.getTag(); } int i = 0; for (ParsedSegment segment : segments) { if (TextUtils.isEmpty(segment.text)) { continue; } if (MatchType.None == segment.type) { TextView textView = null; if (null == convertView) { textView = new TextView(mContext); LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); p.bottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.rich_element_margin); textView.setLayoutParams(p); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); // 自定义 ClickableSpan 点击背景,有两种方法: // 1、自定义 LinkMovementMethod,重写其 onTouchEvent 方法; // 2、重写 TextView 的 OnTouchListener。 // 两种方法的核心思想都是获取 touch event 事件,通过对 TextView 中的 ClickableSpan // 文本设置和移除 BackgroundColorSpan 来改变其点击背景。 if (Constants.USE_CUSTOM_LINK) { textView.setMovementMethod(mLinkMovementMethod); } else { textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setOnTouchListener(onTouchListener); } textView.setClickable(false); layout.addView(textView); holder.views.add(textView); } else { textView = (TextView) holder.views.get(i); } textView.setText(segment.text); ++i; } else if (MatchType.Image == segment.type) { ImageView imgView = null; if (null == convertView) { imgView = new ImageView(mContext); LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); p.bottomMargin = mContext.getResources().getDimensionPixelSize(R.dimen.rich_element_margin); imgView.setMaxHeight( mContext.getResources().getDimensionPixelSize(R.dimen.image_max_height)); imgView.setLayoutParams(p); layout.addView(imgView); holder.views.add(imgView); } else { imgView = (ImageView) holder.views.get(i); } // 异步加载图片。 mImageLoader.displayImage( segment.text.toString(), imgView, mOptions, mAnimateFirstListener); ++i; } } return layout; }
@SuppressLint("NewApi") public void onActivityResult(int requestCode, int resultCode, Intent data) { selectedVideos = new ArrayList<String>(); if (resultCode == RESULT_OK && requestCode == VIDEO_RESULT) { try { uriVideo = data.getData(); /*Toast.makeText(createvideo.this, uriVideo.getPath(), Toast.LENGTH_LONG).show();*/ selectedImagePath = uriVideo.getPath(); // selectedImages = new ArrayList<String>(); byte[] ba = getCapturedVideoStream(editvideo.this, data); MyWrite(ba); // selectedImagePath = Base64.encodeBytes(ba); selectedVideos.add(selectedImagePath); /*Toast.makeText(createvideo.this, selectedImagePath, Toast.LENGTH_LONG).show();*/ Bitmap thumb = ThumbnailUtils.createVideoThumbnail( selectedImagePath, MediaStore.Images.Thumbnails.MICRO_KIND); /* * Drawable d = new BitmapDrawable(getResources(),thumb); * //video_intro.setBackgroundDrawable(d); //int height = * img_videointro.getHeight(); //int width = * img_videointro.getWidth(); * img_videointro.setImageBitmap(thumb); d = * getResources().getDrawable(R.drawable.videowith); * img_videointro.setBackgroundDrawable(d); * img_videointro.setPadding(0,10,0,0); */ // img_videointro.getLayoutParams().height = height; // img_videointro.getLayoutParams().width = width; // LinearLayout.LayoutParams layoutParams = new // LinearLayout.LayoutParams(video_intro.getWidth()-10, // video_intro.getHeight()-10); // video_intro.setLayoutParams(layoutParams); // video_intro.setText(""); int height = img_videointro.getHeight(); int width = img_videointro.getWidth(); if (detectVideo.equals("1")) { uploadVideo(c.link.toString() + "/video1.php", "video1"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videointro.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videointro.setBackgroundDrawable(d); img_videointro.setPadding(0, 10, 0, 0); img_videointro.setMaxHeight(height); img_videointro.setMaxWidth(width); } else if (detectVideo.equals("2")) { uploadVideo(c.link.toString() + "/video2.php", "video2"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videopet.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videopet.setBackgroundDrawable(d); img_videopet.setPadding(0, 10, 0, 0); img_videopet.setMaxHeight(height); img_videopet.setMaxWidth(width); } else if (detectVideo.equals("3")) { uploadVideo(c.link.toString() + "/video3.php", "video3"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videoplace.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videoplace.setBackgroundDrawable(d); img_videoplace.setPadding(0, 10, 0, 0); img_videoplace.setMaxHeight(height); img_videoplace.setMaxWidth(width); } else if (detectVideo.equals("4")) { uploadVideo(c.link.toString() + "/video4.php", "video4"); Drawable d = new BitmapDrawable(getResources(), thumb); img_videopick.setImageBitmap(thumb); d = getResources().getDrawable(R.drawable.videowith); img_videopick.setBackgroundDrawable(d); img_videopick.setPadding(0, 10, 0, 0); img_videopick.setMaxHeight(height); img_videopick.setMaxWidth(width); } } catch (Exception e) { } } }
public void setMaxHeight(int maxHeight) { super.setMaxHeight(maxHeight); mMaxHeight = maxHeight; }
// set isi tampilan barang di kategori yang sedang dipilih private void setContentItemsBarang(JSONArray jsonArray) { LinearLayout ll = (LinearLayout) findViewById(R.id.wrapperbarang); ll.removeAllViewsInLayout(); try { for (int i = 0; i < jsonArray.length(); i++) { final JSONObject jsonObject = jsonArray.getJSONObject(i); LinearLayout lytContainer = new LinearLayout(this); lytContainer.setOrientation(LinearLayout.VERTICAL); if (i % 2 == 1) { lytContainer.setBackgroundColor(Color.WHITE); } else { lytContainer.setBackgroundColor(Color.DKGRAY); } Drawable image = JSON_Response.ImageOperations(this, jsonObject.getString("path_gambar"), "image.jpg"); ImageView iv = new ImageView(this); iv.setAdjustViewBounds(true); iv.setMaxHeight(50); iv.setMaxWidth(50); iv.setImageDrawable(image); iv.setPadding(0, 10, 0, 0); lytContainer.addView(iv); TextView t = new TextView(this); t.setText(jsonObject.getString("nama")); t.setGravity(Gravity.CENTER); t.setTypeface(null, Typeface.BOLD); if (i % 2 == 1) { t.setTextColor(Color.BLACK); } else { t.setTextColor(Color.WHITE); } lytContainer.addView(t); TextView t2 = new TextView(this); t2.setGravity(Gravity.CENTER); t2.setText("Jumlah produk yang tersedia : " + jsonObject.getString("jumlah")); if (i % 2 == 1) { t2.setTextColor(Color.BLACK); } else { t2.setTextColor(Color.WHITE); } t2.setPadding(0, 0, 0, 10); lytContainer.addView(t2); lytContainer.setOnClickListener( new OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub try { System.gc(); Intent intent = new Intent(LihatBarangActivity.this, LihatItemBarangActivity.class); intent.putExtra("id", jsonObject.getInt("id")); intent.putExtra("kategori_id", jsonObject.getInt("kategori_id")); intent.putExtra("nama", jsonObject.getString("nama")); intent.putExtra("deskripsi", jsonObject.getString("deskripsi")); intent.putExtra("jumlah", jsonObject.getString("jumlah")); intent.putExtra("harga", jsonObject.getString("harga_satuan")); intent.putExtra("path_gambar", jsonObject.getString("path_gambar")); startActivity(intent); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); ll.addView(lytContainer); } } catch (Exception e) { Log.d("ancret", e.toString()); e.printStackTrace(); } }
public View getView(int position, View convertView, ViewGroup parent) { View slideshowView = convertView; if (position >= getCount()) { return null; } SlideshowPhoto slideshowPhoto = getItem(position); Log.d(LOG_PREFIX, position + " title:" + slideshowPhoto.getTitle()); boolean copyDrawableFromCachedView = false; View cachedView = null; Integer mapKey = new Integer(position); if (slideshowView == null) { // let's check the weak references for this View if (mapWeakRefViews.containsKey(mapKey)) { // we have a key, but the View may be garbage collected WeakReference<View> weakRefView = mapWeakRefViews.get(mapKey); cachedView = weakRefView.get(); if (cachedView == null) { // view was cached, but has been deleted. // it will be replaced later in this method, so don't bother deleting it from the // hashmap } else if (cachedView.getParent() != null) { // Log.i(LOG_PREFIX,position + " was cached, but had a parent. So close!"); copyDrawableFromCachedView = true; } else { Log.d(LOG_PREFIX, position + " returned through weak reference caching. Yeah!"); return cachedView; } } // if no cached value, create it from the resource definition LayoutInflater viewInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); slideshowView = viewInflater.inflate(R.layout.slideshow_item, null); } ImageView slideshowImageView = (ImageView) slideshowView.findViewById(R.id.slideshow_photo); slideshowImageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); slideshowImageView.setAdjustViewBounds(true); // make sure we do not exceed the opengl hardware accl max size slideshowImageView.setMaxHeight(2048); slideshowImageView.setMaxWidth(2048); // The preferred Gallery item background slideshowImageView.setBackgroundResource(mGalleryItemBackground); slideshowImageView.setBackgroundColor(Color.TRANSPARENT); slideshowImageView.setTag(LOADING_TAG); slideshowImageView.setImageResource(R.drawable.loading); // OLD METHOD // These lines of code are in a separate async task in order to not block the UI thread for // approx 300 ms // Drawable drawable = slideshowPhoto.getLargePhotoDrawable(rootPhotoFolder); // slideshowImageView.setImageDrawable(drawable); // new ReadPhotoFromFileTask(slideshowImageView,slideshowPhoto,rootPhotoFolder).execute(); // This section applies if we have a cached view, but it cannot be reuse directly since it has // a parent // let us copy the drawable boolean slideShowImageDrawableMissing = true; if (copyDrawableFromCachedView == true && cachedView != null) { // reusing the drawable from a cached view ImageView cachedSlideshowImageView = (ImageView) cachedView.findViewById(R.id.slideshow_photo); String cachedTag = (String) cachedSlideshowImageView.getTag(); if (cachedSlideshowImageView != null && cachedTag != null && cachedTag.equals(LOADED_TAG)) { slideshowImageView.setImageDrawable(cachedSlideshowImageView.getDrawable()); slideShowImageDrawableMissing = false; Log.d(LOG_PREFIX, position + " Cached photo drawable reused. Yeah!"); } else { Log.i( LOG_PREFIX, position + " Cached Photo is not loaded yet, so could not use cache. Doh!"); } } if (slideShowImageDrawableMissing) { // NEW METHOD // Add to a last-in/first-out queue AsyncQueueableObject queueablePhotoObject = null; queueablePhotoObject = new QueueablePhotoObject( slideshowPhoto, slideshowView, rootPhotoFolder, LOADED_TAG, screenWidthPx, screenHeightPx); asyncReadQueue.add(queueablePhotoObject); Log.d(LOG_PREFIX, position + " is being loaded in a background async task"); } TextView slideshowTitle = (TextView) slideshowView.findViewById(R.id.slideshow_title); slideshowTitle.setText(slideshowPhoto.getTitle()); TextView slideshowDescription = (TextView) slideshowView.findViewById(R.id.slideshow_description); slideshowDescription.setText(slideshowPhoto.getDescription()); // add scrolling to TextView // slideshowDescription.setMovementMethod(new ScrollingMovementMethod()); // find out if we should hide the text descriptions boolean isEmptyTitle = false; if (slideshowPhoto.getTitle() == null || "".equals(slideshowPhoto.getTitle().trim())) { isEmptyTitle = true; } if (doDisplayPhotoTitle == false || slideshowPhoto.isPromotion() || isEmptyTitle) { slideshowTitle.setVisibility(View.INVISIBLE); slideshowDescription.setVisibility(View.INVISIBLE); View layout = slideshowView.findViewById(R.id.slideshow_text_background); layout.setVisibility(View.INVISIBLE); } // lastView = slideshowView; // lastFileName=slideshowPhoto.getFileName(); // add the view to our weak reference caching WeakReference<View> weakRefView = new WeakReference<View>(slideshowView); mapWeakRefViews.put(mapKey, weakRefView); // DEBUG String classLayoutParam = null; Object objectLayoutParam = slideshowView.getLayoutParams(); if (objectLayoutParam != null) { classLayoutParam = objectLayoutParam.getClass().getName(); } Log.d(LOG_PREFIX, "Layout params class=" + classLayoutParam + " value=" + objectLayoutParam); return slideshowView; }