예제 #1
0
 private void startDownloadingOtherPicturesOnWifiNetworkEnvironment() {
   if (backgroundWifiDownloadPicThread == null
       && Utility.isWifi(getActivity())
       && SettingUtility.getEnableBigPic()
       && SettingUtility.isWifiAutoDownloadPic()) {
     final int position = getListView().getFirstVisiblePosition();
     int listVewOrientation = ((VelocityListView) getListView()).getTowardsOrientation();
     WifiAutoDownloadPictureRunnable runnable =
         new WifiAutoDownloadPictureRunnable(getList(), position, listVewOrientation);
     backgroundWifiDownloadPicThread = new Thread(runnable);
     backgroundWifiDownloadPicThread.start();
     AppLogger.i(
         "WifiAutoDownloadPictureRunnable startDownloadingOtherPicturesOnWifiNetworkEnvironment");
   }
 }
예제 #2
0
  public static Bitmap getMiddlePictureInBrowserMSGActivity(
      String url, FileDownloaderHttpHelper.DownloadListener downloadListener) {

    String absoluteFilePath =
        FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_bmiddle);

    File file = new File(absoluteFilePath);

    if (!file.exists() && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (!file.exists()) {
      getBitmapFromNetWork(url, absoluteFilePath, downloadListener);
    }
    file = new File(absoluteFilePath);
    if (file.exists()) {
      DisplayMetrics displayMetrics = GlobalContext.getInstance().getDisplayMetrics();

      Bitmap bitmap =
          decodeBitmapFromSDCard(
              absoluteFilePath, displayMetrics.widthPixels, displayMetrics.heightPixels);
      return bitmap;
    }
    return null;
  }
예제 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setTitle(getString(R.string.filter));

    View title = getLayoutInflater().inflate(R.layout.filteractivity_title_layout, null);
    Switch switchBtn = (Switch) title.findViewById(R.id.switchBtn);
    getActionBar().setCustomView(title, new ActionBar.LayoutParams(Gravity.RIGHT));
    getActionBar().setDisplayShowCustomEnabled(true);

    switchBtn.setChecked(SettingUtility.isEnableFilter());
    switchBtn.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingUtility.setEnableFilter(isChecked);
          }
        });

    if (savedInstanceState == null) {
      getFragmentManager()
          .beginTransaction()
          .replace(android.R.id.content, new FilterFragment())
          .commit();
    }
  }
예제 #4
0
  public static Bitmap getMiddlePictureInBrowserMSGActivity(
      String url, FileDownloaderHttpHelper.DownloadListener downloadListener) {

    try {

      String filePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_bmiddle);

      File file = new File(filePath);

      if (!file.exists() && !SettingUtility.isEnablePic()) {
        return null;
      }

      if (!file.exists()) {
        getBitmapFromNetWork(url, filePath, downloadListener);
      }
      file = new File(filePath);
      if (file.exists()) {
        DisplayMetrics displayMetrics = GlobalContext.getInstance().getDisplayMetrics();
        return decodeBitmapFromSDCard(filePath, displayMetrics.widthPixels, 900);
      }
      return null;
    } catch (OutOfMemoryError ignored) {
      return null;
    }
  }
예제 #5
0
  public static Bitmap getSmallAvatarWithRoundedCorner(String url, int reqWidth, int reqHeight) {

    if (!FileManager.isExternalStorageMounted()) {
      return null;
    }

    String absoluteFilePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.avatar_small);
    absoluteFilePath = absoluteFilePath + ".jpg";

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath);

    if (bitmap == null && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (bitmap == null) {
      boolean result = getBitmapFromNetWork(url, absoluteFilePath, null);
      if (result) bitmap = BitmapFactory.decodeFile(absoluteFilePath);
    }

    if (bitmap != null) {
      if (bitmap.getHeight() < reqHeight || bitmap.getWidth() < reqWidth) {
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
        Bitmap roundedBitmap = ImageEdit.getRoundedCornerBitmap(scaledBitmap);
        bitmap.recycle();
        scaledBitmap.recycle();
        return roundedBitmap;
      }
    }

    return null;
  }
