es-num lines-num-old"> 223
        @Override
224 224
        public Object instantiateItem(View arg0, int arg1) {
225 225
            try {
226
                ((ViewPagerFixed) arg0).addView(listViews.get(arg1 % size), 0);
226
                ((ZoomingViewpager) arg0).addView(listViews.get(arg1 % size), 0);
227 227
228 228
            } catch (Exception e) {
229 229
            }
230 230
            return listViews.get(arg1 % size);
231 231
        }
232 232
233
        @Override
233 234
        public boolean isViewFromObject(View arg0, Object arg1) {
234 235
            return arg0 == arg1;
235 236
        }

+ 9 - 6
app/src/main/java/com/electric/chargingpile/activity/GalleryActivityComment.java

@ -29,8 +29,8 @@ import com.electric.chargingpile.util.Bimp;
29 29
import com.electric.chargingpile.util.PublicWay;
30 30
import com.electric.chargingpile.util.PublicWayONE;
31 31
import com.electric.chargingpile.util.Res;
32
import com.electric.chargingpile.zoom.PhotoView;
33
import com.electric.chargingpile.zoom.ViewPagerFixed;
32
import com.electric.chargingpile.widge.photoview.PhotoView;
33
import com.electric.chargingpile.widge.photoview.ZoomingViewpager;
34 34
35 35
public class GalleryActivityComment extends Activity {
36 36
    private Intent intent;
@ -48,7 +48,7 @@ public class GalleryActivityComment extends Activity {
48 48
    private int location = 0;
49 49
50 50
    private ArrayList<View> listViews = null;
51
    private ViewPagerFixed pager;
51
    private ZoomingViewpager pager;
52 52
    private MyPageAdapter adapter;
53 53
54 54
    public List<Bitmap> bmp = new ArrayList<Bitmap>();
@ -75,7 +75,7 @@ public class GalleryActivityComment extends Activity {
75 75
        position = Integer.parseInt(intent.getStringExtra("position"));
76 76
        isShowOkBt();
77 77
        // 为发送按钮设置文字
78
        pager = (ViewPagerFixed) findViewById(Res.getWidgetID("gallery01"));
78
        pager = (ZoomingViewpager) findViewById(Res.getWidgetID("gallery01"));
79 79
        pager.setBackgroundColor(getResources().getColor(R.color.white));
80 80
        pager.setOnPageChangeListener(pageChangeListener);
81 81
        for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
@ -91,14 +91,17 @@ public class GalleryActivityComment extends Activity {
91 91
92 92
    private OnPageChangeListener pageChangeListener = new OnPageChangeListener() {
93 93
94
        @Override
94 95
        public void onPageSelected(int arg0) {
95 96
            location = arg0;
96 97
        }
97 98
99
        @Override
98 100
        public void onPageScrolled(int arg0, float arg1, int arg2) {
99 101
100 102
        }
101 103
104
        @Override
102 105
        public void onPageScrollStateChanged(int arg0) {
103 106
104 107
        }
@ -215,7 +218,7 @@ public class GalleryActivityComment extends Activity {
215 218
        }
216 219
217 220
        public void destroyItem(View arg0, int arg1, Object arg2) {
218
            ((ViewPagerFixed) arg0).removeView(listViews.get(arg1 % size));
221
            ((ZoomingViewpager) arg0).removeView(listViews.get(arg1 % size));
219 222
        }
220 223
221 224
        public void finishUpdate(View arg0) {
@ -223,7 +226,7 @@ public class GalleryActivityComment extends Activity {
223 226
224 227
        public Object instantiateItem(View arg0, int arg1) {
225 228
            try {
226
                ((ViewPagerFixed) arg0).addView(listViews.get(arg1 % size), 0);
229
                ((ZoomingViewpager) arg0).addView(listViews.get(arg1 % size), 0);
227 230
228 231
            } catch (Exception e) {
229 232
            }

+ 7 - 9
app/src/main/java/com/electric/chargingpile/activity/GalleryActivityFeedback.java

@ -6,10 +6,9 @@ import android.content.Intent;
6 6
import android.graphics.Bitmap;
7 7
import android.graphics.BitmapFactory;
8 8
import android.graphics.Color;
9
import android.os.Bundle;
9 10
import android.support.v4.view.PagerAdapter;
10 11
import android.support.v4.view.ViewPager;
11
import android.support.v7.app.AppCompatActivity;
12
import android.os.Bundle;
13 12
import android.view.View;
14 13
import android.view.ViewGroup;
15 14
import android.widget.RelativeLayout;
@ -18,10 +17,9 @@ import android.widget.TextView;
18 17
import com.electric.chargingpile.R;
19 18
import com.electric.chargingpile.util.Bimp;
20 19
import com.electric.chargingpile.util.PublicWay;
21
import com.electric.chargingpile.util.PublicWayONE;
22 20
import com.electric.chargingpile.util.Res;
23
import com.electric.chargingpile.zoom.PhotoView;
24
import com.electric.chargingpile.zoom.ViewPagerFixed;
21
import com.electric.chargingpile.widge.photoview.PhotoView;
22
import com.electric.chargingpile.widge.photoview.ZoomingViewpager;
25 23
26 24
import java.io.ByteArrayInputStream;
27 25
import java.io.ByteArrayOutputStream;
@ -44,7 +42,7 @@ public class GalleryActivityFeedback extends Activity {
44 42
    private int location = 0;
45 43
46 44
    private ArrayList<View> listViews = null;
47
    private ViewPagerFixed pager;
45
    private ZoomingViewpager pager;
48 46
    private MyPageAdapter adapter;
49 47
50 48
    public List<Bitmap> bmp = new ArrayList<Bitmap>();
@ -71,7 +69,7 @@ public class GalleryActivityFeedback extends Activity {
71 69
        position = Integer.parseInt(intent.getStringExtra("position"));
72 70
        isShowOkBt();
73 71
        // 为发送按钮设置文字
74
        pager = (ViewPagerFixed) findViewById(Res.getWidgetID("gallery01"));
72
        pager = (ZoomingViewpager) findViewById(Res.getWidgetID("gallery01"));
75 73
        pager.setBackgroundColor(getResources().getColor(R.color.white));
76 74
        pager.setOnPageChangeListener(pageChangeListener);
77 75
        for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
@ -191,7 +189,7 @@ public class GalleryActivityFeedback extends Activity {
191 189
        }
192 190
193 191
        public void destroyItem(View arg0, int arg1, Object arg2) {
194
            ((ViewPagerFixed) arg0).removeView(listViews.get(arg1 % size));
192
            ((ZoomingViewpager) arg0).removeView(listViews.get(arg1 % size));
195 193
        }
196 194
197 195
        public void finishUpdate(View arg0) {
@ -199,7 +197,7 @@ public class GalleryActivityFeedback extends Activity {
199 197
200 198
        public Object instantiateItem(View arg0, int arg1) {
201 199
            try {
202
                ((ViewPagerFixed) arg0).addView(listViews.get(arg1 % size), 0);
200
                ((ZoomingViewpager) arg0).addView(listViews.get(arg1 % size), 0);
203 201
204 202
            } catch (Exception e) {
205 203
            }

+ 0 - 19
app/src/main/java/com/electric/chargingpile/zoom/Compat.java

@ -1,19 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
import android.os.Build.VERSION;
4
import android.os.Build.VERSION_CODES;
5
import android.view.View;
6
7
public class Compat {
8
	
9
	private static final int SIXTY_FPS_INTERVAL = 1000 / 60;
10
	
11
	public static void postOnAnimation(View view, Runnable runnable) {
12
		if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
13
			SDK16.postOnAnimation(view, runnable);
14
		} else {
15
			view.postDelayed(runnable, SIXTY_FPS_INTERVAL);
16
		}
17
	}
18
19
}

+ 0 - 128
app/src/main/java/com/electric/chargingpile/zoom/IPhotoView.java

@ -1,128 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
import android.graphics.RectF;
4
import android.view.View;
5
import android.widget.ImageView;
6
7
8
public interface IPhotoView {
9
    /**
10
     * Returns true if the PhotoView is set to allow zooming of Photos.
11
     *
12
     * @return true if the PhotoView allows zooming.
13
     */
14
    boolean canZoom();
15
16
    /**
17
     * Gets the Display Rectangle of the currently displayed Drawable. The
18
     * Rectangle is relative to this View and includes all scaling and
19
     * translations.
20
     *
21
     * @return - RectF of Displayed Drawable
22
     */
23
    RectF getDisplayRect();
24
25
    /**
26
     * @return The current minimum scale level. What this value represents depends on the current {@link ImageView.ScaleType}.
27
     */
28
    float getMinScale();
29
30
    /**
31
     * @return The current middle scale level. What this value represents depends on the current {@link ImageView.ScaleType}.
32
     */
33
    float getMidScale();
34
35
    /**
36
     * @return The current maximum scale level. What this value represents depends on the current {@link ImageView.ScaleType}.
37
     */
38
    float getMaxScale();
39
40
    /**
41
     * Returns the current scale value
42
     *
43
     * @return float - current scale value
44
     */
45
    float getScale();
46
47
    /**
48
     * Return the current scale type in use by the ImageView.
49
     */
50
    ImageView.ScaleType getScaleType();
51
52
    /**
53
     * Whether to allow the ImageView's parent to intercept the touch event when the photo is scroll to it's horizontal edge.
54
     */
55
    void setAllowParentInterceptOnEdge(boolean allow);
56
57
    /**
58
     * Sets the minimum scale level. What this value represents depends on the current {@link ImageView.ScaleType}.
59
     */
60
    void setMinScale(float minScale);
61
62
    /**
63
     * Sets the middle scale level. What this value represents depends on the current {@link ImageView.ScaleType}.
64
     */
65
    void setMidScale(float midScale);
66
67
    /**
68
     * Sets the maximum scale level. What this value represents depends on the current {@link ImageView.ScaleType}.
69
     */
70
    void setMaxScale(float maxScale);
71
72
    /**
73
     * Register a callback to be invoked when the Photo displayed by this view is long-pressed.
74
     *
75
     * @param listener - Listener to be registered.
76
     */
77
    void setOnLongClickListener(View.OnLongClickListener listener);
78
79
    /**
80
     * Register a callback to be invoked when the Matrix has changed for this
81
     * View. An example would be the user panning or scaling the Photo.
82
     *
83
     * @param listener - Listener to be registered.
84
     */
85
    void setOnMatrixChangeListener(PhotoViewAttacher.OnMatrixChangedListener listener);
86
87
    /**
88
     * Register a callback to be invoked when the Photo displayed by this View
89
     * is tapped with a single tap.
90
     *
91
     * @param listener - Listener to be registered.
92
     */
93
    void setOnPhotoTapListener(PhotoViewAttacher.OnPhotoTapListener listener);
94
95
    /**
96
     * Register a callback to be invoked when the View is tapped with a single
97
     * tap.
98
     *
99
     * @param listener - Listener to be registered.
100
     */
101
    void setOnViewTapListener(PhotoViewAttacher.OnViewTapListener listener);
102
103
    /**
104
     * Controls how the image should be resized or moved to match the size of
105
     * the ImageView. Any scaling or panning will happen within the confines of
106
     * this {@link ImageView.ScaleType}.
107
     *
108
     * @param scaleType - The desired scaling mode.
109
     */
110
    void setScaleType(ImageView.ScaleType scaleType);
111
112
    /**
113
     * Allows you to enable/disable the zoom functionality on the ImageView.
114
     * When disable the ImageView reverts to using the FIT_CENTER matrix.
115
     *
116
     * @param zoomable - Whether the zoom functionality is enabled.
117
     */
118
    void setZoomable(boolean zoomable);
119
120
    /**
121
     * Zooms to the specified scale, around the focal point given.
122
     *
123
     * @param scale  - Scale to zoom to
124
     * @param focalX - X Focus Point
125
     * @param focalY - Y Focus Point
126
     */
127
    void zoomTo(float scale, float focalX, float focalY);
128
}

+ 0 - 165
app/src/main/java/com/electric/chargingpile/zoom/PhotoView.java

@ -1,165 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
4
import android.content.Context;
5
import android.graphics.RectF;
6
import android.graphics.drawable.Drawable;
7
import android.net.Uri;
8
import android.util.AttributeSet;
9
import android.widget.ImageView;
10
11
import com.electric.chargingpile.zoom.PhotoViewAttacher.OnMatrixChangedListener;
12
import com.electric.chargingpile.zoom.PhotoViewAttacher.OnPhotoTapListener;
13
import com.electric.chargingpile.zoom.PhotoViewAttacher.OnViewTapListener;
14
15
public class PhotoView extends ImageView implements IPhotoView {
16
17
	private final PhotoViewAttacher mAttacher;
18
19
	private ScaleType mPendingScaleType;
20
21
	public PhotoView(Context context) {
22
		this(context, null);
23
	}
24
25
	public PhotoView(Context context, AttributeSet attr) {
26
		this(context, attr, 0);
27
	}
28
	
29
	public PhotoView(Context context, AttributeSet attr, int defStyle) {
30
		super(context, attr, defStyle);
31
		super.setScaleType(ScaleType.MATRIX);
32
		mAttacher = new PhotoViewAttacher(this);
33
34
		if (null != mPendingScaleType) {
35
			setScaleType(mPendingScaleType);
36
			mPendingScaleType = null;
37
		}
38
	}
39
40
	@Override
41
	public boolean canZoom() {
42
		return mAttacher.canZoom();
43
	}
44
45
	@Override
46
	public RectF getDisplayRect() {
47
		return mAttacher.getDisplayRect();
48
	}
49
50
	@Override
51
	public float getMinScale() {
52
		return mAttacher.getMinScale();
53
	}
54
55
	@Override
56
	public float getMidScale() {
57
		return mAttacher.getMidScale();
58
	}
59
60
	@Override
61
	public float getMaxScale() {
62
		return mAttacher.getMaxScale();
63
	}
64
65
	@Override
66
	public float getScale() {
67
		return mAttacher.getScale();
68
	}
69
70
	@Override
71
	public ScaleType getScaleType() {
72
		return mAttacher.getScaleType();
73
	}
74
75
    @Override
76
    public void setAllowParentInterceptOnEdge(boolean allow) {
77
        mAttacher.setAllowParentInterceptOnEdge(allow);
78
    }
79
80
    @Override
81
	public void setMinScale(float minScale) {
82
		mAttacher.setMinScale(minScale);
83
	}
84
85
	@Override
86
	public void setMidScale(float midScale) {
87
		mAttacher.setMidScale(midScale);
88
	}
89
90
	@Override
91
	public void setMaxScale(float maxScale) {
92
		mAttacher.setMaxScale(maxScale);
93
	}
94
95
	@Override
96
	// setImageBitmap calls through to this method
97
	public void setImageDrawable(Drawable drawable) {
98
		super.setImageDrawable(drawable);
99
		if (null != mAttacher) {
100
			mAttacher.update();
101
		}
102
	}
103
104
	@Override
105
	public void setImageResource(int resId) {
106
		super.setImageResource(resId);
107
		if (null != mAttacher) {
108
			mAttacher.update();
109
		}
110
	}
111
112
	@Override
113
	public void setImageURI(Uri uri) {
114
		super.setImageURI(uri);
115
		if (null != mAttacher) {
116
			mAttacher.update();
117
		}
118
	}
119
120
	@Override
121
	public void setOnMatrixChangeListener(OnMatrixChangedListener listener) {
122
		mAttacher.setOnMatrixChangeListener(listener);
123
	}
124
125
	@Override
126
	public void setOnLongClickListener(OnLongClickListener l) {
127
		mAttacher.setOnLongClickListener(l);
128
	}
129
130
	@Override
131
	public void setOnPhotoTapListener(OnPhotoTapListener listener) {
132
		mAttacher.setOnPhotoTapListener(listener);
133
	}
134
135
	@Override
136
	public void setOnViewTapListener(OnViewTapListener listener) {
137
		mAttacher.setOnViewTapListener(listener);
138
	}
139
140
	@Override
141
	public void setScaleType(ScaleType scaleType) {
142
		if (null != mAttacher) {
143
			mAttacher.setScaleType(scaleType);
144
		} else {
145
			mPendingScaleType = scaleType;
146
		}
147
	}
148
149
	@Override
150
	public void setZoomable(boolean zoomable) {
151
		mAttacher.setZoomable(zoomable);
152
	}
153
154
	@Override
155
	public void zoomTo(float scale, float focalX, float focalY) {
156
		mAttacher.zoomTo(scale, focalX, focalY);
157
	}
158
159
	@Override
160
	protected void onDetachedFromWindow() {
161
		mAttacher.cleanup();
162
		super.onDetachedFromWindow();
163
	}
164
165
}

+ 0 - 990
app/src/main/java/com/electric/chargingpile/zoom/PhotoViewAttacher.java

@ -1,990 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
import android.annotation.SuppressLint;
4
import android.content.Context;
5
import android.graphics.Matrix;
6
import android.graphics.Matrix.ScaleToFit;
7
import android.graphics.RectF;
8
import android.graphics.drawable.Drawable;
9
import android.os.Build.VERSION;
10
import android.os.Build.VERSION_CODES;
11
import android.util.Log;
12
import android.view.GestureDetector;
13
import android.view.MotionEvent;
14
import android.view.View;
15
import android.view.View.OnLongClickListener;
16
import android.view.ViewTreeObserver;
17
import android.widget.ImageView;
18
import android.widget.ImageView.ScaleType;
19
import java.lang.ref.WeakReference;
20
21
public class PhotoViewAttacher implements IPhotoView, View.OnTouchListener,
22
		VersionedGestureDetector.OnGestureListener,
23
		GestureDetector.OnDoubleTapListener,
24
		ViewTreeObserver.OnGlobalLayoutListener {
25
26
	static final String LOG_TAG = "PhotoViewAttacher";
27
28
	// let debug flag be dynamic, but still Proguard can be used to remove from
29
	// release builds
30
	static final boolean DEBUG = Log.isLoggable(LOG_TAG, Log.DEBUG);
31
32
	static final int EDGE_NONE = -1;
33
	static final int EDGE_LEFT = 0;
34
	static final int EDGE_RIGHT = 1;
35
	static final int EDGE_BOTH = 2;
36
37
	public static final float DEFAULT_MAX_SCALE = 3.0f;
38
	public static final float DEFAULT_MID_SCALE = 1.75f;
39
	public static final float DEFAULT_MIN_SCALE = 1.0f;
40
41
	private float mMinScale = DEFAULT_MIN_SCALE;
42
	private float mMidScale = DEFAULT_MID_SCALE;
43
	private float mMaxScale = DEFAULT_MAX_SCALE;
44
45
	private boolean mAllowParentInterceptOnEdge = true;
46
47
	private static void checkZoomLevels(float minZoom, float midZoom,
48
			float maxZoom) {
49
		if (minZoom >= midZoom) {
50
			throw new IllegalArgumentException(
51
					"MinZoom should be less than MidZoom");
52
		} else if (midZoom >= maxZoom) {
53
			throw new IllegalArgumentException(
54
					"MidZoom should be less than MaxZoom");
55
		}
56
	}
57
58
	/**
59
	 * @return true if the ImageView exists, and it's Drawable existss
60
	 */
61
	private static boolean hasDrawable(ImageView imageView) {
62
		return null != imageView && null != imageView.getDrawable();
63
	}
64
65
	/**
66
	 * @return true if the ScaleType is supported.
67
	 */
68
	private static boolean isSupportedScaleType(final ScaleType scaleType) {
69
		if (null == scaleType) {
70
			return false;
71
		}
72
73
		switch (scaleType) {
74
		case MATRIX:
75
			throw new IllegalArgumentException(scaleType.name()
76
					+ " is not supported in PhotoView");
77
78
		default:
79
			return true;
80
		}
81
	}
82
83
	/**
84
	 * Set's the ImageView's ScaleType to Matrix.
85
	 */
86
	private static void setImageViewScaleTypeMatrix(ImageView imageView) {
87
		if (null != imageView) {
88
			if (imageView instanceof PhotoView) {
89
				/**
90
				 * PhotoView sets it's own ScaleType to Matrix, then diverts all
91
				 * calls setScaleType to this.setScaleType. Basically we don't
92
				 * need to do anything here
93
				 */
94
			} else {
95
				imageView.setScaleType(ScaleType.MATRIX);
96
			}
97
		}
98
	}
99
100
	private WeakReference<ImageView> mImageView;
101
	private ViewTreeObserver mViewTreeObserver;
102
103
	// Gesture Detectors
104
	private GestureDetector mGestureDetector;
105
	private VersionedGestureDetector mScaleDragDetector;
106
107
	// These are set so we don't keep allocating them on the heap
108
	private final Matrix mBaseMatrix = new Matrix();
109
	private final Matrix mDrawMatrix = new Matrix();
110
	private final Matrix mSuppMatrix = new Matrix();
111
	private final RectF mDisplayRect = new RectF();
112
	private final float[] mMatrixValues = new float[9];
113
114
	// Listeners
115
	private OnMatrixChangedListener mMatrixChangeListener;
116
	private OnPhotoTapListener mPhotoTapListener;
117
	private OnViewTapListener mViewTapListener;
118
	private OnLongClickListener mLongClickListener;
119
120
	private int mIvTop, mIvRight, mIvBottom, mIvLeft;
121
	private FlingRunnable mCurrentFlingRunnable;
122
	private int mScrollEdge = EDGE_BOTH;
123
124
	private boolean mZoomEnabled;
125
	private ScaleType mScaleType = ScaleType.FIT_CENTER;
126
127
	public PhotoViewAttacher(ImageView imageView) {
128
		mImageView = new WeakReference<ImageView>(imageView);
129
130
		imageView.setOnTouchListener(this);
131
132
		mViewTreeObserver = imageView.getViewTreeObserver();
133
		mViewTreeObserver.addOnGlobalLayoutListener(this);
134
135
		// Make sure we using MATRIX Scale Type
136
		setImageViewScaleTypeMatrix(imageView);
137
138
		if (!imageView.isInEditMode()) {
139
			// Create Gesture Detectors...
140
			mScaleDragDetector = VersionedGestureDetector.newInstance(
141
					imageView.getContext(), this);
142
143
			mGestureDetector = new GestureDetector(imageView.getContext(),
144
					new GestureDetector.SimpleOnGestureListener() {
145
146
						// forward long click listener
147
						@Override
148
						public void onLongPress(MotionEvent e) {
149
							if (null != mLongClickListener) {
150
								mLongClickListener.onLongClick(mImageView.get());
151
							}
152
						}
153
					});
154
155
			mGestureDetector.setOnDoubleTapListener(this);
156
157
			// Finally, update the UI so that we're zoomable
158
			setZoomable(true);
159
		}
160
	}
161
162
	@Override
163
	public final boolean canZoom() {
164
		return mZoomEnabled;
165
	}
166
167
	/**
168
	 * Clean-up the resources attached to this object. This needs to be called
169
	 * when the ImageView is no longer used. A good example is from
170
	 * {@link View#onDetachedFromWindow()} or from
171
	 * {@link android.app.Activity#onDestroy()}. This is automatically called if
172
	 */
173
	@SuppressLint("NewApi")
174
	// @SuppressWarnings("deprecation")
175
	// public final void cleanup() {
176
	// if (null != mImageView) {
177
	// mImageView.get().getViewTreeObserver().removeGlobalOnLayoutListener(this);
178
	// }
179
	// mViewTreeObserver = null;
180
	//
181
	// // Clear listeners too
182
	// mMatrixChangeListener = null;
183
	// mPhotoTapListener = null;
184
	// mViewTapListener = null;
185
	//
186
	// // Finally, clear ImageView
187
	// mImageView = null;
188
	// }
189
	@SuppressWarnings("deprecation")
190
	public final void cleanup() {
191
		if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
192
			if (null != mImageView) {
193
				mImageView.get().getViewTreeObserver()
194
						.removeOnGlobalLayoutListener(this);
195
			}
196
197
			if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
198
				mViewTreeObserver.removeOnGlobalLayoutListener(this);
199
200
				mViewTreeObserver = null;
201
202
				// Clear listeners too
203
				mMatrixChangeListener = null;
204
				mPhotoTapListener = null;
205
				mViewTapListener = null;
206
				// Finally, clear ImageView
207
				mImageView = null;
208
			}
209
210
		} else {
211
			if (null != mImageView) {
212
				mImageView.get().getViewTreeObserver()
213
						.removeGlobalOnLayoutListener(this);
214
			}
215
216
			if (null != mViewTreeObserver && mViewTreeObserver.isAlive()) {
217
				mViewTreeObserver.removeGlobalOnLayoutListener(this);
218
219
				mViewTreeObserver = null;
220
221
				// Clear listeners too
222
				mMatrixChangeListener = null;
223
				mPhotoTapListener = null;
224
				mViewTapListener = null;
225
				// Finally, clear ImageView
226
				mImageView = null;
227
			}
228
		}
229
	}
230
231
	@Override
232
	public final RectF getDisplayRect() {
233
		checkMatrixBounds();
234
		return getDisplayRect(getDisplayMatrix());
235
	}
236
237
	public final ImageView getImageView() {
238
		ImageView imageView = null;
239
240
		if (null != mImageView) {
241
			imageView = mImageView.get();
242
		}
243
244
		// If we don't have an ImageView, call cleanup()
245
		if (null == imageView) {
246
			cleanup();
247
			throw new IllegalStateException(
248
					"ImageView no longer exists. You should not use this PhotoViewAttacher any more.");
249
		}
250
251
		return imageView;
252
	}
253
254
	@Override
255
	public float getMinScale() {
256
		return mMinScale;
257
	}
258
259
	@Override
260
	public float getMidScale() {
261
		return mMidScale;
262
	}
263
264
	@Override
265
	public float getMaxScale() {
266
		return mMaxScale;
267
	}
268
269
	@Override
270
	public final float getScale() {
271
		return getValue(mSuppMatrix, Matrix.MSCALE_X);
272
	}
273
274
	@Override
275
	public final ScaleType getScaleType() {
276
		return mScaleType;
277
	}
278
279
	@Override
280
	public final boolean onDoubleTap(MotionEvent ev) {
281
		try {
282
			float scale = getScale();
283
			float x = ev.getX();
284
			float y = ev.getY();
285
286
			if (scale < mMidScale) {
287
				zoomTo(mMidScale, x, y);
288
			} else if (scale >= mMidScale && scale < mMaxScale) {
289
				zoomTo(mMaxScale, x, y);
290
			} else {
291
				zoomTo(mMinScale, x, y);
292
			}
293
		} catch (ArrayIndexOutOfBoundsException e) {
294
			// Can sometimes happen when getX() and getY() is called
295
		}
296
297
		return true;
298
	}
299
300
	@Override
301
	public final boolean onDoubleTapEvent(MotionEvent e) {
302
		// Wait for the confirmed onDoubleTap() instead
303
		return false;
304
	}
305
306
	@Override
307
	public final void onDrag(float dx, float dy) {
308
		if (DEBUG) {
309
			Log.d(LOG_TAG, String.format("onDrag: dx: %.2f. dy: %.2f", dx, dy));
310
		}
311
312
		ImageView imageView = getImageView();
313
314
		if (null != imageView && hasDrawable(imageView)) {
315
			mSuppMatrix.postTranslate(dx, dy);
316
			checkAndDisplayMatrix();
317
318
			/**
319
			 * Here we decide whether to let the ImageView's parent to start
320
			 * taking over the touch event.
321
			 * 
322
			 * First we check whether this function is enabled. We never want
323
			 * the parent to take over if we're scaling. We then check the edge
324
			 * we're on, and the direction of the scroll (i.e. if we're pulling
325
			 * against the edge, aka 'overscrolling', let the parent take over).
326
			 */
327
			if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling()) {
328
				if (mScrollEdge == EDGE_BOTH
329
						|| (mScrollEdge == EDGE_LEFT && dx >= 1f)
330
						|| (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
331
					imageView.getParent().requestDisallowInterceptTouchEvent(
332
							false);
333
				}
334
			}
335
		}
336
	}
337
338
	@Override
339
	public final void onFling(float startX, float startY, float velocityX,
340
			float velocityY) {
341
		if (DEBUG) {
342
			Log.d(LOG_TAG, "onFling. sX: " + startX + " sY: " + startY
343
					+ " Vx: " + velocityX + " Vy: " + velocityY);
344
		}
345
346
		ImageView imageView = getImageView();
347
		if (hasDrawable(imageView)) {
348
			mCurrentFlingRunnable = new FlingRunnable(imageView.getContext());
349
			mCurrentFlingRunnable.fling(imageView.getWidth(),
350
					imageView.getHeight(), (int) velocityX, (int) velocityY);
351
			imageView.post(mCurrentFlingRunnable);
352
		}
353
	}
354
355
	@Override
356
	public final void onGlobalLayout() {
357
		ImageView imageView = getImageView();
358
359
		if (null != imageView && mZoomEnabled) {
360
			final int top = imageView.getTop();
361
			final int right = imageView.getRight();
362
			final int bottom = imageView.getBottom();
363
			final int left = imageView.getLeft();
364
365
			/**
366
			 * We need to check whether the ImageView's bounds have changed.
367
			 * This would be easier if we targeted API 11+ as we could just use
368
			 * View.OnLayoutChangeListener. Instead we have to replicate the
369
			 * work, keeping track of the ImageView's bounds and then checking
370
			 * if the values change.
371
			 */
372
			if (top != mIvTop || bottom != mIvBottom || left != mIvLeft
373
					|| right != mIvRight) {
374
				// Update our base matrix, as the bounds have changed
375
				updateBaseMatrix(imageView.getDrawable());
376
377
				// Update values as something has changed
378
				mIvTop = top;
379
				mIvRight = right;
380
				mIvBottom = bottom;
381
				mIvLeft = left;
382
			}
383
		}
384
	}
385
386
	@Override
387
	public final void onScale(float scaleFactor, float focusX, float focusY) {
388
		if (DEBUG) {
389
			Log.d(LOG_TAG, String.format(
390
					"onScale: scale: %.2f. fX: %.2f. fY: %.2f", scaleFactor,
391
					focusX, focusY));
392
		}
393
394
		if (hasDrawable(getImageView())
395
				&& (getScale() < mMaxScale || scaleFactor < 1f)) {
396
			mSuppMatrix.postScale(scaleFactor, scaleFactor, focusX, focusY);
397
			checkAndDisplayMatrix();
398
		}
399
	}
400
401
	@Override
402
	public final boolean onSingleTapConfirmed(MotionEvent e) {
403
		ImageView imageView = getImageView();
404
405
		if (null != imageView) {
406
			if (null != mPhotoTapListener) {
407
				final RectF displayRect = getDisplayRect();
408
409
				if (null != displayRect) {
410
					final float x = e.getX(), y = e.getY();
411
412
					// Check to see if the user tapped on the photo
413
					if (displayRect.contains(x, y)) {
414
415
						float xResult = (x - displayRect.left)
416
								/ displayRect.width();
417
						float yResult = (y - displayRect.top)
418
								/ displayRect.height();
419
420
						mPhotoTapListener.onPhotoTap(imageView, xResult,
421
								yResult);
422
						return true;
423
					}
424
				}
425
			}
426
			if (null != mViewTapListener) {
427
				mViewTapListener.onViewTap(imageView, e.getX(), e.getY());
428
			}
429
		}
430
431
		return false;
432
	}
433
434
	@Override
435
	public final boolean onTouch(View v, MotionEvent ev) {
436
		boolean handled = false;
437
438
		if (mZoomEnabled) {
439
			switch (ev.getAction()) {
440
			case MotionEvent.ACTION_DOWN:
441
				// First, disable the Parent from intercepting the touch
442
				// event
443
				v.getParent().requestDisallowInterceptTouchEvent(true);
444
445
				// If we're flinging, and the user presses down, cancel
446
				// fling
447
				cancelFling();
448
				break;
449
450
			case MotionEvent.ACTION_CANCEL:
451
			case MotionEvent.ACTION_UP:
452
				// If the user has zoomed less than min scale, zoom back
453
				// to min scale
454
				if (getScale() < mMinScale) {
455
					RectF rect = getDisplayRect();
456
					if (null != rect) {
457
						v.post(new AnimatedZoomRunnable(getScale(), mMinScale,
458
								rect.centerX(), rect.centerY()));
459
						handled = true;
460
					}
461
				}
462
				break;
463
			}
464
465
			// Check to see if the user double tapped
466
			if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
467
				handled = true;
468
			}
469
470
			// Finally, try the Scale/Drag detector
471
			if (null != mScaleDragDetector
472
					&& mScaleDragDetector.onTouchEvent(ev)) {
473
				handled = true;
474
			}
475
		}
476
477
		return handled;
478
	}
479
480
	@Override
481
	public void setAllowParentInterceptOnEdge(boolean allow) {
482
		mAllowParentInterceptOnEdge = allow;
483
	}
484
485
	@Override
486
	public void setMinScale(float minScale) {
487
		checkZoomLevels(minScale, mMidScale, mMaxScale);
488
		mMinScale = minScale;
489
	}
490
491
	@Override
492
	public void setMidScale(float midScale) {
493
		checkZoomLevels(mMinScale, midScale, mMaxScale);
494
		mMidScale = midScale;
495
	}
496
497
	@Override
498
	public void setMaxScale(float maxScale) {
499
		checkZoomLevels(mMinScale, mMidScale, maxScale);
500
		mMaxScale = maxScale;
501
	}
502
503
	@Override
504
	public final void setOnLongClickListener(OnLongClickListener listener) {
505
		mLongClickListener = listener;
506
	}
507
508
	@Override
509
	public final void setOnMatrixChangeListener(OnMatrixChangedListener listener) {
510
		mMatrixChangeListener = listener;
511
	}
512
513
	@Override
514
	public final void setOnPhotoTapListener(OnPhotoTapListener listener) {
515
		mPhotoTapListener = listener;
516
	}
517
518
	@Override
519
	public final void setOnViewTapListener(OnViewTapListener listener) {
520
		mViewTapListener = listener;
521
	}
522
523
	@Override
524
	public final void setScaleType(ScaleType scaleType) {
525
		if (isSupportedScaleType(scaleType) && scaleType != mScaleType) {
526
			mScaleType = scaleType;
527
528
			// Finally update
529
			update();
530
		}
531
	}
532
533
	@Override
534
	public final void setZoomable(boolean zoomable) {
535
		mZoomEnabled = zoomable;
536
		update();
537
	}
538
539
	public final void update() {
540
		ImageView imageView = getImageView();
541
542
		if (null != imageView) {
543
			if (mZoomEnabled) {
544
				// Make sure we using MATRIX Scale Type
545
				setImageViewScaleTypeMatrix(imageView);
546
547
				// Update the base matrix using the current drawable
548
				updateBaseMatrix(imageView.getDrawable());
549
			} else {
550
				// Reset the Matrix...
551
				resetMatrix();
552
			}
553
		}
554
	}
555
556
	@Override
557
	public final void zoomTo(float scale, float focalX, float focalY) {
558
		ImageView imageView = getImageView();
559
560
		if (null != imageView) {
561
			imageView.post(new AnimatedZoomRunnable(getScale(), scale, focalX,
562
					focalY));
563
		}
564
	}
565
566
	protected Matrix getDisplayMatrix() {
567
		mDrawMatrix.set(mBaseMatrix);
568
		mDrawMatrix.postConcat(mSuppMatrix);
569
		return mDrawMatrix;
570
	}
571
572
	private void cancelFling() {
573
		if (null != mCurrentFlingRunnable) {
574
			mCurrentFlingRunnable.cancelFling();
575
			mCurrentFlingRunnable = null;
576
		}
577
	}
578
579
	/**
580
	 * Helper method that simply checks the Matrix, and then displays the result
581
	 */
582
	private void checkAndDisplayMatrix() {
583
		checkMatrixBounds();
584
		setImageViewMatrix(getDisplayMatrix());
585
	}
586
587
	private void checkImageViewScaleType() {
588
		ImageView imageView = getImageView();
589
590
		/**
591
		 * PhotoView's getScaleType() will just divert to this.getScaleType() so
592
		 * only call if we're not attached to a PhotoView.
593
		 */
594
		if (null != imageView && !(imageView instanceof PhotoView)) {
595
			if (imageView.getScaleType() != ScaleType.MATRIX) {
596
				throw new IllegalStateException(
597
						"The ImageView's ScaleType has been changed since attaching a PhotoViewAttacher");
598
			}
599
		}
600
	}
601
602
	private void checkMatrixBounds() {
603
		final ImageView imageView = getImageView();
604
		if (null == imageView) {
605
			return;
606
		}
607
608
		final RectF rect = getDisplayRect(getDisplayMatrix());
609
		if (null == rect) {
610
			return;
611
		}
612
613
		final float height = rect.height(), width = rect.width();
614
		float deltaX = 0, deltaY = 0;
615
616
		final int viewHeight = imageView.getHeight();
617
		if (height <= viewHeight) {
618
			switch (mScaleType) {
619
			case FIT_START:
620
				deltaY = -rect.top;
621
				break;
622
			case FIT_END:
623
				deltaY = viewHeight - height - rect.top;
624
				break;
625
			default:
626
				deltaY = (viewHeight - height) / 2 - rect.top;
627
				break;
628
			}
629
		} else if (rect.top > 0) {
630
			deltaY = -rect.top;
631
		} else if (rect.bottom < viewHeight) {
632
			deltaY = viewHeight - rect.bottom;
633
		}
634
635
		final int viewWidth = imageView.getWidth();
636
		if (width <= viewWidth) {
637
			switch (mScaleType) {
638
			case FIT_START:
639
				deltaX = -rect.left;
640
				break;
641
			case FIT_END:
642
				deltaX = viewWidth - width - rect.left;
643
				break;
644
			default:
645
				deltaX = (viewWidth - width) / 2 - rect.left;
646
				break;
647
			}
648
			mScrollEdge = EDGE_BOTH;
649
		} else if (rect.left > 0) {
650
			mScrollEdge = EDGE_LEFT;
651
			deltaX = -rect.left;
652
		} else if (rect.right < viewWidth) {
653
			deltaX = viewWidth - rect.right;
654
			mScrollEdge = EDGE_RIGHT;
655
		} else {
656
			mScrollEdge = EDGE_NONE;
657
		}
658
659
		// Finally actually translate the matrix
660
		mSuppMatrix.postTranslate(deltaX, deltaY);
661
	}
662
663
	/**
664
	 * Helper method that maps the supplied Matrix to the current Drawable
665
	 * 
666
	 * @param matrix
667
	 *            - Matrix to map Drawable against
668
	 * @return RectF - Displayed Rectangle
669
	 */
670
	private RectF getDisplayRect(Matrix matrix) {
671
		ImageView imageView = getImageView();
672
673
		if (null != imageView) {
674
			Drawable d = imageView.getDrawable();
675
			if (null != d) {
676
				mDisplayRect.set(0, 0, d.getIntrinsicWidth(),
677
						d.getIntrinsicHeight());
678
				matrix.mapRect(mDisplayRect);
679
				return mDisplayRect;
680
			}
681
		}
682
		return null;
683
	}
684
685
	/**
686
	 * Helper method that 'unpacks' a Matrix and returns the required value
687
	 * 
688
	 * @param matrix
689
	 *            - Matrix to unpack
690
	 * @param whichValue
691
	 *            - Which value from Matrix.M* to return
692
	 * @return float - returned value
693
	 */
694
	private float getValue(Matrix matrix, int whichValue) {
695
		matrix.getValues(mMatrixValues);
696
		return mMatrixValues[whichValue];
697
	}
698
699
	/**
700
	 * Resets the Matrix back to FIT_CENTER, and then displays it.s
701
	 */
702
	private void resetMatrix() {
703
		mSuppMatrix.reset();
704
		setImageViewMatrix(getDisplayMatrix());
705
		checkMatrixBounds();
706
	}
707
708
	private void setImageViewMatrix(Matrix matrix) {
709
		ImageView imageView = getImageView();
710
		if (null != imageView) {
711
712
			checkImageViewScaleType();
713
			imageView.setImageMatrix(matrix);
714
715
			// Call MatrixChangedListener if needed
716
			if (null != mMatrixChangeListener) {
717
				RectF displayRect = getDisplayRect(matrix);
718
				if (null != displayRect) {
719
					mMatrixChangeListener.onMatrixChanged(displayRect);
720
				}
721
			}
722
		}
723
	}
724
725
	/**
726
	 * Calculate Matrix for FIT_CENTER
727
	 * 
728
	 * @param d
729
	 *            - Drawable being displayed
730
	 */
731
	private void updateBaseMatrix(Drawable d) {
732
		ImageView imageView = getImageView();
733
		if (null == imageView || null == d) {
734
			return;
735
		}
736
737
		final float viewWidth = imageView.getWidth();
738
		final float viewHeight = imageView.getHeight();
739
		final int drawableWidth = d.getIntrinsicWidth();
740
		final int drawableHeight = d.getIntrinsicHeight();
741
742
		mBaseMatrix.reset();
743
744
		final float widthScale = viewWidth / drawableWidth;
745
		final float heightScale = viewHeight / drawableHeight;
746
747
		if (mScaleType == ScaleType.CENTER) {
748
			mBaseMatrix.postTranslate((viewWidth - drawableWidth) / 2F,
749
					(viewHeight - drawableHeight) / 2F);
750
751
		} else if (mScaleType == ScaleType.CENTER_CROP) {
752
			float scale = Math.max(widthScale, heightScale);
753
			mBaseMatrix.postScale(scale, scale);
754
			mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
755
					(viewHeight - drawableHeight * scale) / 2F);
756
757
		} else if (mScaleType == ScaleType.CENTER_INSIDE) {
758
			float scale = Math.min(1.0f, Math.min(widthScale, heightScale));
759
			mBaseMatrix.postScale(scale, scale);
760
			mBaseMatrix.postTranslate((viewWidth - drawableWidth * scale) / 2F,
761
					(viewHeight - drawableHeight * scale) / 2F);
762
763
		} else {
764
			RectF mTempSrc = new RectF(0, 0, drawableWidth, drawableHeight);
765
			RectF mTempDst = new RectF(0, 0, viewWidth, viewHeight);
766
767
			switch (mScaleType) {
768
			case FIT_CENTER:
769
				mBaseMatrix
770
						.setRectToRect(mTempSrc, mTempDst, ScaleToFit.CENTER);
771
				break;
772
773
			case FIT_START:
774
				mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.START);
775
				break;
776
777
			case FIT_END:
778
				mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.END);
779
				break;
780
781
			case FIT_XY:
782
				mBaseMatrix.setRectToRect(mTempSrc, mTempDst, ScaleToFit.FILL);
783
				break;
784
785
			default:
786
				break;
787
			}
788
		}
789
790
		resetMatrix();
791
	}
792
793
	/**
794
	 * Interface definition for a callback to be invoked when the internal
795
	 * Matrix has changed for this View.
796
	 * 
797
	 * @author Chris Banes
798
	 */
799
	public static interface OnMatrixChangedListener {
800
		/**
801
		 * Callback for when the Matrix displaying the Drawable has changed.
802
		 * This could be because the View's bounds have changed, or the user has
803
		 * zoomed.
804
		 * 
805
		 * @param rect
806
		 *            - Rectangle displaying the Drawable's new bounds.
807
		 */
808
		void onMatrixChanged(RectF rect);
809
	}
810
811
	/**
812
	 * Interface definition for a callback to be invoked when the Photo is
813
	 * tapped with a single tap.
814
	 * 
815
	 * @author Chris Banes
816
	 */
817
	public static interface OnPhotoTapListener {
818
819
		/**
820
		 * A callback to receive where the user taps on a photo. You will only
821
		 * receive a callback if the user taps on the actual photo, tapping on
822
		 * 'whitespace' will be ignored.
823
		 * 
824
		 * @param view
825
		 *            - View the user tapped.
826
		 * @param x
827
		 *            - where the user tapped from the of the Drawable, as
828
		 *            percentage of the Drawable width.
829
		 * @param y
830
		 *            - where the user tapped from the top of the Drawable, as
831
		 *            percentage of the Drawable height.
832
		 */
833
		void onPhotoTap(View view, float x, float y);
834
	}
835
836
	/**
837
	 * Interface definition for a callback to be invoked when the ImageView is
838
	 * tapped with a single tap.
839
	 * 
840
	 * @author Chris Banes
841
	 */
842
	public static interface OnViewTapListener {
843
844
		/**
845
		 * A callback to receive where the user taps on a ImageView. You will
846
		 * receive a callback if the user taps anywhere on the view, tapping on
847
		 * 'whitespace' will not be ignored.
848
		 * 
849
		 * @param view
850
		 *            - View the user tapped.
851
		 * @param x
852
		 *            - where the user tapped from the left of the View.
853
		 * @param y
854
		 *            - where the user tapped from the top of the View.
855
		 */
856
		void onViewTap(View view, float x, float y);
857
	}
858
859
	private class AnimatedZoomRunnable implements Runnable {
860
861
		// These are 'postScale' values, means they're compounded each iteration
862
		static final float ANIMATION_SCALE_PER_ITERATION_IN = 1.07f;
863
		static final float ANIMATION_SCALE_PER_ITERATION_OUT = 0.93f;
864
865
		private final float mFocalX, mFocalY;
866
		private final float mTargetZoom;
867
		private final float mDeltaScale;
868
869
		public AnimatedZoomRunnable(final float currentZoom,
870
				final float targetZoom, final float focalX, final float focalY) {
871
			mTargetZoom = targetZoom;
872
			mFocalX = focalX;
873
			mFocalY = focalY;
874
875
			if (currentZoom < targetZoom) {
876
				mDeltaScale = ANIMATION_SCALE_PER_ITERATION_IN;
877
			} else {
878
				mDeltaScale = ANIMATION_SCALE_PER_ITERATION_OUT;
879
			}
880
		}
881
882
		public void run() {
883
			ImageView imageView = getImageView();
884
885
			if (null != imageView) {
886
				mSuppMatrix.postScale(mDeltaScale, mDeltaScale, mFocalX,
887
						mFocalY);
888
				checkAndDisplayMatrix();
889
890
				final float currentScale = getScale();
891
892
				if ((mDeltaScale > 1f && currentScale < mTargetZoom)
893
						|| (mDeltaScale < 1f && mTargetZoom < currentScale)) {
894
					// We haven't hit our target scale yet, so post ourselves
895
					// again
896
					Compat.postOnAnimation(imageView, this);
897
898
				} else {
899
					// We've scaled past our target zoom, so calculate the
900
					// necessary scale so we're back at target zoom
901
					final float delta = mTargetZoom / currentScale;
902
					mSuppMatrix.postScale(delta, delta, mFocalX, mFocalY);
903
					checkAndDisplayMatrix();
904
				}
905
			}
906
		}
907
	}
908
909
	private class FlingRunnable implements Runnable {
910
911
		private final ScrollerProxy mScroller;
912
		private int mCurrentX, mCurrentY;
913
914
		public FlingRunnable(Context context) {
915
			mScroller = ScrollerProxy.getScroller(context);
916
		}
917
918
		public void cancelFling() {
919
			if (DEBUG) {
920
				Log.d(LOG_TAG, "Cancel Fling");
921
			}
922
			mScroller.forceFinished(true);
923
		}
924
925
		public void fling(int viewWidth, int viewHeight, int velocityX,
926
				int velocityY) {
927
			final RectF rect = getDisplayRect();
928
			if (null == rect) {
929
				return;
930
			}
931
932
			final int startX = Math.round(-rect.left);
933
			final int minX, maxX, minY, maxY;
934
935
			if (viewWidth < rect.width()) {
936
				minX = 0;
937
				maxX = Math.round(rect.width() - viewWidth);
938
			} else {
939
				minX = maxX = startX;
940
			}
941
942
			final int startY = Math.round(-rect.top);
943
			if (viewHeight < rect.height()) {
944
				minY = 0;
945
				maxY = Math.round(rect.height() - viewHeight);
946
			} else {
947
				minY = maxY = startY;
948
			}
949
950
			mCurrentX = startX;
951
			mCurrentY = startY;
952
953
			if (DEBUG) {
954
				Log.d(LOG_TAG, "fling. StartX:" + startX + " StartY:" + startY
955
						+ " MaxX:" + maxX + " MaxY:" + maxY);
956
			}
957
958
			// If we actually can move, fling the scroller
959
			if (startX != maxX || startY != maxY) {
960
				mScroller.fling(startX, startY, velocityX, velocityY, minX,
961
						maxX, minY, maxY, 0, 0);
962
			}
963
		}
964
965
		@Override
966
		public void run() {
967
			ImageView imageView = getImageView();
968
			if (null != imageView && mScroller.computeScrollOffset()) {
969
970
				final int newX = mScroller.getCurrX();
971
				final int newY = mScroller.getCurrY();
972
973
				if (DEBUG) {
974
					Log.d(LOG_TAG, "fling run(). CurrentX:" + mCurrentX
975
							+ " CurrentY:" + mCurrentY + " NewX:" + newX
976
							+ " NewY:" + newY);
977
				}
978
979
				mSuppMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY);
980
				setImageViewMatrix(getDisplayMatrix());
981
982
				mCurrentX = newX;
983
				mCurrentY = newY;
984
985
				// Post On animation
986
				Compat.postOnAnimation(imageView, this);
987
			}
988
		}
989
	}
990
}

+ 0 - 13
app/src/main/java/com/electric/chargingpile/zoom/SDK16.java

@ -1,13 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
import android.annotation.TargetApi;
4
import android.view.View;
5
6
@TargetApi(16)
7
public class SDK16 {
8
9
	public static void postOnAnimation(View view, Runnable r) {
10
		view.postOnAnimation(r);
11
	}
12
	
13
}

+ 0 - 101
app/src/main/java/com/electric/chargingpile/zoom/ScrollerProxy.java

@ -1,101 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
import android.annotation.TargetApi;
4
import android.content.Context;
5
import android.os.Build.VERSION;
6
import android.os.Build.VERSION_CODES;
7
import android.widget.OverScroller;
8
import android.widget.Scroller;
9
10
public abstract class ScrollerProxy {
11
12
	public static ScrollerProxy getScroller(Context context) {
13
		if (VERSION.SDK_INT < VERSION_CODES.GINGERBREAD) {
14
			return new PreGingerScroller(context);
15
		} else {
16
			return new GingerScroller(context);
17
		}
18
	}
19
20
	public abstract boolean computeScrollOffset();
21
22
	public abstract void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY,
23
			int maxY, int overX, int overY);
24
25
	public abstract void forceFinished(boolean finished);
26
27
	public abstract int getCurrX();
28
29
	public abstract int getCurrY();
30
31
	@TargetApi(9)
32
	private static class GingerScroller extends ScrollerProxy {
33
34
		private OverScroller mScroller;
35
36
		public GingerScroller(Context context) {
37
			mScroller = new OverScroller(context);
38
		}
39
40
		@Override
41
		public boolean computeScrollOffset() {
42
			return mScroller.computeScrollOffset();
43
		}
44
45
		@Override
46
		public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY,
47
				int overX, int overY) {
48
			mScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY, overX, overY);
49
		}
50
51
		@Override
52
		public void forceFinished(boolean finished) {
53
			mScroller.forceFinished(finished);
54
		}
55
56
		@Override
57
		public int getCurrX() {
58
			return mScroller.getCurrX();
59
		}
60
61
		@Override
62
		public int getCurrY() {
63
			return mScroller.getCurrY();
64
		}
65
	}
66
67
	private static class PreGingerScroller extends ScrollerProxy {
68
69
		private Scroller mScroller;
70
71
		public PreGingerScroller(Context context) {
72
			mScroller = new Scroller(context);
73
		}
74
75
		@Override
76
		public boolean computeScrollOffset() {
77
			return mScroller.computeScrollOffset();
78
		}
79
80
		@Override
81
		public void fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY,
82
				int overX, int overY) {
83
			mScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY);
84
		}
85
86
		@Override
87
		public void forceFinished(boolean finished) {
88
			mScroller.forceFinished(finished);
89
		}
90
91
		@Override
92
		public int getCurrX() {
93
			return mScroller.getCurrX();
94
		}
95
96
		@Override
97
		public int getCurrY() {
98
			return mScroller.getCurrY();
99
		}
100
	}
101
}

