Example usage for android.widget ImageView setImageBitmap

List of usage examples for android.widget ImageView setImageBitmap

Introduction

In this page you can find the example usage for android.widget ImageView setImageBitmap.

Prototype

@android.view.RemotableViewMethod
public void setImageBitmap(Bitmap bm) 

Source Link

Document

Sets a Bitmap as the content of this ImageView.

Usage

From source file:com.DGSD.Teexter.UI.Recipient.BaseRecipientAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final RecipientEntry entry = mEntries.get(position);
    switch (entry.getEntryType()) {
    case RecipientEntry.ENTRY_TYPE_WAITING_FOR_DIRECTORY_SEARCH: {
        return convertView != null ? convertView
                : mInflater.inflate(getWaitingForDirectorySearchLayout(), parent, false);
    }/*from  w  ww.j av a  2 s  .  c om*/
    default: {
        String displayName = entry.getDisplayName();
        String destination = entry.getDestination();
        if (TextUtils.isEmpty(displayName) || TextUtils.equals(displayName, destination)) {
            displayName = destination;
            destination = null;
        }

        final View itemView = convertView != null ? convertView
                : mInflater.inflate(getItemLayout(), parent, false);
        final TextView displayNameView = (TextView) itemView.findViewById(getDisplayNameId());
        final TextView destinationView = (TextView) itemView.findViewById(getDestinationId());
        final TextView destinationTypeView = (TextView) itemView.findViewById(getDestinationTypeId());
        final ImageView imageView = (ImageView) itemView.findViewById(getPhotoId());
        displayNameView.setText(displayName);
        if (!TextUtils.isEmpty(destination)) {
            destinationView.setText(destination);
        } else {
            destinationView.setText(null);
        }
        if (destinationTypeView != null) {
            final CharSequence destinationType = Email.getTypeLabel(mContext.getResources(),
                    entry.getDestinationType(), entry.getDestinationLabel()).toString().toUpperCase();

            destinationTypeView.setText(destinationType);
        }

        if (entry.isFirstLevel()) {
            displayNameView.setVisibility(View.VISIBLE);
            if (imageView != null) {
                imageView.setVisibility(View.VISIBLE);
                final byte[] photoBytes = entry.getPhotoBytes();
                if (photoBytes != null && imageView != null) {
                    final Bitmap photo = BitmapFactory.decodeByteArray(photoBytes, 0, photoBytes.length);
                    imageView.setImageBitmap(photo);
                } else {
                    imageView.setImageResource(getDefaultPhotoResource());
                }
            }
        } else {
            displayNameView.setVisibility(View.GONE);
            if (imageView != null) {
                imageView.setVisibility(View.INVISIBLE);
            }
        }
        return itemView;
    }
    }
}

