Example usage for android.widget ImageView setAdjustViewBounds

List of usage examples for android.widget ImageView setAdjustViewBounds

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setAdjustViewBounds(boolean adjustViewBounds) 

Source Link

Document

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

Usage

From source file:galilei.kelimekavanozu.view.ImageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    if (context.get() != null) {
        final int drawableId = theme.getImageList().get(position + 1);
        final ImageView view = new ImageView(context.get());
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setContentDescription(context.get().getResources().getString(R.string.content_desc_poempic));
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setAdjustViewBounds(true);
        view.setTag(drawableId);/* w w  w.  j  a  va2 s . c  om*/
        container.addView(view, 0);
        view.post(new Runnable() {
            @Override
            public void run() {
                ImageLoader.getImageLoader().load(drawableId, view);
            }
        });
        return view;
    }
    return null;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

@Override
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    PackageManager pm = context.getPackageManager();
    Drawable icon = null;/*  www .j  a  v  a2s.com*/
    String appName;
    if (obj.getJson() != null && obj.getJson().has(ANDROID_PACKAGE_NAME)) {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
    } else {
        appName = "Unknown";
    }
    if (!(obj instanceof DbObj)) {
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Preparing application " + appName + "...";
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
        return;
    }

    DbObj dbParentObj = (DbObj) obj;
    boolean rendered = false;

    Intent launch = getLaunchIntent(context, dbParentObj);
    List<ResolveInfo> infos = pm.queryIntentActivities(launch, 0);
    if (infos.size() > 0) {
        ResolveInfo info = infos.get(0);
        if (info.activityInfo.labelRes != 0) {
            appName = info.activityInfo.loadLabel(pm).toString();
            icon = info.loadIcon(pm);
        } else {
            appName = info.activityInfo.name;
        }
    } else {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
    }
    // TODO: Safer reference to containing view
    if (icon != null) {
        View parentView = (View) frame.getParent().getParent();
        ImageView avatar = (ImageView) parentView.findViewById(R.id.icon);
        avatar.setImageDrawable(icon);

        TextView label = (TextView) parentView.findViewById(R.id.name_text);
        label.setText(appName);
    }

    // TODO: obj.getLatestChild().render();
    String selection = getRenderableClause();
    String[] selectionArgs = null;
    Cursor cursor = dbParentObj.getSubfeed().query(selection, selectionArgs);
    if (cursor.moveToFirst()) {
        DbObj dbObj = App.instance().getMusubi().objForCursor(cursor);
        DbObjects.getFeedRenderer(dbObj.getType()).render(context, frame, dbObj, allowInteractions);
        rendered = true;
    }

    if (!rendered) {
        String text;
        if (icon != null) {
            ImageView iv = new ImageView(context);
            iv.setImageDrawable(icon);
            iv.setAdjustViewBounds(true);
            iv.setMaxWidth(60);
            iv.setMaxHeight(60);
            iv.setLayoutParams(CommonLayouts.WRAPPED);
            frame.addView(iv);
            text = appName;
        } else {
            text = "New application: " + appName + ".";
        }
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}

