newList = new ArrayList<>();
99 | for (Media media : medias) {
100 | Uri key = media.getUri();
101 | Media newItem = media.clone();
102 | if (choseMedias.containsKey(key)) {
103 | Integer choseNum = choseMedias.get(key);
104 | if (choseNum == null) {
105 | choseNum = 0;
106 | }
107 | newItem.setChoseNum(choseNum);
108 | }
109 | newList.add(newItem);
110 | }
111 | return newList;
112 | }
113 |
114 | public static String getDuration(long duration) {
115 | long hour = 0;
116 | if (duration > HOUR) {
117 | hour = duration / HOUR;
118 | duration = duration - hour * HOUR;
119 | }
120 | long minute = 0;
121 | if (duration > MINUTE) {
122 | minute = duration / MINUTE;
123 | duration = duration - minute * MINUTE;
124 | }
125 | long sec = duration / 1000;
126 | StringBuilder stringBuilder = new StringBuilder();
127 | if (hour > 0) {
128 | stringBuilder.append(hour).append(":");
129 | }
130 | if (minute > 0) {
131 | stringBuilder.append(minute).append(":");
132 | } else {
133 | stringBuilder.append(0).append(":");
134 | }
135 | if (sec > 0) {
136 | if (sec > 10) {
137 | stringBuilder.append(sec);
138 | } else {
139 | stringBuilder.append(0).append(sec);
140 | }
141 | } else {
142 | stringBuilder.append("00");
143 | }
144 | return stringBuilder.toString();
145 | }
146 |
147 | public static String getDate(Context context, long dateTaken) {
148 | Calendar now = Calendar.getInstance();
149 | Calendar calendar = Calendar.getInstance();
150 | calendar.setTimeInMillis(dateTaken);
151 |
152 | if (now.get(Calendar.YEAR) == calendar.get(Calendar.YEAR)) {
153 | if (now.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)) {
154 | if (now.get(Calendar.DAY_OF_MONTH) == calendar.get(Calendar.DAY_OF_MONTH)) {
155 | return SelectorHelper.textEngine.currentWeek(context);
156 | }
157 | return SelectorHelper.textEngine.currentMonth(context);
158 | }
159 | return getMd(dateTaken);
160 | }
161 | return getYmd(dateTaken);
162 | }
163 |
164 | private static String getYmd(long dateTaken) {
165 | return getTimeStr(dateTaken, "yyyy-MM-dd");
166 | }
167 |
168 | private static String getMd(long dateTaken) {
169 | return getTimeStr(dateTaken, "MM-dd");
170 | }
171 |
172 | private static String getTimeStr(long time, String format) {
173 | Date date = new Date();
174 | date.setTime(time);
175 | @SuppressLint("SimpleDateFormat")
176 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
177 | return simpleDateFormat.format(date);
178 | }
179 |
180 | public static void playVideo(Context context, Media media) {
181 | Intent intent = new Intent(Intent.ACTION_VIEW);
182 | intent.setDataAndType(media.getUri(), "video/*");
183 | try {
184 | context.startActivity(intent);
185 | } catch (ActivityNotFoundException e) {
186 | Toast.makeText(context, SelectorHelper.textEngine.notFoundVideoPlayer(context), Toast.LENGTH_SHORT).show();
187 | }
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/selectorlibrary/src/main/java/net/arvin/selector/uis/widgets/editable/PaintColorBarLayout.java:
--------------------------------------------------------------------------------
1 | package net.arvin.selector.uis.widgets.editable;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.graphics.drawable.Drawable;
9 | import android.graphics.drawable.LayerDrawable;
10 | import android.graphics.drawable.ShapeDrawable;
11 | import android.graphics.drawable.shapes.RoundRectShape;
12 | import android.util.AttributeSet;
13 | import android.util.Log;
14 | import android.view.Gravity;
15 | import android.view.View;
16 | import android.widget.ImageView;
17 | import android.widget.LinearLayout;
18 |
19 | import androidx.annotation.Nullable;
20 |
21 | import net.arvin.selector.R;
22 | import net.arvin.selector.uis.fragments.EditFragment;
23 | import net.arvin.selector.utils.UiUtil;
24 |
25 | /**
26 | * Created by arvinljw on 2020/8/13 18:26
27 | * Function:
28 | * Desc:
29 | */
30 | public class PaintColorBarLayout extends LinearLayout {
31 | public static final int BAR_STYLE_PAINTING = 0;
32 | public static final int BAR_STYLE_EDITING = 1;
33 |
34 | private int barStyle;
35 | private int[] colors;
36 |
37 | private int selectPos;
38 | private int startSize;
39 | private LayoutParams params;
40 | private OnColorSelectListener colorSelectListener;
41 |
42 | public PaintColorBarLayout(Context context) {
43 | this(context, null);
44 | }
45 |
46 | public PaintColorBarLayout(Context context, @Nullable AttributeSet attrs) {
47 | this(context, attrs, 0);
48 | }
49 |
50 | public PaintColorBarLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
51 | super(context, attrs, defStyleAttr);
52 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.PaintColorBarLayout);
53 | barStyle = typedArray.getInt(R.styleable.PaintColorBarLayout_barStyle, BAR_STYLE_PAINTING);
54 | typedArray.recycle();
55 | init();
56 | }
57 |
58 | private void init() {
59 | setOrientation(LinearLayout.HORIZONTAL);
60 | setGravity(Gravity.CENTER_VERTICAL);
61 |
62 | initData();
63 | }
64 |
65 | private void initData() {
66 | initColors();
67 | addColorViews();
68 | }
69 |
70 | private void initColors() {
71 | colors = new int[7];
72 | colors[0] = R.color.ps_paint_color_bar_white;
73 | colors[1] = R.color.ps_paint_color_bar_black;
74 | colors[2] = R.color.ps_paint_color_bar_red;
75 | colors[3] = R.color.ps_paint_color_bar_yellow;
76 | colors[4] = R.color.ps_paint_color_bar_green;
77 | colors[5] = R.color.ps_paint_color_bar_blue;
78 | colors[6] = R.color.ps_paint_color_bar_purple;
79 | }
80 |
81 | private void addColorViews() {
82 | params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
83 | startSize = 0;
84 | selectPos = 0;
85 | if (barStyle == BAR_STYLE_PAINTING) {
86 | startSize = 2;
87 | selectPos = 2;
88 | }
89 |
90 | int size = colors.length + startSize;
91 | selectPos += startSize;
92 |
93 | float itemSize = UiUtil.dp2px(getContext(), 24);
94 | float horizontalSpacing = (UiUtil.getScreenWidth(getContext()) - itemSize * size - getPaddingLeft() - getPaddingRight()) / (size * 2);
95 |
96 | if (barStyle == BAR_STYLE_PAINTING) {
97 | addImages(itemSize, horizontalSpacing);
98 | }
99 |
100 | for (int i = 0; i < colors.length; i++) {
101 | addView(getColorView(itemSize, horizontalSpacing, i), params);
102 | }
103 |
104 | getChildAt(selectPos).setSelected(true);
105 | }
106 |
107 | private ColorView getColorView(float itemSize, float horizontalSpacing, final int pos) {
108 | int color = colors[pos];
109 | ColorView colorView = new ColorView(getContext());
110 | int padding = (int) horizontalSpacing;
111 | colorView.setPadding(padding, padding, padding, padding);
112 | colorView.setItemSize(itemSize + horizontalSpacing * 2);
113 | colorView.setColorId(color);
114 | addClickListener(colorView, startSize + pos);
115 |
116 | return colorView;
117 | }
118 |
119 | private void addImages(float itemSize, float horizontalSpacing) {
120 | addView(getMscView(itemSize, horizontalSpacing), params);
121 | addView(getBlurView(itemSize, horizontalSpacing), params);
122 | }
123 |
124 | private ColorView getMscView(float itemSize, float horizontalSpacing) {
125 | ColorView mscView = new ColorView(getContext());
126 | int padding = (int) horizontalSpacing;
127 | mscView.setPadding(padding, padding, padding, padding);
128 | mscView.setItemSize(itemSize + horizontalSpacing * 2);
129 | mscView.setImageId(R.drawable.ps_img_msc);
130 | addClickListener(mscView, 0);
131 | return mscView;
132 | }
133 |
134 | private ColorView getBlurView(float itemSize, float horizontalSpacing) {
135 | ColorView blurView = new ColorView(getContext());
136 | int padding = (int) horizontalSpacing;
137 | blurView.setPadding(padding, padding, padding, padding);
138 | blurView.setItemSize(itemSize + horizontalSpacing * 2);
139 | blurView.setImageId(R.drawable.ps_img_blur);
140 | addClickListener(blurView, 1);
141 | return blurView;
142 | }
143 |
144 | private void addClickListener(ColorView mscView, final int pos) {
145 | mscView.setOnClickListener(new OnClickListener() {
146 | @Override
147 | public void onClick(View v) {
148 | getChildAt(selectPos).setSelected(false);
149 | getChildAt(pos).setSelected(true);
150 | selectPos = pos;
151 | invalidate();
152 | if (colorSelectListener != null) {
153 | int[] color = getPaintColor();
154 | colorSelectListener.onColorSelected(color[0], color[1]);
155 | }
156 | }
157 | });
158 | }
159 |
160 | public int[] getPaintColor() {
161 | int index = selectPos;
162 | if (barStyle == BAR_STYLE_PAINTING) {
163 | index -= startSize;
164 | }
165 | if (index < 0) {
166 | return new int[]{index, OnColorSelectListener.TYPE_IMAGE};
167 | }
168 | if (barStyle == BAR_STYLE_EDITING && index == 0) {
169 | return new int[]{getResources().getColor(colors[index]), OnColorSelectListener.TYPE_COLOR_WITHE};
170 | }
171 | return new int[]{getResources().getColor(colors[index]), OnColorSelectListener.TYPE_COLOR};
172 | }
173 |
174 | public void setOnColorSelectListener(OnColorSelectListener listener) {
175 | this.colorSelectListener = listener;
176 | }
177 |
178 | public interface OnColorSelectListener {
179 | int TYPE_COLOR = 0;
180 | int TYPE_IMAGE = 1;
181 | //是颜色类型,输入文字是白色文字和背景设置的时候要设置为黑的
182 | int TYPE_COLOR_WITHE = 2;
183 |
184 | void onColorSelected(int color, int type);
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/selectorlibrary/src/main/java/net/arvin/selector/uis/widgets/GridDivider.java:
--------------------------------------------------------------------------------
1 | package net.arvin.selector.uis.widgets;
2 |
3 | import android.graphics.Canvas;
4 | import android.graphics.Color;
5 | import android.graphics.Paint;
6 | import android.graphics.Rect;
7 | import android.view.View;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.recyclerview.widget.GridLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | /**
14 | * Created by arvinljw on 2020/7/17 17:12
15 | * Function:
16 | * Desc:
17 | */
18 | public class GridDivider extends RecyclerView.ItemDecoration {
19 |
20 | private int dividerHeight;
21 | private Paint dividerPaint;
22 |
23 | public GridDivider(int dividerHeight) {
24 | this.dividerHeight = dividerHeight;
25 | dividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
26 | dividerPaint.setColor(Color.TRANSPARENT);
27 | }
28 |
29 | @Override
30 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
31 | super.getItemOffsets(outRect, view, parent, state);
32 | if (parent.getAdapter() == null) {
33 | return;
34 | }
35 | if (!(parent.getLayoutManager() instanceof GridLayoutManager)) {
36 | return;
37 | }
38 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
39 | int position = parent.getChildAdapterPosition(view);
40 | int spanCount = layoutManager.getSpanCount();
41 | int column = position % spanCount + 1;//第几列
42 | int totalCount = parent.getAdapter().getItemCount();
43 |
44 | if (layoutManager.getOrientation() == GridLayoutManager.VERTICAL) {
45 | outRect.top = 0;
46 | outRect.bottom = dividerHeight;
47 | outRect.left = (column - 1) * dividerHeight / spanCount; //左侧为(当前条目数-1)/总条目数*divider宽度
48 | outRect.right = (spanCount - column) * dividerHeight / spanCount;//右侧为(总条目数-当前条目数)/总条目数*divider宽度
49 | } else {
50 | column = position / spanCount + 1;//第几列
51 | int totalColumn = totalCount / spanCount + (totalCount % spanCount == 0 ? 0 : 1);//总列数
52 | outRect.top = 0;
53 | outRect.bottom = dividerHeight;
54 | outRect.left = (column - 1) * dividerHeight / totalColumn; //左侧为(当前条目数-1)/总条目数*divider宽度
55 | outRect.right = (totalColumn - column) * dividerHeight / totalColumn;//右侧为(总条目数-当前条目数)/总条目数*divider宽度
56 | }
57 | }
58 |
59 | @Override
60 | public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
61 | super.onDraw(c, parent, state);
62 | if (!(parent.getLayoutManager() instanceof GridLayoutManager)) {
63 | return;
64 | }
65 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
66 | if (layoutManager.getOrientation() == GridLayoutManager.VERTICAL) {
67 | drawGridVertical(c, parent);
68 | } else {
69 | drawGridHorizontal(c, parent);
70 | }
71 | }
72 |
73 | private void drawGridVertical(Canvas c, RecyclerView parent) {
74 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
75 | float left, top, right, bottom;
76 | int childCount = parent.getChildCount();
77 | for (int i = 0; i < childCount; i++) {
78 | View child = parent.getChildAt(i);
79 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
80 | int spanCount = layoutManager.getSpanCount();
81 | int position = parent.getChildAdapterPosition(child);
82 | int column = position % spanCount + 1;//第几列
83 |
84 | //绘制下边
85 | left = child.getLeft() - layoutParams.leftMargin;
86 | right = child.getRight() + layoutParams.rightMargin + dividerHeight;
87 | top = child.getBottom() + layoutParams.bottomMargin;
88 | bottom = top + dividerHeight;
89 | c.drawRect(left, top, right, bottom, dividerPaint);
90 |
91 | //绘制左边,第一列的都不绘制左边
92 | int dividerLeft = (column - 1) * dividerHeight / spanCount;
93 | right = child.getLeft() - layoutParams.leftMargin;
94 | left = right - dividerLeft;
95 | top = child.getTop() - layoutParams.topMargin;
96 | bottom = child.getBottom() + layoutParams.bottomMargin;
97 | c.drawRect(left, top, right, bottom, dividerPaint);
98 |
99 | //绘制右边,最后一列都不绘制右边
100 | left = child.getRight() + layoutParams.rightMargin;
101 | right = left + (spanCount - column) * dividerHeight / spanCount;
102 | top = child.getTop() - layoutParams.topMargin;
103 | bottom = child.getBottom() + layoutParams.bottomMargin;
104 | if (position == parent.getAdapter().getItemCount() - 1 && spanCount != column) {
105 | right = left + dividerHeight;
106 | }
107 | c.drawRect(left, top, right, bottom, dividerPaint);
108 | }
109 | }
110 |
111 | private void drawGridHorizontal(Canvas c, RecyclerView parent) {
112 | GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
113 | float left, top, right, bottom;
114 | int childCount = parent.getChildCount();
115 | for (int i = 0; i < childCount; i++) {
116 | View child = parent.getChildAt(i);
117 | RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
118 | int spanCount = layoutManager.getSpanCount();
119 | int position = parent.getChildAdapterPosition(child);
120 | int column = position / spanCount + 1;//第几列
121 | int totalCount = parent.getAdapter().getItemCount();
122 | int totalColumn = totalCount / spanCount + (totalCount % spanCount == 0 ? 0 : 1);//总列数
123 |
124 | //绘制下边
125 | left = child.getLeft() - layoutParams.leftMargin;
126 | right = child.getRight() + layoutParams.rightMargin + dividerHeight;
127 | top = child.getBottom() + layoutParams.bottomMargin;
128 | bottom = top + dividerHeight;
129 | if (column != 1) {
130 | left = left - (column - 1) * dividerHeight / totalColumn;//避免view被重用是,左边被回收
131 | }
132 | c.drawRect(left, top, right, bottom, dividerPaint);
133 |
134 | //绘制左边,第一列不画
135 | right = child.getLeft() - layoutParams.leftMargin;
136 | left = right - (column - 1) * dividerHeight / totalColumn;
137 | top = child.getTop() - layoutParams.topMargin;
138 | bottom = child.getBottom() + layoutParams.bottomMargin;
139 | c.drawRect(left, top, right, bottom, dividerPaint);
140 |
141 | //绘制右边,最后一列不画
142 | left = child.getRight() + layoutParams.rightMargin;
143 | right = left + (totalColumn - column) * dividerHeight / totalColumn;
144 | top = child.getTop() - layoutParams.topMargin;
145 | bottom = child.getBottom() + layoutParams.bottomMargin;
146 | if (column == totalColumn - 1 && position + spanCount > totalCount - 1) {
147 | right = left + dividerHeight;
148 | }
149 | c.drawRect(left, top, right, bottom, dividerPaint);
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/selectorlibrary/src/main/java/net/arvin/selector/utils/UiUtil.java:
--------------------------------------------------------------------------------
1 | package net.arvin.selector.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Bundle;
6 | import android.util.DisplayMetrics;
7 | import android.view.View;
8 | import android.view.inputmethod.InputMethodManager;
9 | import android.widget.EditText;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import androidx.core.graphics.drawable.DrawableCompat;
14 | import androidx.fragment.app.Fragment;
15 | import androidx.fragment.app.FragmentActivity;
16 | import androidx.fragment.app.FragmentManager;
17 | import androidx.fragment.app.FragmentTransaction;
18 |
19 | import net.arvin.selector.R;
20 | import net.arvin.selector.SelectorHelper;
21 | import net.arvin.selector.data.Media;
22 | import net.arvin.selector.uis.fragments.EditFragment;
23 | import net.arvin.selector.uis.fragments.PreviewFragment;
24 | import net.arvin.selector.uis.widgets.editable.SpecialBgEditText;
25 |
26 | /**
27 | * Created by arvinljw on 2020/8/1 17:33
28 | * Function:
29 | * Desc:
30 | */
31 | public class UiUtil {
32 |
33 | public static float dp2px(Context context, int dp) {
34 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
35 | return metrics.density * dp;
36 | }
37 |
38 | public static float sp2px(Context context, int sp) {
39 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
40 | return metrics.scaledDensity * sp;
41 | }
42 |
43 | public static int getScreenWidth(Context context) {
44 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
45 | return metrics.widthPixels;
46 | }
47 |
48 | public static int getScreenHeight(Context context) {
49 | DisplayMetrics metrics = context.getResources().getDisplayMetrics();
50 | return metrics.heightPixels;
51 | }
52 |
53 | public static void dealEnsureText(TextView tvEnsure, int choseCount, int maxCount) {
54 | if (maxCount == 1) {
55 | tvEnsure.setVisibility(View.GONE);
56 | return;
57 | }
58 | tvEnsure.setEnabled(choseCount > 0);
59 | tvEnsure.setText(SelectorHelper.textEngine.ensureChoose(tvEnsure.getContext(), choseCount, maxCount));
60 | }
61 |
62 | public static void dealPreviewEnsureText(TextView tvEnsure, int choseCount, int maxCount) {
63 | tvEnsure.setText(SelectorHelper.textEngine.ensureChoose(tvEnsure.getContext(), choseCount, maxCount));
64 | }
65 |
66 | public static void dealPreviewText(TextView tvPreview, int choseCount) {
67 | tvPreview.setEnabled(choseCount != 0);
68 | tvPreview.setText(SelectorHelper.textEngine.previewCount(tvPreview.getContext(), choseCount));
69 | }
70 |
71 | public static void setDrawableLeft(TextView textView, int drawableLeftResId) {
72 | Drawable drawable = textView.getResources().getDrawable(drawableLeftResId);
73 | drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
74 | textView.setCompoundDrawables(drawable, null, null, null);
75 | }
76 |
77 | public static void showPreviewFragment(FragmentActivity activity, boolean previewAll, int pos) {
78 | PreviewFragment previewFragment;
79 | FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
80 | FragmentTransaction transaction = supportFragmentManager.beginTransaction();
81 | String tag = PreviewFragment.class.getName();
82 | Fragment cacheFragment = supportFragmentManager.findFragmentByTag(tag);
83 | Bundle bundle = new Bundle();
84 | bundle.putBoolean(PreviewFragment.KEY_PREVIEW_ALL, previewAll);
85 | bundle.putInt(PreviewFragment.KEY_PREVIEW_POS, pos);
86 | transaction.setCustomAnimations(R.anim.ps_fade_in, R.anim.ps_fade_out);
87 | if (cacheFragment == null) {
88 | previewFragment = new PreviewFragment();
89 | previewFragment.setArguments(bundle);
90 | transaction.add(R.id.ps_layout_container, previewFragment, tag);
91 | } else {
92 | previewFragment = (PreviewFragment) cacheFragment;
93 | previewFragment.update(bundle);
94 | transaction.show(previewFragment);
95 | }
96 | transaction.commitAllowingStateLoss();
97 | }
98 |
99 | public static void hideFragment(FragmentActivity activity, Fragment fragment) {
100 | activity.getSupportFragmentManager().beginTransaction()
101 | .setCustomAnimations(R.anim.ps_fade_in, R.anim.ps_fade_out)
102 | .hide(fragment).commitAllowingStateLoss();
103 | }
104 |
105 | public static void removeFragment(FragmentActivity activity, Fragment fragment) {
106 | activity.getSupportFragmentManager().beginTransaction()
107 | .setCustomAnimations(R.anim.ps_fade_in, R.anim.ps_fade_out)
108 | .remove(fragment).commitAllowingStateLoss();
109 | }
110 |
111 | public static boolean isShowPreviewFragment(FragmentActivity activity) {
112 | FragmentManager fragmentManager = activity.getSupportFragmentManager();
113 | Fragment fragment = fragmentManager.findFragmentByTag(PreviewFragment.class.getName());
114 | if (fragment != null && !fragment.isHidden()) {
115 | hideFragment(activity, fragment);
116 | return true;
117 | }
118 | return false;
119 | }
120 |
121 | public static void addEditFragment(FragmentActivity activity, Media media) {
122 | FragmentManager supportFragmentManager = activity.getSupportFragmentManager();
123 | FragmentTransaction transaction = supportFragmentManager.beginTransaction();
124 | transaction.setCustomAnimations(R.anim.ps_fade_in, R.anim.ps_fade_out);
125 | EditFragment fragment = new EditFragment();
126 | Bundle bundle = new Bundle();
127 | bundle.putParcelable(EditFragment.KEY_MEDIA, media);
128 | fragment.setArguments(bundle);
129 | transaction.add(R.id.ps_layout_container, fragment, EditFragment.class.getName());
130 | transaction.commitAllowingStateLoss();
131 | }
132 |
133 | public static boolean hasEditFragment(FragmentActivity activity) {
134 | FragmentManager fragmentManager = activity.getSupportFragmentManager();
135 | EditFragment fragment = (EditFragment) fragmentManager.findFragmentByTag(EditFragment.class.getName());
136 | if (fragment == null) {
137 | return false;
138 | }
139 | if (fragment.hideEditView()) {
140 | return true;
141 | }
142 | removeFragment(activity, fragment);
143 | return true;
144 | }
145 |
146 |
147 | public static void setTint(ImageView imgPencil, Drawable drawable, int color) {
148 | if (drawable != null) {
149 | Drawable drawableWrap = DrawableCompat.wrap(drawable);
150 | DrawableCompat.setTint(drawableWrap, color);
151 | imgPencil.setImageDrawable(drawableWrap);
152 | }
153 | }
154 |
155 | public static void closeKeyboard(EditText editText) {
156 | InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
157 | imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
158 | }
159 |
160 | public static void showKeyboard(EditText editText) {
161 | editText.setFocusable(true);
162 | editText.setFocusableInTouchMode(true);
163 | editText.requestFocus();
164 | InputMethodManager inputManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
165 | inputManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
166 | }
167 |
168 | public static float getStatusBarHeight(Context context) {
169 | int result = 0;
170 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
171 | if (resourceId > 0) {
172 | result = context.getResources().getDimensionPixelSize(resourceId);
173 | }
174 | return result;
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/selectorlibrary/src/main/java/net/arvin/selector/utils/AnimUtil.java:
--------------------------------------------------------------------------------
1 | package net.arvin.selector.utils;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.AnimatorSet;
6 | import android.animation.ObjectAnimator;
7 | import android.animation.ValueAnimator;
8 | import android.content.ActivityNotFoundException;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.graphics.Color;
12 | import android.view.View;
13 | import android.view.animation.LinearInterpolator;
14 | import android.widget.ImageView;
15 | import android.widget.Toast;
16 |
17 | import androidx.recyclerview.widget.RecyclerView;
18 | import androidx.recyclerview.widget.SimpleItemAnimator;
19 |
20 | import net.arvin.selector.SelectorHelper;
21 | import net.arvin.selector.data.Media;
22 |
23 | /**
24 | * Created by arvinljw on 2020/8/1 17:30
25 | * Function:
26 | * Desc:
27 | */
28 | public class AnimUtil {
29 |
30 | public static final int DURATION_1000 = 1000;
31 | public static final int DURATION_500 = 500;
32 | public static final int DURATION_200 = 200;
33 | public static final int DURATION_50 = 50;
34 |
35 | public static void removeChangeAnim(RecyclerView recyclerView) {
36 | RecyclerView.ItemAnimator itemAnimator = recyclerView.getItemAnimator();
37 | if (itemAnimator instanceof SimpleItemAnimator) {
38 | ((SimpleItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
39 | }
40 | }
41 |
42 | public static void rotation(final ImageView imgArrow, final boolean isOpen) {
43 | if (imgArrow.getTag() instanceof ObjectAnimator) {
44 | ObjectAnimator anim = (ObjectAnimator) imgArrow.getTag();
45 | anim.cancel();
46 | }
47 | float start, end;
48 | if (isOpen) {
49 | start = 0;
50 | end = 180;
51 | } else {
52 | start = 180;
53 | end = 360;
54 | }
55 |
56 | ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(imgArrow, "rotation", start, end).setDuration(DURATION_200);
57 | rotationAnim.addListener(new AnimatorListenerAdapter() {
58 | @Override
59 | public void onAnimationEnd(Animator animation) {
60 | super.onAnimationEnd(animation);
61 | if (!isOpen) {
62 | imgArrow.setRotation(0);
63 | }
64 | }
65 | });
66 | rotationAnim.setInterpolator(new LinearInterpolator());
67 | rotationAnim.start();
68 | imgArrow.setTag(rotationAnim);
69 | }
70 |
71 | public static void folderOpenHide(final View layoutFolder, View folderList, int maxHeight, final boolean isOpen) {
72 | if (layoutFolder.getTag() instanceof ObjectAnimator) {
73 | ObjectAnimator anim = (ObjectAnimator) layoutFolder.getTag();
74 | anim.cancel();
75 | }
76 | float start, end;
77 | int startA, endA;
78 | if (isOpen) {
79 | start = -maxHeight;
80 | end = 0;
81 |
82 | startA = 0x00;
83 | endA = 0x88;
84 | } else {
85 | start = 0;
86 | end = -maxHeight;
87 | startA = 0x88;
88 | endA = 0x00;
89 | }
90 | if (isOpen) {
91 | layoutFolder.setVisibility(View.VISIBLE);
92 | }
93 | ObjectAnimator translationYAnim = ObjectAnimator.ofFloat(folderList, "translationY", start, end);
94 | translationYAnim.setDuration(DURATION_200);
95 |
96 | ValueAnimator alphaAnim = ValueAnimator.ofInt(startA, endA);
97 | alphaAnim.setDuration(DURATION_50);
98 | alphaAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
99 | @Override
100 | public void onAnimationUpdate(ValueAnimator animation) {
101 | int alpha = (int) animation.getAnimatedValue();
102 | int bgColor = Color.argb(alpha, 0, 0, 0);
103 | layoutFolder.setBackgroundColor(bgColor);
104 | }
105 | });
106 |
107 | AnimatorSet animatorSet = new AnimatorSet();
108 | animatorSet.setInterpolator(new LinearInterpolator());
109 | animatorSet.addListener(new AnimatorListenerAdapter() {
110 |
111 | @Override
112 | public void onAnimationEnd(Animator animation) {
113 | super.onAnimationEnd(animation);
114 | if (!isOpen) {
115 | layoutFolder.setVisibility(View.GONE);
116 | }
117 | }
118 | });
119 | animatorSet.playTogether(translationYAnim, alphaAnim);
120 | animatorSet.start();
121 |
122 | layoutFolder.setTag(animatorSet);
123 | }
124 |
125 | public static void fadeShow(final View view) {
126 | Object tag = view.getTag();
127 | if (tag instanceof ObjectAnimator) {
128 | ((ObjectAnimator) tag).cancel();
129 | }
130 | if (view.getAlpha() == 1) {
131 | return;
132 | }
133 | ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 0, 1).setDuration(DURATION_200);
134 | animator.setInterpolator(new LinearInterpolator());
135 | animator.start();
136 | }
137 |
138 | public static void fadeHide(final View view) {
139 | if (view.getAlpha() == 0) {
140 | return;
141 | }
142 | view.postDelayed(new Runnable() {
143 | @Override
144 | public void run() {
145 | ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 1, 0).setDuration(DURATION_200);
146 | animator.setInterpolator(new LinearInterpolator());
147 | animator.start();
148 | }
149 | }, DURATION_1000);
150 | }
151 |
152 | public static void fadeHideBar(final View view) {
153 | if (view.getAlpha() == 0) {
154 | return;
155 | }
156 | ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 1, 0).setDuration(DURATION_200);
157 | animator.setInterpolator(new LinearInterpolator());
158 | animator.addListener(new AnimatorListenerAdapter() {
159 | @Override
160 | public void onAnimationEnd(Animator animation) {
161 | super.onAnimationEnd(animation);
162 | view.setVisibility(View.GONE);
163 | }
164 | });
165 | animator.start();
166 | }
167 |
168 | public static void fadeShowBar(View view, boolean showNow) {
169 | view.setVisibility(View.VISIBLE);
170 | if (showNow) {
171 | view.setAlpha(1);
172 | return;
173 | }
174 | if (view.getAlpha() == 1) {
175 | return;
176 | }
177 | ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 0, 1).setDuration(DURATION_200);
178 | animator.setInterpolator(new LinearInterpolator());
179 | animator.start();
180 | }
181 |
182 | public static void playVideo(Context context, Media media) {
183 | Intent intent = new Intent(Intent.ACTION_VIEW);
184 | intent.setDataAndType(media.getUri(), "video/*");
185 | try {
186 | context.startActivity(intent);
187 | } catch (ActivityNotFoundException e) {
188 | Toast.makeText(context, SelectorHelper.textEngine.notFoundVideoPlayer(context), Toast.LENGTH_SHORT).show();
189 | }
190 | }
191 |
192 | public static void translationY(View target, boolean show, int height, AnimatorListenerAdapter listenerAdapter) {
193 | float startY;
194 | float endY;
195 |
196 | if (show) {
197 | target.setVisibility(View.VISIBLE);
198 | startY = -height;
199 | endY = 0;
200 | } else {
201 | startY = 0;
202 | endY = -height;
203 | }
204 | ObjectAnimator anim = ObjectAnimator.ofFloat(target, "translationY", startY, endY).setDuration(DURATION_200);
205 | anim.setInterpolator(new LinearInterpolator());
206 | if (listenerAdapter != null) {
207 | anim.addListener(listenerAdapter);
208 | }
209 | anim.start();
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/selectorlibrary/src/main/java/net/arvin/selector/uis/widgets/editable/CropRotateView.java:
--------------------------------------------------------------------------------
1 | package net.arvin.selector.uis.widgets.editable;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Matrix;
7 | import android.graphics.Paint;
8 | import android.graphics.RectF;
9 | import android.graphics.drawable.Drawable;
10 | import android.util.AttributeSet;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 |
14 | import androidx.annotation.Nullable;
15 |
16 | import net.arvin.selector.utils.UiUtil;
17 |
18 | /**
19 | * Created by arvinljw on 2020/9/18 14:57
20 | * Function:
21 | * Desc:
22 | */
23 | public class CropRotateView extends View {
24 | private Paint shadowPaint;
25 | private Paint borderPaint;
26 |
27 | public RectF cropRect;
28 | //图片和裁剪边框任一拖动就表示拖动
29 | private boolean isDragging;
30 | private float borderWidth;
31 | private float lineWidth;
32 | private float cornerWidth;
33 | private float cornerHeight;
34 |
35 | public CropRotateView(Context context) {
36 | this(context, null);
37 | }
38 |
39 | public CropRotateView(Context context, @Nullable AttributeSet attrs) {
40 | this(context, attrs, 0);
41 | }
42 |
43 | public CropRotateView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
44 | super(context, attrs, defStyleAttr);
45 | init();
46 | }
47 |
48 | private void init() {
49 | shadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
50 | int shadowColor = Color.parseColor("#66000000");
51 | shadowPaint.setColor(shadowColor);
52 | shadowPaint.setStyle(Paint.Style.FILL);
53 |
54 | borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
55 | borderPaint.setStyle(Paint.Style.STROKE);
56 |
57 | borderWidth = UiUtil.dp2px(getContext(), 2);
58 | lineWidth = UiUtil.dp2px(getContext(), 1);
59 | cornerWidth = UiUtil.dp2px(getContext(), 4);
60 | cornerHeight = UiUtil.dp2px(getContext(), 20);
61 |
62 | }
63 |
64 | @Override
65 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
66 | setMeasuredDimension(getSize(getSuggestedMinimumWidth(), widthMeasureSpec),
67 | getSize(getSuggestedMinimumHeight(), heightMeasureSpec));
68 | }
69 |
70 | public static int getSize(int size, int measureSpec) {
71 | int result = size;
72 | int specMode = MeasureSpec.getMode(measureSpec);
73 | int specSize = MeasureSpec.getSize(measureSpec);
74 |
75 | switch (specMode) {
76 | case MeasureSpec.UNSPECIFIED:
77 | case MeasureSpec.AT_MOST:
78 | result = size;
79 | break;
80 | case MeasureSpec.EXACTLY:
81 | result = specSize;
82 | break;
83 | }
84 | return result;
85 | }
86 |
87 | public void setCropRect(RectF rect) {
88 | if (rect == null) {
89 | cropRect = null;
90 | invalidate();
91 | return;
92 | }
93 | if (cropRect == null) {
94 | cropRect = new RectF();
95 | }
96 | cropRect.set(rect);
97 | invalidate();
98 | }
99 |
100 | public RectF getCropRect() {
101 | RectF rectF = new RectF();
102 | rectF.set(cropRect);
103 | rectF.left = 0;
104 | rectF.right = UiUtil.getScreenWidth(getContext());
105 | float scale = rectF.width() / cropRect.width();
106 | float scaleHeight = cropRect.height() * scale;
107 | rectF.top = rectF.top - (scaleHeight - cropRect.height()) / 2 + getTransY();
108 | rectF.bottom = rectF.bottom + (scaleHeight - cropRect.height()) / 2 + getTransY();
109 | return rectF;
110 | }
111 |
112 | public float getScale() {
113 | return UiUtil.getScreenWidth(getContext()) / cropRect.width();
114 | }
115 |
116 | public float getTransY() {
117 | return UiUtil.dp2px(getContext(), 28);
118 | }
119 |
120 | @Override
121 | public boolean onTouchEvent(MotionEvent event) {
122 | return super.onTouchEvent(event);
123 | }
124 |
125 | @Override
126 | protected void onDraw(Canvas canvas) {
127 | super.onDraw(canvas);
128 | if (cropRect == null) {
129 | return;
130 | }
131 |
132 | drawLeftRect(canvas);
133 | drawTopRect(canvas);
134 | drawRightRect(canvas);
135 | drawBottomRect(canvas);
136 |
137 | drawBorder(canvas);
138 | drawLine(canvas);
139 | drawCorner(canvas);
140 | }
141 |
142 | private void drawBorder(Canvas canvas) {
143 | borderPaint.setStrokeWidth(borderWidth);
144 | borderPaint.setColor(Color.parseColor("#CCFFFFFF"));
145 |
146 | canvas.drawRect(cropRect, borderPaint);
147 | }
148 |
149 | private void drawLine(Canvas canvas) {
150 | borderPaint.setStrokeWidth(lineWidth);
151 | borderPaint.setColor(Color.parseColor("#20FFFFFF"));
152 |
153 | //绘制竖线
154 | for (int i = 0; i < 2; i++) {
155 | float vx = cropRect.left + (cropRect.width() * (i + 1)) / 3;
156 | float startY = cropRect.top;
157 | float stopY = cropRect.bottom;
158 | canvas.drawLine(vx, startY, vx, stopY, borderPaint);
159 | }
160 |
161 | //绘制横线
162 | for (int i = 0; i < 2; i++) {
163 | float startX = cropRect.left;
164 | float hy = cropRect.top + (cropRect.height() * (i + 1)) / 3;
165 | float stopX = cropRect.right;
166 | canvas.drawLine(startX, hy, stopX, hy, borderPaint);
167 | }
168 | }
169 |
170 | private void drawCorner(Canvas canvas) {
171 | borderPaint.setStrokeWidth(cornerWidth);
172 | borderPaint.setColor(Color.parseColor("#FFFFFF"));
173 |
174 | //左上
175 | drawVerticalLine(canvas, cropRect.left - cornerWidth + borderWidth, cropRect.top - cornerWidth + borderWidth);
176 | drawHorizontalLine(canvas, cropRect.left - cornerWidth, cropRect.top - cornerWidth + borderWidth);
177 |
178 | //左下
179 | drawVerticalLine(canvas, cropRect.left - cornerWidth + borderWidth, cropRect.bottom - cornerHeight + cornerWidth);
180 | drawHorizontalLine(canvas, cropRect.left - cornerWidth + borderWidth, cropRect.bottom + cornerWidth - borderWidth);
181 |
182 | //右上
183 | drawVerticalLine(canvas, cropRect.right + cornerWidth - borderWidth, cropRect.top - cornerWidth + borderWidth);
184 | drawHorizontalLine(canvas, cropRect.right - cornerHeight + cornerWidth, cropRect.top - cornerWidth + borderWidth);
185 |
186 | //右下
187 | drawVerticalLine(canvas, cropRect.right + cornerWidth - borderWidth, cropRect.bottom - cornerHeight + cornerWidth);
188 | drawHorizontalLine(canvas, cropRect.right - cornerHeight + cornerWidth, cropRect.bottom + cornerWidth - borderWidth);
189 |
190 | }
191 |
192 | private void drawVerticalLine(Canvas canvas, float startX, float startY) {
193 | canvas.drawLine(startX, startY, startX, startY + cornerHeight, borderPaint);
194 | }
195 |
196 | private void drawHorizontalLine(Canvas canvas, float startX, float startY) {
197 | canvas.drawLine(startX, startY, startX + cornerHeight, startY, borderPaint);
198 | }
199 |
200 | private void drawLeftRect(Canvas canvas) {
201 | if (isDragging) {
202 | return;
203 | }
204 | canvas.drawRect(0, cropRect.top, cropRect.left, cropRect.bottom, shadowPaint);
205 | }
206 |
207 | private void drawTopRect(Canvas canvas) {
208 | if (isDragging) {
209 | return;
210 | }
211 | canvas.drawRect(0, 0, getWidth(), cropRect.top, shadowPaint);
212 | }
213 |
214 | private void drawRightRect(Canvas canvas) {
215 | if (isDragging) {
216 | return;
217 | }
218 | canvas.drawRect(cropRect.right, cropRect.top, getWidth(), cropRect.bottom, shadowPaint);
219 | }
220 |
221 | private void drawBottomRect(Canvas canvas) {
222 | if (isDragging) {
223 | return;
224 | }
225 | canvas.drawRect(0, cropRect.bottom, getWidth(), getHeight(), shadowPaint);
226 | }
227 | }
228 |
--------------------------------------------------------------------------------
/selectorlibrary/src/main/java/net/arvin/selector/data/Media.java:
--------------------------------------------------------------------------------
1 | package net.arvin.selector.data;
2 |
3 | import android.net.Uri;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 |
7 | import androidx.annotation.NonNull;
8 |
9 | import java.util.Arrays;
10 |
11 | /**
12 | * Created by arvinljw on 2020/7/16 16:13
13 | * Function:
14 | * Desc:
15 | */
16 | @SuppressWarnings({"unused", "deprecation"})
17 | public class Media implements Parcelable, Cloneable {
18 | private long id;
19 | private String mimeType;
20 | private long bucketId;
21 | private String bucketName;
22 | private Uri uri;
23 | private long size;
24 | private long duration;
25 | private int width;
26 | private int height;
27 | private long dateTaken;
28 | /**
29 | * copy from {@link android.provider.MediaStore.Files.FileColumns#DATA}
30 | * Absolute filesystem path to the media item on disk.
31 | *
32 | * Note that apps may not have filesystem permissions to directly access
33 | * this path. Instead of trying to open this path directly, apps should
34 | * use {@link android.content.ContentResolver#openFileDescriptor(Uri, String)} to gain
35 | * access.
36 | *
37 | * @deprecated Apps may not have filesystem permissions to directly
38 | * access this path. Instead of trying to open this path
39 | * directly, apps should use
40 | * {@link android.content.ContentResolver#openFileDescriptor(Uri, String)}
41 | * to gain access.
42 | */
43 | @Deprecated
44 | private String path;
45 |
46 | private int choseNum;
47 |
48 | public static Media createMedia(long id, String mimeType, long bucketId, String bucketName, Uri uri, long size,
49 | long duration, int width, int height, long dateTaken, String path) {
50 | Media media = new Media();
51 | media.id = id;
52 | media.mimeType = mimeType;
53 | media.bucketId = bucketId;
54 | media.bucketName = bucketName;
55 | media.uri = uri;
56 | media.size = size;
57 | media.duration = duration;
58 | media.width = width;
59 | media.height = height;
60 | media.dateTaken = dateTaken;
61 | media.path = path;
62 | return media;
63 | }
64 |
65 | public long getId() {
66 | return id;
67 | }
68 |
69 | public void setId(long id) {
70 | this.id = id;
71 | }
72 |
73 | public String getMimeType() {
74 | return mimeType;
75 | }
76 |
77 | public void setMimeType(String mimeType) {
78 | this.mimeType = mimeType;
79 | }
80 |
81 | public long getBucketId() {
82 | return bucketId;
83 | }
84 |
85 | public void setBucketId(long bucketId) {
86 | this.bucketId = bucketId;
87 | }
88 |
89 | public String getBucketName() {
90 | return bucketName;
91 | }
92 |
93 | public void setBucketName(String bucketName) {
94 | this.bucketName = bucketName;
95 | }
96 |
97 | public Uri getUri() {
98 | return uri;
99 | }
100 |
101 | public void setUri(Uri uri) {
102 | this.uri = uri;
103 | }
104 |
105 | public long getSize() {
106 | return size;
107 | }
108 |
109 | public void setSize(long size) {
110 | this.size = size;
111 | }
112 |
113 | public long getDuration() {
114 | return duration;
115 | }
116 |
117 | public void setDuration(long duration) {
118 | this.duration = duration;
119 | }
120 |
121 | public int getWidth() {
122 | return width;
123 | }
124 |
125 | public void setWidth(int width) {
126 | this.width = width;
127 | }
128 |
129 | public int getHeight() {
130 | return height;
131 | }
132 |
133 | public void setHeight(int height) {
134 | this.height = height;
135 | }
136 |
137 | public long getDateTaken() {
138 | return dateTaken;
139 | }
140 |
141 | public void setDateTaken(long dateTaken) {
142 | this.dateTaken = dateTaken;
143 | }
144 |
145 | /**
146 | * copy from {@link android.provider.MediaStore.Files.FileColumns#DATA}
147 | * Absolute filesystem path to the media item on disk.
148 | *
149 | * Note that apps may not have filesystem permissions to directly access
150 | * this path. Instead of trying to open this path directly, apps should
151 | * use {@link android.content.ContentResolver#openFileDescriptor(Uri, String)} to gain
152 | * access.
153 | *
154 | * @deprecated Apps may not have filesystem permissions to directly
155 | * access this path. Instead of trying to open this path
156 | * directly, apps should use
157 | * {@link android.content.ContentResolver#openFileDescriptor(Uri, String)}
158 | * to gain access.
159 | */
160 | @Deprecated
161 | public String getPath() {
162 | return path;
163 | }
164 |
165 | public void setPath(String path) {
166 | this.path = path;
167 | }
168 |
169 | public int getChoseNum() {
170 | return choseNum;
171 | }
172 |
173 | public void setChoseNum(int choseNum) {
174 | this.choseNum = choseNum;
175 | }
176 |
177 | @NonNull
178 | @Override
179 | public String toString() {
180 | return "Media{" +
181 | "bucketId=" + bucketId +
182 | ", bucketName='" + bucketName + '\'' +
183 | ", uri='" + uri + '\'' +
184 | ", size=" + size +
185 | ", dateTaken=" + dateTaken +
186 | '}';
187 | }
188 |
189 | @Override
190 | public boolean equals(Object o) {
191 | if (this == o) return true;
192 | if (o == null || getClass() != o.getClass()) return false;
193 | Media media = (Media) o;
194 | return id == media.id &&
195 | uri.equals(media.uri);
196 | }
197 |
198 | @Override
199 | public int hashCode() {
200 | return Arrays.hashCode(new Object[]{id, uri});
201 | }
202 |
203 | @Override
204 | public int describeContents() {
205 | return 0;
206 | }
207 |
208 | @Override
209 | public void writeToParcel(Parcel dest, int flags) {
210 | dest.writeLong(this.id);
211 | dest.writeString(this.mimeType);
212 | dest.writeLong(this.bucketId);
213 | dest.writeString(this.bucketName);
214 | dest.writeParcelable(this.uri, flags);
215 | dest.writeLong(this.size);
216 | dest.writeLong(this.duration);
217 | dest.writeInt(this.width);
218 | dest.writeInt(this.height);
219 | dest.writeLong(this.dateTaken);
220 | }
221 |
222 | public Media() {
223 | }
224 |
225 | protected Media(Parcel in) {
226 | this.id = in.readLong();
227 | this.mimeType = in.readString();
228 | this.bucketId = in.readLong();
229 | this.bucketName = in.readString();
230 | this.uri = in.readParcelable(Uri.class.getClassLoader());
231 | this.size = in.readLong();
232 | this.duration = in.readLong();
233 | this.width = in.readInt();
234 | this.height = in.readInt();
235 | this.dateTaken = in.readLong();
236 | }
237 |
238 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
239 | @Override
240 | public Media createFromParcel(Parcel source) {
241 | return new Media(source);
242 | }
243 |
244 | @Override
245 | public Media[] newArray(int size) {
246 | return new Media[size];
247 | }
248 | };
249 |
250 | @NonNull
251 | @Override
252 | public Media clone() {
253 | Media media = null;
254 | try {
255 | media = (Media) super.clone();
256 | } catch (CloneNotSupportedException e) {
257 | e.printStackTrace();
258 | }
259 | if (media == null) {
260 | media = new Media();
261 | }
262 | media.id = id;
263 | media.mimeType = mimeType;
264 | media.bucketId = bucketId;
265 | media.bucketName = bucketName;
266 | media.uri = uri;
267 | media.size = size;
268 | media.duration = duration;
269 | media.width = width;
270 | media.height = height;
271 | media.dateTaken = dateTaken;
272 | return media;
273 | }
274 | }
275 |
--------------------------------------------------------------------------------