From source file:com.BeatYourRecord.SubmitActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    boolean haveConnectedWifi = false;
    boolean haveConnectedMobile = false;
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] netInfo = cm.getAllNetworkInfo();
    for (NetworkInfo ni : netInfo) {
        if (ni.getTypeName().equalsIgnoreCase("WIFI"))
            if (ni.isConnected())
                haveConnectedWifi = true;
        if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
            if (ni.isConnected())
                haveConnectedMobile = true;
    }//from   www .  j  av  a2  s.  co  m
    if (haveConnectedWifi == false) {
        showDialog(11);
    }
    super.onCreate(savedInstanceState);

    // SharedPreferences pref = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
    //Editor editor = pref.edit();
    //auth = pref.getString("BYR_session", null);
    /*SharedPreferences pref6 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
      Editor editor7 = pref6.edit();
      //this.setContentView(R.layout.submit);
        String logoutme = pref6.getString("log", null);
        //log.v("log",logoutme);
     */
    SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
    Editor editor1 = pref1.edit();
    tourid = pref1.getString("id", null);
    logout = pref1.getString("log", null);
    filepath = pref1.getString("filepath", null);
    //log.v("id",tourid);
    //log.v("log",logout);

    Log.v("reached here first", "reached here first");
    File f = new File("/data/data/com.BeatYourRecord/shared_prefs/Tester15.xml");
    if (f.exists() && logout.equals("yes") == false) {

        //log.v("yyy","yyy");
        SharedPreferences pref = SubmitActivity.this.getSharedPreferences("Tester15", 0); // 0 - for private mode
        Editor editor = pref.edit();
        this.setContentView(R.layout.submit);
        auth = pref.getString("BYR_session", null);

    } else {
        //log.v("yyy","yyy1");
        this.setContentView(R.layout.submit1);
        showDialog(10);
    }

    //   String checksession = pref.getString("BYR_session", null);
    //   //log.v("checksession", checksession);

    ////log.v("Authhere",auth);
    this.authorizer = new ClientLoginAuthorizer.ClientLoginAuthorizerFactory().getAuthorizer(this,
            ClientLoginAuthorizer.YOUTUBE_AUTH_TOKEN_TYPE);

    dbHelper = new DbHelper(this);
    dbHelper = dbHelper.open();

    Intent intent = this.getIntent();
    this.videoUri = intent.getData();
    SharedPreferences pref1223 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
    Editor editor1223 = pref1223.edit();
    filepath = pref1223.getString("filepath", null);
    // this.videoUri =

    //   Uri path = Uri.parse(filepath);
    //File f1 = new File(filepath);  
    //Uri imageUri = Uri.fromFile(f1);
    //this.videoUri = imageUri;
    //this.videoUri = path;

    Log.v("Reached here second", "Reached here secord");
    //this.videoUri= Uri.fromFile(new File("/sdcard/Movies/com.BeatYourRecord/BYR_tournName_dateTim_20130724181901222.mp4"));
    //log.v("haha","haha");

    MediaScannerConnectionClient mediaScannerClient = new MediaScannerConnectionClient() {
        private MediaScannerConnection msc = null;
        {
            msc = new MediaScannerConnection(getApplicationContext(), this);
            msc.connect();
        }

        public void onMediaScannerConnected() {
            msc.scanFile(filepath, null);
        }

        public void onScanCompleted(String path, Uri uri) {
            //This is where you get your content uri
            Log.d("test3", uri.toString());
            needed = uri;
            // videoUri=needed;

            msc.disconnect();
        }
    };

    String videoPath = "";

    try {
        videoPath = getFilePathFromUri(this.videoUri);
        filepath1 = videoPath;
        Log.v("videoPath", videoPath);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    File videoFile = new File(videoPath);

    this.ytdDomain = intent.getExtras().getString(DbHelper.YTD_DOMAIN);
    this.assignmentId = intent.getExtras().getString(DbHelper.ASSIGNMENT_ID);

    this.domainHeader = (TextView) this.findViewById(R.id.domainHeader);
    domainHeader.setText(SettingActivity.getYtdDomains(this).get(this.ytdDomain));

    this.preferences = this.getSharedPreferences(MainActivity.SHARED_PREF_NAME, Activity.MODE_PRIVATE);
    this.youTubeName = preferences.getString(DbHelper.YT_ACCOUNT, null);

    final Button submitButton = (Button) findViewById(R.id.submitButton);
    submitButton.setEnabled(false);

    submitButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_LEGAL);
        }
    });
    addusertotournament();
    Button cancelButton = (Button) findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
            //Editor editor = pref1.edit();
            //editor.putString("filepath", permfilepath); 
            //editor.commit();
            Intent intent = new Intent(SubmitActivity.this, DetailsActivity.class);
            //    intent.putExtra(DbHelper.YTD_DOMAIN, "TODO-appname.appspot.com");

            //intent.setData(Uri.fromFile(file));   
            startActivity(intent);
            finish();
            // setResult(RESULT_CANCELED);
            //finish();
        }
    });

    Button forgotButton = (Button) findViewById(R.id.forgotButton);

    forgotButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //SharedPreferences pref1 = SubmitActivity.this.getSharedPreferences("TourPref", 0); // 0 - for private mode
            //Editor editor = pref1.edit();
            //editor.putString("filepath", permfilepath); 
            //editor.commit();

            SharedPreferences pref155 = getApplicationContext().getSharedPreferences("TourPref", 0); // 0 - for private mode
            Editor editor155 = pref155.edit();

            editor155.putString("filepath", filepath1);
            editor155.commit();
            Log.v("fielpathss", filepath1);
            Intent intent = new Intent(SubmitActivity.this, DetailsActivity.class);
            //    intent.putExtra(DbHelper.YTD_DOMAIN, "TODO-appname.appspot.com");

            //intent.setData(Uri.fromFile(file));   
            startActivity(intent);
            //   finish();
            // setResult(RESULT_CANCELED);
            //finish();
        }
    });

    EditText titleEdit = (EditText) findViewById(R.id.submitTitle);
    titleEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            enableSubmitIfReady();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    EditText descriptionEdit = (EditText) findViewById(R.id.submitDescription);
    descriptionEdit.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            enableSubmitIfReady();
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    Cursor cursor = this.managedQuery(this.videoUri, null, null, null, null);

    if (cursor.getCount() == 0) {
        Log.d(LOG_TAG, "not a valid video uri");
        Toast.makeText(SubmitActivity.this, "not a valid video uri", Toast.LENGTH_LONG).show();
    } else {
        getVideoLocation();

        if (cursor.moveToFirst()) {

            long id = cursor.getLong(cursor.getColumnIndex(Video.VideoColumns._ID));
            this.dateTaken = new Date(cursor.getLong(cursor.getColumnIndex(Video.VideoColumns.DATE_TAKEN)));
            Log.v("here", "here12");
            SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yyyy hh:mm aaa");
            Configuration userConfig = new Configuration();
            Settings.System.getConfiguration(getContentResolver(), userConfig);
            /* Calendar cal = Calendar.getInstance(userConfig.locale);
             TimeZone tz = cal.getTimeZone();*/
            Log.v("here", "here13");

            // dateFormat.setTimeZone(tz);

            TextView dateTakenView = (TextView) findViewById(R.id.dateCaptured);
            dateTakenView.setText("Date captured: " + dateFormat.format(dateTaken));

            ImageView thumbnail = (ImageView) findViewById(R.id.thumbnail);
            ContentResolver crThumb = getContentResolver();
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 1;
            Bitmap curThumb = MediaStore.Video.Thumbnails.getThumbnail(crThumb, id,
                    MediaStore.Video.Thumbnails.MICRO_KIND, options);
            thumbnail.setImageBitmap(curThumb);
        }
    }
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * /*from ww  w.  j  a v  a  2s. c  o  m*/
 *
 * @param localThumb
 *            
 * @param iv
 * @param thumbnailUrl
 *            
 * @param message
 */
