Java Code Examples for android.widget.ImageView.setImageBitmap()

The following are Jave code examples for showing how to use setImageBitmap() of the android.widget.ImageView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: EyeShopping   File: MainActivity.java   View Source Code Vote up 7 votes
@Override
public Object instantiateItem(ViewGroup container, final int position) {
    View itemView = LayoutInflater.from(mContext).inflate(R.layout.main_pager_item, container, false);

    ImageView imageView = (ImageView) itemView.findViewById(R.id.pager_item_image_view);
    imageView.setImageBitmap(mResources[position]);

    if(position < recommend_bitmaps.size() &&
            position != 0)
    {
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(), ActivityShowVisuallySimilarImagesSelect.class);
                intent.putExtra("url", urls.get(position-1));
                intent.putExtra("uri", uris.get(position-1));
                startActivityForResult(intent, SELECT_REQUEST);
            }
        });
    }

    container.addView(itemView);
    return itemView;
}
 
Example 2
Project: publicProject   File: ImageLoader.java   View Source Code Vote up 7 votes
/**
 * The default implementation of ImageListener which handles basic functionality
 * of showing a default image until the network response is received, at which point
 * it will switch to either the actual image or the error image.
 * @param view The imageView that the listener is associated with.
 * @param defaultImageResId Default image resource ID to use, or 0 if it doesn't exist.
 * @param errorImageResId Error image resource ID to use, or 0 if it doesn't exist.
 */
public static ImageListener getImageListener(final ImageView view,
        final int defaultImageResId, final int errorImageResId) {
    return new ImageListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (errorImageResId != 0) {
                view.setImageResource(errorImageResId);
            }
        }

        @Override
        public void onResponse(ImageContainer response, boolean isImmediate) {
            if (response.getBitmap() != null) {
                view.setImageBitmap(response.getBitmap());
            } else if (defaultImageResId != 0) {
                view.setImageResource(defaultImageResId);
            }
        }
    };
}
 
Example 3
Project: buildAPKsSamples   File: BitmapScaling.java   View Source Code Vote up 7 votes
private void addScaledImageView(Bitmap original, int sampleSize, LinearLayout container) {

        // inSampleSize tells the loader how much to scale the final image, which it does at
        // load time by simply reading less pixels for every pixel value in the final bitmap.
        // Note that it only scales by powers of two, so a value of two results in a bitmap
        // 1/2 the size of the original and a value of four results in a bitmap 1/4 the original
        // size. Intermediate values are rounded down, so a value of three results in a bitmap 1/2
        // the original size.

        BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
        bitmapOptions.inSampleSize = sampleSize;

        Bitmap scaledBitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.jellybean_statue, bitmapOptions);
        ImageView scaledImageView = new ImageView(this);
        scaledImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        scaledImageView.setImageBitmap(scaledBitmap);
        container.addView(scaledImageView);
    }
 
Example 4
Project: cordova-plugin-image-picker   File: ImageFetcher.java   View Source Code Vote up 7 votes
/**
 * Once the image is downloaded, associates it to the imageView
 */
@Override
protected void onPostExecute(Bitmap bitmap) {
    if (isCancelled()) {
        bitmap = null;
    }
    addBitmapToCache(position, bitmap);
    if (imageViewReference != null) {
        ImageView imageView = imageViewReference.get();
        BitmapFetcherTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView);
        if (this == bitmapDownloaderTask) {
            imageView.setImageBitmap(bitmap);
            Animation anim = AnimationUtils.loadAnimation(imageView.getContext(), android.R.anim.fade_in);
            imageView.setAnimation(anim);
            anim.start();
        }
    } else {
        setInvisible();
    }
}
 