+ 0 - 253
app/src/main/java/com/electric/chargingpile/zoom/VersionedGestureDetector.java

@ -1,253 +0,0 @@
1
package com.electric.chargingpile.zoom;
2
3
import android.annotation.TargetApi;
4
import android.content.Context;
5
import android.os.Build;
6
import android.util.FloatMath;
7
import android.view.MotionEvent;
8
import android.view.ScaleGestureDetector;
9
import android.view.ScaleGestureDetector.OnScaleGestureListener;
10
import android.view.VelocityTracker;
11
import android.view.ViewConfiguration;
12
13
public abstract class VersionedGestureDetector {
14
	static final String LOG_TAG = "VersionedGestureDetector";
15
	OnGestureListener mListener;
16
17
	public static VersionedGestureDetector newInstance(Context context, OnGestureListener listener) {
18
		final int sdkVersion = Build.VERSION.SDK_INT;
19
		VersionedGestureDetector detector = null;
20
21
		if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
22
			detector = new CupcakeDetector(context);
23
		} else if (sdkVersion < Build.VERSION_CODES.FROYO) {
24
			detector = new EclairDetector(context);
25
		} else {
26
			detector = new FroyoDetector(context);
27
		}
28
29
		detector.mListener = listener;
30
31
		return detector;
32
	}
