Example usage for android.widget ImageView setScaleType

List of usage examples for android.widget ImageView setScaleType

Introduction

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

Prototype

public void setScaleType(ScaleType scaleType) 

Source Link

Document

Controls how the image should be resized or moved to match the size of this ImageView.

Usage

From source file:net.evecom.androidecssp.activity.pub.EmergencyNotification.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.emergency_info_activity);

    // 1//from w w w . ja va 2s  . c  o  m
    viewpager = (ViewPager) findViewById(R.id.my_viewpager_id);
    // 4DepthPageTransformer
    // viewpager.setPageTransformer(true, new DepthPageTransformer());
    viewpager.setPageTransformer(true, new RotateDownTransformer());
    // 2
    viewpager.setAdapter(new PagerAdapter() {
        @Override
        // item page
        public Object instantiateItem(ViewGroup container, int position) {
            //  switchpage
            ImageView imageView = new ImageView(EmergencyNotification.this);
            imageView.setImageResource(imagesId[position]);
            // 
            imageView.setScaleType(ScaleType.CENTER_CROP);

            // imageViewcontainer page
            container.addView(imageView);
            // imageViewlist
            imageViews.add(imageView);
            // imageView
            return imageView;
        }

        @Override
        // destroyItem
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(imageViews.get(position));
        }

        @Override
        //  adapter
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        // 
        public int getCount() {
            return imagesId.length;
        }
    });

}

From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java

private void restoreImageViewScale() {
    if (mSavedScaleType != null) {
        if (DEBUG) {
            Log.d(TAG, "restoreImageViewScale to " + mSavedScaleType);
        }/*from  w  w w .ja v a2  s  . c  om*/
        ImageView imageView = mViewHolder.mImageView;
        imageView.setScaleType(mSavedScaleType);
        if (mSavedScaleType == ScaleType.MATRIX) {
            imageView.setImageMatrix(mSavedMatrix);
        }
        // only restore once unless another save happens
        mSavedScaleType = null;
        updateImageViewAfterScaleTypeChange(imageView);
    }
}

From source file:com.pixate.freestyle.fragment.GridViewFragment.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    /** ImageView for each grid view item */
    ImageView imageView;
    if (convertView == null) {
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(mWidth, mHeight));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    } else {//from   www. ja  va 2  s.  co m
        imageView = (ImageView) convertView;
    }

    imageView.setBackgroundResource(R.drawable.grid_item_background);

    return imageView;
}

From source file:com.tundem.alternativefindr.ApplicationActivity.java

public void init_application(View v) {
    WebImageView alternative_icon = ((WebImageView) v.findViewById(R.id.alternative_icon));
    TextView alternative_votes = ((TextView) v.findViewById(R.id.alternative_votes));
    TextView alternative_name = ((TextView) v.findViewById(R.id.alternative_name));
    TextView alternative_license = ((TextView) v.findViewById(R.id.alternative_license));
    LinearLayout alternative_platforms = ((LinearLayout) v.findViewById(R.id.alternative_platforms_container));
    //TextView alternative_description = ((TextView) v.findViewById(R.id.alternative_description));

    /* Set ImageView */
    alternative_icon.setImageUrl(mApplication.getIconUrl());

    /* Set Texts */
    alternative_votes.setText(String.valueOf(mApplication.getVotes()) + "\nVotes");
    alternative_name.setText(mApplication.getName());
    alternative_license.setText(mApplication.getLicense());
    //alternative_description.setText(application.getShortDescription());

    if (mApplication.getPlatforms() != null) {
        List<Integer> resIds = new LinkedList<Integer>();
        for (String s : mApplication.getPlatforms()) {
            if (!TextUtils.isEmpty(s)) {
                int resId = getResId(s.toLowerCase());
                if (!resIds.contains(resId) && resId != -1)
                    resIds.add(resId);//from   ww w.java  2 s.com
            }
        }
        for (Integer resId : resIds) {
            ImageView iv = new ImageView(this);

            iv.setScaleType(ScaleType.FIT_CENTER);

            float sizeInDip = 18f;
            int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInDip,
                    this.getResources().getDisplayMetrics());
            LayoutParams lp = new LayoutParams(padding, padding);
            iv.setLayoutParams(lp);
            iv.setImageResource(resId);

            alternative_platforms.addView(iv);
        }

    }
}

From source file:edu.ucsb.cs.cs185.inspirante.share.ShareActivity.java

protected void startDetailDialog(int position) {

    Bundle arguments = new Bundle();
    arguments.putString("FROM", "SINGLE_IMAGE");
    arguments.putString("URL", mCardImages.get(position).mUrl);
    arguments.putInt("TYPE", mCardImages.get(position).mType);
    DetailBlurDialog fragment = new DetailBlurDialog();

    fragment.setArguments(arguments);/*from  ww w . j  a va  2  s . c o m*/
    FragmentManager ft = getSupportFragmentManager();

    fragment.show(ft, "dialog");
    //TODO: move takeScreenShot method to somewhere else from CardsFragment

    Bitmap map = CardsFragment.takeScreenShot(this);
    Bitmap fast = CardsFragment.BlurBuilder.blur(getApplicationContext(), map);
    final Drawable draw = new BitmapDrawable(getResources(), fast);

    ImageView background = (ImageView) findViewById(R.id.activity_background);
    background.bringToFront();
    background.setScaleType(ImageView.ScaleType.FIT_XY);
    background.setImageDrawable(draw);

}