Example 5
Project: Huochexing12306   File: StationDetailAty.java   View Source Code Vote up 7 votes
public void loadViews() {
	titles = new String[mMapBitmaps.size()];
	mPics = new ArrayList<ImageView>();
	mDots = new ArrayList<View>();
	int i=0;
	for(String key:mMapBitmaps.keySet()){
		titles[i++] = key;
		ImageView iv1 = new ImageView(StationDetailAty.this);
		iv1.setImageBitmap(mMapBitmaps.get(key));
		iv1.setScaleType(ScaleType.CENTER_CROP);
		iv1.setOnClickListener(new MyOnClickListener(i));
		mPics.add(iv1);
		
		ImageView iv2 = new ImageView(StationDetailAty.this);
		iv2.setBackgroundResource(R.drawable.dot_normal);
		mDots.add(iv2);
	}
	tvTitle.setText(titles[0]);
}
 
Example 6
Project: OSS-purple-06   File: CardNewsPagerAdapter.java   View Source Code Vote up 7 votes
public Object instantiateItem(ViewGroup container, int position){
    View v = inflater.inflate(R.layout.viewpager_image,null);
    ImageView imgView = (ImageView) v.findViewById(R.id.viewPagerImage);
    //이미지를 가져옴
    Uri uri = Uri.fromFile(new File(cards.get(position)));

    try {
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(inflater.getContext().getContentResolver(),uri);
        int nh = (int) (bitmap.getHeight() * (1024.0 / bitmap.getWidth()));
        Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 1024, nh, true);

        imgView.setImageBitmap(scaled);

    } catch (IOException e) {
        e.printStackTrace();
    }
    container.addView(v);

    return v;
}
 
Example 7
Project: weex-uikit   File: WXImageTest.java   View Source Code Vote up 6 votes
@Test
public void testSetImageBitmap(){
  ImageView imageView = mWXImage.initComponentHostView(Robolectric.setupActivity(TestActivity.class));
  imageView.setLayoutParams(new ViewGroup.LayoutParams(
      ViewGroup.LayoutParams.WRAP_CONTENT,
      ViewGroup.LayoutParams.WRAP_CONTENT));
  imageView.setImageBitmap(null);
  assertNull(imageView.getDrawable());

  imageView.setImageBitmap(Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565));
  assertNotNull(imageView.getDrawable());
}
 
Example 8
Project: FireFiles   File: IconHelper.java   View Source Code Vote up 6 votes
/**
 * Load thumbnails for a directory list item.
 * @param uri The URI for the file being represented.
 * @param mimeType The mime type of the file being represented.
 * @param docFlags Flags for the file being represented.
 * @param iconThumb The itemview's thumbnail icon.
 * @param iconMimeBackground
 * @return
 */
public void loadThumbnail(Uri uri, String path, String mimeType, int docFlags, int docIcon,
                          ImageView iconMime, ImageView iconThumb, View iconMimeBackground) {
    boolean cacheHit = false;

    final String docAuthority = uri.getAuthority();
    String docId = DocumentsContract.getDocumentId(uri);
    final boolean supportsThumbnail = (docFlags & Document.FLAG_SUPPORTS_THUMBNAIL) != 0;
    final boolean allowThumbnail = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mimeType);
    final boolean showThumbnail = supportsThumbnail && allowThumbnail && mThumbnailsEnabled;
    if (showThumbnail) {
        final Bitmap cachedResult = mCache.get(uri);
        if (cachedResult != null) {
            iconThumb.setImageBitmap(cachedResult);
            cacheHit = true;
            iconMimeBackground.setVisibility(View.GONE);
        } else {
            iconThumb.setImageDrawable(null);
            final LoaderTask task = new LoaderTask(uri, path, mimeType, mThumbSize, iconThumb,
                    iconMime, iconMimeBackground);
            iconThumb.setTag(task);
            ProviderExecutor.forAuthority(docAuthority).execute(task);
        }
    }

    if (cacheHit) {
        iconMime.setImageDrawable(null);
        iconMime.setAlpha(0f);
        iconThumb.setAlpha(1f);
    } else {
        // Add a mime icon if the thumbnail is being loaded in the background.
        iconThumb.setImageDrawable(null);
        iconMime.setImageDrawable(getDocumentIcon(mContext, docAuthority, docId, mimeType, docIcon));
        iconMime.setAlpha(1f);
        iconThumb.setAlpha(0f);
    }
}
 