33
34
	public abstract boolean onTouchEvent(MotionEvent ev);
35
36
	public abstract boolean isScaling();
37
38
	public static interface OnGestureListener {
39
		public void onDrag(float dx, float dy);
40
41
		public void onFling(float startX, float startY, float velocityX, float velocityY);
42
43
		public void onScale(float scaleFactor, float focusX, float focusY);
44
	}
45
46
	private static class CupcakeDetector extends VersionedGestureDetector {
47
48
		float mLastTouchX;
49
		float mLastTouchY;
50
		final float mTouchSlop;
51
		final float mMinimumVelocity;
52
53
		public CupcakeDetector(Context context) {
54
			final ViewConfiguration configuration = ViewConfiguration.get(context);
55
			mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
56
			mTouchSlop = configuration.getScaledTouchSlop();
57
		}
58
59
		private VelocityTracker mVelocityTracker;
60
		private boolean mIsDragging;
61
62
		float getActiveX(MotionEvent ev) {
63
			return ev.getX();
64
		}
65
66
		float getActiveY(MotionEvent ev) {
67
			return ev.getY();
68
		}
69
70
		public boolean isScaling() {
71
			return false;
72
		}
73
74
		@Override
75
		public boolean onTouchEvent(MotionEvent ev) {
76
			switch (ev.getAction()) {
77
				case MotionEvent.ACTION_DOWN: {
78
					mVelocityTracker = VelocityTracker.obtain();
79
					mVelocityTracker.addMovement(ev);
80
81
					mLastTouchX = getActiveX(ev);
82
					mLastTouchY = getActiveY(ev);
83
					mIsDragging = false;
84
					break;
85
				}
86
87
				case MotionEvent.ACTION_MOVE: {
88
					final float x = getActiveX(ev);
89
					final float y = getActiveY(ev);
90
					final float dx = x - mLastTouchX, dy = y - mLastTouchY;
91
92
					if (!mIsDragging) {
93
						// Use Pythagoras to see if drag length is larger than
94
						// touch slop
95
						mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
96
					}
97
98
					if (mIsDragging) {
99
						mListener.onDrag(dx, dy);
100
						mLastTouchX = x;
101
						mLastTouchY = y;
102
103
						if (null != mVelocityTracker) {
104
							mVelocityTracker.addMovement(ev);
105
						}
106
					}
107
					break;
108
				}
109
110
				case MotionEvent.ACTION_CANCEL: {
111
					// Recycle Velocity Tracker
112
					if (null != mVelocityTracker) {
113
						mVelocityTracker.recycle();
114
						mVelocityTracker = null;
115
					}
116
					break;
117
				}
118
119
				case MotionEvent.ACTION_UP: {
120
					if (mIsDragging) {
121
						if (null != mVelocityTracker) {
122
							mLastTouchX = getActiveX(ev);
123
							mLastTouchY = getActiveY(ev);
124
125
							// Compute velocity within the last 1000ms
126
							mVelocityTracker.addMovement(ev);
127
							mVelocityTracker.computeCurrentVelocity(1000);
128
129
							final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();
130
131
							// If the velocity is greater than minVelocity, call
132
							// listener
133
							if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
134
								mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
135
							}
136
						}
137
					}
138
139
					// Recycle Velocity Tracker
140
					if (null != mVelocityTracker) {
141
						mVelocityTracker.recycle();
142
						mVelocityTracker = null;
143
					}
144
					break;
145
				}
146
			}
147
148
			return true;
149
		}