예제 #6
0
    @Override
    public void run() {
      if (!SettingUtility.getEnableAutoRefresh()) {
        return;
      }

      if (!Utility.isTaskStopped(dbTask)) {
        return;
      }

      if (!allowRefresh()) {
        return;
      }

      if (!Utility.isWifi(getActivity())) {
        return;
      }

      if (isListViewFling()
          || !isVisible()
          || ((MainTimeLineActivity) getActivity()).getSlidingMenu().isMenuShowing()) {
        return;
      }

      Bundle bundle = new Bundle();
      bundle.putBoolean(BundleArgsConstants.SCROLL_TO_TOP, false);
      bundle.putBoolean(BundleArgsConstants.AUTO_REFRESH, true);
      getLoaderManager().restartLoader(NEW_MSG_LOADER_ID, bundle, msgAsyncTaskLoaderCallback);
    }
예제 #7
0
 @Override
 protected void onResumeFragments() {
   super.onResumeFragments();
   if (SettingUtility.isClickToTopTipFirstShow()) {
     ViewTarget target = new ViewTarget(getClickToTopView());
     ShowcaseView.insertShowcaseView(target, this, R.string.tip, R.string.click_to_top_tip);
   }
 }
예제 #8
0
 private void readClipboard() {
   ClipboardManager cm =
       (ClipboardManager) getApplicationContext().getSystemService(Context.CLIPBOARD_SERVICE);
   ClipData cmContent = cm.getPrimaryClip();
   if (cmContent == null) {
     return;
   }
   ClipData.Item item = cmContent.getItemAt(0);
   if (item != null) {
     String url = item.coerceToText(this).toString();
     boolean a =
         !TextUtils.isEmpty(url) && !url.equals(SettingUtility.getLastFoundWeiboAccountLink());
     boolean b = Utility.isWeiboAccountIdLink(url) || Utility.isWeiboAccountDomainLink(url);
     if (a && b) {
       OpenWeiboAccountLinkDialog dialog = new OpenWeiboAccountLinkDialog(url);
       dialog.show(getSupportFragmentManager(), "");
       SettingUtility.setLastFoundWeiboAccountLink(url);
     }
   }
 }
예제 #9
0
 @Override
 public void onResume() {
   super.onResume();
   addRefresh();
   GlobalContext.getInstance().registerForAccountChangeListener(this);
   if (SettingUtility.getEnableAutoRefresh()) {
     this.newMsgTipBar.setType(TopTipBar.Type.ALWAYS);
   } else {
     this.newMsgTipBar.setType(TopTipBar.Type.AUTO);
   }
 }
예제 #10
0
  public static Bitmap getThumbnailPictureWithRoundedCorner(String url) {

    String absoluteFilePath =
        FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_thumbnail);

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath);

    if (bitmap != null) {
      return ImageEdit.getRoundedCornerBitmap(bitmap);
    } else if (SettingUtility.isEnablePic()) {
      getBitmapFromNetWork(url, absoluteFilePath, null);
      bitmap = BitmapFactory.decodeFile(absoluteFilePath);
      if (bitmap != null) return ImageEdit.getRoundedCornerBitmap(bitmap);
    }
    return null;
  }
예제 #11
0
 @Override
 protected void newMsgLoaderSuccessCallback(MessageListBean newValue, Bundle loaderArgs) {
   if (Utility.isAllNotNull(getActivity(), newValue) && newValue.getSize() > 0) {
     if (loaderArgs != null && loaderArgs.getBoolean(BundleArgsConstants.AUTO_REFRESH, false)) {
       addNewDataAndRememberPositionAutoRefresh(newValue);
     } else {
       boolean scrollToTop = SettingUtility.isReadStyleEqualWeibo();
       if (scrollToTop) {
         addNewDataWithoutRememberPosition(newValue);
       } else {
         addNewDataAndRememberPosition(newValue);
       }
     }
     putToGroupDataMemoryCache(currentGroupId, getList());
     FriendsTimeLineDBTask.asyncReplace(getList(), accountBean.getUid(), currentGroupId);
   }
 }
예제 #12
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
      accountBean = savedInstanceState.getParcelable("account");
    } else {
      Intent intent = getIntent();
      accountBean = intent.getParcelableExtra(BundleArgsConstants.ACCOUNT_EXTRA);
    }

    if (accountBean == null) {
      accountBean = GlobalContext.getInstance().getAccountBean();
    }

    GlobalContext.getInstance().setGroup(null);
    GlobalContext.getInstance().setAccountBean(accountBean);
    SettingUtility.setDefaultAccountId(accountBean.getUid());

    buildInterface(savedInstanceState);
  }