From source file:de.uulm.graphicalpasswords.openuyi.UYICreatePasswordActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uyi_create_password);
    // Show the Up button in the action bar.
    setupActionBar();/*from w w  w .j av  a  2  s . co  m*/

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    length = Integer.parseInt(sharedPref.getString("uyi_length", "10"));

    originalViews = new ImageView[length];
    distortedViews = new ImageView[length];
    selectedPictures = new Picture[length];

    Bundle bundle = new Bundle();
    bundle.putInt("length", length);
    DialogFragment intro = new IntroDialogFragment();
    intro.setArguments(bundle);
    intro.show(getFragmentManager(), "intro");

    vibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);

    Arrays.fill(selectedPictures, null);

    gallery = (Gallery) findViewById(R.id.uyi_gallery_originals);
    gallery.setAdapter(new UYIImageAdapter(this));

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageView viewOriginal = new ImageView(UYICreatePasswordActivity.this);
            ImageView viewDistorted = new ImageView(UYICreatePasswordActivity.this);

            int i = 0;
            for (; i < selectedPictures.length; i++) {
                if (i == selectedPictures.length - 1 && selectedPictures[i] != null) {
                    removePicture(i);
                }
                if (selectedPictures[i] == null || i == selectedPictures.length - 1) {
                    viewOriginal = originalViews[i];
                    viewDistorted = distortedViews[i];
                    selectedPictures[i] = ((UYIImageAdapter) parent.getAdapter()).getPicture(position);
                    vibrator.vibrate(100);

                    ScrollView sv = (ScrollView) findViewById(R.id.uyi_choosepi_scrollview);
                    int height = originalViews[0].getMeasuredHeight();
                    sv.scrollTo(0, (i * height) - 200);

                    break;
                }
            }

            int originalImageResource = ((UYIImageAdapter) parent.getAdapter()).getImageResource(position);
            viewOriginal.setImageResource(originalImageResource);
            viewDistorted.setImageResource(
                    ((UYIImageAdapter) parent.getAdapter()).getDistortedImageResource(position));
            ((UYIImageAdapter) parent.getAdapter()).removePicture(position);

            OnLongClickListener listener = new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    vibrator.vibrate(200);
                    int viewid = v.getId();
                    int index = -1;

                    for (int i = 0; i < originalViews.length; i++) {
                        if (originalViews[i].getId() == viewid) {
                            index = i;
                            break;
                        } else if (distortedViews[i].getId() == viewid) {
                            index = i;
                            break;
                        }
                    }
                    Bundle bundle = new Bundle();
                    bundle.putInt("index", index);
                    DialogFragment dialog = new DeleteImageDialogFragment();
                    dialog.setArguments(bundle);
                    dialog.show(getFragmentManager(), "delete");
                    return false;
                }
            };

            viewOriginal.setOnLongClickListener(listener);
            viewDistorted.setOnLongClickListener(listener);

            // Check
            int count = 0;
            for (int j = 0; j < selectedPictures.length; j++) {
                if (selectedPictures[j] != null) {
                    count++;
                }
            }
            if (count == selectedPictures.length) {
                findViewById(R.id.uyi_save).setClickable(true);
                findViewById(R.id.uyi_save).setEnabled(true);
            }
        }
    });

    table = (TableLayout) findViewById(R.id.uyi_choosepi_tablelayout);
    LayoutParams params = new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT,
            android.widget.TableRow.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    for (int i = 0; i < length; i++) {
        TableRow row = new TableRow(table.getContext());

        originalViews[i] = new ImageView(row.getContext());
        originalViews[i].setAdjustViewBounds(true);
        originalViews[i].setScaleType(ScaleType.FIT_XY);
        originalViews[i].setPadding(3, 3, 3, 3);
        originalViews[i].setImageResource(R.drawable.oempty);
        originalViews[i].setId(100 + i);

        distortedViews[i] = new ImageView(row.getContext());
        distortedViews[i].setAdjustViewBounds(true);
        distortedViews[i].setScaleType(ScaleType.FIT_XY);
        distortedViews[i].setPadding(3, 3, 3, 3);
        distortedViews[i].setImageResource(R.drawable.wempty);
        distortedViews[i].setId(1000 + i);

        ImageView arrow = new ImageView(row.getContext());
        arrow.setAdjustViewBounds(true);
        arrow.setScaleType(ScaleType.FIT_XY);
        arrow.setMaxWidth(80);
        arrow.setPadding(3, 3, 3, 3);
        arrow.setImageResource(R.drawable.arrow_active);
        arrow.setLayoutParams(params);

        row.addView(originalViews[i]);
        row.addView(arrow);
        row.addView(distortedViews[i]);
        table.addView(row);
    }
}

From source file:com.vk.sdk.dialogs.VKShareDialog.java