150
	}
151
152
	@TargetApi(5)
153
	private static class EclairDetector extends CupcakeDetector {
154
		private static final int INVALID_POINTER_ID = -1;
155
		private int mActivePointerId = INVALID_POINTER_ID;
156
		private int mActivePointerIndex = 0;
157
158
		public EclairDetector(Context context) {
159
			super(context);
160
		}
161
162
		@Override
163
		float getActiveX(MotionEvent ev) {
164
			try {
165
				return ev.getX(mActivePointerIndex);
166
			} catch (Exception e) {
167
				return ev.getX();
168
			}
169
		}
170
171
		@Override
172
		float getActiveY(MotionEvent ev) {
173
			try {
174
				return ev.getY(mActivePointerIndex);
175
			} catch (Exception e) {
176
				return ev.getY();
177
			}
178
		}
179
180
		@Override
181
		public boolean onTouchEvent(MotionEvent ev) {
182
			final int action = ev.getAction();
183
			switch (action & MotionEvent.ACTION_MASK) {
184
				case MotionEvent.ACTION_DOWN:
185
					mActivePointerId = ev.getPointerId(0);
186
					break;
187
				case MotionEvent.ACTION_CANCEL:
188
				case MotionEvent.ACTION_UP:
189
					mActivePointerId = INVALID_POINTER_ID;
190
					break;
191
				case MotionEvent.ACTION_POINTER_UP:
192
					final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
193
					final int pointerId = ev.getPointerId(pointerIndex);
194
					if (pointerId == mActivePointerId) {
195
						// This was our active pointer going up. Choose a new
196
						// active pointer and adjust accordingly.
197
						final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
198
						mActivePointerId = ev.getPointerId(newPointerIndex);
199
						mLastTouchX = ev.getX(newPointerIndex);
200
						mLastTouchY = ev.getY(newPointerIndex);
201
					}
202
					break;
203
			}
204
205
			mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
206
			return super.onTouchEvent(ev);
207
		}
208
	}