예제 #13
0
  public static Bitmap getTimeLineBigAvatarWithRoundedCorner(
      String url, int reqWidth, int reqHeight) {

    if (!FileManager.isExternalStorageMounted()) {
      return null;
    }

    String absoluteFilePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.avatar_large);
    absoluteFilePath = absoluteFilePath + ".jpg";

    boolean fileExist = new File(absoluteFilePath).exists();

    if (!fileExist && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (!fileExist) {
      boolean result = getBitmapFromNetWork(url, absoluteFilePath, null);
      if (!result) return null;
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(absoluteFilePath, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    options.inJustDecodeBounds = false;
    options.inPurgeable = true;
    options.inInputShareable = true;

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath, options);

    if (bitmap != null) {
      Bitmap roundBitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
      bitmap.recycle();
      return roundBitmap;
    }

    return bitmap;
  }
예제 #14
0
  public static Bitmap getBigAvatarWithRoundedCorner(String url) {

    if (!FileManager.isExternalStorageMounted()) {
      return null;
    }

    String absoluteFilePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.avatar_large);
    absoluteFilePath = absoluteFilePath + ".jpg";

    Bitmap bitmap = BitmapFactory.decodeFile(absoluteFilePath);

    if (bitmap == null && SettingUtility.isEnablePic()) {
      getBitmapFromNetWork(url, absoluteFilePath, null);
      bitmap = BitmapFactory.decodeFile(absoluteFilePath);
    }

    if (bitmap != null) {
      bitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
    }

    return bitmap;
  }
예제 #15
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.write_weibo:
       Intent intent = new Intent(getActivity(), WriteWeiboActivity.class);
       intent.putExtra("token", token);
       intent.putExtra("account", accountBean);
       startActivity(intent);
       break;
     case R.id.refresh:
       if (allowRefresh()) {
         getPullToRefreshListView().setRefreshing();
         loadNewMsg();
       }
       break;
     case R.id.switch_theme:
       // make sure activity has saved current left menu position
       ((MainTimeLineActivity) getActivity()).saveNavigationPositionToDB();
       SettingUtility.switchToAnotherTheme();
       ((MainTimeLineActivity) getActivity()).reload();
       break;
   }
   return super.onOptionsItemSelected(item);
 }
예제 #16
0
  public static Bitmap getMiddlePictureInTimeLine(
      String url,
      int reqWidth,
      int reqHeight,
      FileDownloaderHttpHelper.DownloadListener downloadListener) {

    //        int useWidth = 400;
    int useWidth = reqWidth;

    String absoluteFilePath =
        FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_bmiddle);

    File file = new File(absoluteFilePath);

    if (!file.exists() && !SettingUtility.isEnablePic()) {
      return null;
    }

    if (!file.exists()) {
      getBitmapFromNetWork(url, absoluteFilePath, downloadListener);
    }

    if (absoluteFilePath.endsWith(".gif")) {
      return getMiddlePictureInTimeLineGif(absoluteFilePath, reqWidth, reqHeight);
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(absoluteFilePath, options);

    int height = options.outHeight;
    int width = options.outWidth;

    int cutHeight = 0;
    int cutWidth = 0;

    if (height >= reqHeight && width >= useWidth) {
      cutHeight = reqHeight;
      cutWidth = useWidth;

    } else if (height < reqHeight && width >= useWidth) {

      cutHeight = height;
      cutWidth = (useWidth * cutHeight) / reqHeight;

    } else if (height >= reqHeight && width < useWidth) {

      cutWidth = width;
      cutHeight = (reqHeight * cutWidth) / useWidth;

    } else if (height < reqHeight && width < useWidth) {

      float betweenWidth = ((float) useWidth - (float) width) / (float) width;
      float betweenHeight = ((float) reqHeight - (float) height) / (float) height;

      if (betweenWidth > betweenHeight) {
        cutWidth = width;
        cutHeight = (reqHeight * cutWidth) / useWidth;

      } else {
        cutHeight = height;
        cutWidth = (useWidth * cutHeight) / reqHeight;
      }
    }

    if (cutWidth > 0 && cutHeight > 0) {

      int startX = 0;

      if (cutWidth < width) {
        startX = (width - cutWidth) / 2;
      }

      try {
        BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(absoluteFilePath, false);
        if (decoder != null) {
          Bitmap region =
              decoder.decodeRegion(new Rect(startX, 0, startX + cutWidth, cutHeight), null);
          Bitmap scale = null;
          if (region.getHeight() < reqHeight && region.getWidth() < reqWidth) {
            scale = Bitmap.createScaledBitmap(region, reqWidth, reqHeight, true);
          }
          if (scale == null) {
            Bitmap anotherValue = ImageEdit.getRoundedCornerBitmap(region);
            region.recycle();

            return anotherValue;
            //                        return region;
          } else {
            Bitmap anotherValue = ImageEdit.getRoundedCornerBitmap(scale);
            region.recycle();
            scale.recycle();
            return anotherValue;
            //                        return scale;
          }
        }
      } catch (IOException ignored) {
        // do nothing
      }
    }

    return null;
  }
