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:Main.java

public static void setSize(View view, int w, int h) {
    view.setMinimumWidth(w);//from w w  w. j  av a 2s  .  c  om
    view.setMinimumHeight(h);
    if (view instanceof ImageView) {
        ImageView iv = (ImageView) view;
        iv.setAdjustViewBounds(true);
        iv.setMaxWidth(w);
        iv.setMaxHeight(h);
    }
}

From source file:Main.java

public static View getView(int width, Context mContext) {
    // Make an ImageView to show a photo
    ImageView i = new ImageView(mContext);
    i.setAdjustViewBounds(true);
    i.setLayoutParams(new AbsListView.LayoutParams(width, AbsListView.LayoutParams.WRAP_CONTENT));
    // Give it a nice background
    //i.setBackgroundResource(R.drawable.picture_frame);
    return i;//from   w  ww  .j a  v a 2 s  .  c o  m
}

From source file:Main.java

/**
 * Sets the image for an ImageView.//from   ww w . j  a  v  a  2 s . c o m
 */
public static void setImage(ImageView view, Drawable drawable) {
    view.setImageDrawable(drawable);
    if (drawable != null) {
        view.setAdjustViewBounds(true);
    }
    view.requestLayout();
}

From source file:com.dm.material.dashboard.candybar.helpers.ViewHelper.java

public static void removeSearchViewSearchIcon(@Nullable View view) {
    if (view != null) {
        ImageView searchIcon = (ImageView) view;
        ViewGroup linearLayoutSearchView = (ViewGroup) view.getParent();
        if (linearLayoutSearchView != null) {
            linearLayoutSearchView.removeView(searchIcon);
            linearLayoutSearchView.addView(searchIcon);

            searchIcon.setAdjustViewBounds(true);
            searchIcon.setMaxWidth(0);//from  w  w w  . j  ava2 s  .  com
            searchIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            searchIcon.setImageDrawable(null);
        }
    }
}

From source file:com.connectsdk.smarthomesampler.dialog.HueFragmentDialog.java

@NonNull
@Override/*from  w w  w  .  j  a va  2s . c  o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context context = getActivity();
    final ImageView image = new ImageView(getActivity());
    image.setAdjustViewBounds(true);
    image.setImageResource(R.drawable.press_smartbridge);

    return new AlertDialog.Builder(context).setTitle(R.string.press_hue_button).setView(image)
            .setCancelable(true).create();
}

From source file:com.facebook.notifications.internal.asset.handlers.BitmapAssetHandler.java

@NonNull
@Override//w w  w.  j a v  a2 s  .  c o  m
public View createView(@NonNull BitmapAsset asset, @NonNull Context context) {
    ImageView imageView = new ImageView(context);
    imageView.setImageBitmap(asset.getBitmap());
    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    imageView.setAdjustViewBounds(true);

    return imageView;
}

From source file:com.snypir.callback.view.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//from  www . j a va  2s.c o  m
 */
protected ImageView createDefaultTabView(Context context) {
    ImageView imageView = new ImageView(context);
    imageView.setAdjustViewBounds(true);

    int padding = (int) (TAB_VIEW_PADDING_VERTICAL_DIPS * getResources().getDisplayMetrics().density);
    imageView.setPadding(padding, padding, padding, padding);

    return imageView;
}

From source file:gov.nasa.arc.geocam.geocam.CameraPreviewActivity.java

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

    // Window and view properties
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.camera_preview);

    // Load bitmap from intent data and display in imageview
    mImageUri = getIntent().getData();/*from   w  w w  .  ja v a  2s  .  co  m*/
    try {
        mImageData = new JSONObject(getIntent().getExtras().getString("data"));
    } catch (JSONException e1) {
        Log.d(GeoCamMobile.DEBUG_ID, "Error unserializing JSON data from intent");
        mImageData = new JSONObject();
    }

    try {
        final BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = 4;
        InputStream in = getContentResolver().openInputStream(mImageUri);
        Bitmap bitmap = BitmapFactory.decodeStream(in, null, opts);

        //Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mImageUri);
        ImageView imageView = (ImageView) findViewById(R.id.camera_preview_imageview);
        imageView.setAdjustViewBounds(true);
        imageView.setScaleType(ScaleType.CENTER_INSIDE);
        imageView.setImageBitmap(bitmap);
    } catch (FileNotFoundException e) {
        Log.d(GeoCamMobile.DEBUG_ID, "Error loading bitmap in CameraPreviewActivity");
    }

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String defaultNotes = settings.getString(GeoCamMobile.SETTINGS_DEFAULT_NOTES_KEY, "");

    // Set default notes
    EditText notesText = (EditText) findViewById(R.id.camera_preview_edittext);
    notesText.setText(defaultNotes + " ");

    // Buttons
    mFireButton = (ImageButton) findViewById(R.id.camera_preview_fire_button);
    mFireButton.setImageDrawable(getResources().getDrawable(R.drawable.fire_icon_default));
    mFireButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_PICK);
            intent.setClass(CameraPreviewActivity.this, FireIconActivity.class);
            startActivityForResult(intent, PICK_ICON_REQUEST);
        }
    });

    final ImageButton deleteButton = (ImageButton) findViewById(R.id.camera_preview_delete_button);
    deleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            CameraPreviewActivity.this.showDialog(DIALOG_DELETE_PHOTO);
        }
    });

    final ImageButton saveButton = (ImageButton) findViewById(R.id.camera_preview_save_button);
    saveButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mImageNote = ((EditText) findViewById(R.id.camera_preview_edittext)).getText().toString();
            Log.d(GeoCamMobile.DEBUG_ID, "Setting image note to: " + mImageNote);
            saveWithAnnotation();
        }
    });

    mForeground = new ForegroundTracker(this);
}