209
210
	@TargetApi(8)
211
	private static class FroyoDetector extends EclairDetector {
212
213
		private final ScaleGestureDetector mDetector;
214
215
		// Needs to be an inner class so that we don't hit
216
		// VerifyError's on API 4.
217
		private final OnScaleGestureListener mScaleListener = new OnScaleGestureListener() {
218
219
			@Override
220
			public boolean onScale(ScaleGestureDetector detector) {
221
				mListener.onScale(detector.getScaleFactor(), detector.getFocusX(), detector.getFocusY());
222
				return true;
223
			}
224
225
			@Override
226
			public boolean onScaleBegin(ScaleGestureDetector detector) {
227
				return true;
228
			}
229
230
			@Override
231
			public void onScaleEnd(ScaleGestureDetector detector) {
232
				// NO-OP
233
			}
234
		};
235
236
		public FroyoDetector(Context context) {
237
			super(context);
238
			mDetector = new ScaleGestureDetector(context, mScaleListener);
239
		}
240
241
		@Override
242
		public boolean isScaling() {
243
			return mDetector.isInProgress();
244
		}
245
246
		@Override
247
		public boolean onTouchEvent(MotionEvent ev) {
248
			mDetector.onTouchEvent(ev);
249
			return super.onTouchEvent(ev);
250
		}
251
252
	}
253
}

+ 0 - 36
app/src/main/java/com/electric/chargingpile/zoom/ViewPagerFixed.java

@ -1,36 +0,0 @@
1
package com.electric.chargingpile.zoom;
2

3
import android.content.Context;
4
import android.util.AttributeSet;
5
import android.view.MotionEvent;
6

7
public class ViewPagerFixed extends android.support.v4.view.ViewPager {
8

9
    public ViewPagerFixed(Context context) {
10
        super(context);
11
    }
12

13
    public ViewPagerFixed(Context context, AttributeSet attrs) {
14
        super(context, attrs);
15
    }
16

17
    @Override
18
    public boolean onTouchEvent(MotionEvent ev) {
19
        try {
20
            return super.onTouchEvent(ev);
21
        } catch (IllegalArgumentException ex) {
22
            ex.printStackTrace();
23
        }
24
        return false;
25
    }
26

27
    @Override
28
    public boolean onInterceptTouchEvent(MotionEvent ev) {
29
        try {
30
            return super.onInterceptTouchEvent(ev);
31
        } catch (IllegalArgumentException ex) {
32
            ex.printStackTrace();
33
        }
34
        return false;
35
    }
36
}

完成评论视频详情页 · 522af193e4 - Gogs: Go Git Service
Browse Source

完成评论视频详情页

hy 4 years ago
parent
commit
522af193e4

+ 4 - 3
app/build.gradle

@ -223,9 +223,10 @@ dependencies {
223 223
    //    implementation 'com.github.castorflex.verticalviewpager:library:19.0.1'
224 224
    // sqlite异常结局
225 225
    implementation 'net.zetetic:android-database-sqlcipher:3.5.7@aar'
226
    implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-java:v8.1.5-jitpack'
227
    implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-armv7a:v8.1.5-jitpack'
228
    implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-armv64:v8.1.5-jitpack'
226
    implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-java:v8.2.0-release-jitpack'
227
    implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-armv7a:v8.2.0-release-jitpack'
228
    implementation 'com.github.CarGuo.GSYVideoPlayer:gsyVideoPlayer-arm64:v8.2.0-release-jitpack'
229
229 230
    implementation 'com.wang.avi:library:2.1.3'
230 231
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
231 232
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'

+ 4 - 0
app/src/main/AndroidManifest.xml

@ -103,6 +103,10 @@
103 103
            android:name=".activity.ImageDisplayActivity"
104 104
            android:screenOrientation="portrait"/>
105 105
        <activity
106
            android:windowSoftInputMode="adjustResize|stateHidden"
107
            android:name=".activity.CommentVideoDetailActivity"
108
            android:screenOrientation="portrait"/>
109
        <activity
106 110
            android:name=".activity.VideoCompressionActivity"
107 111
            android:screenOrientation="portrait"/>
108 112
        <activity

+ 1 - 1
app/src/main/java/com/electric/chargingpile/activity/ChatActivity.java

@ -61,7 +61,7 @@ public class ChatActivity extends AppCompatActivity implements View.OnClickListe
61 61
        initView();
62 62
        initListener();
63 63
        isRefresh = true;
64
        updateView(0);
64
        updateView(1);
65 65
    }
