List of usage examples for android.graphics Bitmap createScaledBitmap
public static Bitmap createScaledBitmap(@NonNull Bitmap src, int dstWidth, int dstHeight, boolean filter)
From source file:it.angelic.soulissclient.fragments.TagDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false); rootView.setTag(TAG);/*w ww. ja v a 2s.c om*/ Log.i(Constants.TAG, "onCreateView with size of data:" + collectedTagTypicals.size()); appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.appBar_layout); swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshContainer); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); if (collectedTag != null) { UDPHelper.stateRequest(opzioni, 1, collectedTag.getAssignedTypicals().get(0).getNodeId()); Log.d(Constants.TAG, "stateRequest for node:" + collectedTag.getAssignedTypicals().get(0).getNodeId()); } if (!opzioni.isSoulissReachable()) { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), getString(R.string.status_souliss_notreachable), Toast.LENGTH_SHORT).show(); swipeLayout.setRefreshing(false); } }); } } }).start(); } }); swipeLayout.setColorSchemeResources(R.color.std_blue, R.color.std_blue_shadow); // BEGIN_INCLUDE(initializeRecyclerView) mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshContainer); // LinearLayout tagContainer = (LinearLayout) rootView.findViewById(R.id.tagContainer); //mLayoutManager = new LinearLayoutManager(getActivity()); if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER); } mCurrentLayoutManagerType = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? LayoutManagerType.GRID_LAYOUT_MANAGER : LayoutManagerType.LINEAR_LAYOUT_MANAGER; setRecyclerViewLayoutManager(mCurrentLayoutManagerType); parallaxExtAdapter = new ParallaxExenderAdapter(opzioni, (TagDetailActivity) getActivity(), collectedTagTypicals, tagId); //HeaderLayoutManagerFixed layoutManagerFixed = new HeaderLayoutManagerFixed(getActivity()); //HEADER // View header = getLayoutInflater(null).inflate(R.layout.head_tagdetail, tagContainer, false); // layoutManagerFixed.setHeaderIncrementFixer(header); mLogoIcon = (ImageView) getActivity().findViewById(R.id.imageTagIcon); if (collectedTag.getIconResourceId() != 0) mLogoIcon.setImageResource(collectedTag.getIconResourceId()); mLogoImg = (ImageView) getActivity().findViewById(R.id.photo); bro = (TextView) getActivity().findViewById(R.id.tagTextView); collapseToolbar = (CollapsingToolbarLayout) getActivity().findViewById(R.id.Collapselayout); fab = (FloatingActionButton) getActivity().findViewById(R.id.fabTag); //EDIT TAG fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alert = AlertDialogHelper.renameSoulissObjectDialog(getActivity(), bro, null, datasource, collectedTag); alert.show(); } }); fab.hide(false); fab.postDelayed(new Runnable() { @Override public void run() { fab.show(true); } }, 500); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); for (SoulissTypical typ : collectedTagTypicals) { UDPHelper.stateRequest(opzioni, 4, typ.getSlot()); } //Avvisa solo if (!opzioni.isSoulissReachable()) { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), getString(R.string.status_souliss_notreachable), Toast.LENGTH_SHORT).show(); swipeLayout.setRefreshing(false); } }); } } }).start(); } }); swipeLayout.setColorSchemeResources(R.color.std_blue, R.color.std_blue_shadow); if (bro != null && collectedTag != null) { // bro.setText(collectedTag.getNiceName()); collapseToolbar.setTitle(collectedTag.getNiceName()); } if (collectedTag != null && collectedTag.getImagePath() != null) { File picture = new File(getRealPathFromURI(Uri.parse(collectedTag.getImagePath()))); // File picture = new File(Uri.parse(collectedTag.getImagePath()).getPath()); if (picture.exists()) { //ImageView imageView = (ImageView)findViewById(R.id.imageView); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap myBitmap = BitmapFactory.decodeFile(picture.getAbsolutePath(), options); if (myBitmap.getHeight() > mRecyclerView.getWidth()) myBitmap = Bitmap.createScaledBitmap(myBitmap, myBitmap.getWidth() / 2, myBitmap.getHeight() / 2, true); Log.i(Constants.TAG, "bitmap size " + myBitmap.getRowBytes()); mLogoImg.setImageBitmap(myBitmap); } try { mLogoImg.setImageURI(Uri.parse(collectedTag.getImagePath())); } catch (Exception e) { Log.d(TAG, "can't set logo", e); } } //parallaxExtAdapter.setShouldClipView(true); // parallaxExtAdapter.setParallaxHeader(header, mRecyclerView); registerForContextMenu(mRecyclerView); return rootView; }
From source file:br.com.brolam.cloudvision.ui.helpers.ImagesHelper.java
/** * Reduzir o tamanho de uma imagem e atualizar o arquivo da imagem. * @param filepath informar o endereo completo da imagem * @param width informar a largura em pixel * @param height informar a altura em pixels * @throws IOException//from w w w . j a va 2 s. c o m */ private void resizeImage(String filepath, int width, int height) throws IOException { //Bitmap bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(filepath), 720, 1280, true); Bitmap bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(filepath), width, height, true); File imageFile = new File(filepath); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); byte[] data = byteArrayOutputStream.toByteArray(); FileOutputStream outputStream = new FileOutputStream(imageFile); outputStream.write(data); outputStream.close(); }
From source file:nl.privacybarometer.privacyvandaag.fragment.EntryFragment.java
private void refreshUI(Cursor entryCursor) { if (entryCursor != null) { String feedTitle = entryCursor.isNull(mFeedNamePos) ? entryCursor.getString(mFeedUrlPos) : entryCursor.getString(mFeedNamePos); BaseActivity activity = (BaseActivity) getActivity(); activity.setTitle(feedTitle);/* ww w . j a va2s. c o m*/ // ModPrivacyVandaag: Get icon from resource drawable instead of retrieved favicon blob in database int mIconResourceId = entryCursor.getInt(mIconIdPos); if (mIconResourceId > 0) { Drawable mDrawable = ContextCompat.getDrawable(MainApplication.getContext(), mIconResourceId); Bitmap bitmap = ((BitmapDrawable) mDrawable).getBitmap(); if (bitmap != null) { BitmapDrawable mIcon; mIcon = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, 36, 36, true)); activity.getSupportActionBar().setIcon(mIcon); } } else { activity.getSupportActionBar().setIcon(null); } /* Following code no longer needed byte[] iconBytes = entryCursor.getBlob(mFeedIconPos); Bitmap bitmap = UiUtils.getScaledBitmap(iconBytes, 24); if (bitmap != null) { activity.getSupportActionBar().setIcon(new BitmapDrawable(getResources(), bitmap)); } else { activity.getSupportActionBar().setIcon(null); } */ // End ModPrivacyVandaag mFavorite = entryCursor.getInt(mIsFavoritePos) == 1; activity.invalidateOptionsMenu(); // Listen the mobilizing task if (FetcherService.hasMobilizationTask(mEntriesIds[mCurrentPagerPos])) { showSwipeProgress(); // If the service is not started, start it here to avoid an infinite loading if (!PrefUtils.getBoolean(PrefUtils.IS_REFRESHING, false)) { MainApplication.getContext() .startService(new Intent(MainApplication.getContext(), FetcherService.class) .setAction(FetcherService.ACTION_MOBILIZE_FEEDS)); } } else { hideSwipeProgress(); } // Mark the article as read if (entryCursor.getInt(mIsReadPos) != 1) { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread(new Runnable() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getReadContentValues(), null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }).start(); } } }
From source file:com.miz.functions.MizLib.java
/** * Returns a custom theme background image as Bitmap. * @param height//from w w w . j a v a 2s . c om * @param width * @return Bitmap with the background image */ public static Bitmap getCustomThemeBackground(int height, int width, String url) { try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Config.RGB_565; options.inDither = true; Bitmap bm = BitmapFactory.decodeFile(url, options); float scaleWidth = bm.getWidth() / ((float) width); float scaleHeight = bm.getHeight() / ((float) height); if (scaleWidth > scaleHeight) bm = Bitmap.createScaledBitmap(bm, (int) (bm.getWidth() / scaleHeight), (int) (bm.getHeight() / scaleHeight), true); else bm = Bitmap.createScaledBitmap(bm, (int) (bm.getWidth() / scaleWidth), (int) (bm.getHeight() / scaleWidth), true); bm = Bitmap.createBitmap(bm, (bm.getWidth() - width) / 2, (bm.getHeight() - height) / 2, width, height); return bm; } catch (Exception e) { return null; } }
From source file:io.bunnyblue.noticedog.app.overlay.ui.OverlayNotificationBarView.java
private Drawable normalizeIcon(Drawable icon) { return new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), 80, 80, false)); }
From source file:rpassmore.app.fillthathole.ViewHazardActivity.java
private void storeNewPhoto(Bitmap bitmap, String photoUrl) { // shrink bitmap for thumb nail image Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 120, 120, false); // save scaled image to jpg byte array ByteArrayOutputStream out = new ByteArrayOutputStream(); scaledBitmap.compress(Bitmap.CompressFormat.PNG, 90, out); // store thumb nail from photo hazard.setPhoto(out.toByteArray());//from ww w . j ava 2 s . c o m hazard.setPhotoUrl(photoUrl); try { out.close(); } catch (IOException e) { Log.e(getPackageName(), "Error scaling and storing thumbnail", e); } // display the thumbnail image.setImageBitmap(scaledBitmap); dbAdapter.open(); long id = dbAdapter.save(hazard); hazard.setId(id); dbAdapter.close(); }
From source file:geert.stef.sm.beheerautokm.Overview.java
public Bitmap resizeBitmap(Bitmap bitmap) { if (bitmap.getHeight() > 4096 || bitmap.getWidth() > 4096) { int width = (int) (bitmap.getWidth() * 0.9); int height = (int) (bitmap.getHeight() * 0.9); Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, width, height, false); resizeBitmap(resizedBitmap);/*ww w . jav a 2s . c o m*/ return resizedBitmap; } else { return bitmap; } }
From source file:de.qspool.clementineremote.backend.ClementinePlayerConnection.java
/** * Update the notification with the new track info *///from www . j ava 2 s . c o m private void updateNotification() { if (mLastSong != null) { Bitmap scaledArt = Bitmap.createScaledBitmap(mLastSong.getArt(), mNotificationWidth, mNotificationHeight, false); mNotifyBuilder.setLargeIcon(scaledArt); mNotifyBuilder.setContentTitle(mLastSong.getArtist()); mNotifyBuilder.setContentText(mLastSong.getTitle() + " / " + mLastSong.getAlbum()); } else { mNotifyBuilder.setContentTitle(App.mApp.getString(R.string.app_name)); mNotifyBuilder.setContentText(App.mApp.getString(R.string.player_nosong)); } mNotificationManager.notify(App.NOTIFY_ID, mNotifyBuilder.build()); }
From source file:com.mobility.android.ui.vehicle.AddVehicleActivity.java
private Observable<String> base64(File file) { return Observable.create(new Observable.OnSubscribe<String>() { @Override//from w w w . jav a2s . c om public void call(Subscriber<? super String> subscriber) { try { FileInputStream in = new FileInputStream(file); ByteArrayOutputStream out = new ByteArrayOutputStream(); Bitmap bitmap = BitmapFactory.decodeStream(in); try { in.close(); } catch (IOException e) { e.printStackTrace(); } Bitmap scaled = Bitmap.createScaledBitmap(bitmap, 960, 720, false); bitmap.recycle(); scaled.compress(Bitmap.CompressFormat.JPEG, 60, out); subscriber.onNext(Base64.encodeToString(out.toByteArray(), Base64.DEFAULT)); subscriber.onCompleted(); } catch (FileNotFoundException e) { subscriber.onError(e); } } }); }
From source file:com.dexin.MainActivity.java
public Bitmap scaleBitmapDown(Bitmap bitmap, int maxDimension) { int originalWidth = bitmap.getWidth(); int originalHeight = bitmap.getHeight(); int resizedWidth = maxDimension; int resizedHeight = maxDimension; if (originalHeight > originalWidth) { resizedHeight = maxDimension;//from w ww.ja v a2 s.co m resizedWidth = (int) (resizedHeight * (float) originalWidth / (float) originalHeight); } else if (originalWidth > originalHeight) { resizedWidth = maxDimension; resizedHeight = (int) (resizedWidth * (float) originalHeight / (float) originalWidth); } else if (originalHeight == originalWidth) { resizedHeight = maxDimension; resizedWidth = maxDimension; } return Bitmap.createScaledBitmap(bitmap, resizedWidth, resizedHeight, false); }