예제 #17
0
  public static Bitmap getRoundedCornerPic(
      String url, int reqWidth, int reqHeight, FileLocationMethod method) {
    try {

      if (!FileManager.isExternalStorageMounted()) {
        return null;
      }

      String filePath = FileManager.getFilePathFromUrl(url, method);
      if (!filePath.endsWith(".jpg") && !filePath.endsWith(".gif")) filePath = filePath + ".jpg";

      boolean fileExist = new File(filePath).exists();

      if (!fileExist && !SettingUtility.isEnablePic()) {
        return null;
      }

      if (!fileExist) {
        boolean result = getBitmapFromNetWork(url, filePath, null);
        if (!result) return null;
      }

      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(filePath, options);

      options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
      options.inJustDecodeBounds = false;
      options.inPurgeable = true;
      options.inInputShareable = true;

      Bitmap bitmap = BitmapFactory.decodeFile(filePath, options);

      if (bitmap == null) {
        // this picture is broken,so delete it
        new File(filePath).delete();
        return null;
      }

      if (bitmap.getHeight() < reqHeight || bitmap.getWidth() < reqWidth) {

        int[] size = calcResize(bitmap.getWidth(), bitmap.getHeight(), reqWidth, reqHeight);
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, size[0], size[1], true);

        if (scaledBitmap != bitmap) {
          bitmap.recycle();
          bitmap = scaledBitmap;
        }

        Bitmap roundedBitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
        if (roundedBitmap != bitmap) {
          bitmap.recycle();
          bitmap = roundedBitmap;
        }
        return bitmap;
      }

      return bitmap;
    } catch (OutOfMemoryError ignored) {
      ignored.printStackTrace();
      return null;
    }
  }
  @Override
  protected void bindViewData(final ViewHolder holder, int position) {
    Drawable drawable = bg.get(holder);
    if (drawable != null) {
      holder.listview_root.setBackgroundDrawable(drawable);
    } else {
      drawable = holder.listview_root.getBackground();
      bg.put(holder, drawable);
    }

    if (listView.getCheckedItemPosition() == position + listView.getHeaderViewsCount()) {
      holder.listview_root.setBackgroundColor(checkedBG);
    }

    final MessageBean msg = bean.get(position);

    UserBean user = msg.getUser();
    if (user != null) {
      holder.username.setVisibility(View.VISIBLE);
      if (!TextUtils.isEmpty(user.getRemark())) {
        holder.username.setText(
            new StringBuilder(user.getScreen_name())
                .append("(")
                .append(user.getRemark())
                .append(")")
                .toString());
      } else {
        holder.username.setText(user.getScreen_name());
      }
      if (!showOriStatus && !SettingUtility.getEnableCommentRepostListAvatar()) {
        holder.avatar.setLayoutParams(new RelativeLayout.LayoutParams(0, 0));
      } else {
        buildAvatar(holder.avatar, position, user);
      }
    } else {
      holder.username.setVisibility(View.INVISIBLE);
      holder.avatar.setVisibility(View.INVISIBLE);
    }

    if (!TextUtils.isEmpty(msg.getListViewSpannableString())) {
      boolean haveCachedHeight = msgHeights.get(msg.getIdLong()) != null;
      ViewGroup.LayoutParams layoutParams = holder.content.getLayoutParams();
      if (haveCachedHeight) {
        layoutParams.height = msgHeights.get(msg.getIdLong());
      } else {
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
      }

      boolean haveCachedWidth = msgWidths.get(msg.getIdLong()) != null;
      if (haveCachedWidth) {
        layoutParams.width = msgWidths.get(msg.getIdLong());
      } else {
        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
      }

      holder.content.requestLayout();
      holder.content.setText(msg.getListViewSpannableString());
      if (!haveCachedHeight) {
        msgHeights.append(msg.getIdLong(), layoutParams.height);
      }

      if (!haveCachedWidth) {
        msgWidths.append(msg.getIdLong(), layoutParams.width);
      }
    } else {
      TimeLineUtility.addJustHighLightLinks(msg);
      holder.content.setText(msg.getListViewSpannableString());
    }

    holder.time.setTime(msg.getMills());
    if (holder.source != null) {
      holder.source.setText(msg.getSourceString());
    }

    if (showOriStatus) {
      boolean checkRepostsCount = (msg.getReposts_count() != 0);
      boolean checkCommentsCount = (msg.getComments_count() != 0);
      boolean checkPic =
          msg.havePicture()
              || (msg.getRetweeted_status() != null && msg.getRetweeted_status().havePicture());
      checkPic = (checkPic && !SettingUtility.isEnablePic());
      boolean checkGps = (msg.getGeo() != null);

      if (!checkRepostsCount && !checkCommentsCount && !checkPic && !checkGps) {
        holder.count_layout.setVisibility(View.INVISIBLE);
      } else {
        holder.count_layout.setVisibility(View.VISIBLE);

        if (checkPic) {
          holder.timeline_pic.setVisibility(View.VISIBLE);
        } else {
          holder.timeline_pic.setVisibility(View.GONE);
        }

        if (checkGps) {
          holder.timeline_gps.setVisibility(View.VISIBLE);
        } else {
          holder.timeline_gps.setVisibility(View.INVISIBLE);
        }

        if (checkRepostsCount) {
          holder.repost_count.setText(String.valueOf(msg.getReposts_count()));
          holder.repost_count.setVisibility(View.VISIBLE);
        } else {
          holder.repost_count.setVisibility(View.GONE);
        }

        if (checkCommentsCount) {
          holder.comment_count.setText(String.valueOf(msg.getComments_count()));
          holder.comment_count.setVisibility(View.VISIBLE);
        } else {
          holder.comment_count.setVisibility(View.GONE);
        }
      }
    }

    holder.repost_content.setVisibility(View.GONE);
    holder.repost_content_pic.setVisibility(View.GONE);
    holder.repost_content_pic_multi.setVisibility(View.GONE);

    holder.content_pic.setVisibility(View.GONE);
    holder.content_pic_multi.setVisibility(View.GONE);

    if (msg.havePicture()) {
      if (msg.isMultiPics()) {
        buildMultiPic(msg, holder.content_pic_multi);
      } else {
        buildPic(msg, holder.content_pic, position);
      }
    }

    MessageBean repost_msg = msg.getRetweeted_status();

    if (repost_msg != null && showOriStatus) {
      if (holder.repost_layout != null) {
        holder.repost_layout.setVisibility(View.VISIBLE);
      }
      holder.repost_flag.setVisibility(View.VISIBLE);
      // sina weibo official account can send repost message with picture, f**k sina weibo
      if (holder.content_pic.getVisibility() != View.GONE) {
        holder.content_pic.setVisibility(View.GONE);
      }
      buildRepostContent(msg, repost_msg, holder, position);

      if (holder.content_pic_multi != holder.repost_content_pic_multi) {
        interruptPicDownload(holder.content_pic_multi);
      }
      if (holder.repost_content_pic != holder.content_pic) {
        interruptPicDownload(holder.repost_content_pic);
      }
    } else {
      if (holder.content_pic_multi != holder.repost_content_pic_multi) {
        interruptPicDownload(holder.repost_content_pic_multi);
      }
      if (holder.repost_content_pic != holder.content_pic) {
        interruptPicDownload(holder.repost_content_pic);
      }
      if (holder.repost_layout != null) {
        holder.repost_layout.setVisibility(View.GONE);
      }
      holder.repost_flag.setVisibility(View.GONE);
    }

    boolean interruptPic = false;
    boolean interruptMultiPic = false;
    boolean interruptRepostPic = false;
    boolean interruptRepostMultiPic = false;

    if (msg.havePicture()) {
      if (msg.isMultiPics()) {
        interruptPic = true;
      } else {
        interruptMultiPic = true;
      }
    }

    if (repost_msg != null && showOriStatus) {

      if (repost_msg.havePicture()) {
        if (repost_msg.isMultiPics()) {
          interruptRepostPic = true;
        } else {
          interruptRepostMultiPic = true;
        }
      }
    }

    if (interruptPic && interruptRepostPic) {
      interruptPicDownload(holder.content_pic);
      interruptPicDownload(holder.repost_content_pic);
    }

    if (interruptMultiPic && interruptRepostMultiPic) {
      interruptPicDownload(holder.content_pic_multi);
      interruptPicDownload(holder.repost_content_pic_multi);
    }

    if (interruptPic && !interruptRepostPic) {
      if (holder.content_pic != holder.repost_content_pic) {
        interruptPicDownload(holder.content_pic);
      }
    }

    if (!interruptPic && interruptRepostPic) {
      if (holder.content_pic != holder.repost_content_pic) {
        interruptPicDownload(holder.repost_content_pic);
      }
    }

    if (interruptMultiPic && !interruptRepostMultiPic) {
      if (holder.content_pic_multi != holder.repost_content_pic_multi) {
        interruptPicDownload(holder.content_pic_multi);
      }
    }

    if (!interruptMultiPic && interruptRepostMultiPic) {
      if (holder.content_pic_multi != holder.repost_content_pic_multi) {
        interruptPicDownload(holder.repost_content_pic_multi);
      }
    }
  }
  @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;
  }