66 66
67 67
    private void initView() {

+ 2 - 2
app/src/main/java/com/electric/chargingpile/activity/ChatContentListActivity.java

@ -370,8 +370,8 @@ public class ChatContentListActivity extends AppCompatActivity {
370 370
371 371
            videoPlayer.setGSYVideoProgressListener(new GSYVideoProgressListener() {
372 372
                @Override
373
                public void onProgress(int i, int i1, int i2, int i3) {
374
                    progressBar.setProgress(i);
373
                public void onProgress(long progress, long secProgress, long currentPosition, long duration) {
374
                    progressBar.setProgress(Math.toIntExact(progress));
375 375
                }
376 376
            });
377 377

+ 131 - 0
app/src/main/java/com/electric/chargingpile/activity/CommentVideoDetailActivity.java

@ -0,0 +1,131 @@
1
package com.electric.chargingpile.activity;
2
3
import android.content.Context;
4
import android.content.Intent;
5
import android.os.Bundle;
6
import android.util.Log;
7
8
import androidx.annotation.Nullable;
9
import androidx.appcompat.app.AppCompatActivity;
10
11
import com.electric.chargingpile.R;
12
import com.electric.chargingpile.application.MainApplication;
13
import com.electric.chargingpile.data.SingleCommentBean;
14
import com.electric.chargingpile.util.JsonUtils;
15
import com.electric.chargingpile.util.LoadingDialog;
16
import com.electric.chargingpile.video.VideoPlayer;
17
import com.google.gson.Gson;
18
import com.shuyu.gsyvideoplayer.video.base.GSYVideoView;
19
import com.zhy.http.okhttp.OkHttpUtils;
20
import com.zhy.http.okhttp.callback.StringCallback;
21
22
import org.json.JSONException;
23
import org.json.JSONObject;
24
25
import okhttp3.Call;
26
27
public class CommentVideoDetailActivity extends AppCompatActivity {
28
29
    private VideoPlayer mVideoPlayer;
30
    private Gson mGson=new Gson();
31
    private String pid;
32
    private LoadingDialog mLoadingDialog = null ;
33
    @Override
34
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
35
        super.onCreate(savedInstanceState);
36
        setContentView(R.layout.activity_video_detail);
37
        initView();
38
        pid = getIntent().getStringExtra("id");
39
        if (null != pid && !pid.equals("")) {
40
            getCommentData();
41
        }
42
43
    }
44
45
46
    private void initView() {
47
        mLoadingDialog = new LoadingDialog(this);
48
        mLoadingDialog.setCanceledOnTouchOutside(false);
49
50
        mVideoPlayer = findViewById(R.id.videoPlayer);
51
52
    }
53
54
55
    private void getCommentData() {
56
        String url = MainApplication.url + "/zhannew/basic/web/index.php/tpappcomments/get-sub-comments?id=" + pid;
57
        Log.e("getCommentData_url=", url);
58
        mLoadingDialog.show();
59
        OkHttpUtils.get().url(url).build().execute(new StringCallback() {
60
            @Override
61
            public void onError(Call call, Exception e) {
62
                if (mLoadingDialog.isShowing()){
63
                    mLoadingDialog.dismiss();
64
                }
65
            }
66
67
            @Override
68
            public void onResponse(String response) {
69
                if (mLoadingDialog.isShowing()){
70
                    mLoadingDialog.dismiss();
71
                }
72
73
                Log.e("respone==", response);
74
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
75
                if (null != rtnCode && rtnCode.equals("01")) {
76
                    try {
77
                        JSONObject jsonObj = new JSONObject(response);
78
                        String commentData = jsonObj.getString("data");
79
                        Log.e("commentBean==", commentData);
80
                        JSONObject obj = new JSONObject(commentData);
81
                        SingleCommentBean singleCommentBean = mGson.fromJson(commentData, SingleCommentBean.class);
82
                        String fileUrl = singleCommentBean.getFileUrl();
83
                        String url = MainApplication.CDN + fileUrl;
84
                        mVideoPlayer.setUp(url, true, "");
85
                        mVideoPlayer.startPlayLogic();
86
87
                    } catch (JSONException e) {
88
                        e.printStackTrace();
89
                        Log.e("respone==", "onResponse: "+e.getMessage());
90
                    }
91
                } else {
92
93
                }
94
            }
95
        });
96
    }
97
98
    @Override
99
    protected void onResume() {
100
        super.onResume();
101
        playOrPause();
102
    }
103
    private void playOrPause() {
104
        int currentStatue = mVideoPlayer.getCurrentState();
105
        if (currentStatue == GSYVideoView.CURRENT_STATE_PLAYING) {
106
            mVideoPlayer.onVideoPause();
107
        } else if (currentStatue == GSYVideoView.CURRENT_STATE_PAUSE) {
108
            mVideoPlayer.onVideoResume(false);
109
        } else {
110
            mVideoPlayer.startPlayLogic();
111
        }
112
    }
113
114
    @Override
115
    protected void onPause() {
116
        super.onPause();
117
        playOrPause();
118
    }
119
120
    @Override
121
    protected void onDestroy() {
122
        super.onDestroy();
123
        mVideoPlayer.release();
124
    }
125
126
    public  static void actioinStart(Context context, String id){
127
        Intent intent = new Intent(context, CommentVideoDetailActivity.class);
128
        intent.putExtra("id",id);
129
        context.startActivity(intent);
130
    }
131
}

+ 112 - 30
app/src/main/java/com/electric/chargingpile/activity/SingleCommentActivity.java

@ -7,6 +7,7 @@ import android.os.Bundle;
7 7
import android.os.Handler;
8 8
import android.text.SpannableString;
9 9
import android.text.Spanned;
10
import android.text.TextUtils;
10 11
import android.text.style.ForegroundColorSpan;
11 12
import android.util.Log;
12 13
import android.view.LayoutInflater;
@ -21,11 +22,13 @@ import android.widget.ScrollView;
21 22
import android.widget.TextView;
22 23
import android.widget.Toast;
23 24
25
import com.bumptech.glide.Glide;
24 26
import com.electric.chargingpile.R;
25 27
import com.electric.chargingpile.adapter.ZhanSCommentsAdapter;
26 28
import com.electric.chargingpile.application.MainApplication;
27 29
import com.electric.chargingpile.data.MyOtto;
28 30
import com.electric.chargingpile.data.RankinglistRefreshEvent;
31
29 32
import com.electric.chargingpile.fragment.ZhanCommentFragment;
30 33
import com.electric.chargingpile.util.BarColorUtil;
31 34
import com.electric.chargingpile.util.CarTypeUtil;
@ -38,6 +41,7 @@ import com.electric.chargingpile.util.Util;
38 41
import com.electric.chargingpile.view.CircleImageView;
39 42
import com.electric.chargingpile.view.ContainsEmojiEditText;
40 43
import com.electric.chargingpile.view.CustomScrollView;
44
import com.google.gson.Gson;
41 45
import com.squareup.otto.Subscribe;
42 46
import com.squareup.picasso.Picasso;
43 47
import com.zhy.http.okhttp.OkHttpUtils;
@ -58,7 +62,7 @@ import java.util.regex.Pattern;
58 62
import okhttp3.Call;
59 63
60 64
public class SingleCommentActivity extends Activity implements View.OnClickListener {
61
    private ImageView iv_back, iv_commentPic, iv_pgrade, iv_pzan, iv_level_img;
65
    private ImageView iv_back, iv_commentPic, iv_pgrade, iv_pzan, iv_level_img,imgVideo,imgStart,imgTwo,imgThree;
62 66
    private ListView lv_scomment;
63 67
    private CircleImageView iv_picon;
64 68
    private CustomScrollView scrollView;
@ -77,7 +81,8 @@ public class SingleCommentActivity extends Activity implements View.OnClickListe
77 81
    private RelativeLayout rl_point;
78 82
    private android.view.animation.Animation animation;
79 83
    private ImageView certified_icon;
80
84
    private RelativeLayout imgLayout;
85
    private Gson mGson = new Gson();
81 86
    @Override
82 87
    protected void onCreate(Bundle savedInstanceState) {
83 88
        super.onCreate(savedInstanceState);
@ -114,6 +119,11 @@ public class SingleCommentActivity extends Activity implements View.OnClickListe
114 119
        certified_icon = (ImageView)findViewById(R.id.certified_icon);
115 120
        fl_ptag = (TagFlowLayout) findViewById(R.id.fl_ptag);
116 121
        iv_commentPic = (ImageView) findViewById(R.id.iv_commentPic);
122
        imgTwo = (ImageView) findViewById(R.id.imgTwo);
123
        imgThree = (ImageView) findViewById(R.id.imgThree);
124
        imgVideo = (ImageView) findViewById(R.id.imgVideo);
125
        imgStart = (ImageView) findViewById(R.id.imgStart);
126
        imgLayout = findViewById(R.id.imgLayout);
117 127
        iv_pgrade = (ImageView) findViewById(R.id.iv_pgrade);
118 128
        iv_pzan = (ImageView) findViewById(R.id.iv_pzan);
119 129
        et_commet = (ContainsEmojiEditText) findViewById(R.id.et_commet);
@ -167,12 +177,10 @@ public class SingleCommentActivity extends Activity implements View.OnClickListe
167 177
                        Log.e("single==", "dealData: size=" + datas.size());
168 178
                        lv_scomment.setAdapter(new ZhanSCommentsAdapter(datas, SingleCommentActivity.this, getApplicationContext(), "2", ""));
169 179
170
                        new Handler().post(new Runnable() {
171
                            @Override
172
                            public void run() {
180
                        new Handler().post(()-> {
173 181
                                scrollView.fullScroll(ScrollView.FOCUS_UP);
174 182
                            }
175
                        });
183
                        );
176 184
                    } catch (JSONException e) {
177 185
                        e.printStackTrace();
178 186
                    }
@ -284,32 +292,96 @@ public class SingleCommentActivity extends Activity implements View.OnClickListe
284 292
            }
285 293
        }
286 294
        //设置图片
287
        String thumUrl = JsonUtils.getKeyResult(data, "thumUrl");
288 295
        String fileUrl = JsonUtils.getKeyResult(data, "fileUrl");
289
        if (!thumUrl.equals("")) {
290
            iv_commentPic.setVisibility(View.VISIBLE);
291
//            String url = "http://59.110.68.162"+"/zhannew/uploadfile/"+thumUrl;
292
            String url = MainApplication.url + "/zhannew/uploadfile/" + thumUrl;
293
            String file_url = MainApplication.url + "/zhannew/uploadfile/" + fileUrl;
294
//            String file_url = "http://59.110.68.162"+"/zhannew/uploadfile/"+fileUrl;
295
            final String[] ss = {file_url};
296
            Picasso.with(MainApplication.context)
297
                    .load(url)
298
                    .placeholder(R.drawable.icon_user1118)
299
                    .error(R.drawable.icon_user1118)
300
                    .into(iv_commentPic);
301
            iv_commentPic.setOnClickListener(new View.OnClickListener() {
302
                @Override
303
                public void onClick(View v) {
304
                    Intent intent = new Intent(getApplicationContext(), ImagePagerActivity.class);
305
                    // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取
306
                    intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, ss);
307
                    intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, 0);
308
                    startActivity(intent);
309
                }
296
        fileUrl=fileUrl==null?"":fileUrl;
297
        String file2Url =  JsonUtils.getKeyResult(data, "file2Url");
298
        file2Url=file2Url==null?"":file2Url;
299
        String file3Url =  JsonUtils.getKeyResult(data, "file3Url");
300
        file3Url=file3Url==null?"":file3Url;
301
        String type = JsonUtils.getKeyResult(data, "type")==null?"":JsonUtils.getKeyResult(data, "type"); //23 视频,24 图片
302
        if (type.equals("23")){
303
           imgVideo.setVisibility(View.VISIBLE);
304
           imgStart.setVisibility(View.VISIBLE);
305
           imgLayout.setVisibility(View.VISIBLE);
306
307
           iv_commentPic.setVisibility(View.GONE);
308
           imgTwo.setVisibility(View.GONE);
309
           imgThree.setVisibility(View.GONE);
310
311
            String thumUrl = JsonUtils.getKeyResult(data, "thumUrl");
312
            if (!TextUtils.isEmpty(thumUrl) && !TextUtils.isEmpty(fileUrl)){
313
                Glide.with(this)
314
                        .load(MainApplication.CDN +thumUrl)
315
                        .into(imgVideo);
316
317
                imgVideo.setOnClickListener(v->{
318
                    CommentVideoDetailActivity.actioinStart(this,pid);
319
                });
320
            }
321
322
        }else {
323
324
            imgVideo.setVisibility(View.GONE);
325
            imgStart.setVisibility(View.GONE);
326
327
328
            if (!fileUrl.equals("")) {
329
                iv_commentPic.setVisibility(View.VISIBLE);
330
                imgLayout.setVisibility(View.VISIBLE);
331
332
                Picasso.with(this)
333
                        .load(MainApplication.url + "/zhannew/uploadfile/"+fileUrl)
334
                        .into(iv_commentPic);
335
336
            } else {
337
                iv_commentPic.setVisibility(View.GONE);
338
                imgLayout.setVisibility(View.GONE);
339
            }
340
            if (!file2Url.equals("")) {
341
                imgTwo.setVisibility(View.VISIBLE);
342
                Picasso.with(this)
343
                        .load(MainApplication.url + "/zhannew/uploadfile/"+file2Url)
344
                        .into(imgTwo);
345
            } else {
346
                imgTwo.setVisibility(View.GONE);
347
            }
348
            if (!file3Url.equals("")) {
349
                imgThree.setVisibility(View.VISIBLE);
350
                Picasso.with(this)
351
                        .load(MainApplication.url + "/zhannew/uploadfile/"+file3Url)
352
                        .into(imgThree);
353
            } else {
354
                imgThree.setVisibility(View.GONE);
355
            }
356
357
            String[] fileUrlArray = null;
358
            if (!TextUtils.isEmpty(fileUrl) && !TextUtils.isEmpty(file2Url) &&!TextUtils.isEmpty(file3Url)){
359
                fileUrlArray =new String[]{
360
                        MainApplication.url + "/zhannew/uploadfile/"+fileUrl,
361
                        MainApplication.url + "/zhannew/uploadfile/"+file2Url,
362
                        MainApplication.url + "/zhannew/uploadfile/"+file3Url
363
                };
364
            }else  if (!TextUtils.isEmpty(fileUrl) && !TextUtils.isEmpty(file2Url)){
365
                fileUrlArray =new String[]{
366
                        MainApplication.url + "/zhannew/uploadfile/"+fileUrl,
367
                        MainApplication.url + "/zhannew/uploadfile/"+file2Url
368
                };
369
            }else  if (!TextUtils.isEmpty(fileUrl)){
370
                fileUrlArray =new String[]{ MainApplication.url + "/zhannew/uploadfile/"+fileUrl};
371
            }
372
373
374
            String[] finalFileUrlArray = fileUrlArray;
375
            iv_commentPic.setOnClickListener(v->{
376
                startImagePager(finalFileUrlArray, 0);
377
            });
378
379
            imgTwo.setOnClickListener(v->{
380
                startImagePager(finalFileUrlArray, 1);
381
            });
382
            imgThree.setOnClickListener(v->{
383
                startImagePager(finalFileUrlArray, 2);
310 384
            });
311
        } else {
312
            iv_commentPic.setVisibility(View.GONE);
313 385
        }
314 386
        //设置评分
315 387
        String grade = JsonUtils.getKeyResult(data, "star_level");
@ -422,6 +494,16 @@ public class SingleCommentActivity extends Activity implements View.OnClickListe
422 494
423 495
    }
424 496
497
    private void startImagePager(String[] finalFileUrlArray, int i) {
498
499
500
        Intent intent = new Intent(SingleCommentActivity.this, ImagePagerActivity.class);
501
        // 图片url,为了演示这里使用常量,一般从数据库中或网络中获取
502
        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, finalFileUrlArray);
503
        intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, i);
504
        startActivity(intent);
505
    }
506
425 507
    @Override