private void showVideoThumbView(String localThumb, ImageView iv, String thumbnailUrl, final EMMessage message) {
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(localThumb);
    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) {
                VideoMessageBody videoBody = (VideoMessageBody) message.getBody();
                EMLog.d(TAG, "video view is on click");
                Intent intent = new Intent(activity, ShowVideoActivity.class);
                intent.putExtra("localpath", videoBody.getLocalUrl());
                intent.putExtra("secret", videoBody.getSecret());
                intent.putExtra("remotepath", videoBody.getRemoteUrl());
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    message.isAcked = true;
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);

            }
        });

    } else {
        new LoadVideoImageTask().execute(localThumb, thumbnailUrl, iv, activity, message, this);
    }

}

From source file:com.android.tv.settings.dialog.DialogFragment.java

private void setContentView(View content) {
    TextView titleView = (TextView) content.findViewById(R.id.title);
    TextView breadcrumbView = (TextView) content.findViewById(R.id.breadcrumb);
    TextView descriptionView = (TextView) content.findViewById(R.id.description);
    titleView.setText(mTitle);/*from www.j a  va  2 s .c  o m*/
    breadcrumbView.setText(mBreadcrumb);
    descriptionView.setText(mDescription);
    final ImageView iconImageView = (ImageView) content.findViewById(R.id.icon);
    if (mIconBackgroundColor != Color.TRANSPARENT) {
        iconImageView.setBackgroundColor(mIconBackgroundColor);
    }

    if (AccessibilityHelper.forceFocusableViews(getActivity())) {
        titleView.setFocusable(true);
        titleView.setFocusableInTouchMode(true);
        descriptionView.setFocusable(true);
        descriptionView.setFocusableInTouchMode(true);
        breadcrumbView.setFocusable(true);
        breadcrumbView.setFocusableInTouchMode(true);
    }

    if (mIconResourceId != 0) {
        iconImageView.setImageResource(mIconResourceId);
        updateViewSize(iconImageView);
    } else {
        if (mIconBitmap != null) {
            iconImageView.setImageBitmap(mIconBitmap);
            updateViewSize(iconImageView);
        } else {
            if (mIconUri != null) {
                iconImageView.setVisibility(View.INVISIBLE);

                DrawableDownloader bitmapDownloader = DrawableDownloader.getInstance(content.getContext());
                mBitmapCallBack = new BitmapCallback() {
                    @Override
                    public void onBitmapRetrieved(Drawable bitmap) {
                        if (bitmap != null) {
                            mIconBitmap = (bitmap instanceof BitmapDrawable)
                                    ? ((BitmapDrawable) bitmap).getBitmap()
                                    : null;
                            iconImageView.setVisibility(View.VISIBLE);
                            iconImageView.setImageDrawable(bitmap);
                            updateViewSize(iconImageView);
                        }
                    }
                };

                bitmapDownloader.getBitmap(new BitmapWorkerOptions.Builder(content.getContext())
                        .resource(mIconUri).width(iconImageView.getLayoutParams().width).build(),
                        mBitmapCallBack);
            } else {
                iconImageView.setVisibility(View.GONE);
            }
        }
    }

    content.setTag(R.id.title, titleView);
    content.setTag(R.id.breadcrumb, breadcrumbView);
    content.setTag(R.id.description, descriptionView);
    content.setTag(R.id.icon, iconImageView);
}

