List of usage examples for android.widget ImageView setScaleType
public void setScaleType(ScaleType scaleType)
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == UCrop.REQUEST_CROP) { File cropFile = new File(UCrop.getOutput(data).getPath()); int index = 0; for (int id : postImageViewIds) { ImageView mImageView = (ImageView) rootView.findViewById(id); if (mImageView.getTag() == null) { rootView.findViewById(postImageViewPlusIds[index]).setVisibility(View.VISIBLE); rootView.findViewById(postImageViewRemoveIds[index]).setVisibility(View.VISIBLE); mImageView.setImageBitmap(BitmapFactory.decodeFile(cropFile.getPath())); mImageView.setScaleType(ImageView.ScaleType.FIT_XY); mImageView.setPadding(10, 10, 10, 10); mImageView.setTag(cropFile.getPath()); mImageViewTitle.setImageDrawable(((ImageView) rootView.findViewById(id)).getDrawable()); mImageViewTitle.setTag(id); break; }/* w w w.j av a 2 s .co m*/ index++; } } else if (resultCode == Activity.RESULT_OK && requestCode == PICK_PHOTO_FOR_AVATAR) { UCrop.of(data.getData(), Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"))) .withMaxResultSize(1920, 1920).start(getContext(), this); } else if (resultCode == Activity.RESULT_OK && requestCode == TAKE_PHOTO_FOR_AVATAR) { UCrop.of(Uri.fromFile(takeFile), Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"))) .withMaxResultSize(1920, 1920).start(getContext(), this); } else if (resultCode == UCrop.RESULT_ERROR) { final Throwable cropError = UCrop.getError(data); Log.d("mox", "croperror" + cropError.toString()); } else if (resultCode == Activity.RESULT_OK && requestCode == SEARCH_ADDRESS) { AddressModel mAddressModel = (AddressModel) data.getSerializableExtra("data"); setAddressModel(mAddressModel); } else if (resultCode == Activity.RESULT_OK && requestCode == PICK_VIDEO_FOR_AVATAR) { String path = getPath(data.getData()); showVideoAlertDialog(path); } else if (resultCode == Activity.RESULT_OK && requestCode == TAKE_VIDEO_FOR_AVATAR) { String path = takeFile.getPath(); showVideoAlertDialog(path); } }
From source file:net.lacolaco.smileessence.activity.MainActivity.java
public void updateActionBarIcon() { Twitter twitter = new TwitterApi(currentAccount).getTwitter(); final ImageView homeIcon = (ImageView) findViewById(android.R.id.home); ShowUserTask userTask = new ShowUserTask(twitter, currentAccount.userID) { @Override//from ww w . jav a 2 s.c o m protected void onPostExecute(User user) { super.onPostExecute(user); if (user != null) { String urlHttps = user.getProfileImageURLHttps(); homeIcon.setScaleType(ImageView.ScaleType.FIT_CENTER); new BitmapURLTask(urlHttps, homeIcon).execute(); } } }; userTask.execute(); }
From source file:com.b44t.ui.Components.PasscodeView.java
public PasscodeView(final Context context) { super(context); setWillNotDraw(false);/*from w w w . j av a 2s . com*/ setVisibility(GONE); backgroundFrameLayout = new FrameLayout(context); addView(backgroundFrameLayout); LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; backgroundFrameLayout.setLayoutParams(layoutParams); passwordFrameLayout = new FrameLayout(context); addView(passwordFrameLayout); layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; passwordFrameLayout.setLayoutParams(layoutParams); ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageResource(R.drawable.ic_launcher /* EDIT BY MR -- was: passcode_logo */); passwordFrameLayout.addView(imageView); layoutParams = (LayoutParams) imageView.getLayoutParams(); if (AndroidUtilities.density < 1) { layoutParams.width = AndroidUtilities.dp(30); layoutParams.height = AndroidUtilities.dp(30); } else { layoutParams.width = AndroidUtilities.dp(40); layoutParams.height = AndroidUtilities.dp(40); } layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; layoutParams.bottomMargin = AndroidUtilities.dp(100); imageView.setLayoutParams(layoutParams); passcodeTextView = new TextView(context); passcodeTextView.setTextColor(0xffffffff); passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL); passwordFrameLayout.addView(passcodeTextView); layoutParams = (LayoutParams) passcodeTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.bottomMargin = AndroidUtilities.dp(62); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passcodeTextView.setLayoutParams(layoutParams); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); passwordEditText.setTextColor(0xffffffff); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); passwordEditText.setTypeface(Typeface.DEFAULT); passwordEditText.setBackgroundDrawable(null); AndroidUtilities.clearCursorDrawable(passwordEditText); passwordFrameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(70); layoutParams.rightMargin = AndroidUtilities.dp(70); layoutParams.bottomMargin = AndroidUtilities.dp(6); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_DONE) { processDone(false); return true; } return false; } }); passwordEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) { processDone(false); } } }); passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); checkImage = new ImageView(context); checkImage.setImageResource(R.drawable.passcode_check); checkImage.setScaleType(ImageView.ScaleType.CENTER); checkImage.setBackgroundResource(R.drawable.bar_selector_lock); passwordFrameLayout.addView(checkImage); layoutParams = (LayoutParams) checkImage.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(60); layoutParams.height = AndroidUtilities.dp(60); layoutParams.bottomMargin = AndroidUtilities.dp(4); layoutParams.rightMargin = AndroidUtilities.dp(10); layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT; checkImage.setLayoutParams(layoutParams); checkImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processDone(false); } }); FrameLayout lineFrameLayout = new FrameLayout(context); lineFrameLayout.setBackgroundColor(0x26ffffff); passwordFrameLayout.addView(lineFrameLayout); layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = AndroidUtilities.dp(1); layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT; layoutParams.leftMargin = AndroidUtilities.dp(20); layoutParams.rightMargin = AndroidUtilities.dp(20); lineFrameLayout.setLayoutParams(layoutParams); numbersFrameLayout = new FrameLayout(context); addView(numbersFrameLayout); layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP | Gravity.LEFT; numbersFrameLayout.setLayoutParams(layoutParams); lettersTextViews = new ArrayList<>(10); numberTextViews = new ArrayList<>(10); numberFrameLayouts = new ArrayList<>(10); for (int a = 0; a < 10; a++) { TextView textView = new TextView(context); textView.setTextColor(0xffffffff); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36); textView.setGravity(Gravity.CENTER); textView.setText(String.format(Locale.US, "%d", a)); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); numberTextViews.add(textView); textView = new TextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12); textView.setTextColor(0x7fffffff); textView.setGravity(Gravity.CENTER); numbersFrameLayout.addView(textView); layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(20); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; textView.setLayoutParams(layoutParams); switch (a) { case 0: textView.setText("+"); break; case 2: textView.setText("ABC"); break; case 3: textView.setText("DEF"); break; case 4: textView.setText("GHI"); break; case 5: textView.setText("JKL"); break; case 6: textView.setText("MNO"); break; case 7: textView.setText("PQRS"); break; case 8: textView.setText("TUV"); break; case 9: textView.setText("WXYZ"); break; default: break; } lettersTextViews.add(textView); } eraseView = new ImageView(context); eraseView.setScaleType(ImageView.ScaleType.CENTER); eraseView.setImageResource(R.drawable.passcode_delete); numbersFrameLayout.addView(eraseView); layoutParams = (LayoutParams) eraseView.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(50); layoutParams.height = AndroidUtilities.dp(50); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; eraseView.setLayoutParams(layoutParams); for (int a = 0; a < 11; a++) { FrameLayout frameLayout = new FrameLayout(context); frameLayout.setBackgroundResource(R.drawable.bar_selector_lock); frameLayout.setTag(a); if (a == 10) { frameLayout.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { passwordEditText.setText(""); return true; } }); } frameLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int tag = (Integer) v.getTag(); switch (tag) { case 0: appendCharacter("0"); break; case 1: appendCharacter("1"); break; case 2: appendCharacter("2"); break; case 3: appendCharacter("3"); break; case 4: appendCharacter("4"); break; case 5: appendCharacter("5"); break; case 6: appendCharacter("6"); break; case 7: appendCharacter("7"); break; case 8: appendCharacter("8"); break; case 9: appendCharacter("9"); break; case 10: String text = passwordEditText.getText().toString(); if (text.length() > 0) { passwordEditText.setText(text.substring(0, text.length() - 1)); } break; } if (passwordEditText.getText().toString().length() == 4) { processDone(false); } } }); numberFrameLayouts.add(frameLayout); } for (int a = 10; a >= 0; a--) { FrameLayout frameLayout = numberFrameLayouts.get(a); numbersFrameLayout.addView(frameLayout); layoutParams = (LayoutParams) frameLayout.getLayoutParams(); layoutParams.width = AndroidUtilities.dp(100); layoutParams.height = AndroidUtilities.dp(100); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; frameLayout.setLayoutParams(layoutParams); } }
From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java
private void displaySplash() { // Don't show the splash screen if this app appears to be registered if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString(InformOnlineState.DEVICE_ID, null) instanceof String) { return;//from w w w. j a v a 2 s. c om } // Fetch the splash screen Drawable Drawable image = null; try { // Attempt to load the configured default splash screen // The following code only works in 1.6+ // BitmapDrawable bitImage = new BitmapDrawable(getResources(), FileUtils.SPLASH_SCREEN_FILE_PATH); BitmapDrawable bitImage = new BitmapDrawable( FileUtilsExtended.EXTERNAL_FILES + File.separator + FileUtilsExtended.SPLASH_SCREEN_FILE); if (bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0 && bitImage.getIntrinsicWidth() > 0) { image = bitImage; } } catch (Exception e) { // TODO: log exception for debugging? } // TODO: rework if (image == null) { // no splash provided... // if (FileUtils.storageReady() && !((new File(FileUtils.DEFAULT_CONFIG_PATH)).exists())) { // Show the built-in splash image if the config directory // does not exist. Otherwise, suppress the icon. image = getResources().getDrawable(R.drawable.gc_color); // } if (image == null) return; } // Create ImageView to hold the Drawable... ImageView view = new ImageView(getApplicationContext()); // Initialise it with Drawable and full-screen layout parameters view.setImageDrawable(image); int width = getWindowManager().getDefaultDisplay().getWidth(); int height = getWindowManager().getDefaultDisplay().getHeight(); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height, 0); view.setLayoutParams(lp); view.setScaleType(ScaleType.CENTER); view.setBackgroundColor(Color.WHITE); // And wrap the image view in a frame layout so that the full-screen layout parameters are honoured FrameLayout layout = new FrameLayout(getApplicationContext()); layout.addView(view); // Create the toast and set the view to be that of the FrameLayout mSplashToast = Toast.makeText(getApplicationContext(), "splash screen", Toast.LENGTH_LONG); mSplashToast.setView(layout); mSplashToast.setGravity(Gravity.CENTER, 0, 0); mSplashToast.show(); }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private Bitmap fillLowerLeft(final Drawable drawable, ImageView imageView, Bitmap prevBm) { // Compute matrix to fill viewer with drawable starting with upper left // Stretching till 2nd edge is crossed (filling screen) with correct aspect ratio. Matrix m = new Matrix(); m.reset();//from w w w. j av a 2 s . c o m int imgWidth = drawable.getIntrinsicWidth(); int imgHeight = drawable.getIntrinsicHeight(); int viewWidth = imageView.getWidth(); int viewHeight = imageView.getHeight(); float xScale = (float) viewWidth / imgWidth; float yScale = (float) viewHeight / imgHeight; float maxScale = Math.max(xScale, yScale); float dy = (imgHeight * maxScale - viewHeight) / maxScale; // dy = imgHeight / 2; m.preTranslate(0, -dy); m.postScale(maxScale, maxScale); imageView.setScaleType(ImageView.ScaleType.MATRIX); imageView.setImageMatrix(m); imageView.setImageDrawable(drawable); return prevBm; }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * ?//w w w. j a v a 2 s . c om */ private void drawImage() { int size = rectList.size(); Rect endRect = rectList.get(size - 1); Rect realEndRect = endRect; // ?left???,,? if (size > 2) { Rect endPreRect = rectList.get(size - 2); if (endRect.left == endPreRect.left) { if (endRect.width() > endPreRect.width()) { realEndRect = endPreRect; } else { realEndRect = endRect; } } } Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.del); ImageView imageView = new ImageView(mContext); imageView.setImageBitmap(bitmap); imageView.setScaleType(ScaleType.CENTER); imageView.setTag(selectContext); MyAbsoluteLayout.LayoutParams lp = new MyAbsoluteLayout.LayoutParams( MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, realEndRect.right, realEndRect.bottom); imageView.setLayoutParams(lp); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String tag = (String) v.getTag(); lineView.remove(tag); myLayout.removeView(v); if (onTextSelectListener != null) { onTextSelectListener.cancle(tag.split(SELECT_SPLIT)[0]); } } }); myLayout.addView(imageView, lp); }
From source file:com.android.systemui.statusbar.phone.NavigationBarView.java
private void addLightsOutButton(LinearLayout root, View v, boolean landscape, boolean empty) { ImageView addMe = new ImageView(mContext); addMe.setLayoutParams(v.getLayoutParams()); addMe.setImageResource(//from w w w . ja va 2s . co m empty ? R.drawable.ic_sysbar_lights_out_dot_large : R.drawable.ic_sysbar_lights_out_dot_small); addMe.setScaleType(ImageView.ScaleType.CENTER); addMe.setVisibility(empty ? View.INVISIBLE : View.VISIBLE); if (landscape) root.addView(addMe, 0); else root.addView(addMe); }
From source file:com.acc.android.util.widget.adapter.ImageAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { // if (false) { // if (this.accFileCallback == null) { // return null; // }/*from www. j a v a 2s . c om*/ ACCFile accFile = this.imageData.getAccFiles().get(position); ImageView imageView = !this.isBig ? new ImageView(this.context) : new AutoImageView(this.context, position == 0, position == this.getCount() - 1, this.onSingleTapListener); Bitmap bitmap = this.bitmapProviderManager.getBitmap(accFile); // if (bitmap == null || bitmap.isRecycled()) { // bitmap = BitmapManager.getInstance(context).getBlankBitmap(); // } // LogUtil.systemOut("bitmap == null:"); // LogUtil.systemOut(bitmap == null); // if (true) { if (this.isBig) { imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); } // this.isBig ? // :autoImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // imageView.setBackgroundResource(R.drawable.login_input); // } // System.out.println(position); imageView.setImageBitmap(bitmap); if (this.isBig && accFile.getProgress() != null) { ((AutoImageView) imageView).setProgress(accFile.getProgress()); } // } return imageView; }
From source file:com.elephant.ediyou.imagecache2.ImageWorker.java
/** * Load an image specified by the data parameter into an ImageView (override * {@link ImageWorker#processBitmap(Object)} to define the processing logic). A memory and disk * cache will be used if an {@link ImageCache} has been set using * {@link ImageWorker#setImageCache(ImageCache)}. If the image is found in the memory cache, it * is set immediately, otherwise an {@link AsyncTask} will be created to asynchronously load the * bitmap./*from ww w. j av a 2 s .c om*/ * * @param data The URL of the image to download. * @param imageView The ImageView to bind the downloaded image to. */ public void loadImage(Object data, ImageView imageView) { if (data == null) { return; } Bitmap bitmap = null; if (mImageCache != null) { bitmap = mImageCache.getBitmapFromMemCache(String.valueOf(data)); } if (bitmap != null) { // Bitmap found in memory cache // imageView.closeTimer(); imageView.setImageBitmap(bitmap); } else if (cancelPotentialWork(data, imageView)) { final BitmapWorkerTask task = new BitmapWorkerTask(imageView); final AsyncDrawable asyncDrawable = new AsyncDrawable(mResources, mLoadingBitmap, task); // imageView.closeTimer(); imageView.setImageDrawable(asyncDrawable); // imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); imageView.setScaleType(ImageView.ScaleType.FIT_XY); // NOTE: This uses a custom version of AsyncTask that has been pulled from the // framework and slightly modified. Refer to the docs at the top of the class // for more info on what was changed. task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data); } }