List of usage examples for android.support.v4.graphics.drawable RoundedBitmapDrawableFactory create
public static RoundedBitmapDrawable create(Resources resources, InputStream inputStream)
From source file:com.concavenp.artistrymuse.BaseAppCompatActivity.java
private BitmapImageViewTarget createBitmapImageViewTarget(final ImageView imageView) { return new BitmapImageViewTarget(imageView) { @Override/*from w ww . j a v a 2 s . c om*/ protected void setResource(Bitmap bitmap) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); int borderWidthHalf = 10; int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); int newBitmapSquare = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquare, newBitmapSquare, Bitmap.Config.ARGB_8888); // Initialize a new Canvas to draw empty bitmap Canvas canvas = new Canvas(roundedBitmap); // Calculation to draw bitmap at the circular bitmap center position int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; canvas.drawBitmap(bitmap, x, y, null); // Initializing a new Paint instance to draw circular border Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf * 2); borderPaint.setColor(ResourcesCompat.getColor(getResources(), R.color.myApp_accent_700, null)); canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquare / 2, borderPaint); RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), roundedBitmap); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }; }
From source file:com.stockita.stockitapointofsales.activities.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // ButterKnife ButterKnife.bind(this); // Set the Toolbar setSupportActionBar(mCoordinator.getmToolbar()); // Set the Navigation draw layout ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, mCoordinator.getmToolbar(), R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.addDrawerListener(toggle);//from w w w . j a v a2s . co m toggle.syncState(); // Navigation draw view NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); /** * The code below is about the nav_header */ View headerLayout = navigationView.getHeaderView(0); final ImageView imageView = (ImageView) headerLayout.findViewById(R.id.imageView); TextView name = (TextView) headerLayout.findViewById(R.id.textView1); TextView email = (TextView) headerLayout.findViewById(R.id.textView2); // Display user image in circular frame, in the navigation header if (mPhotoUrl != null) { Glide.with(this).load("https://lh3.googleusercontent.com" + mPhotoUrl).asBitmap() .into(new BitmapImageViewTarget(imageView) { @Override protected void setResource(@NonNull Bitmap resource) { super.setResource(resource); RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(getResources(), resource); circularBitmapDrawable.setCircular(true); imageView.setImageDrawable(circularBitmapDrawable); } }); } // Display the user name and email on the nav_header name.setText(mUserName); email.setText(Utility.decodeEmail(mUserEncodedEmail)); /** * Create the adapter that will return a fragment for each of the * primary sections of the activity. */ mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); /* Set up the ViewPager with the sections adapter. */ if (mCoordinator.getmViewPagerContainer() != null) { mCoordinator.getmViewPagerContainer().setAdapter(mSectionsPagerAdapter); } /* Tab layout */ if (mCoordinator.getmTabs() != null) { mCoordinator.getmTabs().setupWithViewPager(mCoordinator.getmViewPagerContainer()); } /** * This listener is to get the tab position, however it does an other think * but we are only interested for the current tab position */ if (mCoordinator.getmTabs() != null) { mCoordinator.getmTabs().addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { /* First we invoke this method for mViewPager */ mCoordinator.getmViewPagerContainer().setCurrentItem(tab.getPosition()); /** * Then we can assign the value of the current position to * a static field, there are some other way to do this. */ sSelection = tab.getPosition(); /** * Make the FAB invisible in some selection */ if (tab.getPosition() == 2) { mCoordinator.getmFab().setVisibility(View.INVISIBLE); } else { mCoordinator.getmFab().setVisibility(View.VISIBLE); } } @Override public void onTabUnselected(TabLayout.Tab tab) { // If sliding then finish the action mode if (mActionMode != null) { mActionMode.finish(); } } @Override public void onTabReselected(TabLayout.Tab tab) { } }); } /** * Restore saved instance state on configuration changes */ if (savedInstanceState != null) { // Restore the fragment instance state mItemMasterListFragmentUI = (ItemMasterListFragmentUI) getFragmentManager() .getFragment(savedInstanceState, KEY_ONE); mSalesListFragmentUI = (SalesPendingListFragmentUI) getFragmentManager().getFragment(savedInstanceState, KEY_TWO); mOpenSalesHeaderListFragmentUI = (OpenSalesHeaderListFragmentUI) getFragmentManager() .getFragment(savedInstanceState, KEY_THREE); aaItemMasterUserUid = savedInstanceState.getString(KEY_AA_ONE); aaItemMasterPushKey = savedInstanceState.getString(KEY_AA_TWO); qqUserUid = savedInstanceState.getString(KEY_MM_ONE); qqSalesHeaderModel = savedInstanceState.getParcelable(KEY_MM_TWO); qqSalesDetailModelList = savedInstanceState.getParcelableArrayList(KEY_MM_THREE); qqCashPaid = savedInstanceState.getString(KEY_MM_FOUR); qqChangeCash = savedInstanceState.getString(KEY_MM_FIVE); } }
From source file:io.development.tymo.adapters.FeedZoomMoreAdapter.java
@Override public void onBindViewHolder(SimpleViewHolder holder, int position) { ActivityServer feedCubeModel;/*from w w w . j a v a 2s . c o m*/ FlagServer feedFlagModel; holder.adapter = new PersonSmallAdapter(listPeople.get(position), mContext); holder.recyclerView.setAdapter(holder.adapter); if (mItems.get(position) instanceof ActivityServer) { holder.textDescription.setVisibility(View.VISIBLE); holder.cubeLowerBox.setVisibility(View.VISIBLE); holder.locationBox.setVisibility(View.VISIBLE); holder.pieceIcon.setVisibility(View.VISIBLE); holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE); holder.cubeLowerBoxIcon.setVisibility(View.VISIBLE); feedCubeModel = (ActivityServer) mItems.get(position); holder.textTitle.setText(feedCubeModel.getTitle()); holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.grey_900)); holder.textDescription.setText(feedCubeModel.getTitle()); if (feedCubeModel.getDescription() != null && !feedCubeModel.getDescription().matches("")) holder.textDescription.setText(feedCubeModel.getDescription()); else holder.textDescription.setVisibility(View.GONE); holder.cubeLowerBox.setVisibility(View.VISIBLE); holder.cubeUpperBoxIcon.setVisibility(View.VISIBLE); holder.flagButton.setVisibility(View.GONE); holder.cubeUpperBoxIcon.setColorFilter(feedCubeModel.getCubeColorUpper()); holder.cubeLowerBoxIcon.setColorFilter(feedCubeModel.getCubeColor()); Glide.clear(holder.pieceIcon); Glide.with(mContext).load(feedCubeModel.getCubeIcon()).asBitmap() .diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.pieceIcon); Calendar calendar = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar.set(feedCubeModel.getYearStart(), feedCubeModel.getMonthStart() - 1, feedCubeModel.getDayStart()); calendar2.set(feedCubeModel.getYearEnd(), feedCubeModel.getMonthEnd() - 1, feedCubeModel.getDayEnd()); String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK), calendar); String dayStart = String.format("%02d", feedCubeModel.getDayStart()); String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar.getTime().getTime()); int yearStart = feedCubeModel.getYearStart(); String hourStart = String.format("%02d", feedCubeModel.getHourStart()); String minuteStart = String.format("%02d", feedCubeModel.getMinuteStart()); String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK), calendar2); String dayEnd = String.format("%02d", feedCubeModel.getDayEnd()); String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar2.getTime().getTime()); int yearEnd = feedCubeModel.getYearEnd(); String hourEnd = String.format("%02d", feedCubeModel.getHourEnd()); String minuteEnd = String.format("%02d", feedCubeModel.getMinuteEnd()); if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) { if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) { holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart)); } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd)); } } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd, yearEnd, hourEnd, minuteEnd)); } if (!feedCubeModel.getLocation().matches("")) { SharedPreferences mSharedPreferences = mContext.getSharedPreferences(Constants.USER_CREDENTIALS, MODE_PRIVATE); boolean location = mSharedPreferences.getBoolean(Constants.LOCATION, true); if (location) { LocationManager manager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && lat != -500 && (feedCubeModel.getLat() != 0 && feedCubeModel.getLng() != 0)) { double distance = Utilities.distance(lat, lng, feedCubeModel.getLat(), feedCubeModel.getLng()); if (distance < 1) { distanceText = mContext.getResources().getString(R.string.distance_meters, (int) (distance * 1000)) + " "; } else { distanceText = mContext.getResources().getString(R.string.distance_km, (int) distance) + " "; } } else distanceText = ""; } else distanceText = ""; if (!distanceText.matches("")) { final SpannableStringBuilder sb = new SpannableStringBuilder( distanceText + feedCubeModel.getLocation()); final StyleSpan styleBold = new StyleSpan(Typeface.BOLD); sb.setSpan(styleBold, 0, distanceText.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); holder.location.setText(sb); } else { holder.location.setText(feedCubeModel.getLocation()); } } else { holder.locationBox.setVisibility(View.GONE); distanceText = ""; } if (!feedCubeModel.getUser().getPhoto().matches("")) { Glide.clear(holder.photoCreator); Glide.with(mContext).load(feedCubeModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new BitmapImageViewTarget(holder.photoCreator) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.photoCreator.setImageDrawable(circularBitmapDrawable); } }); } else holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty); if (feedCubeModel.getFavoriteCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more); } else if (feedCubeModel.getKnowCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more); } else if (feedCubeModel.getUser().getEmail().equals(email)) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more); } else { holder.photoCreatorRingBox.setVisibility(View.INVISIBLE); } } else { feedFlagModel = (FlagServer) mItems.get(position); holder.textTitle.setText(mContext.getResources().getString(R.string.flag_available)); holder.textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.flag_available)); if (feedFlagModel.getTitle().matches("")) { holder.textDescription.setVisibility(View.GONE); } else { holder.textDescription.setText(feedFlagModel.getTitle()); } holder.cubeLowerBox.setVisibility(View.GONE); holder.cubeUpperBoxIcon.setVisibility(View.GONE); holder.flagButton.setVisibility(View.VISIBLE); holder.locationBox.setVisibility(View.GONE); Calendar calendar = Calendar.getInstance(); Calendar calendar2 = Calendar.getInstance(); calendar.set(feedFlagModel.getYearStart(), feedFlagModel.getMonthStart() - 1, feedFlagModel.getDayStart()); calendar2.set(feedFlagModel.getYearEnd(), feedFlagModel.getMonthEnd() - 1, feedFlagModel.getDayEnd()); String dayOfWeekStart = dateFormat.todayTomorrowYesterdayCheck(calendar.get(Calendar.DAY_OF_WEEK), calendar); String dayStart = String.format("%02d", feedFlagModel.getDayStart()); String monthStart = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar.getTime().getTime()); int yearStart = feedFlagModel.getYearStart(); String hourStart = String.format("%02d", feedFlagModel.getHourStart()); String minuteStart = String.format("%02d", feedFlagModel.getMinuteStart()); String dayOfWeekEnd = dateFormat.todayTomorrowYesterdayCheck(calendar2.get(Calendar.DAY_OF_WEEK), calendar2); String dayEnd = String.format("%02d", feedFlagModel.getDayEnd()); String monthEnd = new SimpleDateFormat("MM", mContext.getResources().getConfiguration().locale) .format(calendar2.getTime().getTime()); int yearEnd = feedFlagModel.getYearEnd(); String hourEnd = String.format("%02d", feedFlagModel.getHourEnd()); String minuteEnd = String.format("%02d", feedFlagModel.getMinuteEnd()); if (calendar.get(Calendar.DATE) == calendar2.get(Calendar.DATE)) { if (hourStart.matches(hourEnd) && minuteStart.matches(minuteEnd)) { holder.date.setText(mContext.getResources().getString(R.string.date_format_04, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart)); } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_05, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, hourEnd, minuteEnd)); } } else { holder.date.setText(mContext.getResources().getString(R.string.date_format_06, dayOfWeekStart, dayStart, monthStart, yearStart, hourStart, minuteStart, dayOfWeekEnd, dayEnd, monthEnd, yearEnd, hourEnd, minuteEnd)); } if (!feedFlagModel.getUser().getPhoto().matches("")) { Glide.clear(holder.photoCreator); Glide.with(mContext).load(feedFlagModel.getUser().getPhoto()).asBitmap().thumbnail(0.1f) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(new BitmapImageViewTarget(holder.photoCreator) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(mContext.getResources(), resource); circularBitmapDrawable.setCircular(true); holder.photoCreator.setImageDrawable(circularBitmapDrawable); } }); } else holder.photoCreator.setImageResource(R.drawable.ic_profile_photo_empty); if (feedFlagModel.getFavoriteCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_favorite_zoom_more); } else if (feedFlagModel.getKnowCreator() > 0) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_my_contact_zoom_more); } else if (feedFlagModel.getUser().getEmail().equals(email)) { holder.photoCreatorRingBox.setVisibility(View.VISIBLE); holder.photoCreatorRing.setBackgroundResource(R.drawable.bg_shape_ring_you_zoom_more); } else { holder.photoCreatorRingBox.setVisibility(View.INVISIBLE); } } if (holder.flagButton.getVisibility() == View.VISIBLE) { holder.pieceBox.startAnimation(animation2); } else { holder.pieceBox.startAnimation(animation2); } holder.textBox.startAnimation(animation); holder.triangle.startAnimation(animation); }
From source file:com.android.mms.ui.MessageListItem.java
@Override public void setImage(String name, Bitmap bitmap) { showMmsView(true);// w w w.j av a 2 s . c o m try { RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); drawable.setCornerRadius(MmsConfig.getMmsCornerRadius()); mImageView.setImageDrawable(drawable); mImageView.setVisibility(VISIBLE); } catch (java.lang.OutOfMemoryError e) { Log.e(TAG, "setImage: out of memory: ", e); } }
From source file:com.android.incallui.CallCardFragment.java
/** * Set all the ImageViews to the same photo. Currently there are 2 photo views: the large one * (which fills about the bottom half of the screen) and the small one, which displays as a * circle next to the primary contact info. This method does not handle whether the ImageView * is shown or not.// w w w . jav a 2 s .co m * * @param photo The photo to set for the image views. */ private void setDrawableToImageViews(Drawable photo) { if (photo == null) { photo = ContactInfoCache.getInstance(getView().getContext()).getDefaultContactPhotoDrawable(); } if (mPrimaryPhotoDrawable == photo) { return; } mPrimaryPhotoDrawable = photo; mPhotoLarge.setImageDrawable(photo); // Modify the drawable to be round for the smaller ImageView. Bitmap bitmap = drawableToBitmap(photo); if (bitmap != null) { final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); drawable.setAntiAlias(true); drawable.setCornerRadius(bitmap.getHeight() / 2); photo = drawable; } mPhotoSmall.setImageDrawable(photo); }
From source file:com.android.contacts.common.ContactPhotoManager.java
/** * Given a bitmap, returns a drawable that is configured to display the bitmap based on the * specified request./* w ww . j av a 2 s . c o m*/ */ private Drawable getDrawableForBitmap(Resources resources, Bitmap bitmap, Request request) { if (request.mIsCircular) { final RoundedBitmapDrawable drawable = RoundedBitmapDrawableFactory.create(resources, bitmap); drawable.setAntiAlias(true); drawable.setCornerRadius(bitmap.getHeight() / 2); return drawable; } else { return new BitmapDrawable(resources, bitmap); } }
From source file:com.yk.notification.util.BitmapUtil.java
/** * //from w w w. j av a2 s . c om * @param bitmap * @return */ public static Bitmap createRoundImageWithBorder(Context context, Bitmap bitmap) { // int bitmapWidth = bitmap.getWidth(); // int bitmapHeight = bitmap.getHeight(); // pixel int borderWidthHalf = 20; //?? int bitmapSquareWidth = Math.min(bitmapWidth, bitmapHeight); //? int newBitmapSquareWidth = bitmapSquareWidth + borderWidthHalf; Bitmap roundedBitmap = Bitmap.createBitmap(newBitmapSquareWidth, newBitmapSquareWidth, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(roundedBitmap); int x = borderWidthHalf + bitmapSquareWidth - bitmapWidth; int y = borderWidthHalf + bitmapSquareWidth - bitmapHeight; //???,?X,Y?2 ?? canvas.drawBitmap(bitmap, x / 2, y / 2, null); Paint borderPaint = new Paint(); borderPaint.setStyle(Paint.Style.STROKE); borderPaint.setStrokeWidth(borderWidthHalf); borderPaint.setColor(Color.WHITE); // canvas.drawCircle(canvas.getWidth() / 2, canvas.getWidth() / 2, newBitmapSquareWidth / 2, borderPaint); RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(context.getResources(), roundedBitmap); roundedBitmapDrawable.setGravity(Gravity.CENTER); roundedBitmapDrawable.setCircular(true); return getBitmapFromDrawable(roundedBitmapDrawable); }