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.intel.xdk.base.Base.java

public void showSplashScreen() {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            //treat displays larger than 6" as tablets
            DisplayMetrics dm = new DisplayMetrics();
            cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
            double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
            double screenInches = Math.sqrt(x + y);
            if (screenInches > 6) {
                isTablet = true;/*from   w w w  .  ja va2s.  c om*/
            }

            //used for calculating status bar height
            int deviceWidth = dm.widthPixels;
            int deviceHeight = dm.heightPixels;
            if (deviceWidth > deviceHeight) {
                deviceWidth = dm.heightPixels;
                deviceHeight = dm.widthPixels;
            }

            //get the splash screen image from asssets
            Bitmap bm = null;
            try {
                if (isTablet) {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen_tablet.jpg");
                } else {
                    bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen.jpg");
                }
            } catch (IOException ioe) {
            }

            //if the splash screen assets are missing, don't try to show the splash screen
            if (bm == null) {
                return;
            }

            if (Debug.isDebuggerConnected())
                Log.i("[intel.xdk]", "splash");

            ActivityInfo ai = null;
            int splashViewId = 0;
            try {
                ai = cordova.getActivity().getPackageManager().getActivityInfo(
                        cordova.getActivity().getComponentName(),
                        PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA);

                if (isTablet) {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet_ls",
                                "layout", cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet",
                                "layout", cordova.getActivity().getPackageName());
                    }
                } else {
                    if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash_ls", "layout",
                                cordova.getActivity().getPackageName());
                    } else {
                        splashViewId = cordova.getActivity().getResources().getIdentifier("splash", "layout",
                                cordova.getActivity().getPackageName());
                    }
                }
                LayoutInflater inflater = LayoutInflater.from(cordova.getActivity());
                splashView = inflater.inflate(splashViewId, null);

                //set the splash screen image
                //http://stackoverflow.com/questions/7776445/in-android-can-i-use-image-from-assets-in-layout-xml
                ImageView backgroundImage = (ImageView) splashView
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                backgroundImage.setImageBitmap(bm);
                ((ViewGroup) root.getParent()).addView(splashView);
                splashView.bringToFront();

                //hack to fix splash screen size when it is smaller than screen            
                ImageView splashImage = (ImageView) cordova.getActivity()
                        .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id",
                                cordova.getActivity().getPackageName()));
                LayoutParams params = splashImage.getLayoutParams();
                Rect imgBounds = splashImage.getDrawable().getBounds();
                int splashHeight = params.height;
                int splashWidth = params.width;

                //make copies in case we have to switch for landscape - not sure if needed, this is a last minute hack
                int deviceWidthCopy, deviceHeightCopy;
                deviceWidthCopy = deviceWidth;
                deviceHeightCopy = deviceHeight;
                if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
                    int temp = deviceWidthCopy;
                    deviceWidthCopy = deviceHeightCopy;
                    deviceHeightCopy = temp;
                }
                if (splashHeight < deviceHeightCopy || splashWidth < deviceWidthCopy) {
                    float scaleH = (float) deviceHeightCopy / splashHeight;
                    float scaleW = (float) deviceWidthCopy / splashWidth;
                    float scale = Math.max(scaleH, scaleW);
                    params.height *= scale;
                    params.width *= scale;
                    splashImage.setLayoutParams(params);
                }

                cordova.getActivity().setProgressBarIndeterminateVisibility(true);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

}

From source file:com.android.nobadgift.DashboardActivity.java

