示例#1
0
  public MsgDetailReadWorker(WeiboDetailImageView view, MessageBean msg) {
    this.view = view;
    this.pb = this.view.getProgressBar();
    this.msg = msg;
    this.retry = view.getRetryButton();
    retry.setVisibility(View.INVISIBLE);

    oriPath =
        FileManager.getFilePathFromUrl(msg.getOriginal_pic(), FileLocationMethod.picture_large);

    if (ImageUtility.isThisBitmapCanRead(oriPath)
        && TaskCache.isThisUrlTaskFinished(msg.getOriginal_pic())) {

      onPostExecute(oriPath);
      cancel(true);
      return;
    }

    middlePath =
        FileManager.getFilePathFromUrl(msg.getBmiddle_pic(), FileLocationMethod.picture_bmiddle);

    if (ImageUtility.isThisBitmapCanRead(middlePath)
        && TaskCache.isThisUrlTaskFinished(msg.getBmiddle_pic())) {
      onPostExecute(middlePath);
      cancel(true);
      return;
    }

    pb.setVisibility(View.VISIBLE);
    pb.setIndeterminate(true);
  }
示例#2
0
  private void readNormalPic(String path) {

    Bitmap bitmap = ImageUtility.readNormalPic(path, 2000, 2000);

    view.setTag(true);
    view.getImageView().setTag(true);
    view.setVisibility(View.VISIBLE);
    view.setImageBitmap(bitmap);
    view.setAlpha(0.0f);
    view.animate().alpha(1.0f).setDuration(200);
  }
    @Override
    public Boolean call() throws Exception {
      synchronized (TimeLineBitmapDownloader.pauseDownloadWorkLock) {
        while (TimeLineBitmapDownloader.pauseDownloadWork
            && !Thread.currentThread().isInterrupted()) {
          try {
            TimeLineBitmapDownloader.pauseDownloadWorkLock.wait();
          } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
          }
        }
      }
      String filePath = FileManager.generateDownloadFileName(url);

      String actualDownloadUrl = url;

      switch (method) {
        case picture_thumbnail:
          actualDownloadUrl = url.replace("thumbnail", "webp180");
          break;
        case picture_bmiddle:
          actualDownloadUrl = url.replace("bmiddle", "webp720");
          break;
        case picture_large:
          actualDownloadUrl = url.replace("large", "woriginal");
          break;
      }

      boolean result =
          ImageUtility.getBitmapFromNetWork(
              actualDownloadUrl,
              filePath,
              new FileDownloaderHttpHelper.DownloadListener() {
                @Override
                public void pushProgress(int progress, int max) {
                  JobCallable.this.progress = progress;
                  JobCallable.this.max = max;
                  for (FileDownloaderHttpHelper.DownloadListener downloadListener :
                      downloadListenerList) {
                    if (downloadListener != null) {
                      downloadListener.pushProgress(progress, max);
                    }
                  }
                }
              });

      if (result) {
        DownloadPicturesDBTask.add(
            this.url, FileManager.generateDownloadFileName(this.url), this.method);
      }

      TaskCache.removeDownloadTask(url, futureTask);
      return result;
    }