private void addBitmapToPreview(Bitmap sourceBitmap) {
    if (getActivity() == null)
        return;//w ww . j  av  a 2 s . co m
    Bitmap b = VKUIHelper.getRoundedCornerBitmap(sourceBitmap, SHARE_PHOTO_HEIGHT, SHARE_PHOTO_CORNER_RADIUS);
    if (b == null)
        return;
    ImageView iv = new ImageView(getActivity());
    iv.setImageBitmap(b);
    iv.setAdjustViewBounds(true);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    params.setMargins(mPhotoLayout.getChildCount() > 0 ? SHARE_PHOTO_MARGIN_LEFT : 0, 0, 0, 0);

    mPhotoLayout.addView(iv, params);
    mPhotoLayout.invalidate();
    mPhotoScroll.invalidate();
}

From source file:org.addhen.smssync.presentation.view.ui.activity.GettingStartedActivity.java

private void renderViewPageIndicators() {
    float scale = getResources().getDisplayMetrics().density;
    int padding = (int) (5 * scale + 0.5f);

    for (int i = 0; i < mNumOfPages - 1; i++) {
        ImageView circle = new ImageView(this);
        circle.setImageResource(R.drawable.ic_swipe_indicator_white_18dp);
        circle.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        circle.setAdjustViewBounds(true);
        circle.setPadding(padding, 0, padding, 0);
        mCircles.addView(circle);/*from www  .  j  av  a 2  s  .c o m*/
    }

    setIndicator(0);
}

From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestSection.java

private static ImageView createAndAddLogoView(ViewGroup parent, int startMargin) {
    ImageView view = new ImageView(parent.getContext());
    view.setMaxWidth(//from w ww. jav  a2s.c o  m
            parent.getContext().getResources().getDimensionPixelSize(R.dimen.payments_section_logo_width));
    view.setAdjustViewBounds(true);

    // The logo has a pre-defined height and width.
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, startMargin);
    parent.addView(view, params);
    return view;
}

From source file:com.ushahidi.android.app.ui.phone.AddCheckinActivity.java

@Override
public View makeView() {

    ImageView i = new ImageView(this);
    i.setAdjustViewBounds(true);
    i.setScaleType(ImageView.ScaleType.FIT_XY);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

    return i;// w  w w  .j  a v  a2s.  c  o m
}

From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java

/**
 * After returning from the camera activity, get the photo information
 * and send it into the structure to get it ready.
 *///w w w. ja  v  a2s. co  m

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        Photo photo = new Photo(imageBitmap);
        ImageView newImage = new ImageView(getApplicationContext());
        newImage.setImageBitmap(photo.getImage());
        newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        newImage.setAdjustViewBounds(true);
        //gallery.removeAllViews();
        gallery.addView(newImage);
        photos.add(photo);
    }

}

From source file:org.catnut.plugin.zhihu.ZhihuItemFragment.java

private ImageView getImageView() {
    ImageView image = new ImageView(getActivity());
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, 10, 0, 10);/*from w w  w  .j  a v a 2s . c o m*/
    image.setLayoutParams(lp);
    image.setAdjustViewBounds(true);
    image.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return CatnutUtils.imageOverlay(v, event);
        }
    });
    image.setOnClickListener(this);
    return image;
}