private void displayConfirmationDialog() {
    try {/*  w w  w .j  av a 2  s  . c  o m*/
        Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.custom_dialog);
        dialog.setTitle("Successfully Scanned!");
        dialog.setCanceledOnTouchOutside(true);
        dialog.setCancelable(true);
        dialog.setOnDismissListener(new OnDismissListener() {
            public void onDismiss(DialogInterface dialog) {
                displayInfoDialog();
            }
        });
        TextView text = (TextView) dialog.findViewById(R.id.dialogText);
        text.setText("\"" + itemName + "\"");
        ImageView image = (ImageView) dialog.findViewById(R.id.dialogImage);
        image.setImageBitmap(retrievedImage);
        dialog.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:FacebookImageLoader.java

public void load(String filename, ImageView imageView) {
    Bitmap bitmap = getBitmapFromCache(filename);
    if (bitmap == null) {
        forceLoad(filename, imageView);/*from   ww w.  j av a2s.c  o m*/
    } else {
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.mobicage.rogerthat.FriendDetailOrInviteActivity.java

private void updateView() {
    final ImageView image = (ImageView) findViewById(R.id.friend_avatar);

    if (mFriend == null) {
        image.setVisibility(View.INVISIBLE);
        return;//  w  w  w .j  a  v a 2s.  com
    }
    image.setVisibility(View.VISIBLE);
    final TextView nameView = (TextView) findViewById(R.id.friend_name);

    if (mFriend.avatar == null) {
        image.setImageBitmap(mFriendsPlugin.getMissingFriendAvatarBitmap());
    } else {
        final Bitmap avatarBitmap = BitmapFactory.decodeByteArray(mFriend.avatar, 0, mFriend.avatar.length);
        image.setImageBitmap(ImageHelper.getRoundedCornerAvatar(avatarBitmap));
    }

    setTitle(mFriend.getDisplayName());
    nameView.setText(mFriend.getDisplayName());
    nameView.setTextColor(ContextCompat.getColor(this, android.R.color.primary_text_light));

    final LinearLayout profileDataContainer = (LinearLayout) findViewById(R.id.profile_data);
    if (AppConstants.PROFILE_DATA_FIELDS.length > 0) {
        profileDataContainer.removeAllViews();
        profileDataContainer.setVisibility(View.VISIBLE);
        Map<String, String> profileData = mFriend.getProfileDataDict();
        for (String k : AppConstants.PROFILE_DATA_FIELDS) {
            final LinearLayout ll = (LinearLayout) View.inflate(this, R.layout.profile_data_detail, null);
            final TextView tvKey = (TextView) ll.findViewById(R.id.profile_data_detail_key);
            final TextView tvVal = (TextView) ll.findViewById(R.id.profile_data_detail_value);

            String v = profileData == null ? null : profileData.get(k);
            if (v == null) {
                v = getString(R.string.unknown);
            }
            tvKey.setText(k);
            tvKey.setTextColor(LookAndFeelConstants.getPrimaryColor(this));
            tvVal.setText(v);

            profileDataContainer.addView(ll);
        }
    } else {
        profileDataContainer.setVisibility(View.GONE);
    }
}

From source file:com.mb.kids_mind.Adapter.SimilarListAdapter2.java

public void requestMyImage(final ImageView loading, final LinearLayout loadinglinear, ImageView image,
        String userImagePath) {//from   ww  w. jav a2 s. com
    AQuery aq = new AQuery(image);
    loading.setVisibility(View.VISIBLE);
    loadinglinear.setVisibility(View.VISIBLE);
    loadingViewAnim.start();
    if (userImagePath.equals("")) {
        // aq.id(R.id.my_image).image(R.drawable.photo1);  
    } else {
        String url = Const.IMAGE_LOAD_URL + "/" + userImagePath;
        url = url.trim();
        aq.image(url, false, false, 0, 0, new BitmapAjaxCallback() { // my_image <== ImageView
            @Override
            public void callback(String url, ImageView iv, Bitmap bm, AjaxStatus status) {

                if (bm != null) {
                    loading.setVisibility(View.GONE);
                    loadinglinear.setVisibility(View.GONE);
                    loadingViewAnim.stop();
                    iv.setImageBitmap(bm);
                }
            }
        });
    }
}

From source file:com.alex.view.loop.IndicatorView.java

/**
 * //  www . j a v  a2  s. c om
 *
 * @return
 */
private View makeIndicatorItem() {
    ImageView iv = new ImageView(getContext());
    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    lp.width = normalBp.getWidth();
    lp.height = normalBp.getHeight();
    lp.rightMargin = mInterval;
    iv.setImageBitmap(normalBp);
    iv.setLayoutParams(lp);
    return iv;
}

From source file:smartparking.smartparking.util.ImageDownloader.java

/**
 * Same as {@link #download(String, ImageView)}, with the possibility to provide an additional
 * cookie that will be used when the image will be retrieved.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 * @param cookie A cookie String that will be used by the http connection.
 *///from  w ww .  j a va2 s. co m
public void download(String url, ImageView imageView, String cookie) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);
    if (bitmap == null) {
        forceDownload(url, imageView, cookie);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:app.jorge.mobile.com.transportalert.ScrollingActivity.java

private void addCard(LinearLayout item, CardFactory.TUBE_LINE line) {

    CardTube card = CardFactory.getCard(line);
    View child = getLayoutInflater().inflate(R.layout.tube_line, null);

    ImageView imageView = (ImageView) child.findViewById(R.id.iconTube);
    //imageView.setImageResource(card.getIcon());
    imageView.setImageBitmap(decodeSampledBitmapFromResource(getResources(), card.getIcon(), 100, 100));

    TextView lineName = (TextView) child.findViewById(R.id.tubeName);
    lineName.setText(card.getName());// w  w  w. java 2  s .  com
    lineName.setTextColor(Color.parseColor(card.getColour()));

    TextView text = (TextView) child.findViewById(R.id.tubeStatus);
    text.setText(card.getStatus());

    item.addView(child);

    child.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            View imageView = v.findViewById(R.id.iconTube);
            imageView.setTransitionName(getString(R.string.activity_image_trans));

            View textTubeNameView = v.findViewById(R.id.tubeName);
            textTubeNameView.setTransitionName(getString(R.string.activity_text_tube_name));

            View textStatusView = v.findViewById(R.id.tubeStatus);
            textStatusView.setTransitionName(getString(R.string.activity_text_tube_status));

            Intent intent = new Intent(ScrollingActivity.this, DetailActivity.class);
            Pair<View, String> pair1 = Pair.create(imageView, imageView.getTransitionName());
            Pair<View, String> pair2 = Pair.create(textTubeNameView, textTubeNameView.getTransitionName());
            Pair<View, String> pair3 = Pair.create(textStatusView, textStatusView.getTransitionName());

            ActivityOptionsCompat options = ActivityOptionsCompat
                    .makeSceneTransitionAnimation(ScrollingActivity.this, pair1, pair2, pair3);

            String line = ((TextView) textTubeNameView).getText().toString();
            String status = ((TextView) textStatusView).getText().toString();

            LineStatuses ls = tubeStatus.get(line);
            if ((ls != null) && (ls.getDisruption() != null)) {
                intent.putExtra(getString(R.string.activity_info_category), ls.getDisruption().getCategory());
                intent.putExtra(getString(R.string.activity_info_description),
                        ls.getDisruption().getDescription());
                intent.putExtra(getString(R.string.activity_info_additional),
                        ls.getDisruption().getAdditionalInfo());
                intent.putExtra(getString(R.string.activity_info_icon), line);
                intent.putExtra(getString(R.string.activity_info_status), status);

                startActivity(intent, options.toBundle());
            }

        }
    });

}