From source file:org.telegram.ui.IdenticonActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from w w w . j  a  v  a 2  s .  c  o  m*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new LinearLayout(context);
    LinearLayout linearLayout = (LinearLayout) fragmentView;
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setWeightSum(100);
    linearLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20),
            AndroidUtilities.dp(20));
    linearLayout.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));

    ImageView identiconView = new ImageView(context);
    identiconView.setScaleType(ImageView.ScaleType.FIT_XY);
    frameLayout.addView(identiconView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    frameLayout.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), AndroidUtilities.dp(10));
    linearLayout.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));

    TextView textView = new TextView(context);
    textView.setTextColor(ContextCompat.getColor(context, R.color.secondary_text));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLinksClickable(true);
    textView.setClickable(true);
    textView.setMovementMethod(new LinkMovementMethodMy());
    //textView.setAutoLinkMask(Linkify.WEB_URLS);
    textView.setLinkTextColor(Theme.MSG_LINK_TEXT_COLOR);
    textView.setGravity(Gravity.CENTER);
    frameLayout.addView(textView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id);
    if (encryptedChat != null) {
        IdenticonDrawable drawable = new IdenticonDrawable();
        identiconView.setImageDrawable(drawable);
        drawable.setEncryptedChat(encryptedChat);
        TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id);
        SpannableStringBuilder hash = new SpannableStringBuilder();
        if (encryptedChat.key_hash.length > 16) {
            String hex = Utilities.bytesToHex(encryptedChat.key_hash);
            for (int a = 0; a < 32; a++) {
                if (a != 0) {
                    if (a % 8 == 0) {
                        hash.append('\n');
                    } else if (a % 4 == 0) {
                        hash.append(' ');
                    }
                }
                hash.append(hex.substring(a * 2, a * 2 + 2));
                hash.append(' ');
            }
            hash.append("\n\n");
        }
        hash.append(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription",
                R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
        final String url = "telegram.org";
        int index = hash.toString().indexOf(url);
        if (index != -1) {
            hash.setSpan(
                    new URLSpanReplacement(
                            LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)),
                    index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.setText(hash);
    }

    return fragmentView;
}

From source file:com.miz.mizuu.fragments.ActorPhotoFragment.java

public void onViewCreated(View v, Bundle savedInstanceState) {
    super.onViewCreated(v, savedInstanceState);

    final ProgressBar pbar = (ProgressBar) v.findViewById(R.id.progressBar1);
    ImageView img = (ImageView) v.findViewById(R.id.imageView1);

    if (MizLib.isPortrait(getActivity()) && mPortraitPhotos
            || !MizLib.isPortrait(getActivity()) && !mPortraitPhotos)
        img.setScaleType(ScaleType.CENTER_CROP);

    mPicasso.load(mPhotoUrl).error(R.drawable.noactor).into(img, new Callback() {

        @Override//  ww  w  .  j a v  a  2s  .c om
        public void onError() {
            pbar.setVisibility(View.GONE);
        }

        @Override
        public void onSuccess() {
            pbar.setVisibility(View.GONE);
        }

    });
    img.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isAdded()) {
                mBus.post(new Object());
            }
        }
    });
}

From source file:edu.ucsb.cs.cs185.inspirante.searchbyranking.SearchByRankingFragment.java

protected void startDetailDialog(Cards.CardImage cardImage) {

    Bundle arguments = new Bundle();
    arguments.putString("FROM", "SINGLE_IMAGE");
    arguments.putString("URL", cardImage.mUrl);
    arguments.putInt("TYPE", cardImage.mType);
    DetailBlurDialog fragment = new DetailBlurDialog();

    fragment.setArguments(arguments);/* w w w . jav  a 2s  .c  o  m*/
    FragmentManager ft = getActivity().getSupportFragmentManager();

    fragment.show(ft, "dialog");
    //TODO: move takeScreenShot method to somewhere else from CardsFragment

    Bitmap map = CardsFragment.takeScreenShot(getActivity());
    Bitmap fast = CardsFragment.BlurBuilder.blur(getContext(), map);
    final Drawable draw = new BitmapDrawable(getResources(), fast);

    ImageView background = (ImageView) getActivity().findViewById(R.id.activity_background);
    background.bringToFront();
    background.setScaleType(ImageView.ScaleType.FIT_XY);
    background.setImageDrawable(draw);
}

From source file:cn.qbcbyb.library.view.PagerTabStrip.java

private void addIconTab(final int position) {

    ImageView tab = new ImageView(getContext());
    tab.setImageResource(indicatorDrawable);
    tab.setScaleType(ImageView.ScaleType.CENTER);

    addTab(position, tab);/*from  www.j  av  a  2 s .  com*/

}

From source file:com.rightscale.app.dashboard.ShowServerMonitoring.java

public void consumeImage(Bitmap bitmap, String tag) {
    ImageView view = (ImageView) findViewById(R.id.show_server_monitoring_graph);

    if (bitmap != null) {
        view.setScaleType(ImageView.ScaleType.FIT_CENTER);
        view.setImageBitmap(bitmap);//from   w w w  .  j  av  a 2 s. c  om
    } else {
        view.setScaleType(ImageView.ScaleType.CENTER);
        view.setImageDrawable(
                getBaseContext().getResources().getDrawable(android.R.drawable.ic_menu_close_clear_cancel));
    }
}