426 508
    public void onClick(View v) {
427 509
        switch (v.getId()) {

+ 31 - 11
app/src/main/java/com/electric/chargingpile/adapter/NewPingLunAdapter.java

@ -28,6 +28,7 @@ import com.electric.chargingpile.R;
28 28
import com.electric.chargingpile.activity.ImagePagerActivity;
29 29
import com.electric.chargingpile.activity.NewZhanDetailsActivity;
30 30
import com.electric.chargingpile.activity.SingleCommentActivity;
31
import com.electric.chargingpile.activity.CommentVideoDetailActivity;
31 32
import com.electric.chargingpile.application.MainApplication;
32 33
import com.electric.chargingpile.util.JsonUtils;
33 34
import com.electric.chargingpile.util.Util;
@ -153,29 +154,48 @@ public class NewPingLunAdapter extends BaseAdapter {
153 154
        }
154 155
155 156
        {
157
            final View finalConvertView2 = convertView;
156 158
            try {
159
                String is_play = TextUtils.isEmpty( datas.get(position).getString("is_play"))?"": datas.get(position).getString("is_play")  ; //0 审核未通过 item隐藏,1 审核通过,item显示
160
161
                if (TextUtils.isEmpty(is_play) && is_play.equals("1")){
162
                    convertView.setVisibility(View.VISIBLE);
163
                }else{
164
                    convertView.setVisibility(View.GONE);
165
                }
166
157 167
//                "fileUrl":"","thumUrl":""
158 168
                //父级评论图片
159 169
                String fileUrl = datas.get(position).getString("fileUrl");
160 170
                String file2Url = datas.get(position).getString("file2Url");
161 171
                String file3Url = datas.get(position).getString("file3Url");
162
                String type = datas.get(position).getString("type"); //23 视频,24 图片
172
173
174
                fileUrl=fileUrl==null?"":fileUrl;
175
                file2Url=file2Url==null?"":file2Url;
176
                file3Url=file3Url==null?"":file3Url;
177
                String type = TextUtils.isEmpty(datas.get(position).getString("type"))?"":datas.get(position).getString("type"); //23 视频,24 图片
163 178
                if (type.equals("23")){
164
                    String thumUrl = datas.get(position).getString("thumUrl");
165
                    if (!TextUtils.isEmpty(thumUrl)){
166
                        holder.imgVideo.setVisibility(View.VISIBLE);
167
                        holder.imgStart.setVisibility(View.VISIBLE);
179
                    holder.imgVideo.setVisibility(View.VISIBLE);
180
                    holder.imgStart.setVisibility(View.VISIBLE);
181
                    holder.imgLayout.setVisibility(View.VISIBLE);
168 182
169
                        holder.iv_commentPic.setVisibility(View.GONE);
170
                        holder.imgTwo.setVisibility(View.GONE);
171
                        holder.imgThree.setVisibility(View.GONE);
183
                    holder.iv_commentPic.setVisibility(View.GONE);
184
                    holder.imgTwo.setVisibility(View.GONE);
185
                    holder.imgThree.setVisibility(View.GONE);
172 186
187
                    String thumUrl = datas.get(position).getString("thumUrl");
188
                    if (!TextUtils.isEmpty(thumUrl) && !TextUtils.isEmpty(fileUrl)){
173 189
                        Glide.with(MainApplication.context)
174
                                .load(MainApplication.CDN +fileUrl)
190
                                .load(MainApplication.CDN +thumUrl)
175 191
                                .into(holder.imgVideo);
176 192
177 193
                        holder.imgVideo.setOnClickListener(v->{
178
194
                            try {
195
                                CommentVideoDetailActivity.actioinStart(finalConvertView2.getContext(),datas.get(position).getString("id"));
196
                            } catch (JSONException e) {
197
                                e.printStackTrace();
198
                            }
179 199
                        });
180 200
                    }
181 201
                }else {
@ -230,7 +250,7 @@ public class NewPingLunAdapter extends BaseAdapter {
230 250
                        fileUrlArray =new String[]{ MainApplication.url + "/zhannew/uploadfile/"+fileUrl};
231 251
                    }
232 252
233
                    final View finalConvertView2 = convertView;
253
234 254
                    String[] finalFileUrlArray = fileUrlArray;
235 255
                    holder.iv_commentPic.setOnClickListener(new View.OnClickListener() {
236 256
                        @Override

+ 23 - 14
app/src/main/java/com/electric/chargingpile/adapter/ZhanCommentsAapter.java

@ -27,6 +27,7 @@ import com.electric.chargingpile.activity.LoginActivity;
27 27
import com.electric.chargingpile.activity.MainMapActivity;
28 28
import com.electric.chargingpile.activity.NewZhanDetailsActivity;
29 29
import com.electric.chargingpile.activity.SingleCommentActivity;
30
import com.electric.chargingpile.activity.CommentVideoDetailActivity;
30 31
import com.electric.chargingpile.application.MainApplication;
31 32
import com.electric.chargingpile.fragment.ZhanCommentFragment;
32 33
import com.electric.chargingpile.util.CarTypeUtil;
@ -431,33 +432,41 @@ public class ZhanCommentsAapter extends BaseAdapter {
431 432
432 433
                    }
433 434
                });
435
436
                String is_play = TextUtils.isEmpty( datas.get(position).getString("is_play"))?"": datas.get(position).getString("is_play")  ; //0 审核未通过 item隐藏,1 审核通过,item显示
437
438
                if (TextUtils.isEmpty(is_play) && is_play.equals("1")){
439
                    convertView.setVisibility(View.VISIBLE);
440
                }else{
441
                    convertView.setVisibility(View.GONE);
442
                }
443
434 444
                //父级评论图片
435 445
                String fileUrl = datas.get(position).getString("fileUrl");
436 446
                String file2Url = datas.get(position).getString("file2Url");
437 447
                String file3Url = datas.get(position).getString("file3Url");
438
                String type = datas.get(position).getString("type"); //23 视频,24 图片
448
                fileUrl = fileUrl == null?"":fileUrl;
449
                file2Url= file2Url == null?"":file2Url;
450
                file3Url= file3Url == null?"":file3Url;
451
                String type = TextUtils.isEmpty(datas.get(position).getString("type"))?"":datas.get(position).getString("type"); //23 视频,24 图片
439 452
                if (type.equals("23")){
453
                    holder.imgVideo.setVisibility(View.VISIBLE);
454
                    holder.imgStart.setVisibility(View.VISIBLE);
455
                    holder.imgLayout.setVisibility(View.VISIBLE);
440 456
441
                    String thumUrl = datas.get(position).getString("thumUrl");
442
                    if (!TextUtils.isEmpty(thumUrl)){
443
                        holder.imgVideo.setVisibility(View.VISIBLE);
444
                        holder.imgStart.setVisibility(View.VISIBLE);
445
446
                        holder.iv_commentPic.setVisibility(View.GONE);
447
                        holder.imgTwo.setVisibility(View.GONE);
448
                        holder.imgThree.setVisibility(View.GONE);
457
                    holder.iv_commentPic.setVisibility(View.GONE);
458
                    holder.imgTwo.setVisibility(View.GONE);
459
                    holder.imgThree.setVisibility(View.GONE);
449 460
461
                    String thumUrl = datas.get(position).getString("thumUrl");
462
                    if (!TextUtils.isEmpty(thumUrl) && !TextUtils.isEmpty(fileUrl)){
450 463
                        Glide.with(MainApplication.context)
451 464
                                .load(MainApplication.CDN +thumUrl)
452 465
                                .into(holder.imgVideo);
453 466
454 467
                        holder.imgVideo.setOnClickListener(v->{
455 468
                            try {
456
                                if (!datas.get(position).getString("id").equals("") && null != datas.get(position).getString("id")) {
457
                                    Intent intent = new Intent(finalConvertView1.getContext(), SingleCommentActivity.class);
458
                                    intent.putExtra("id", datas.get(position).getString("id"));
459
                                    finalConvertView1.getContext().startActivity(intent);
460
                                }
469
                                CommentVideoDetailActivity.actioinStart(finalConvertView1.getContext(),datas.get(position).getString("id"));
461 470
                            } catch (JSONException e) {
462 471
                                e.printStackTrace();
463 472
                            }

+ 287 - 0
app/src/main/java/com/electric/chargingpile/data/SingleCommentBean.java

@ -0,0 +1,287 @@
1
package com.electric.chargingpile.data;
2
3
import java.util.List;
4
5
6
public class SingleCommentBean  {
7
8
    private String id;
9
10
    private String ancestorid;
11
12
    private String parentid;
13
14
    private String userid;
15
16
    private String agreeNum;
17
18
    private String tel;
19
20
    private String hascar;
21
22
    private String zhanid;
23
24
    private String content;
25
26
    private String fileUrl;
27
28
    private String file2Url;
29
30
    private String file3Url;
31
32
    private String theme;
33
34
    private String isPlay;
35
36
    private String type;
37
38
    private String thumUrl;
39
40
    private String addtime;
41
42
    private String nickname;
43
44
    private String userpic;
45
46
    private String username;
47
48
    private String chexing;
49
50
    private String fine;
51
52
    private String commentsCount;
53
54
    private String starLevel;
55
56
    private String tag;
57
58
    private List<SubcommentBean> subcomments;
59
60
    private Integer isCertifiedOwner;
61
62
    private String title;
63
64
    public String getId() {
65
        return id;
66
    }
67
68
    public void setId(String id) {
69
        this.id = id;
70
    }
71
72
    public String getAncestorid() {
73
        return ancestorid;
74
    }
75
76
    public void setAncestorid(String ancestorid) {
77
        this.ancestorid = ancestorid;
78
    }
79
80
    public String getParentid() {
81
        return parentid;
82
    }
83
84
    public void setParentid(String parentid) {
85
        this.parentid = parentid;
86
    }
87
88
    public String getUserid() {
89
        return userid;
90
    }
91
92
    public void setUserid(String userid) {
93
        this.userid = userid;
94
    }
95
96
    public String getAgreeNum() {
97
        return agreeNum;
98
    }
99
100
    public void setAgreeNum(String agreeNum) {
101
        this.agreeNum = agreeNum;
102
    }
103
104
    public String getTel() {
105
        return tel;
106
    }
107
108
    public void setTel(String tel) {
109
        this.tel = tel;
110
    }
111
112
    public String getHascar() {
113
        return hascar;
114
    }
115
116
    public void setHascar(String hascar) {
117
        this.hascar = hascar;
118
    }
119
120
    public String getZhanid() {
121
        return zhanid;
122
    }
123
124
    public void setZhanid(String zhanid) {
125
        this.zhanid = zhanid;
126
    }
127
128
    public String getContent() {
129
        return content;
130
    }
131
132
    public void setContent(String content) {
133
        this.content = content;
134
    }
135
136
    public String getFileUrl() {
137
        return fileUrl;
138
    }
139
140
    public void setFileUrl(String fileUrl) {
141
        this.fileUrl = fileUrl;
142
    }
143
144
    public String getFile2Url() {
145
        return file2Url;
146
    }
147
148
    public void setFile2Url(String file2Url) {
149
        this.file2Url = file2Url;
150
    }
151
152
    public String getFile3Url() {
153
        return file3Url;
154
    }
155
156
    public void setFile3Url(String file3Url) {
157
        this.file3Url = file3Url;
158
    }
159
160
    public String getTheme() {
161
        return theme;
162
    }
163
164
    public void setTheme(String theme) {
165
        this.theme = theme;
166
    }
167
168
    public String getIsPlay() {
169
        return isPlay;
170
    }
171
172
    public void setIsPlay(String isPlay) {
173
        this.isPlay = isPlay;
174
    }
175
176
    public String getType() {
177
        return type;
178
    }
179
180
    public void setType(String type) {
181
        this.type = type;
182
    }
183
184
    public String getThumUrl() {
185
        return thumUrl;
186
    }
187
188
    public void setThumUrl(String thumUrl) {
189
        this.thumUrl = thumUrl;
190
    }
191
192
    public String getAddtime() {
193
        return addtime;
194
    }
195
196
    public void setAddtime(String addtime) {
197
        this.addtime = addtime;
198
    }
199
200
    public String getNickname() {
201
        return nickname;
202
    }
203
204
    public void setNickname(String nickname) {
205
        this.nickname = nickname;
206
    }
207
208
    public String getUserpic() {
209
        return userpic;
210
    }
211
212
    public void setUserpic(String userpic) {
213
        this.userpic = userpic;
214
    }
215
216
    public String getUsername() {
217
        return username;
218
    }
219
220
    public void setUsername(String username) {
221
        this.username = username;
222
    }
223
224
    public String getChexing() {
225
        return chexing;
226
    }
227
228
    public void setChexing(String chexing) {
229
        this.chexing = chexing;
230
    }
231
232
    public String getFine() {
233
        return fine;
234
    }
235
236
    public void setFine(String fine) {
237
        this.fine = fine;
238
    }
239
240
    public String getCommentsCount() {
241
        return commentsCount;
242
    }
243
244
    public void setCommentsCount(String commentsCount) {
245
        this.commentsCount = commentsCount;
246
    }
247
248
    public String getStarLevel() {
249
        return starLevel;
250
    }
251
252
    public void setStarLevel(String starLevel) {
253
        this.starLevel = starLevel;
254
    }
255
256
    public String getTag() {
257
        return tag;
258
    }
259
260
    public void setTag(String tag) {
261
        this.tag = tag;
262
    }
263
264
    public List<SubcommentBean> getSubcomments() {
265
        return subcomments;
266
    }
267
268
    public void setSubcomments(List<SubcommentBean> subcomments) {
269
        this.subcomments = subcomments;
270
    }
271
272
    public Integer getIsCertifiedOwner() {
273
        return isCertifiedOwner;
274
    }
275
276
    public void setIsCertifiedOwner(Integer isCertifiedOwner) {
277
        this.isCertifiedOwner = isCertifiedOwner;
278
    }
279
280
    public String getTitle() {
281
        return title;
282
    }
283
284
    public void setTitle(String title) {
285
        this.title = title;
286
    }
287
}

+ 153 - 0
app/src/main/java/com/electric/chargingpile/data/SubcommentBean.java

@ -0,0 +1,153 @@
1
package com.electric.chargingpile.data;
2
3
public class SubcommentBean {
4
    private String id;
5
6
    private String ancestorid;
7
8
    private String parentid;
9
10
    private String userid;
11
12
    private String tel;
13
14
    private String hascar;
15
16
    private String zhanid;
17
18
    private String content;
19
20
    private String addtime;
21
22
    private String nickname;
23
24
    private String userpic;
25
26
    private String username;
27
28
    private String child;
29
30
    private String pnickname;
31
32
    private String ptel;
33
34
    public String getId() {
35
        return id;
36
    }
37
38
    public void setId(String id) {
39
        this.id = id;
40
    }
41
42
    public String getAncestorid() {
43
        return ancestorid;
44
    }
45
46
    public void setAncestorid(String ancestorid) {
47
        this.ancestorid = ancestorid;
48
    }
49
50
    public String getParentid() {
51
        return parentid;
52
    }
53
54
    public void setParentid(String parentid) {
55
        this.parentid = parentid;
56
    }
57
58
    public String getUserid() {
59
        return userid;
60
    }
61
62
    public void setUserid(String userid) {
63
        this.userid = userid;
64
    }
65
66
    public String getTel() {
67
        return tel;
68
    }
69
70
    public void setTel(String tel) {
71
        this.tel = tel;
72
    }
73
74
    public String getHascar() {
75
        return hascar;
76
    }
77
78
    public void setHascar(String hascar) {
79
        this.hascar = hascar;
80
    }
81
82
    public String getZhanid() {
83
        return zhanid;
84
    }
85
86
    public void setZhanid(String zhanid) {
87
        this.zhanid = zhanid;
88
    }
89
90
    public String getContent() {
91
        return content;
92
    }
93
94
    public void setContent(String content) {
95
        this.content = content;
96
    }
97
98
    public String getAddtime() {
99
        return addtime;
100
    }
101
102
    public void setAddtime(String addtime) {
103
        this.addtime = addtime;
104
    }
105
106
    public String getNickname() {
107
        return nickname;
108
    }
109
110
    public void setNickname(String nickname) {
111
        this.nickname = nickname;
112
    }
113
114
    public String getUserpic() {
115
        return userpic;
116
    }
117
118
    public void setUserpic(String userpic) {
119
        this.userpic = userpic;
120
    }
121
122
    public String getUsername() {
123
        return username;
124
    }
125
126
    public void setUsername(String username) {
127
        this.username = username;
128
    }
129
130
    public String getChild() {
131
        return child;
132
    }
133
134
    public void setChild(String child) {
135
        this.child = child;
136
    }
137
138
    public String getPnickname() {
139
        return pnickname;
140
    }
141
142
    public void setPnickname(String pnickname) {
143
        this.pnickname = pnickname;
144
    }
145
146
    public String getPtel() {
147
        return ptel;
148
    }
149
150
    public void setPtel(String ptel) {
151
        this.ptel = ptel;
152
    }
153
}

+ 2 - 0
app/src/main/res/layout/activity_chat.xml

@ -22,6 +22,7 @@
22 22
            android:orientation="horizontal">
23 23
24 24
            <TextView
25
                android:visibility="gone"
25 26
                android:id="@+id/act_bar_title_recommend"
26 27
                android:layout_width="wrap_content"
27 28
                android:layout_height="match_parent"
@ -34,6 +35,7 @@
34 35
                android:textSize="18sp" />
35 36
36 37
            <View
38
                android:visibility="gone"
37 39
                android:layout_width="1dp"
38 40
                android:layout_height="15dp"
39 41
                android:background="@color/ui_6d" />

+ 64 - 15
app/src/main/res/layout/activity_single_comment.xml

@ -7,7 +7,7 @@
7 7
    android:layout_width="match_parent"
8 8
    android:layout_height="match_parent"
9 9
    android:background="@color/white"
10
    tools:context="com.electric.chargingpile.activity.SingleCommentActivity">
10
   >
11 11
12 12
    <com.zhy.autolayout.AutoRelativeLayout
13 13
        android:id="@+id/rl_title"
@ -171,7 +171,7 @@
171 171
                    android:layout_alignLeft="@+id/tv_pname"
172 172
                    android:layout_marginTop="10dp"
173 173
                    android:layout_marginRight="15dp"
174
                    android:text=""
174
                    tools:text="sssssssssgin"
175 175
                    android:textAppearance="?android:attr/textAppearanceSmall"
176 176
                    android:textSize="15sp"
177 177
                    android:visibility="visible" />
@ -186,31 +186,75 @@
186 186
                    android:visibility="visible"
187 187
                    zhy:max_select="-1" />
188 188
189
                <ImageView
190
                    android:id="@+id/iv_commentPic"
191
                    android:layout_width="65dp"
192
                    android:layout_height="65dp"
189
                <RelativeLayout
190
                    android:layout_marginTop="10dp"
191
                    android:id="@+id/imgLayout"
193 192
                    android:layout_below="@+id/fl_ptag"
194 193
                    android:layout_alignLeft="@+id/tv_pcontext"
195
                    android:layout_marginTop="10dp"
196
                    android:scaleType="centerCrop"
197
                    android:visibility="gone" />
194
                    android:layout_width="match_parent"
195
                    android:layout_height="wrap_content">
196
                    <ImageView
197
                        tools:visibility="visible"
198
                        android:id="@+id/iv_commentPic"
199
                        android:layout_width="65dp"
200
                        android:layout_height="65dp"
201
                        android:scaleType="centerCrop"
202
                        android:visibility="gone" />
203
                    <ImageView
204
                        android:layout_marginEnd="4dp"
205
                        android:layout_marginStart="4dp"
206
                        android:id="@+id/imgTwo"
207
                        tools:visibility="visible"
208
                        android:layout_width="65dp"
209
                        android:layout_height="65dp"
210
                        android:layout_toRightOf="@+id/iv_commentPic"
211
                        android:scaleType="centerCrop"
212
                        android:visibility="gone" />
213
                    <ImageView
214
                        android:id="@+id/imgThree"
215
                        tools:visibility="visible"
216
                        android:layout_width="65dp"
217
                        android:layout_height="65dp"
218
                        android:layout_toRightOf="@+id/imgTwo"
219
                        android:scaleType="centerCrop"
220
                        android:visibility="gone" />
221
222
                    <ImageView
223
                        tools:visibility="visible"
224
                        android:id="@+id/imgVideo"
225
                        android:layout_width="110dp"
226
                        android:layout_height="62dp"
227
                        android:scaleType="centerCrop"
228
                        android:visibility="gone" />
229
230
                    <ImageView
231
                        android:layout_centerInParent="true"
232
                        android:id="@+id/imgStart"
233
                        android:layout_width="wrap_content"
234
                        android:layout_height="wrap_content"
235
                        android:layout_alignEnd="@+id/imgVideo"
236
                        android:layout_alignParentStart="true"
237
                        android:src="@drawable/app_talk_video_icon"
238
                        android:visibility="gone"
239
                        tools:visibility="visible" />
240
                </RelativeLayout>
198 241
199 242
                <TextView
200 243
                    android:id="@+id/tv_ptime"
201 244
                    android:layout_width="wrap_content"
202 245
                    android:layout_height="wrap_content"
203
                    android:layout_below="@+id/iv_commentPic"
246
                    android:layout_below="@+id/imgLayout"
204 247
                    android:layout_alignStart="@+id/tv_pcontext"
205 248
                    android:layout_alignLeft="@+id/tv_pcontext"
206 249
                    android:layout_marginTop="10dp"
207 250
                    android:layout_marginBottom="8dp"
208
                    android:text=""
251
                    tools:text="2020-04-14"
209 252
                    android:textAppearance="?android:attr/textAppearanceSmall"
210 253
                    android:textColor="#c8c8c8"
211 254
                    android:textSize="12sp" />
212 255
213 256
                <TextView
257
                    tools:visibility="visible"
214 258
                    android:id="@+id/tv_pdelete"
215 259
                    android:layout_width="wrap_content"
216 260
                    android:layout_height="wrap_content"
@ -228,7 +272,7 @@
228 272
                    android:id="@+id/ll_pzan"
229 273
                    android:layout_width="wrap_content"
230 274
                    android:layout_height="wrap_content"
231
                    android:layout_below="@+id/iv_commentPic"
275
                    android:layout_below="@+id/imgLayout"
232 276
                    android:layout_toLeftOf="@+id/tv_preply"
233 277
                    android:paddingLeft="10dp"
234 278
                    android:paddingTop="10dp"
@ -261,7 +305,7 @@
261 305
                    android:id="@+id/tv_preply"
262 306
                    android:layout_width="wrap_content"
263 307
                    android:layout_height="wrap_content"
264
                    android:layout_below="@+id/iv_commentPic"
308
                    android:layout_below="@+id/imgLayout"
265 309
                    android:layout_alignEnd="@+id/tv_pcontext"
266 310
                    android:layout_alignRight="@+id/tv_pcontext"
267 311
                    android:layout_alignParentRight="true"
@ -277,6 +321,7 @@
277 321
278 322
279 323
                <TextView
324
                    tools:visibility="visible"
280 325
                    android:id="@+id/tv_childName"
281 326
                    android:layout_width="wrap_content"
282 327
                    android:layout_height="wrap_content"
@ -289,6 +334,7 @@
289 334
                    android:visibility="gone" />
290 335
291 336
                <TextView
337
                    tools:visibility="visible"
292 338
                    android:id="@+id/textView14"
293 339
                    android:layout_width="wrap_content"
294 340
                    android:layout_height="wrap_content"
@ -301,6 +347,7 @@
301 347
                    android:visibility="gone" />
302 348
303 349
                <TextView
350
                    tools:visibility="visible"
304 351
                    android:id="@+id/tv_parentName"
305 352
                    android:layout_width="wrap_content"
306 353
                    android:layout_height="wrap_content"
@ -313,6 +360,7 @@
313 360
                    android:visibility="gone" />
314 361
315 362
                <TextView
363
                    tools:visibility="visible"
316 364
                    android:id="@+id/tv_commentDetail"
317 365
                    android:layout_width="wrap_content"
318 366
                    android:layout_height="wrap_content"
@ -325,6 +373,7 @@
325 373
                    android:visibility="gone" />
326 374
327 375
                <com.electric.chargingpile.view.MyListView
376
328 377
                    android:id="@+id/lv_scomment"
329 378
                    android:layout_width="match_parent"
330 379
                    android:layout_height="wrap_content"
@ -395,7 +444,7 @@
395 444
                <!--android:background="@color/bg_row"-->
396 445
                <!--android:layout_below="@+id/ll_comment"/>-->
397 446
                <View
398
447
                    tools:visibility="visible"
399 448
                    android:layout_width="match_parent"
400 449
                    android:layout_height="0.5dp"
401 450
                    android:layout_below="@+id/tv_ptime"
@ -656,10 +705,10 @@
656 705
    </LinearLayout>
657 706
658 707
    <RelativeLayout
708
        tools:visibility="visible"
659 709
        android:id="@+id/rl_point"
660 710
        android:layout_width="80dp"
661 711
        android:layout_height="80dp"
662
        android:layout_alignBottom="@+id/sv"
663 712
        android:layout_alignParentBottom="true"
664 713
        android:layout_centerHorizontal="true"
665 714
        android:layout_marginBottom="50dp"

+ 16 - 0
app/src/main/res/layout/activity_video_detail.xml

@ -0,0 +1,16 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:app="http://schemas.android.com/apk/res-auto"
4
    xmlns:tools="http://schemas.android.com/tools"
5
    android:layout_width="match_parent"
6
    android:layout_height="match_parent">
7
8
    <com.electric.chargingpile.video.VideoPlayer
9
        android:id="@+id/videoPlayer"
10
        android:layout_width="wrap_content"
11
        android:layout_height="wrap_content"
12
        app:layout_constraintEnd_toEndOf="parent"
13
        app:layout_constraintStart_toStartOf="parent"
14
        app:layout_constraintTop_toTopOf="parent" />
15
16
</androidx.constraintlayout.widget.ConstraintLayout>

问题描述修改完成 · 4b8ab939f1 - Gogs: Go Git Service
Browse Source

问题描述修改完成

huyuguo 6 years ago
parent
commit
4b8ab939f1

+ 45 - 17
app/src/main/java/com/electric/chargingpile/activity/EditQuestionTwoActivity.java

@ -7,6 +7,7 @@ import android.content.Intent;
7 7
import android.graphics.Bitmap;
8 8
import android.graphics.BitmapFactory;
9 9
import android.graphics.Matrix;
10
import android.net.Uri;
10 11
import android.os.Bundle;
11 12
import android.os.Handler;
12 13
@ -28,6 +29,7 @@ import com.electric.chargingpile.R;
28 29
import com.electric.chargingpile.application.MainApplication;
29 30
import com.electric.chargingpile.util.AndroidBug5497Workaround;
30 31
import com.electric.chargingpile.util.BarColorUtil;
32
import com.electric.chargingpile.util.FileUtils;
31 33
import com.electric.chargingpile.util.ImageUitl;
32 34
import com.electric.chargingpile.util.JsonUtils;
33 35
import com.electric.chargingpile.util.ScreenUtils;
@ -86,6 +88,7 @@ public class EditQuestionTwoActivity extends AppCompatActivity implements View.O
86 88
    public static android.view.animation.Animation animation;
87 89
    private static final int RC_ALBUM_PERM = 123;
88 90
    public static final int REQUEST_CODE_CHOOSE = 339;
91
    private Bitmap insertBitmap;
89 92
90 93
    @Override
91 94
    protected void onCreate(Bundle savedInstanceState) {
@ -351,22 +354,18 @@ public class EditQuestionTwoActivity extends AppCompatActivity implements View.O
351 354
352 355
                try {
353 356
                    et_new_content.measure(0, 0);
354
                    int width = ScreenUtils.getScreenWidth(EditQuestionTwoActivity.this);
355
                    int height = ScreenUtils.getScreenHeight(EditQuestionTwoActivity.this);
356
                    ArrayList<String> photos = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
357
                    //可以同时插入多张图片
358
                    for (String imagePath : photos) {
359
                        Bitmap bitmap = ImageUitl.getSmallBitmap(imagePath, width, height);//压缩图片
360
                        if (com.electric.chargingpile.util.ImageUtils.readPictureDegree(imagePath) != 0) {
361
                            bitmap = imageZoom(com.electric.chargingpile.util.ImageUtils.toturn(bitmap));
362
                        } else {
363
                            bitmap = imageZoom(bitmap);
364
                        }
365
                        c_path = imagePath;
366
                        imagePath = SDCardUtil.saveToSdCard(bitmap);
367
                        u_path = imagePath;
368
                        subscriber.onNext(imagePath);
369
                    }
357
                    List<Uri> uriList = Matisse.obtainResult(data);
358
                    Uri uri = uriList.get(0);
359
                    Bitmap bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
360
                    File file = FileUtils.from(EditQuestionTwoActivity.this, uri);
361
362
                    bitmap = FileUtils.rotateIfRequired(file, bitmap);
363
                    bitmap = imageZoom(bitmap);
364
                    insertBitmap = bitmap;
365
366
                    u_path = SDCardUtil.saveToSdCard(bitmap);
367
368
                    subscriber.onNext(u_path);
370 369
                    subscriber.onComplete();
371 370
                } catch (Exception e) {
372 371
                    e.printStackTrace();
@ -380,7 +379,8 @@ public class EditQuestionTwoActivity extends AppCompatActivity implements View.O
380 379
                    @Override
381 380
                    public void onComplete() {
382 381
                        insertDialog.dismiss();
383
                        compressAndUpload(c_path, u_path);
382
//                        compressAndUpload(c_path, u_path);
383
                        uploadPic(insertBitmap, u_path);
384 384
                    }
385 385
386 386
                    @Override
@ -461,6 +461,34 @@ public class EditQuestionTwoActivity extends AppCompatActivity implements View.O
461 461
462 462
    }
463 463
464
    private void uploadPic(Bitmap bitmap, final String path) {
465
        String url = MainApplication.url + "/zhannew/basic/web/index.php/fileupload/uploadone";
466
        OkHttpUtils.post().url(url).
467
                addParams("file", FileUtils.bitmapToString(bitmap)).
468
                addParams("filename", "android.jpg").
469
                addParams("id", creat_id)
470
                .build().execute(new StringCallback() {
471
            @Override
472
            public void onError(Call call, Exception e) {
473
                e.printStackTrace();
474
            }
475
476
            @Override
477
            public void onResponse(String response) {
478
                loadingDialog.dismiss();
479
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
480
                if ("01".equals(rtnCode)) {
481
                    String fileUrl = JsonUtils.getKeyResult(response, "fileUrl");
482
                    map.put(path, fileUrl);
483
                    et_new_content.addEditTextAtIndex(et_new_content.getLastIndex(), " ");
484
                    ToastUtil.showToast(getApplicationContext(), "图片插入成功", Toast.LENGTH_SHORT);
485
                } else {
486
                    ToastUtil.showToast(getApplicationContext(), "图片插入失败", Toast.LENGTH_SHORT);
487
                }
488
            }
489
        });
490
    }
491
464 492
    @Override
465 493
    public void onClick(View v) {
466 494
        switch (v.getId()) {