From source file:de.geeksfactory.opacclient.frontend.ResultsAdapter.java

@Override
public View getView(int position, View contentView, ViewGroup viewGroup) {
    View view;/* ww w.j ava 2s.c o m*/

    // position always 0-7
    if (objects.get(position) == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_searchresult, viewGroup, false);
        return view;
    }

    SearchResult item = objects.get(position);

    if (contentView == null) {
        LayoutInflater layoutInflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.listitem_searchresult, viewGroup, false);
    } else {
        view = contentView;
    }

    TextView tv = (TextView) view.findViewById(R.id.tvResult);
    tv.setText(Html.fromHtml(item.getInnerhtml()));

    ImageView ivType = (ImageView) view.findViewById(R.id.ivType);

    PreferenceDataSource pds = new PreferenceDataSource(getContext());
    ConnectivityManager connMgr = (ConnectivityManager) getContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (item.getCoverBitmap() != null) {
        ivType.setImageBitmap(BitmapUtils.bitmapFromBytes(item.getCoverBitmap()));
        ivType.setVisibility(View.VISIBLE);
        ivType.setPadding(0, 0, 0, 0);
    } else if ((pds.isLoadCoversOnDataPreferenceSet()
            || !ConnectivityManagerCompat.isActiveNetworkMetered(connMgr)) && item.getCover() != null) {
        LoadCoverTask lct = new LoadCoverTask(ivType, item);
        lct.execute();
        ivType.setImageResource(R.drawable.ic_loading);
        ivType.setVisibility(View.VISIBLE);
        ivType.setPadding(0, 0, 0, 0);
    } else if (item.getType() != null && item.getType() != MediaType.NONE) {
        ivType.setImageResource(getResourceByMediaType(item.getType()));
        ivType.setVisibility(View.VISIBLE);
        ivType.setPadding(padding8dp, padding8dp, padding8dp, padding8dp);
    } else {
        ivType.setVisibility(View.INVISIBLE);
    }
    ImageView ivStatus = (ImageView) view.findViewById(R.id.ivStatus);

    if (item.getStatus() != null) {
        ivStatus.setVisibility(View.VISIBLE);
        switch (item.getStatus()) {
        case GREEN:
            ivStatus.setImageResource(R.drawable.status_light_green_check);
            break;
        case RED:
            ivStatus.setImageResource(R.drawable.status_light_red_cross);
            break;
        case YELLOW:
            ivStatus.setImageResource(R.drawable.status_light_yellow_alert);
            break;
        case UNKNOWN:
            ivStatus.setVisibility(View.INVISIBLE);
            break;
        }
    } else {
        ivStatus.setVisibility(View.GONE);
    }

    return view;
}

From source file:com.example.foodstagram.FacebookImageLoader.java

public void load(String filename, ImageView imageView) {
    Bitmap bitmap = getBitmapFromCache(filename);
    if (bitmap == null) {
        forceLoad(filename, imageView);//from  ww w . ja  v  a 2s  .  c o m
    } else {
        imageView.setImageBitmap(bitmap);
    }

    // custom added code
    //listItem.notifyDataChanged();
}