Example 9
Project: lqrwechatrongcloud   File: VideoThumbLoader.java   View Source Code Vote up 6 votes
public void showThumb(String path, ImageView imgview, int width, int height) {

        if (getVideoThumbToCache(path) == null) {
            // 异步加载
            imgview.setTag(path);
            new MyBobAsynctack(imgview, path, width, height).execute(path);
        } else {
            imgview.setImageBitmap(getVideoThumbToCache(path));
        }

    }
 
Example 10
Project: DailyStudy   File: ImageLoader.java   View Source Code Vote up 6 votes
@Override
public void handleMessage(Message msg) {
    super.handleMessage(msg);
    LoaderResult result = (LoaderResult) msg.obj;
    ImageView imageView = result.imageView;
    imageView.setImageBitmap(result.bitmap);
    String uri = (String) imageView.getTag(TAG_KEY_URL);
    if (uri.equals(result.uri)) {
        imageView.setImageBitmap(result.bitmap);
    }
}
 
Example 11
Project: Sendroid   File: ImageRequest.java   View Source Code Vote up 6 votes
public void into(ImageView imageView) {
        if (imageView == null) {
            return;
        }
        if (bitmap != null) {
            imageView.setImageBitmap(bitmap);
        } else {
//            imageView.setErrorHolder();
        }
    }
 
Example 12
Project: ywApplication   File: PlatformGridView.java   View Source Code Vote up 5 votes
private LinearLayout getView(int position, OnClickListener ocL, Context context) {
	Bitmap logo;
	String label;
	OnClickListener listener;
	if (beans[position] instanceof Platform) {
		logo = getIcon((Platform) beans[position]);
		label = getName((Platform) beans[position]);
		listener = ocL;
	} else {
		logo = ((CustomerLogo) beans[position]).enableLogo;
		label = ((CustomerLogo) beans[position]).label;
		listener = ocL;
	}

	LinearLayout ll = new LinearLayout(context);
	ll.setOrientation(LinearLayout.VERTICAL);

	ImageView iv = new ImageView(context);
	int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5);
	iv.setPadding(dp_5, dp_5, dp_5, dp_5);
	iv.setScaleType(ScaleType.CENTER_INSIDE);
	LayoutParams lpIv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpIv.setMargins(dp_5, dp_5, dp_5, dp_5);
	lpIv.gravity = Gravity.CENTER_HORIZONTAL;
	iv.setLayoutParams(lpIv);
	iv.setImageBitmap(logo);
	ll.addView(iv);

	TextView tv = new TextView(context);
	tv.setTextColor(0xff000000);
	tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	tv.setSingleLine();
	tv.setIncludeFontPadding(false);
	LayoutParams lpTv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpTv.gravity = Gravity.CENTER_HORIZONTAL;
	lpTv.weight = 1;
	lpTv.setMargins(dp_5, 0, dp_5, dp_5);
	tv.setLayoutParams(lpTv);
	tv.setText(label);
	ll.addView(tv);
	ll.setOnClickListener(listener);

	return ll;
}
 