From source file:com.chrslee.csgopedia.app.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //Looks like he did this layout via code this is a layoutparams object
    //it defines the metrics and bounds of a specific view
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    //Creating a FrameLayout a FrameLayout is basically a empty container
    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(params);//from   w  w  w .  j  a  v a2s.  c o  m
    //setting the params from above

    // First - image section
    //Building the imageview via code
    LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgParams.gravity = Gravity.CENTER;
    //setting all centered
    ImageView iv = new ImageView(context);
    iv.setLayoutParams(imgParams);
    iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iv.setAdjustViewBounds(true);
    iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID"));
    //seting the iconID as the image of this imageView

    // Second - prices section
    //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
    //        .getDisplayMetrics());
    //

    //LinearLayout is another container it just take the
    //widgets inside it and display them in a linear order
    LinearLayout linLayout = new LinearLayout(context);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    linLayout.setLayoutParams(params);
    linLayout.setGravity(Gravity.CENTER);

    // Get prices
    ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet
    String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg
    TextView placeholder = new TextView(context); ///this is a textview for the name of the item
    if (cd.isConnectedToInternet()) {//if its connected to internet then
        if (query.equals("-1")) {//if the skin is regular he display is not for sale
            placeholder.setText("Regular skins are not for sale!");
            linLayout.addView(placeholder);
        } else {//else he calls the scrappperAsyncTask with the query
            new ScraperAsyncTask(linLayout).execute(query);
        }
    } else {//if its not connected he display the message here
        placeholder.setText("Please connect to the Internet to view prices.");
        linLayout.addView(placeholder);
    }

    //here he defines which tab he is displaying, Now I see why he used the same fragment,
    //this is a bad practice, he created both widgets before but just displays one of them
    //for each case if its the first tab he display the image if its the second the prices
    if (position == 0) {
        fl.addView(iv);
    } else {
        fl.addView(linLayout);
    }

    //Then he returns the framelayout (container) to display it in the screen
    return fl;
}

From source file:mobisocial.musubi.objects.WebAppObj.java

@Override
public View createView(Context context, ViewGroup parent) {
    LinearLayout frame = new LinearLayout(context);
    frame.setLayoutParams(CommonLayouts.FULL_WIDTH);
    frame.setOrientation(LinearLayout.VERTICAL);

    LinearLayout appBar = new LinearLayout(context);
    appBar.setLayoutParams(CommonLayouts.FULL_WIDTH);
    appBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(appBar);/*from  w  ww  . ja v a2 s .  c o m*/

    Drawable icon = context.getResources().getDrawable(R.drawable.ic_menu_globe);
    ImageView iv = new ImageView(context);
    iv.setImageDrawable(icon);
    iv.setAdjustViewBounds(true);
    iv.setMaxWidth(60);
    iv.setMaxHeight(60);
    iv.setLayoutParams(CommonLayouts.WRAPPED);
    appBar.addView(iv);

    TextView tv = new TextView(context);
    tv.setLayoutParams(CommonLayouts.WRAPPED);
    tv.setGravity(Gravity.CENTER_VERTICAL);
    appBar.addView(tv);

    LinearLayout actionBar = new LinearLayout(context);
    actionBar.setLayoutParams(CommonLayouts.WRAPPED);
    actionBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(actionBar);

    Button b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setText("Run");
    b.setOnClickListener(getRunListener());
    actionBar.addView(b);

    b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setOnClickListener(getAddListener());
    actionBar.addView(b);

    return frame;
}