Skip to content

Commit

Permalink
add feature
Browse files Browse the repository at this point in the history
  • Loading branch information
REBOOTERS committed Sep 17, 2018
1 parent e464197 commit 523da78
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 1 deletion.
11 changes: 11 additions & 0 deletions matisse/src/main/java/com/zhihu/matisse/SelectionCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ public SelectionCreator originalEnable(boolean enable) {
return this;
}


/**
* Determines Whether to hide top and bottom toolbar in PreView mode ,when user tap the picture
* @param enable
* @return {@link SelectionCreator} for fluent API.
*/
public SelectionCreator autoHideToolbarOnSingleTap(boolean enable) {
mSelectionSpec.autoHideToobar = enable;
return this;
}

/**
* Maximum original size,the unit is MB. Only useful when {link@originalEnable} set true
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class SelectionSpec {
public boolean hasInited;
public OnSelectedListener onSelectedListener;
public boolean originalable;
public boolean autoHideToobar;
public int originalMaxSize;
public OnCheckedListener onCheckedListener;

Expand Down Expand Up @@ -87,6 +88,7 @@ private void reset() {
imageEngine = new GlideEngine();
hasInited = true;
originalable = false;
autoHideToobar = false;
originalMaxSize = Integer.MAX_VALUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.zhihu.matisse.R;
import com.zhihu.matisse.internal.entity.IncapableCause;
Expand All @@ -38,9 +41,10 @@
import com.zhihu.matisse.internal.ui.widget.IncapableDialog;
import com.zhihu.matisse.internal.utils.PhotoMetadataUtils;
import com.zhihu.matisse.internal.utils.Platform;
import com.zhihu.matisse.listener.OnFragmentInteractionListener;

public abstract class BasePreviewActivity extends AppCompatActivity implements View.OnClickListener,
ViewPager.OnPageChangeListener {
ViewPager.OnPageChangeListener, OnFragmentInteractionListener {

public static final String EXTRA_DEFAULT_BUNDLE = "extra_default_bundle";
public static final String EXTRA_RESULT_BUNDLE = "extra_result_bundle";
Expand All @@ -65,6 +69,10 @@ public abstract class BasePreviewActivity extends AppCompatActivity implements V
private CheckRadioView mOriginal;
protected boolean mOriginalEnable;

private FrameLayout mBottomToolbar;
private FrameLayout mTopToolbar;
private boolean mIsToolbarHide = false;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
setTheme(SelectionSpec.getInstance().themeId);
Expand Down Expand Up @@ -103,6 +111,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mPager.setAdapter(mAdapter);
mCheckView = (CheckView) findViewById(R.id.check_view);
mCheckView.setCountable(mSpec.countable);
mBottomToolbar = findViewById(R.id.bottom_toolbar);
mTopToolbar = findViewById(R.id.top_toolbar);

mCheckView.setOnClickListener(new View.OnClickListener() {

Expand Down Expand Up @@ -190,6 +200,36 @@ public void onClick(View v) {
}
}

@Override
public void onClick() {
if (!mSpec.autoHideToobar) {
return;
}

if (mIsToolbarHide) {
mTopToolbar.animate()
.setInterpolator(new FastOutSlowInInterpolator())
.translationYBy(mTopToolbar.getMeasuredHeight())
.start();
mBottomToolbar.animate()
.translationYBy(-mBottomToolbar.getMeasuredHeight())
.setInterpolator(new FastOutSlowInInterpolator())
.start();
} else {
mTopToolbar.animate()
.setInterpolator(new FastOutSlowInInterpolator())
.translationYBy(-mTopToolbar.getMeasuredHeight())
.start();
mBottomToolbar.animate()
.setInterpolator(new FastOutSlowInInterpolator())
.translationYBy(mBottomToolbar.getMeasuredHeight())
.start();
}

mIsToolbarHide = !mIsToolbarHide;

}

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package com.zhihu.matisse.internal.ui;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -30,13 +32,15 @@
import com.zhihu.matisse.internal.entity.Item;
import com.zhihu.matisse.internal.entity.SelectionSpec;
import com.zhihu.matisse.internal.utils.PhotoMetadataUtils;
import com.zhihu.matisse.listener.OnFragmentInteractionListener;

import it.sephiroth.android.library.imagezoom.ImageViewTouch;
import it.sephiroth.android.library.imagezoom.ImageViewTouchBase;

public class PreviewItemFragment extends Fragment {

private static final String ARGS_ITEM = "args_item";
private OnFragmentInteractionListener mListener;

public static PreviewItemFragment newInstance(Item item) {
PreviewItemFragment fragment = new PreviewItemFragment();
Expand Down Expand Up @@ -81,6 +85,15 @@ public void onClick(View v) {
ImageViewTouch image = (ImageViewTouch) view.findViewById(R.id.image_view);
image.setDisplayType(ImageViewTouchBase.DisplayType.FIT_TO_SCREEN);

image.setSingleTapListener(new ImageViewTouch.OnImageViewTouchSingleTapListener() {
@Override
public void onSingleTapConfirmed() {
if (mListener != null) {
mListener.onClick();
}
}
});

Point size = PhotoMetadataUtils.getBitmapSize(item.getContentUri(), getActivity());
if (item.isGif()) {
SelectionSpec.getInstance().imageEngine.loadGifImage(getContext(), size.x, size.y, image,
Expand All @@ -96,4 +109,22 @@ public void resetView() {
((ImageViewTouch) getView().findViewById(R.id.image_view)).resetMatrix();
}
}


@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.zhihu.matisse.listener;

/**
* @author: zhuyongging
* @date: 2018-09-17
* @desc PreViewItemFragment 和 BasePreViewActivity 通信的接口 ,为了方便拿到 ImageViewTouch 的点击事件
*/
public interface OnFragmentInteractionListener {
/**
* ImageViewTouch 被点击了
*/
void onClick();
}
1 change: 1 addition & 0 deletions matisse/src/main/res/layout/activity_media_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
</FrameLayout>

<FrameLayout
android:id="@+id/top_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void onSelected(
})
.originalEnable(true)
.maxOriginalSize(10)
.autoHideToolbarOnSingleTap(true)
.setOnCheckedListener(new OnCheckedListener() {
@Override
public void onCheck(boolean isChecked) {
Expand Down

0 comments on commit 523da78

Please sign in to comment.