From source file:paulscode.android.mupen64plusae.SplashActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get app data and user preferences
    mAppData = new AppData(this);
    mGlobalPrefs = new GlobalPrefs(this, mAppData);
    mGlobalPrefs.enforceLocale(this);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Ensure that any missing preferences are populated with defaults (e.g. preference added to
    // new release)
    PreferenceManager.setDefaultValues(this, R.xml.preferences_audio, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_data, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_display, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_input, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_library, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_touchscreen, false);

    // Ensure that selected plugin names and other list preferences are valid
    // @formatter:off
    final Resources res = getResources();
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_ORIENTATION, R.string.displayOrientation_default,
            R.array.displayOrientation_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_POSITION, R.string.displayPosition_default,
            R.array.displayPosition_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_SCALING, R.string.displayScaling_default,
            R.array.displayScaling_values);
    PrefUtil.validateListPreference(res, mPrefs, VIDEO_HARDWARE_TYPE, R.string.videoHardwareType_default,
            R.array.videoHardwareType_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_PLUGIN, R.string.audioPlugin_default,
            R.array.audioPlugin_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SDL_BUFFER_SIZE, R.string.audioSDLBufferSize_default,
            R.array.audioSDLBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SLES_BUFFER_SIZE, R.string.audioSLESBufferSize_default,
            R.array.audioSLESBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, TOUCHSCREEN_AUTO_HOLD, R.string.touchscreenAutoHold_default,
            R.array.touchscreenAutoHold_values);
    PrefUtil.validateListPreference(res, mPrefs, NAVIGATION_MODE, R.string.navigationMode_default,
            R.array.navigationMode_values);

    if (!mPrefs.getBoolean("seen_survey", false)) {
        LinearLayout dialogLayout = new LinearLayout(this);
        dialogLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        dialogLayout.setOrientation(LinearLayout.VERTICAL);
        TextView message = new TextView(this);
        message.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        message.setText("We have recently changed our icon and we want your feedback!\n\n"
                + "Please take a few moments to fill out this feedback form so we can make improvements. "
                + "You will need a Google account to fill out this form. This is so we don't have duplicates.");
        message.setPadding(16, 16, 16, 16);
        dialogLayout.addView(message);/*  w ww  .  java 2  s. c  o m*/
        ImageView icon = new ImageView(this);
        icon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        icon.setAdjustViewBounds(true);
        icon.setPadding(16, 16, 16, 16);
        icon.setImageResource(R.drawable.ic_playstore_ouya);
        dialogLayout.addView(icon);
        AlertDialog dialog = new AlertDialog.Builder().setTitle("We want your feedback!").setView(iconLayout)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "https://docs.google.com/forms/d/1F2stkHvb0Rx5vfmaz50OtTfT73XjHK2GEXZj9a_x-yw/viewform"));
                        SplashActivity.this.startActivity(i);
                    }
                }).setNegativeButton(getString(android.R.string.cancel), null).create();
        mPrefs.edit().putBoolean("seen_survey", true).apply();
        dialog.show();
    }
    //Check for invalid data path
    String dataPathString = mPrefs.getString(DATA_PATH, null);

    if (dataPathString == null || dataPathString.isEmpty()
            || dataPathString.contains(res.getString(R.string.pathGameSaves_default))) {
        String defValue = res.getString(R.string.pathGameSaves_default);
        String newDefValue = PathPreference.validate(defValue);

        mPrefs.edit().putString(DATA_PATH, newDefValue).commit();
    }

    // @formatter:on

    // Refresh the preference data wrapper
    mGlobalPrefs = new GlobalPrefs(this, mAppData);

    // Make sure custom skin directory exist
    new File(mGlobalPrefs.touchscreenCustomSkinsDir).mkdirs();

    // Initialize the OUYA interface if running on OUYA
    if (AppData.IS_OUYA_HARDWARE)
        OuyaFacade.getInstance().init(this, DEVELOPER_ID);

    // Initialize the toast/status bar notifier
    Notifier.initialize(this);

    // Don't let the activity sleep in the middle of extraction
    getWindow().setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Lay out the content
    setContentView(R.layout.splash_activity);
    mTextView = (TextView) findViewById(R.id.mainText);

    if (mGlobalPrefs.isBigScreenMode) {
        final ImageView splash = (ImageView) findViewById(R.id.mainImage);
        splash.setImageResource(R.drawable.publisherlogo_ouya);
    }

    requestPermissions();

    // Popup a warning if the installation appears to be corrupt
    if (!mAppData.isValidInstallation()) {
        Popups.showInvalidInstall(this);
    }
}