From source file:com.channelsoft.common.bitmapUtil.ImageWorker.java

/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView//from  w ww. j  a v  a2s .c om
 * @param bitmap
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap) {
    if ("0".equals(imageView.getTag())) {
        // ??
        bitmap = toGrayscale(bitmap);
    }
    if (mFadeInBitmap) {
        // Transition drawable with a transparent drwabale and the final bitmap
        final TransitionDrawable td = new TransitionDrawable(new Drawable[] {
                new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) });
        // Set background to loading bitmap
        //TODO: miaolikui delete 20121229
        //            imageView.setBackgroundDrawable(
        //                    new BitmapDrawable(mResources, mLoadingBitmap));

        Log.d(TAG, tagStr + ":imageView.setImageDrawable:" + System.currentTimeMillis());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        Log.d(TAG, tagStr + ":imageView.setImageBitmap:" + System.currentTimeMillis());
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.gsma.rcs.ri.messaging.adapter.TalkCursorAdapter.java

private void bindRcsFileTransferInView(View view, Cursor cursor) {
    final RcsFileTransferInViewHolder holder = (RcsFileTransferInViewHolder) view.getTag();
    holder.getTimestampText()/*from   w w  w. j  a va2  s .  c om*/
            .setText(DateUtils.getRelativeTimeSpanString(cursor.getLong(holder.getColumnTimestampIdx()),
                    System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));
    String mimeType = cursor.getString(holder.getColumnMimetypeIdx());
    StringBuilder sb = new StringBuilder(cursor.getString(holder.getColumnFilenameIdx()));
    long filesize = cursor.getLong(holder.getColumnFilesizeIdx());
    long transferred = cursor.getLong(holder.getColumnTransferredIdx());
    final ImageView imageView = holder.getFileImageView();
    imageView.setOnClickListener(null);
    imageView.setLayoutParams(mImageParamsDefault);
    imageView.setImageResource(R.drawable.ri_filetransfer_off);
    if (filesize != transferred) {
        holder.getProgressText()
                .setText(sb.append(" : ").append(Utils.getProgressLabel(transferred, filesize)).toString());
    } else {
        imageView.setImageResource(R.drawable.ri_filetransfer_on);
        final Uri file = Uri.parse(cursor.getString(holder.getColumnContentIdx()));
        final RcsService.ReadStatus readStatus = RcsService.ReadStatus
                .valueOf(cursor.getInt(holder.getColumnReadStatusIdx()));
        final String id = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID));
        if (Utils.isImageType(mimeType)) {
            final String filePath = FileUtils.getPath(mContext, file);
            if (filePath != null) {
                LruCache<String, BitmapCacheInfo> memoryCache = bitmapCache.getMemoryCache();
                BitmapCacheInfo bitmapCacheInfo = memoryCache.get(filePath);
                if (bitmapCacheInfo == null) {
                    ImageBitmapLoader loader = new ImageBitmapLoader(mContext, memoryCache, MAX_IMAGE_WIDTH,
                            MAX_IMAGE_HEIGHT, new BitmapLoader.SetViewCallback() {
                                @Override
                                public void loadView(BitmapCacheInfo cacheInfo) {
                                    imageView.setImageBitmap(cacheInfo.getBitmap());
                                    imageView.setLayoutParams(mImageParams);
                                }
                            });
                    loader.execute(filePath);
                } else {
                    Bitmap imageBitmap = bitmapCacheInfo.getBitmap();
                    imageView.setImageBitmap(imageBitmap);
                    imageView.setLayoutParams(mImageParams);
                }
                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Utils.showPicture(mActivity, file);
                        markFileTransferAsRead(id, readStatus);
                    }
                });
            }
        } else if (Utils.isAudioType(mimeType)) {
            imageView.setImageResource(R.drawable.headphone);
            imageView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Utils.playAudio(mActivity, file);
                    markFileTransferAsRead(id, readStatus);
                }
            });
        }
        holder.getProgressText().setText(sb.append(" (")
                .append(FileUtils.humanReadableByteCount(filesize, true)).append(")").toString());
    }
    holder.getStatusText().setText(getRcsFileTransferStatus(cursor, holder));
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Clear a view. Applies to ImageView, WebView, and TextView.
 * @return self/*from  ww w  .j a va 2  s .com*/
 */
