List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java
private void setThumbnailImageStorage(ImageView mImageView, String imageString) { // Get the dimensions of the View int targetW = mImageView.getWidth(); int targetH = mImageView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; //BitmapFactory.decodeFile(imagePat, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / targetW, photoH / targetH); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true;//ww w. j av a2 s . c o m // Bitmap bitmap = decodeBase64(imageString)); byte[] b = Base64.decode(imageString, Base64.DEFAULT); InputStream is = new ByteArrayInputStream(b); //Bitmap bitmap = BitmapFactory.decodeStream(is, bmOptions); Bitmap bitmap = BitmapFactory.decodeFile(imageString, bmOptions); mImageView.setImageBitmap(bitmap); }
From source file:com.benefit.buy.library.http.query.AbstractAQuery.java
/** * Set the image of an ImageView.// www . ja v a 2 s . c om * @param resid the resource id * @return self * @see testImage1 */ public T image(int resid) { if (view instanceof ImageView) { ImageView iv = (ImageView) view; iv.setTag(Constants.TAG_URL, null); if (resid == 0) { iv.setImageBitmap(null); } else { iv.setImageResource(resid); } } return self(); }
From source file:com.xiaoyu.DoctorHelp.chat.chatuidemo.adapter.MessageAdapter.java
/** * load image into image view//from ww w .j a va2s . co m * * @param thumbernailPath * @param iv * @param * @return the image exists or not */ private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath, String remoteDir, final EMMessage message) { // String imagename = // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1, // localFullSizePath.length()); // final String remote = remoteDir != null ? remoteDir+imagename : // imagename; final String remote = remoteDir; EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote); // first check if the thumbnail image already loaded into cache Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath); if (bitmap != null) { // thumbnail image is already loaded, reuse the drawable iv.setImageBitmap(bitmap); iv.setClickable(true); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EMLog.d(TAG, "image view on click"); Intent intent = new Intent(activity, ShowBigImage.class); File file = new File(localFullSizePath); if (file.exists()) { Uri uri = Uri.fromFile(file); intent.putExtra("uri", uri); EMLog.d(TAG, "here need to check why download everytime"); } else { // The local full size pic does not exist yet. // ShowBigImage needs to download it from the server // first // intent.putExtra("", message.get); ImageMessageBody body = (ImageMessageBody) message.getBody(); intent.putExtra("secret", body.getSecret()); intent.putExtra("remotepath", remote); } if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat && message.getChatType() != ChatType.ChatRoom) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } activity.startActivity(intent); } }); return true; } else { new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv, activity, message); return true; } }
From source file:com.akop.bach.fragment.playstation.TrophiesFragment.java
private void loadGameDetails() { View view = getView();//from w w w.ja v a 2s . c om if (view == null) return; if (mTitleId < 0) { view.findViewById(R.id.unselected).setVisibility(View.VISIBLE); view.findViewById(R.id.achievement_contents).setVisibility(View.GONE); } else { view.findViewById(R.id.unselected).setVisibility(View.GONE); view.findViewById(R.id.achievement_contents).setVisibility(View.VISIBLE); } if (!mShowGameTotals) return; Context context = getActivity(); ContentResolver cr = context.getContentResolver(); Cursor c = cr.query(Games.CONTENT_URI, GamesFragment.PROJ, Games._ID + "=" + mTitleId, null, null); if (c != null) { try { if (c.moveToFirst()) { int platinum = c.getInt(GamesFragment.COLUMN_UNLOCKED_PLATINUM); int gold = c.getInt(GamesFragment.COLUMN_UNLOCKED_GOLD); int silver = c.getInt(GamesFragment.COLUMN_UNLOCKED_SILVER); int bronze = c.getInt(GamesFragment.COLUMN_UNLOCKED_BRONZE); int progress = c.getInt(GamesFragment.COLUMN_PROGRESS); TextView tv; ImageView iv; ProgressBar pb; if ((tv = (TextView) view.findViewById(R.id.game_title)) != null) tv.setText(c.getString(GamesFragment.COLUMN_TITLE)); if ((tv = (TextView) view.findViewById(R.id.game_progress_ind)) != null) tv.setText(progress + ""); if ((pb = (ProgressBar) view.findViewById(R.id.game_progress_bar)) != null) pb.setProgress(progress); if ((tv = (TextView) view.findViewById(R.id.game_trophies_platinum)) != null) tv.setText(platinum + ""); if ((tv = (TextView) view.findViewById(R.id.game_trophies_gold)) != null) tv.setText(gold + ""); if ((tv = (TextView) view.findViewById(R.id.game_trophies_silver)) != null) tv.setText(silver + ""); if ((tv = (TextView) view.findViewById(R.id.game_trophies_bronze)) != null) tv.setText(bronze + ""); if ((tv = (TextView) view.findViewById(R.id.game_trophies_all)) != null) tv.setText((platinum + gold + silver + bronze) + ""); ImageCache ic = ImageCache.getInstance(); String iconUrl = c.getString(GamesFragment.COLUMN_ICON_URL); Bitmap bmp; if ((bmp = ic.getCachedBitmap(iconUrl, mCp)) != null) { iv = (ImageView) view.findViewById(R.id.game_icon); iv.setImageBitmap(bmp); } else { if (iconUrl != null) { ic.requestImage(iconUrl, new OnImageReadyListener() { @Override public void onImageReady(long id, Object param, Bitmap bmp) { mHandler.post(new Runnable() { @Override public void run() { loadGameDetails(); } }); } }, 0, null, true, mCp); } } } } finally { c.close(); } } }
From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java
/** * load image into image view/*w w w. j a v a 2 s . com*/ * * @param thumbernailPath * @param iv * @param position * @return the image exists or not */ private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath, String remoteDir, final EMMessage message) { // String imagename = // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1, // localFullSizePath.length()); // final String remote = remoteDir != null ? remoteDir+imagename : // imagename; final String remote = remoteDir; EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote); // first check if the thumbnail image already loaded into cache Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath); if (bitmap != null) { // thumbnail image is already loaded, reuse the drawable iv.setImageBitmap(bitmap); iv.setClickable(true); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.err.println("image view on click"); Intent intent = new Intent(activity, ShowBigImage.class); File file = new File(localFullSizePath); if (file.exists()) { Uri uri = Uri.fromFile(file); intent.putExtra("uri", uri); System.err.println("here need to check why download everytime"); } else { // The local full size pic does not exist yet. // ShowBigImage needs to download it from the server // first // intent.putExtra("", message.get); ImageMessageBody body = (ImageMessageBody) message.getBody(); intent.putExtra("secret", body.getSecret()); intent.putExtra("remotepath", remote); } if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } activity.startActivity(intent); } }); return true; } else { new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv, activity, message); return true; } }
From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java
private void loadImage(ImageView imageView, ImageParams params) { if (imageView == null) { return;// w w w. j ava2 s . c om } Bitmap bitmap = null; if (mImageCache != null) { // if (params.loadType == ImageParams.LOAD_TYPE_LOCAL) { bitmap = mImageCache.getBitmapFromMemCache(params.path + params.reqWidth + params.reqHeight); } else if (params.loadType == ImageParams.LOAD_TYPE_THUMB_ID) { bitmap = mImageCache.getBitmapFromMemCache(params.thumbType + params.thumbId); } else if (params.loadType == ImageParams.LOAD_TYPE_THUMB_PATH) { bitmap = mImageCache.getBitmapFromMemCache(params.path); } else if (params.loadType == ImageParams.LOAD_TYPE_HTTP) { bitmap = mImageCache.getBitmapFromMemCache(params.path + params.reqWidth + params.reqHeight); } } if (bitmap != null) { if ("0".equals(imageView.getTag())) { // ?? bitmap = toGrayscale(bitmap); } imageView.setImageBitmap(bitmap); if (params.loadAfterListener != null) { params.loadAfterListener.onImgLoadAfter(true); } } else if (cancelPotentialWork(TextUtils.isEmpty(params.path) ? params.thumbId : params.path, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); imageView.setImageDrawable(asyncDrawable); // NOTE: This uses a custom version of AsyncTask that has been pulled from the // framework and slightly modified. Refer to the docs at the top of the class // for more info on what was changed. if (params.loadType == ImageParams.LOAD_TYPE_HTTP) { task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); } else { task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, params); } } }
From source file:com.keylesspalace.tusky.ComposeActivity.java
private void addMediaToQueue(@Nullable String id, QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize, QueuedMedia.ReadyStage readyStage, @Nullable String description) { final QueuedMedia item = new QueuedMedia(type, uri, new ProgressImageView(this), mediaSize, description); item.id = id;/*w w w . j a v a2s. c o m*/ item.readyStage = readyStage; ImageView view = item.preview; Resources resources = getResources(); int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin); int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(thumbnailViewSize, thumbnailViewSize); layoutParams.setMargins(margin, 0, margin, marginBottom); view.setLayoutParams(layoutParams); view.setScaleType(ImageView.ScaleType.CENTER_CROP); view.setImageBitmap(preview); view.setOnClickListener(v -> onMediaClick(item, v)); view.setContentDescription(getString(R.string.action_delete)); mediaPreviewBar.addView(view); mediaQueued.add(item); int queuedCount = mediaQueued.size(); if (queuedCount == 1) { // If there's one video in the queue it is full, so disable the button to queue more. if (item.type == QueuedMedia.Type.VIDEO) { enableButton(pickButton, false, false); } } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) { // Limit the total media attachments, also. enableButton(pickButton, false, false); } updateHideMediaToggle(); if (item.readyStage != QueuedMedia.ReadyStage.UPLOADED) { waitForMediaLatch.countUp(); try { if (type == QueuedMedia.Type.IMAGE && (mediaSize > STATUS_MEDIA_SIZE_LIMIT || MediaUtils .getImageSquarePixels(getContentResolver(), item.uri) > STATUS_MEDIA_PIXEL_SIZE_LIMIT)) { downsizeMedia(item); } else { uploadMedia(item); } } catch (FileNotFoundException e) { onUploadFailure(item, false); } } }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addFinalPresentRun() { // Two spacers at the begining. View view = new View(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(mSlotWidth, mScreenHeight); mObstacleLayout.addView(view, lp);/* w w w.j av a2 s . c o m*/ view = new View(this); mObstacleLayout.addView(view, lp); // All of these presents are 500 points (but only if you're awesome) if (mElfState == 0) { mRainingPresents = true; } // SIN wave of presents in the middle float center = (float) (mScreenHeight / 2); float amplitude = (float) (mScreenHeight / 4); int count = (3 * SLOTS_PER_SCREEN) - 4; for (int i = 0; i < count; i++) { float x = (float) ((mSlotWidth - mGiftBoxes[0].getWidth()) / 2); float y = center + (amplitude * (float) Math.sin(2.0 * Math.PI * (double) i / (double) count)); Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)]; ImageView iv = new ImageView(this); iv.setImageBitmap(bmp); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); FrameLayout frame = new FrameLayout(this); LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); frame.addView(iv, flp); iv.setTranslationX(x); iv.setTranslationY(y); mObstacleLayout.addView(frame, lp); } // Two spacers at the end. view = new View(this); mObstacleLayout.addView(view, lp); view = new View(this); mObstacleLayout.addView(view, lp); // Account for rounding errors in mSlotWidth int extra = ((3 * mScreenWidth) - (3 * SLOTS_PER_SCREEN * mSlotWidth)); if (extra > 0) { // Add filler to ensure sync with background/foreground scrolls! lp = new LinearLayout.LayoutParams(extra, LinearLayout.LayoutParams.MATCH_PARENT); view = new View(this); mObstacleLayout.addView(view, lp); } }
From source file:biz.bokhorst.xprivacy.ActivityApp.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final int userId = Util.getUserId(Process.myUid()); // Check privacy service client if (!PrivacyService.checkClient()) return;// w ww . j a v a2 s. com // Set layout setContentView(R.layout.restrictionlist); // Get arguments Bundle extras = getIntent().getExtras(); if (extras == null) { finish(); return; } int uid = extras.getInt(cUid); String restrictionName = (extras.containsKey(cRestrictionName) ? extras.getString(cRestrictionName) : null); String methodName = (extras.containsKey(cMethodName) ? extras.getString(cMethodName) : null); // Get app info mAppInfo = new ApplicationInfoEx(this, uid); if (mAppInfo.getPackageName().size() == 0) { finish(); return; } // Set title setTitle(String.format("%s - %s", getString(R.string.app_name), TextUtils.join(", ", mAppInfo.getApplicationName()))); // Handle info click ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo); imgInfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Packages can be selected on the web site Util.viewUri(ActivityApp.this, Uri.parse(String.format(ActivityShare.getBaseURL(ActivityApp.this) + "?package_name=%s", mAppInfo.getPackageName().get(0)))); } }); // Display app name TextView tvAppName = (TextView) findViewById(R.id.tvApp); tvAppName.setText(mAppInfo.toString()); // Background color if (mAppInfo.isSystem()) { LinearLayout llInfo = (LinearLayout) findViewById(R.id.llInfo); llInfo.setBackgroundColor(getResources().getColor(getThemed(R.attr.color_dangerous))); } // Display app icon final ImageView imgIcon = (ImageView) findViewById(R.id.imgIcon); imgIcon.setImageDrawable(mAppInfo.getIcon(this)); // Handle icon click imgIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openContextMenu(imgIcon); } }); // Display on-demand state final ImageView imgCbOnDemand = (ImageView) findViewById(R.id.imgCbOnDemand); if (PrivacyManager.isApplication(mAppInfo.getUid()) && PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true)) { boolean ondemand = PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); imgCbOnDemand.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { boolean ondemand = !PrivacyManager.getSettingBool(-mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, false); PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingOnDemand, Boolean.toString(ondemand)); imgCbOnDemand.setImageBitmap(ondemand ? getOnDemandCheckBox() : getOffCheckBox()); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); } }); } else imgCbOnDemand.setVisibility(View.GONE); // Display restriction state swEnabled = (Switch) findViewById(R.id.swEnable); swEnabled.setChecked( PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true)); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { PrivacyManager.setSetting(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, Boolean.toString(isChecked)); if (mPrivacyListAdapter != null) mPrivacyListAdapter.notifyDataSetChanged(); imgCbOnDemand.setEnabled(isChecked); } }); imgCbOnDemand.setEnabled(swEnabled.isChecked()); // Add context menu to icon registerForContextMenu(imgIcon); // Check if internet access if (!mAppInfo.hasInternet(this)) { ImageView imgInternet = (ImageView) findViewById(R.id.imgInternet); imgInternet.setVisibility(View.INVISIBLE); } // Check if frozen if (!mAppInfo.isFrozen(this)) { ImageView imgFrozen = (ImageView) findViewById(R.id.imgFrozen); imgFrozen.setVisibility(View.INVISIBLE); } // Display version TextView tvVersion = (TextView) findViewById(R.id.tvVersion); tvVersion.setText(TextUtils.join(", ", mAppInfo.getPackageVersionName(this))); // Display package name TextView tvPackageName = (TextView) findViewById(R.id.tvPackageName); tvPackageName.setText(TextUtils.join(", ", mAppInfo.getPackageName())); // Fill privacy list view adapter final ExpandableListView lvRestriction = (ExpandableListView) findViewById(R.id.elvRestriction); lvRestriction.setGroupIndicator(null); mPrivacyListAdapter = new RestrictionAdapter(R.layout.restrictionentry, mAppInfo, restrictionName, methodName); lvRestriction.setAdapter(mPrivacyListAdapter); if (restrictionName != null) { int groupPosition = new ArrayList<String>(PrivacyManager.getRestrictions(this).values()) .indexOf(restrictionName); lvRestriction.expandGroup(groupPosition); lvRestriction.setSelectedGroup(groupPosition); if (methodName != null) { int childPosition = PrivacyManager.getHooks(restrictionName) .indexOf(new Hook(restrictionName, methodName)); lvRestriction.setSelectedChild(groupPosition, childPosition, true); } } // Listen for package add/remove IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_PACKAGE_REMOVED); iff.addDataScheme("package"); registerReceiver(mPackageChangeReceiver, iff); mPackageChangeReceiverRegistered = true; // Up navigation getActionBar().setDisplayHomeAsUpEnabled(true); // Tutorial if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialDetails, false)) { ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE); ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE); } View.OnClickListener listener = new View.OnClickListener() { @Override public void onClick(View view) { ViewParent parent = view.getParent(); while (!parent.getClass().equals(ScrollView.class)) parent = parent.getParent(); ((View) parent).setVisibility(View.GONE); PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialDetails, Boolean.TRUE.toString()); } }; ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener); ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener); // Process actions if (extras.containsKey(cAction)) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancel(mAppInfo.getUid()); if (extras.getInt(cAction) == cActionClear) optionClear(); else if (extras.getInt(cAction) == cActionSettings) optionSettings(); } // Annotate Meta.annotate(this); }
From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java
private void addSpaceOrPresent(int width) { if (width > 0) { mLastObstacle = 0;/* w w w. j ava 2 s .c o m*/ // 1/3 chance of a present. LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, LinearLayout.LayoutParams.MATCH_PARENT); if (mRandom.nextInt(3) == 0) { // Present! // Which one? Bitmap bmp = mGiftBoxes[mRandom.nextInt(mGiftBoxes.length)]; ImageView iv = new ImageView(this); iv.setLayerType(View.LAYER_TYPE_HARDWARE, null); iv.setImageBitmap(bmp); // Position the present int left = mRandom.nextInt(width / 2) + (width / 4) - ((int) ((float) bmp.getWidth() * mScaleX) / 2); int top = mRandom.nextInt(mScreenHeight / 2) + (mScreenHeight / 4) - ((int) ((float) bmp.getHeight() * mScaleY) / 2); FrameLayout frame = new FrameLayout(this); LayoutParams flp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); frame.addView(iv, flp); iv.setTranslationX(left); iv.setTranslationY(top); mObstacleLayout.addView(frame, lp); } else { // Space View view = new View(this); mObstacleLayout.addView(view, lp); } } }