List of usage examples for android.widget ImageView setMaxWidth
@android.view.RemotableViewMethod public void setMaxWidth(int maxWidth)
From source file:Main.java
public static void setSize(View view, int w, int h) { view.setMinimumWidth(w);// w w w . j a v a 2s . c o m 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 void addResourceImage(Activity activity, LinearLayout layout, int imgResource, int width, int height) { ImageView image = new ImageView(activity); image.setImageResource(imgResource); if (width > 0) image.setMaxWidth(width); if (height > 0) image.setMaxHeight(height);/*w w w . jav a2s .c o m*/ image.setScaleType(ImageView.ScaleType.CENTER_INSIDE); layout.addView(image); }
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); searchIcon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); searchIcon.setImageDrawable(null); }/*from ww w . j ava2 s. co m*/ } }
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 w w.jav 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; }
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( parent.getContext().getResources().getDimensionPixelSize(R.dimen.payments_section_logo_width)); view.setAdjustViewBounds(true);/* w w w . jav a 2 s .c om*/ // 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: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;//from w ww . ja va 2s . 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:com.android.browser.GearsBaseDialog.java
/** * Utility method to update the icon./*ww w . j a v a 2 s . c o m*/ * Called on the UI thread. */ public void updateIcon() { if (mIcon == null) { return; } View view = findViewById(R.id.origin_icon); if (view != null) { ImageView imageView = (ImageView) view; imageView.setMaxHeight(MAX_ICON_SIZE); imageView.setMaxWidth(MAX_ICON_SIZE); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageBitmap(mIcon); imageView.setVisibility(View.VISIBLE); } }
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 ww. j a va 2 s. c o 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.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java
private void createNewViewer(LinearLayout linearLayout, final IField field, final int index) { final MultimediaCardEditorActivity context = this; switch (field.getType()) { case TEXT:/* www. ja v a 2 s .c o m*/ // Create a text field and an edit button, opening editing for // the // text field TextView textView = new TextView(this); textView.setText(field.getText()); linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT); break; case IMAGE: ImageView imgView = new ImageView(this); // // BitmapFactory.Options options = new BitmapFactory.Options(); // options.inSampleSize = 2; // Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options); // jpgView.setImageBitmap(bm); LinearLayout.LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); File f = new File(field.getImagePath()); Bitmap b = BitmapUtil.decodeFile(f, getMaxImageSize()); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.ECLAIR) { b = ExifUtil.rotateFromCamera(f, b); } imgView.setImageBitmap(b); imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imgView.setAdjustViewBounds(true); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; imgView.setMaxHeight((int) Math.round(height * 0.6)); imgView.setMaxWidth((int) Math.round(width * 0.7)); linearLayout.addView(imgView, p); break; case AUDIO: AudioView audioView = AudioView.createPlayerInstance(this, R.drawable.av_play, R.drawable.av_pause, R.drawable.av_stop, field.getAudioPath()); linearLayout.addView(audioView); break; default: Log.e("multimedia editor", "Unsupported field type found"); break; } Button editButtonText = new Button(this); editButtonText.setText(gtxt(R.string.multimedia_editor_activity_edit_button)); linearLayout.addView(editButtonText, LinearLayout.LayoutParams.MATCH_PARENT); editButtonText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(context, EditFieldActivity.class); putExtrasAndStartEditActivity(field, index, i); } }); }