public T clear() {
    if (view != null) {
        if (view instanceof ImageView) {
            ImageView iv = ((ImageView) view);
            iv.setImageBitmap(null);
            iv.setTag(Constants.TAG_URL, null);
        } else if (view instanceof WebView) {
            WebView wv = ((WebView) view);
            wv.stopLoading();
            wv.clearView();
            wv.setTag(Constants.TAG_URL, null);
        } else if (view instanceof TextView) {
            TextView tv = ((TextView) view);
            tv.setText("");
        }
    }
    return self();
}

From source file:biz.bokhorst.xprivacy.ActivityApp.java

@Override
protected void onResume() {
    super.onResume();

    // Update switch
    if (swEnabled != null)
        swEnabled.setChecked(/*from   w ww  .j  a va  2 s  . co m*/
                PrivacyManager.getSettingBool(mAppInfo.getUid(), PrivacyManager.cSettingRestricted, true));

    // Update on demand check box
    int userId = Util.getUserId(Process.myUid());
    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());
    }

    // Update list
    if (mPrivacyListAdapter != null)
        mPrivacyListAdapter.notifyDataSetChanged();
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Set the image of an ImageView.//from w  w w.  jav  a  2  s.  c  o  m
 * @param bm Bitmap
 * @return self
 * @see testImage3
 */
public T image(Bitmap bm) {
    if (view instanceof ImageView) {
        ImageView iv = (ImageView) view;
        iv.setTag(Constants.TAG_URL, null);
        iv.setImageBitmap(bm);
    }
    return self();
}

From source file:org.cryptsecure.Utility.java

/**
 * Update tile for OpenStreetMap.//from  ww w. ja  v a 2  s.  c o  m
 * 
 * @param context
 *            the context
 * @param image
 *            the image
 * @param zoom
 *            the zoom
 * @param latitude
 *            the latitude
 * @param longitude
 *            the longitude
 */
public static void updateTile(Context context, final ImageView image, int zoom, double latitude,
        double longitude) {
    final String url = "http://tile.openstreetmap.org/" + getTileNumber(latitude, longitude, zoom) + ".png";

    (new Thread() {
        public void run() {
            try {
                final InputStream is = (InputStream) new URL(url).getContent();
                final Bitmap bm = BitmapFactory.decodeStream(is);
                if (image != null) {
                    final Handler mUIHandler = new Handler(Looper.getMainLooper());
                    mUIHandler.post(new Thread() {
                        @Override
                        public void run() {
                            super.run();
                            image.setImageBitmap(bm);
                        }
                    });

                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }).start();
}