示例#4
0
  private void displayBitmap(Bitmap bitmap) {

    ImageView imageView = viewWeakReference.get();
    if (!isMySelf(imageView)) {
      return;
    }

    if (pbWeakReference != null) {
      ProgressBar pb = pbWeakReference.get();
      if (pb != null) {
        pb.setVisibility(View.INVISIBLE);
      }
    }

    if (bitmap != null) {
      if (IWeiciyuanDrawable != null) {
        IWeiciyuanDrawable.setGifFlag(ImageUtility.isThisPictureGif(getUrl()));
      }
      playImageViewAnimation(imageView, bitmap);
      GlobalContext.getInstance().getBitmapCache().put(data, bitmap);
    } else {
      imageView.setImageDrawable(new ColorDrawable(DebugColor.READ_FAILED));
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.gallery_general_layout, container, false);

    photoView = (PhotoView) view.findViewById(R.id.animation);

    if (SettingUtility.allowClickToCloseGallery()) {

      photoView.setOnViewTapListener(
          new PhotoViewAttacher.OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
              getActivity().onBackPressed();
            }
          });
    }

    LongClickListener longClickListener =
        ((ContainerFragment) getParentFragment()).getLongClickListener();
    photoView.setOnLongClickListener(longClickListener);

    final String path = getArguments().getString("path");
    boolean animateIn = getArguments().getBoolean("animationIn");
    final AnimationRect rect = getArguments().getParcelable("rect");

    if (!animateIn) {

      new MyAsyncTask<Void, Bitmap, Bitmap>() {

        @Override
        protected Bitmap doInBackground(Void... params) {
          Bitmap bitmap =
              ImageUtility.decodeBitmapFromSDCard(
                  path, IMAGEVIEW_SOFT_LAYER_MAX_WIDTH, IMAGEVIEW_SOFT_LAYER_MAX_HEIGHT);
          return bitmap;
        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
          super.onPostExecute(bitmap);
          photoView.setImageBitmap(bitmap);
        }
      }.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);

      return view;
    }

    final Bitmap bitmap =
        ImageUtility.decodeBitmapFromSDCard(
            path, IMAGEVIEW_SOFT_LAYER_MAX_WIDTH, IMAGEVIEW_SOFT_LAYER_MAX_HEIGHT);

    photoView.setImageBitmap(bitmap);

    final Runnable endAction =
        new Runnable() {
          @Override
          public void run() {
            Bundle bundle = getArguments();
            bundle.putBoolean("animationIn", false);
          }
        };

    photoView
        .getViewTreeObserver()
        .addOnPreDrawListener(
            new ViewTreeObserver.OnPreDrawListener() {
              @Override
              public boolean onPreDraw() {

                if (rect == null) {
                  photoView.getViewTreeObserver().removeOnPreDrawListener(this);
                  return true;
                }

                final Rect startBounds = new Rect(rect.scaledBitmapRect);
                final Rect finalBounds = AnimationUtility.getBitmapRectFromImageView(photoView);

                if (finalBounds == null) {
                  photoView.getViewTreeObserver().removeOnPreDrawListener(this);
                  return true;
                }

                float startScale = (float) finalBounds.width() / startBounds.width();

                if (startScale * startBounds.height() > finalBounds.height()) {
                  startScale = (float) finalBounds.height() / startBounds.height();
                }

                int deltaTop = startBounds.top - finalBounds.top;
                int deltaLeft = startBounds.left - finalBounds.left;

                photoView.setPivotY((photoView.getHeight() - finalBounds.height()) / 2);
                photoView.setPivotX((photoView.getWidth() - finalBounds.width()) / 2);

                photoView.setScaleX(1 / startScale);
                photoView.setScaleY(1 / startScale);

                photoView.setTranslationX(deltaLeft);
                photoView.setTranslationY(deltaTop);

                photoView
                    .animate()
                    .translationY(0)
                    .translationX(0)
                    .scaleY(1)
                    .scaleX(1)
                    .setDuration(ANIMATION_DURATION)
                    .setInterpolator(new AccelerateDecelerateInterpolator())
                    .withEndAction(endAction);

                AnimatorSet animationSet = new AnimatorSet();
                animationSet.setDuration(ANIMATION_DURATION);
                animationSet.setInterpolator(new AccelerateDecelerateInterpolator());

                animationSet.playTogether(
                    ObjectAnimator.ofFloat(
                        photoView,
                        "clipBottom",
                        AnimationRect.getClipBottom(rect, finalBounds),
                        0));
                animationSet.playTogether(
                    ObjectAnimator.ofFloat(
                        photoView, "clipRight", AnimationRect.getClipRight(rect, finalBounds), 0));
                animationSet.playTogether(
                    ObjectAnimator.ofFloat(
                        photoView, "clipTop", AnimationRect.getClipTop(rect, finalBounds), 0));
                animationSet.playTogether(
                    ObjectAnimator.ofFloat(
                        photoView, "clipLeft", AnimationRect.getClipLeft(rect, finalBounds), 0));

                animationSet.start();

                photoView.getViewTreeObserver().removeOnPreDrawListener(this);
                return true;
              }
            });

    return view;
  }
  private void buildNotification(String uid) {

    final ValueWrapper valueWrapper = valueBagHashMap.get(uid);

    if (valueWrapper == null) {
      return;
    }

    final AccountBean accountBean = valueWrapper.accountBean;

    final MessageListBean mentionsWeibo = valueWrapper.mentionsWeibo;

    final CommentListBean mentionsComment = valueWrapper.mentionsComment;

    final CommentListBean commentsToMe = valueWrapper.commentsToMe;

    final UnreadBean unreadBean = valueWrapper.unreadBean;

    int currentIndex = valueWrapper.currentIndex;

    Intent clickToOpenAppPendingIntentInner = valueWrapper.clickToOpenAppPendingIntentInner;

    String ticker = valueWrapper.ticker;

    ArrayList<Parcelable> notificationItems = valueWrapper.notificationItems;

    //        int count = Math.min(unreadBean.getMention_status(), data.getSize());

    int count = notificationItems.size();

    if (count == 0) {
      return;
    }

    Parcelable itemBean = notificationItems.get(currentIndex);

    Notification.Builder builder =
        new Notification.Builder(getBaseContext())
            .setTicker(ticker)
            .setContentText(ticker)
            .setSubText(accountBean.getUsernick())
            .setSmallIcon(R.drawable.ic_notification)
            .setAutoCancel(true)
            .setContentIntent(
                getPendingIntent(clickToOpenAppPendingIntentInner, itemBean, accountBean))
            .setOnlyAlertOnce(true);

    builder.setContentTitle(getString(R.string.app_name));

    if (count > 1) {
      builder.setNumber(count);
    }

    Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
        GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver);

    valueWrapper.clearNotificationEventReceiver =
        new RecordOperationAppBroadcastReceiver() {

          // mark these messages as read, write to database
          @Override
          public void onReceive(Context context, Intent intent) {
            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        try {
                          ArrayList<String> ids = new ArrayList<String>();

                          if (mentionsWeibo != null) {
                            for (MessageBean msg : mentionsWeibo.getItemList()) {
                              ids.add(msg.getId());
                            }

                            NotificationDBTask.addUnreadNotification(
                                accountBean.getUid(),
                                ids,
                                NotificationDBTask.UnreadDBType.mentionsWeibo);
                          }

                          ids.clear();

                          if (commentsToMe != null) {

                            for (CommentBean msg : commentsToMe.getItemList()) {
                              ids.add(msg.getId());
                            }

                            NotificationDBTask.addUnreadNotification(
                                accountBean.getUid(),
                                ids,
                                NotificationDBTask.UnreadDBType.commentsToMe);
                          }
                          ids.clear();
                          if (mentionsComment != null) {
                            for (CommentBean msg : mentionsComment.getItemList()) {
                              ids.add(msg.getId());
                            }

                            NotificationDBTask.addUnreadNotification(
                                accountBean.getUid(),
                                ids,
                                NotificationDBTask.UnreadDBType.mentionsComment);
                          }
                        } finally {
                          Utility.unregisterReceiverIgnoredReceiverNotRegisteredException(
                              GlobalContext.getInstance(),
                              valueWrapper.clearNotificationEventReceiver);
                          if (Utility.isDebugMode()) {

                            new Handler(Looper.getMainLooper())
                                .post(
                                    new Runnable() {
                                      @Override
                                      public void run() {
                                        Toast.makeText(
                                                getApplicationContext(),
                                                "weiciyuan:remove notification items"
                                                    + System.currentTimeMillis(),
                                                Toast.LENGTH_SHORT)
                                            .show();
                                      }
                                    });
                          }
                        }
                      }
                    })
                .start();
          }
        };

    IntentFilter intentFilter = new IntentFilter(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    Utility.registerReceiverIgnoredReceiverHasRegisteredHereException(
        GlobalContext.getInstance(), valueWrapper.clearNotificationEventReceiver, intentFilter);

    Intent broadcastIntent = new Intent(RESET_UNREAD_MENTIONS_WEIBO_ACTION);

    PendingIntent deletedPendingIntent =
        PendingIntent.getBroadcast(
            GlobalContext.getInstance(),
            accountBean.getUid().hashCode(),
            broadcastIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(deletedPendingIntent);

    if (itemBean instanceof MessageBean) {
      MessageBean msg = (MessageBean) itemBean;
      Intent intent =
          WriteCommentActivity.newIntentFromNotification(getApplicationContext(), accountBean, msg);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(
          R.drawable.comment_light,
          getApplicationContext().getString(R.string.comments),
          pendingIntent);
    } else if (itemBean instanceof CommentBean) {
      CommentBean commentBean = (CommentBean) itemBean;
      Intent intent =
          WriteReplyToCommentActivity.newIntentFromNotification(
              getApplicationContext(), accountBean, commentBean);
      PendingIntent pendingIntent =
          PendingIntent.getActivity(
              getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(
          R.drawable.reply_to_comment_light,
          getApplicationContext().getString(R.string.reply_to_comment),
          pendingIntent);
    }

    String avatar = ((ItemBean) itemBean).getUser().getAvatar_large();
    String avatarPath = FileManager.getFilePathFromUrl(avatar, FileLocationMethod.avatar_large);
    if (ImageUtility.isThisBitmapCanRead(avatarPath) && TaskCache.isThisUrlTaskFinished(avatar)) {
      Bitmap bitmap = BitmapFactory.decodeFile(avatarPath, new BitmapFactory.Options());
      if (bitmap != null) {
        builder.setLargeIcon(bitmap);
      }
    }

    if (count > 1) {

      String actionName;
      int nextIndex;
      int actionDrawable;
      if (currentIndex < count - 1) {
        nextIndex = currentIndex + 1;
        actionName = getString(R.string.next_message);
        actionDrawable = R.drawable.notification_action_next;
      } else {
        nextIndex = 0;
        actionName = getString(R.string.first_message);
        actionDrawable = R.drawable.notification_action_previous;
      }
      Intent nextIntent =
          BigTextNotificationService.newIntent(
              accountBean,
              mentionsWeibo,
              commentsToMe,
              mentionsComment,
              unreadBean,
              clickToOpenAppPendingIntentInner,
              ticker,
              nextIndex);
      PendingIntent retrySendIntent =
          PendingIntent.getService(
              BigTextNotificationService.this,
              accountBean.getUid().hashCode(),
              nextIntent,
              PendingIntent.FLAG_UPDATE_CURRENT);
      builder.addAction(actionDrawable, actionName, retrySendIntent);
    }

    Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(builder);
    bigTextStyle.setBigContentTitle(
        getItemBigContentTitle(accountBean, notificationItems, currentIndex));
    bigTextStyle.bigText(getItemBigText(notificationItems, currentIndex));
    String summaryText;
    if (count > 1) {
      summaryText = accountBean.getUsernick() + "(" + (currentIndex + 1) + "/" + count + ")";
    } else {
      summaryText = accountBean.getUsernick();
    }
    bigTextStyle.setSummaryText(summaryText);

    builder.setStyle(bigTextStyle);
    Utility.configVibrateLedRingTone(builder);

    NotificationManager notificationManager =
        (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(getMentionsWeiboNotificationId(accountBean), builder.build());
  }
示例#7
0
  @Override
  protected Bitmap doInBackground(String... url) {

    String path = FileManager.getFilePathFromUrl(data, method);

    int height = 0;
    int width = 0;

    switch (method) {
      case avatar_small:
      case avatar_large:
        width =
            GlobalContext.getInstance()
                    .getResources()
                    .getDimensionPixelSize(R.dimen.timeline_avatar_width)
                - Utility.dip2px(5) * 2;
        height =
            GlobalContext.getInstance()
                    .getResources()
                    .getDimensionPixelSize(R.dimen.timeline_avatar_height)
                - Utility.dip2px(5) * 2;
        break;

      case picture_thumbnail:
        width =
            GlobalContext.getInstance()
                .getResources()
                .getDimensionPixelSize(R.dimen.timeline_pic_thumbnail_width);
        height =
            GlobalContext.getInstance()
                .getResources()
                .getDimensionPixelSize(R.dimen.timeline_pic_thumbnail_height);
        break;

      case picture_large:
      case picture_bmiddle:
        if (!isMultiPictures) {
          DisplayMetrics metrics = GlobalContext.getInstance().getDisplayMetrics();

          float reSize = GlobalContext.getInstance().getResources().getDisplayMetrics().density;

          height =
              GlobalContext.getInstance()
                  .getResources()
                  .getDimensionPixelSize(R.dimen.timeline_pic_high_thumbnail_height);
          // 8 is  layout padding
          width = (int) (metrics.widthPixels - (8 + 8) * reSize);
        } else {
          height = width = Utility.dip2px(120);
        }
        break;
    }

    Bitmap bitmap;

    switch (method) {
      case avatar_small:
      case avatar_large:
        bitmap = ImageUtility.getRoundedCornerPic(path, width, height, Utility.dip2px(2));
        break;
      default:
        bitmap = ImageUtility.getRoundedCornerPic(path, width, height, 0);
        break;
    }

    return bitmap;
  }