예제 #20
0
  public FriendsTimeLineTagDao(String access_token, String uid) {

    this.access_token = access_token;
    this.uid = uid;
    this.count = SettingUtility.getMsgCount();
  }
예제 #21
0
  public static Bitmap getMiddlePictureInTimeLine(
      String url,
      int reqWidth,
      int reqHeight,
      FileDownloaderHttpHelper.DownloadListener downloadListener) {
    try {

      String filePath = FileManager.getFilePathFromUrl(url, FileLocationMethod.picture_bmiddle);

      File file = new File(filePath);

      if (!file.exists() && !SettingUtility.isEnablePic()) {
        return null;
      }

      if (!file.exists()) {
        getBitmapFromNetWork(url, filePath, downloadListener);
      }

      if (isGif(filePath)) {
        return getMiddlePictureInTimeLineGif(filePath, reqWidth, reqHeight);
      }

      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(filePath, options);

      int height = options.outHeight;
      int width = options.outWidth;

      int cutHeight = 0;
      int cutWidth = 0;

      if (height >= reqHeight && width >= reqWidth) {
        cutHeight = reqHeight;
        cutWidth = reqWidth;

      } else if (height < reqHeight && width >= reqWidth) {

        cutHeight = height;
        cutWidth = (reqWidth * cutHeight) / reqHeight;

      } else if (height >= reqHeight && width < reqWidth) {

        cutWidth = width;
        cutHeight = (reqHeight * cutWidth) / reqWidth;

      } else if (height < reqHeight && width < reqWidth) {

        float betweenWidth = ((float) reqWidth - (float) width) / (float) width;
        float betweenHeight = ((float) reqHeight - (float) height) / (float) height;

        if (betweenWidth > betweenHeight) {
          cutWidth = width;
          cutHeight = (reqHeight * cutWidth) / reqWidth;

        } else {
          cutHeight = height;
          cutWidth = (reqWidth * cutHeight) / reqHeight;
        }
      }

      if (cutWidth > 0 && cutHeight > 0) {

        int startX = 0;

        if (cutWidth < width) {
          startX = (width - cutWidth) / 2;
        }

        try {
          BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(filePath, false);
          if (decoder != null) {
            Bitmap bitmap =
                decoder.decodeRegion(new Rect(startX, 0, startX + cutWidth, cutHeight), null);
            if (bitmap.getHeight() < reqHeight && bitmap.getWidth() < reqWidth) {
              Bitmap scale = Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true);
              if (scale != bitmap) {
                bitmap.recycle();
                bitmap = scale;
              }
            }
            if (bitmap != null) {
              Bitmap roundedCornerBitmap = ImageEdit.getRoundedCornerBitmap(bitmap);
              if (roundedCornerBitmap != bitmap) {
                bitmap.recycle();
                bitmap = roundedCornerBitmap;
              }

              return bitmap;
            }
          }
        } catch (IOException ignored) {

        }
      }

      return null;
    } catch (OutOfMemoryError ignored) {
      ignored.printStackTrace();
      return null;
    }
  }