Example 13
Project: Huochexing12306   File: EditPage.java   View Source Code Vote up 5 votes
/** 显示平台列表 */
public void afterPlatformListGot() {
	String name = String.valueOf(reqData.get("platform"));
	int size = platformList == null ? 0 : platformList.length;
	views = new View[size];

	final int dp_24 = dipToPx(getContext(), 24);
	LinearLayout.LayoutParams lpItem = new LinearLayout.LayoutParams(dp_24, dp_24);
	final int dp_9 = dipToPx(getContext(), 9);
	lpItem.setMargins(0, 0, dp_9, 0);
	FrameLayout.LayoutParams lpMask = new FrameLayout.LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
	lpMask.gravity = Gravity.LEFT | Gravity.TOP;
	int selection = 0;
	for (int i = 0; i < size; i++) {
		FrameLayout fl = new FrameLayout(getContext());
		fl.setLayoutParams(lpItem);
		if (i >= size - 1) {
			fl.setLayoutParams(new LinearLayout.LayoutParams(dp_24, dp_24));
		}
		llPlat.addView(fl);
		fl.setOnClickListener(this);

		ImageView iv = new ImageView(getContext());
		iv.setScaleType(ScaleType.CENTER_INSIDE);
		iv.setImageBitmap(getPlatLogo(platformList[i]));
		iv.setLayoutParams(new FrameLayout.LayoutParams(
				LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
		fl.addView(iv);

		views[i] = new View(getContext());
		views[i].setBackgroundColor(0xcfffffff);
		views[i].setOnClickListener(this);
		if (name != null && name.equals(platformList[i].getName())) {
			views[i].setVisibility(View.INVISIBLE);
			selection = i;

			// 编辑分享内容的统计
			ShareSDK.logDemoEvent(3, platformList[i]);
		}
		views[i].setLayoutParams(lpMask);
		fl.addView(views[i]);
	}

	final int postSel = selection;
	UIHandler.sendEmptyMessageDelayed(0, 333, new Callback() {
		public boolean handleMessage(Message msg) {
			HorizontalScrollView hsv = (HorizontalScrollView)llPlat.getParent();
			hsv.scrollTo(postSel * (dp_24 + dp_9), 0);
			return false;
		}
	});
}
 
Example 14
Project: Tribe   File: EaseEmojiconIndicatorView.java   View Source Code Vote up 5 votes
public void selectTo(int startPosition, int targetPostion){
    ImageView startView = dotViews.get(startPosition);
    ImageView targetView = dotViews.get(targetPostion);
    startView.setImageBitmap(unselectedBitmap);
    targetView.setImageBitmap(selectedBitmap);
}
 
Example 15
Project: GoalsAndHabits   File: ViewEventActivity.java   View Source Code Vote up 5 votes
/**
 * Saving instant state for every action
 * @param savedInstanceState
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_habit_events);

    Bundle extras = getIntent().getExtras();
    if (extras!=null){
        if (extras.containsKey(HabitHistoryActivity.EXTRA_EVENT_SERIAL)){
            event = (HabitEvent) extras.getSerializable(HabitHistoryActivity.EXTRA_EVENT_SERIAL);
            position = (int) extras.getSerializable(HabitHistoryActivity.EXTRA_EVENT_POSITION);
        }
    }
    if (event==null){
        finish();
        return;
    }

    mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);


    comment = (TextView) findViewById(R.id.eventComment);
    comment.setText(event.getComment());
    image = (ImageView) findViewById(R.id.eventPhoto);
    eventdate = (TextView) findViewById(R.id.eventDate);
    eventdate.setText(dateFormat.format(event.getDate()));
    toolbar = (Toolbar) findViewById(R.id.actionbar);
    toolbar.setTitle("Habit Event");
    toolbar.setNavigationIcon(R.drawable.ic_close_button);
    setSupportActionBar(toolbar);

    if (event.getEncodedPhoto()!=null){
        imageDisplay = ImageController.base64ToImage(event.getEncodedPhoto());
        image.setImageBitmap(imageDisplay);
    }else{
        imageDisplay = null;
    }

    image.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dispatchTakePictureIntent();
        }
    });
}
 
Example 16
Project: YCBaseAdapter   File: BaseViewHolder.java   View Source Code Vote up 5 votes
/**
 * 设置imageView图片
 */
public BaseViewHolder setImageBitmap(int viewId, Bitmap bitmap) {
    ImageView view = getView(viewId);
    view.setImageBitmap(bitmap);
    return this;
}
 
Example 17
Project: Mvvm   File: BindingAdapters.java   View Source Code Vote up 5 votes
@BindingAdapter("android:src")
public static void setSrc(ImageView view, Bitmap bitmap) {
    view.setImageBitmap(bitmap);
}
 
Example 18
Project: zero-to-app-emojistories   File: StoryAdapter.java   View Source Code Vote up 5 votes
public void addImage(byte[] imageBytes, String storyId) {
    storyId += "-photo";

    removeStuffWithThisKey(storyId);

    ImageView imageThing = new ImageView(myContext);

    int gridThingPixels = (int) myContext.getResources().getDimension(R.dimen.grid_thing);
    imageThing.setMaxHeight(gridThingPixels);
    imageThing.setMaxWidth(gridThingPixels);

    Bitmap imageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
    imageThing.setImageBitmap(imageBitmap);

    gridContents.add(new TaggedView(imageThing, storyId));

    this.notifyDataSetChanged();
}
 
Example 19
Project: BaseAdapterRel   File: ViewHolder.java   View Source Code Vote up 5 votes
public ViewHolder setImageBitmap(int viewId, Bitmap bitmap)
{
    ImageView view = getView(viewId);
    view.setImageBitmap(bitmap);
    return this;
}
 
Example 20
Project: piast-trail   File: PlaceDetailsActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.place_details);
    mContext = this;
    mResources = getResources();
    
    mMapFragment = (SupportMapFragment)
            getSupportFragmentManager().findFragmentById(R.id.place_map);
    
    mMapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap map) {
            mMap = map;
            updateUI();
        }
    });
    
    mPlaceId = getIntent().getIntExtra(EXTRA_PLACE_POSITION, -1);
    final VisitableGenerator generator = VisitableGenerator.get(this);
    mPlace = generator.getPlace(mPlaceId);
    mLocation = new Location("");
    mLocation.set(mPlace.getLocation());
    
    mPlaceImageViewFull = (ImageView) findViewById(R.id.place_image_full);
    mPlaceCaption = (TextView) findViewById(R.id.place_caption_full);
    mWebView = (WebView) findViewById(R.id.web_view);
    mBackupEmptyView = (TextView) findViewById(R.id.place_backup_empty_view);
    mIndicator = (ProgressBar) findViewById(R.id.indicator);
    mVisitedCheckBox = (CheckBox) findViewById(R.id.visited_check_box);
    
    mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
    mProgressBar.setMax(100);
    
    mWebView.setWebChromeClient(new WebChromeClient() {
        
        @Override
        public void onProgressChanged(WebView webView, int newProgress) {
            if (newProgress == 100) {
                mProgressBar.setVisibility(View.GONE);
            } else {
                mProgressBar.setVisibility(View.VISIBLE);
                mProgressBar.setProgress(newProgress);
            }
        }
    });
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.loadUrl(mPlace.getWikiUrl());
    
    Bitmap bitmap = PictureUtils.decodeBitmapFromResource(getResources(),
            mPlace.getImgResourceId(), 400, 400);
    
    mPlaceImageViewFull.setImageBitmap(bitmap);
    mPlaceCaption.setText(mPlace.getPlaceNameResId());
    this.getSupportActionBar().setTitle(mPlace.getPlaceNameResId());
    
    mVisitedCheckBox.setChecked(mPlace.isVisited());
    mVisitedCheckBox.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton view, boolean isChecked) {
            mPlace.setVisited(isChecked);
        }
    });
    
    mConnManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    
    NetworkInfo activeNetwork = mConnManager.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnected();
    
    if (!isConnected) {
        mIndicator.setVisibility(View.INVISIBLE);
        mBackupEmptyView.setText(R.string.empty_placeholder);
    }
}