Exemplo n.º 1
0
  @Override
  @TargetApi(21)
  protected Drawable doInBackground(Void... voids) {
    // contact photo
    Uri contactUri = null;
    if (contactId > 0) {
      final Cursor cursorWithContact =
          context
              .getContentResolver()
              .query(
                  Uri.withAppendedPath(SPOCContentProvider.CONTACTS_URI, String.valueOf(contactId)),
                  new String[] {Contact.COLUMN_CONTACT_KEY},
                  null,
                  null,
                  null);
      if (cursorWithContact.moveToFirst()) {
        contactUri =
            Uri.withAppendedPath(
                ContactsContract.Contacts.CONTENT_LOOKUP_URI, cursorWithContact.getString(0));
      }
      cursorWithContact.close();
    } else if (lookupKey != null) {
      contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
    }

    if (contactUri == null) {
      return null;
    }

    final InputStream inputStream =
        ContactsContract.Contacts.openContactPhotoInputStream(
            context.getContentResolver(), contactUri);

    RoundedBitmapDrawable roundedBitmapDrawable;
    if (inputStream != null) {
      roundedBitmapDrawable =
          RoundedBitmapDrawableFactory.create(context.getResources(), inputStream);
      roundedBitmapDrawable.setCircular(true);
      return roundedBitmapDrawable;
    }

    if (Build.VERSION.SDK_INT >= 21) {
      return context.getResources().getDrawable(R.drawable.user, context.getTheme());
    } else {
      //noinspection deprecation
      return context.getResources().getDrawable(R.drawable.user);
    }
  }
  private void testBadgeView() {
    mTestBv.showTextBadge("9");
    mTestBv.getBadgeViewHelper().setBadgeTextSizeSp(15);
    mTestBv.getBadgeViewHelper().setBadgePaddingDp(8);
    mTestBv.getBadgeViewHelper().setBadgeTextColorInt(Color.parseColor("#FF0000"));
    mTestBv.getBadgeViewHelper().setBadgeBgColorInt(Color.parseColor("#00FF00"));
    mTestBv.getBadgeViewHelper().setDragable(true);
    mTestBv.getBadgeViewHelper().setBadgePaddingDp(7);
    mTestBv.getBadgeViewHelper().setBadgeBorderWidthDp(2);
    mTestBv.getBadgeViewHelper().setBadgeBorderColorInt(Color.parseColor("#0000FF"));

    mTestBtv.showCirclePointBadge();

    mNormalBiv.showCirclePointBadge();

    Bitmap avatorBadgeBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.avatar_vip);

    RoundedBitmapDrawable roundedDrawable =
        RoundedBitmapDrawableFactory.create(
            getResources(), BitmapFactory.decodeResource(getResources(), R.mipmap.avator));
    roundedDrawable.getPaint().setAntiAlias(true);
    roundedDrawable.setCornerRadius(30);
    mRoundedBiv.setImageDrawable(roundedDrawable);
    mRoundedBiv.showDrawableBadge(avatorBadgeBitmap);

    Bitmap avatorBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.avator);
    RoundedBitmapDrawable circleDrawable =
        RoundedBitmapDrawableFactory.create(getResources(), avatorBitmap);
    circleDrawable.getPaint().setAntiAlias(true);
    circleDrawable.setCornerRadius(
        Math.max(avatorBitmap.getWidth(), avatorBitmap.getHeight()) / 2.0f);
    mCircleBiv.setImageDrawable(circleDrawable);
    mCircleBiv.showDrawableBadge(avatorBadgeBitmap);

    mTestBll.showDrawableBadge(avatorBadgeBitmap);
    mTestBrl.showTextBadge("LoveAndroid");
    mTestBfl.showTextBadge("8");

    mChatBfab.showTextBadge("8");
    mChatBfab.setDragDismissDelegage(
        new BGADragDismissDelegate() {
          @Override
          public void onDismiss(BGABadgeable badgeable) {
            ToastUtil.show("清空聊天消息");
          }
        });

    new Handler()
        .postDelayed(
            new Runnable() {
              @Override
              public void run() {
                mRoundedBiv.hiddenBadge();
              }
            },
            3000);

    new Handler()
        .postDelayed(
            new Runnable() {
              @Override
              public void run() {
                mRoundedBiv.showCirclePointBadge();
              }
            },
            6000);

    new Handler()
        .postDelayed(
            new Runnable() {
              @Override
              public void run() {
                mRoundedBiv.showDrawableBadge(
                    BitmapFactory.decodeResource(getResources(), R.mipmap.avatar_vip));
              }
            },
            9000);
  }