List of usage examples for android.widget ImageView setImageBitmap
@android.view.RemotableViewMethod public void setImageBitmap(Bitmap bm)
From source file:com.bxduan.apps.secretgallery.ImageDownloader.java
/** * Download the specified image from the Internet and binds it to the provided ImageView. The * binding is immediate if the image is found in the cache and will be done asynchronously * otherwise. A null bitmap will be associated to the ImageView if an error occurs. * * @param url The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. *//*from w ww. j av a2 s . c o m*/ public void download(String url, ImageView imageView) { resetPurgeTimer(); Bitmap bitmap = getBitmapFromCache(url); if (bitmap == null) { forceDownload(url, imageView); } else { cancelPotentialDownload(url, imageView); imageView.setImageBitmap(bitmap); mBitmap = bitmap; mListener.downloadSuccess(); } }
From source file:ca.ualberta.app.activity.CreateAnswerActivity.java
/** * set the image to the imageView/*from ww w . j a v a2 s. c o m*/ * * @param view * View passed to the activity to check which button was pressed. */ // http://www.csdn123.com/html/mycsdn20140110/2d/2d3c6d5adb428b6708901f7060d31800.html public void viewAnswerImage(View view) { LayoutInflater inflater = LayoutInflater.from(view.getContext()); View imgEntryView = inflater.inflate(R.layout.dialog_photo, null); final AlertDialog dialog = new AlertDialog.Builder(view.getContext()).create(); ImageView img = (ImageView) imgEntryView.findViewById(R.id.large_image); img.setImageBitmap(image); dialog.setView(imgEntryView); dialog.show(); imgEntryView.setOnClickListener(new OnClickListener() { public void onClick(View paramView) { dialog.cancel(); } }); }
From source file:name.gumartinm.weather.information.fragment.current.CurrentFragment.java
private void updateUI(final Current current) { // 1. Update units of measurement. final UnitsConversor tempUnitsConversor = new TempUnitsConversor( this.getActivity().getApplicationContext()); final UnitsConversor windConversor = new WindUnitsConversor(this.getActivity().getApplicationContext()); final UnitsConversor pressureConversor = new PressureUnitsConversor( this.getActivity().getApplicationContext()); // 2. Formatters final DecimalFormat numberFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); numberFormatter.applyPattern("###.##"); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss", Locale.US); // 3. Prepare data for UI. String tempMax = ""; if (current.getMain().getTemp_max() != null) { double conversion = (Double) current.getMain().getTemp_max(); conversion = tempUnitsConversor.doConversion(conversion); tempMax = numberFormatter.format(conversion) + tempUnitsConversor.getSymbol(); }//from www. j a v a 2 s . c o m String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = numberFormatter.format(conversion) + tempUnitsConversor.getSymbol(); } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { final String icon = current.getWeather().get(0).getIcon(); picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon).getResourceDrawable()); } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); } String description = this.getString(R.string.text_field_description_when_error); if (current.getWeather().size() > 0) { description = current.getWeather().get(0).getDescription(); } String humidityValue = ""; if ((current.getMain() != null) && (current.getMain().getHumidity() != null)) { final double conversion = (Double) current.getMain().getHumidity(); humidityValue = numberFormatter.format(conversion); } String pressureValue = ""; if ((current.getMain() != null) && (current.getMain().getPressure() != null)) { double conversion = (Double) current.getMain().getPressure(); conversion = pressureConversor.doConversion(conversion); pressureValue = numberFormatter.format(conversion); } String windValue = ""; if ((current.getWind() != null) && (current.getWind().getSpeed() != null)) { double conversion = (Double) current.getWind().getSpeed(); conversion = windConversor.doConversion(conversion); windValue = numberFormatter.format(conversion); } String rainValue = ""; if ((current.getRain() != null) && (current.getRain().get3h() != null)) { final double conversion = (Double) current.getRain().get3h(); rainValue = numberFormatter.format(conversion); } String cloudsValue = ""; if ((current.getClouds() != null) && (current.getClouds().getAll() != null)) { final double conversion = (Double) current.getClouds().getAll(); cloudsValue = numberFormatter.format(conversion); } String snowValue = ""; if ((current.getSnow() != null) && (current.getSnow().get3h() != null)) { final double conversion = (Double) current.getSnow().get3h(); snowValue = numberFormatter.format(conversion); } String feelsLike = ""; if (current.getMain().getTemp() != null) { double conversion = (Double) current.getMain().getTemp(); conversion = tempUnitsConversor.doConversion(conversion); feelsLike = numberFormatter.format(conversion); } String sunRiseTime = ""; if (current.getSys().getSunrise() != null) { final long unixTime = (Long) current.getSys().getSunrise(); final Date unixDate = new Date(unixTime * 1000L); sunRiseTime = dateFormat.format(unixDate); } String sunSetTime = ""; if (current.getSys().getSunset() != null) { final long unixTime = (Long) current.getSys().getSunset(); final Date unixDate = new Date(unixTime * 1000L); sunSetTime = dateFormat.format(unixDate); } // 4. Update UI. final TextView tempMaxView = (TextView) getActivity().findViewById(R.id.weather_current_temp_max); tempMaxView.setText(tempMax); final TextView tempMinView = (TextView) getActivity().findViewById(R.id.weather_current_temp_min); tempMinView.setText(tempMin); final ImageView pictureView = (ImageView) getActivity().findViewById(R.id.weather_current_picture); pictureView.setImageBitmap(picture); final TextView descriptionView = (TextView) getActivity().findViewById(R.id.weather_current_description); descriptionView.setText(description); ((TextView) getActivity().findViewById(R.id.weather_current_humidity_value)).setText(humidityValue); ((TextView) getActivity().findViewById(R.id.weather_current_humidity_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_percent)); ((TextView) getActivity().findViewById(R.id.weather_current_pressure_value)).setText(pressureValue); ((TextView) getActivity().findViewById(R.id.weather_current_pressure_units)) .setText(pressureConversor.getSymbol()); ((TextView) getActivity().findViewById(R.id.weather_current_wind_value)).setText(windValue); ((TextView) getActivity().findViewById(R.id.weather_current_wind_units)).setText(windConversor.getSymbol()); ((TextView) getActivity().findViewById(R.id.weather_current_rain_value)).setText(rainValue); ((TextView) getActivity().findViewById(R.id.weather_current_rain_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_mm3h)); ((TextView) getActivity().findViewById(R.id.weather_current_clouds_value)).setText(cloudsValue); ((TextView) getActivity().findViewById(R.id.weather_current_clouds_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_percent)); ((TextView) getActivity().findViewById(R.id.weather_current_snow_value)).setText(snowValue); ((TextView) getActivity().findViewById(R.id.weather_current_snow_units)) .setText(this.getActivity().getApplicationContext().getString(R.string.text_units_mm3h)); ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_value)).setText(feelsLike); ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_units)) .setText(tempUnitsConversor.getSymbol()); ((TextView) getActivity().findViewById(R.id.weather_current_sunrise_value)).setText(sunRiseTime); ((TextView) getActivity().findViewById(R.id.weather_current_sunset_value)).setText(sunSetTime); this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.VISIBLE); this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.GONE); this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE); }
From source file:hongik.android.project.best.MenuActivity.java
public void drawintent() throws Exception { String query = ("func=menudetail&license=" + license + "&item=" + item); DBConnector conn = new DBConnector(query); conn.start();//from www . ja va2 s .com conn.join(); JSONObject jsonResult = conn.getResult(); boolean result = jsonResult.getBoolean("result"); if (!result) return; JSONObject json = jsonResult.getJSONArray("values").getJSONObject(0); String sname = json.getString("SNAME"); String item = json.getString("PRICE"); String img = json.getString("IMG"); ImageView imageView = (ImageView) findViewById(R.id.menudetail_image); TextViewPlus tvItem = (TextViewPlus) findViewById(R.id.menudetail_item); TextViewPlus tvStore = (TextViewPlus) findViewById(R.id.menudetail_name); TextViewPlus tvPrice = (TextViewPlus) findViewById(R.id.menudetail_price); tvItem.setText(this.item); tvStore.setText(sname); tvPrice.setText(item); ImageLoader imageLoader = new ImageLoader(img); imageLoader.start(); imageLoader.join(); Bitmap bitmap = imageLoader.getBitmap(); imageView.setImageBitmap(bitmap); }
From source file:com.app.sample.chatting.adapter.chat.FaceCategroyAdapter.java
@Override public void setPageIcon(int position, ImageView image) { if (position == 0) { image.setImageResource(R.drawable.icon_face_click); return;/*w w w . j a v a 2 s . com*/ } File file = new File(datas.get(position - 1)); String path = null; for (int i = 0; i < file.list().length; i++) { path = file.list()[i]; if (path.endsWith(".png") || path.endsWith(".jpg") || path.endsWith(".jpeg")) { break; } } Bitmap bitmap = BitmapCreate.bitmapFromFile(file.getAbsolutePath() + "/" + path, 40, 40); image.setImageBitmap(bitmap); }
From source file:com.baseproject.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView./*www . j a v a2 s. c o m*/ * * @param imageView * @param bitmap */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { if (imageView.getTag() instanceof String && "no_animation".equals(String.valueOf(imageView.getTag()))) { imageView.setImageBitmap(bitmap); } else { // Transition drawable with a transparent drwabale and the final // bitmap TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mContext.getResources(), bitmap) }); final WeakReference<TransitionDrawable> tdReference = new WeakReference<TransitionDrawable>(td); td = null; // Set background to loading bitmap final BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), mLoadingBitmap); if (Build.VERSION.SDK_INT >= 16) { imageView.setBackground(bd); } else { imageView.setBackgroundDrawable(bd); } if (null != tdReference.get()) { imageView.setImageDrawable(tdReference.get()); tdReference.get().startTransition(FADE_IN_TIME); } } } else { imageView.setImageBitmap(bitmap); } }
From source file:com.android.browser.GearsBaseDialog.java
/** * Utility method to update the icon./*w w w . j a v a 2s. c om*/ * Called on the UI thread. */ public void updateIcon() { if (mIcon == null) { return; } View view = findViewById(R.id.origin_icon); if (view != null) { ImageView imageView = (ImageView) view; imageView.setMaxHeight(MAX_ICON_SIZE); imageView.setMaxWidth(MAX_ICON_SIZE); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageBitmap(mIcon); imageView.setVisibility(View.VISIBLE); } }
From source file:com.handpoint.headstart.client.ui.ReceiptActivity.java
private void initReceiptView() { Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/roboto-regular.ttf"); TextView merchantName = (TextView) findViewById(R.id.merchant_name); merchantName.setTypeface(tf, Typeface.BOLD); merchantName.setText(getMerchantName()); TextView transactionDateView = (TextView) findViewById(R.id.date); java.text.DateFormat df = DateFormat.getDateFormat(this); transactionDateView.setTypeface(tf); transactionDateView.setText(" " + df.format(mResult.getDateTime())); TextView transactionResult = (TextView) findViewById(R.id.transaction_result); transactionResult.setTypeface(tf, Typeface.BOLD); transactionResult.setText(mResult.getFinancialStatus()); TextView messageView = (TextView) findViewById(R.id.message); messageView.setTypeface(tf);/*from w ww . j av a2 s . co m*/ String message = ((Application) getApplication()).formatErrorMessage(mResult.getStatusMessage(), mResult.getErrorMessage()); messageView.setText(message); ImageView cardSchemeLogo = (ImageView) findViewById(R.id.card_scheme_logo); cardSchemeLogo.setImageDrawable(getCardSchemeLogo()); TextView amountView = (TextView) findViewById(R.id.amount_text); amountView.setTypeface(tf); amountView.setText(getTotalAmount(mResult.getAuthorizedAmount(), mResult.getCurrency())); TextView descriptionView = (TextView) findViewById(R.id.item_description_text); descriptionView.setTypeface(tf); descriptionView.setText(getDescriptionText()); ImageView productImageView = (ImageView) findViewById(R.id.picture); productImageView.setImageBitmap(getImageBitmap()); }
From source file:com.example.administrator.winsoftsalesproject.activity.NavHomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nav_home); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from w w w.j av a 2 s .c om sessionManger = new SessionManger(this); sessionManger.checkLogin(); HashMap<String, String> user = sessionManger.getUserDetails(); home = new Home(); fragmentTransaction(home); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); View header = navigationView.getHeaderView(0); TextView headerName = (TextView) header.findViewById(R.id.nav_name); TextView designation = (TextView) header.findViewById(R.id.nav_designation); ImageView headerImage = (ImageView) header.findViewById(R.id.nav_image); headerName.setText(user.get(sessionManger.KEY_EMPLOYEE_NAME).toUpperCase()); designation.setText(user.get(sessionManger.KEY_DEPARTMENT).toUpperCase()); byte[] decodeString = Base64.decode(user.get(sessionManger.KEY_EMPLOYEE_PHOTO).getBytes(), Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(decodeString, 0, decodeString.length); headerImage.setImageBitmap(bitmap); }
From source file:com.rxsampleapp.RxApiTestActivity.java
public void loadImage(View view) { final String URL_IMAGE = "http://i.imgur.com/2M7Hasn.png"; RxAndroidNetworking.get(URL_IMAGE).setImageScaleType(null).setBitmapMaxHeight(0).setBitmapMaxWidth(0) .setBitmapConfig(Bitmap.Config.ARGB_8888).build().setAnalyticsListener(new AnalyticsListener() { @Override// w w w.ja v a 2s. c o m public void onReceived(long timeTakenInMillis, long bytesSent, long bytesReceived, boolean isFromCache) { Log.d(TAG, " timeTakenInMillis : " + timeTakenInMillis); Log.d(TAG, " bytesSent : " + bytesSent); Log.d(TAG, " bytesReceived : " + bytesReceived); Log.d(TAG, " isFromCache : " + isFromCache); } }).getBitmapObservable().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) .subscribe(new Observer<Bitmap>() { @Override public void onCompleted() { Log.d(TAG, "onComplete Bitmap"); } @Override public void onError(Throwable e) { if (e instanceof ANError) { ANError anError = (ANError) e; if (anError.getErrorCode() != 0) { // received ANError from server // error.getErrorCode() - the ANError code from server // error.getErrorBody() - the ANError body from server // error.getErrorDetail() - just a ANError detail Log.d(TAG, "onError errorCode : " + anError.getErrorCode()); Log.d(TAG, "onError errorBody : " + anError.getErrorBody()); Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } else { // error.getErrorDetail() : connectionError, parseError, requestCancelledError Log.d(TAG, "onError errorDetail : " + anError.getErrorDetail()); } } else { Log.d(TAG, "onError errorMessage : " + e.getMessage()); } } @Override public void onNext(Bitmap bitmap) { Log.d(TAG, "onResponse Bitmap"); ImageView imageView = (ImageView) findViewById(R.id.imageView); imageView.setImageBitmap(bitmap); } }); }