220 | * the more to see {@link Transaction}
221 | *
222 | * @see Transaction
223 | */
224 | public Transaction beginTransaction() {
225 | return mViewController.beginTransaction();
226 | }
227 |
228 | // =============== other ====================//
229 |
230 | /**
231 | * set the animation executor which used to pass one {@link BaseScrapView} to another BaseScrapView
232 | *
233 | * @param executor the animate executor
234 | */
235 | public void setAnimateExecutor(AnimateExecutor executor) {
236 | mViewController.setAnimateExecutor(executor);
237 | }
238 |
239 | }
240 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/CacheHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015
3 | * heaven7(donshine723@gmail.com)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.heaven7.scrap.core.oneac;
18 |
19 | import android.content.Context;
20 | import android.os.Bundle;
21 |
22 | import com.heaven7.java.base.util.Reflector;
23 |
24 | import java.util.Collections;
25 | import java.util.Comparator;
26 | import java.util.HashMap;
27 | import java.util.List;
28 | import java.util.Map;
29 | import java.util.NoSuchElementException;
30 |
31 | /**
32 | * the cache helper for internal use.
33 | * the view stack only cache one instance of the same class name which is a child of BaseScrapView.
34 | * if {@link ExpandArrayList#getMode()} != {@link StackMode#Normal}
35 | *
you can use {@link Transaction#stackMode(StackMode)} to change the default behavior. and the {@link Transaction#commit()} will restore mode
36 | * to default({@link StackMode#ClearPrevious}).
37 | * @see Transaction#stackMode(StackMode)
38 | * @see Transaction#commit()
39 | * @author heaven7
40 | */
41 | /* package */ final class CacheHelper {
42 |
43 | private static final String KEY_STACK_PREFIX = "stack_";
44 | private static final String KEY_CACHE_PREFIX = "cache_";
45 | private static final String KEY_SIZE = "size_";
46 | private static final String KEY_CLASS = "class_";
47 | private static final String KEY_DATA = "data_";
48 | private static final String KEY_MAP_KEY = "key_";
49 | private static final String KEY_CUR_INDEX = "curIndex_";
50 |
51 | final ExpandArrayList mViewStack;
52 | private final HashMap mCachedViewMap;
53 |
54 | private static final Comparator DEFAULT_COMPARATOR = new Comparator() {
55 | @Override
56 | public int compare(BaseScrapView lhs, BaseScrapView rhs) {
57 | return lhs.compareTo(rhs);
58 | }
59 | };
60 |
61 | public CacheHelper() {
62 | mCachedViewMap = new HashMap();
63 | mViewStack = new ExpandArrayList(){
64 | @Override
65 | public boolean add(BaseScrapView baseScrapView) {
66 | if(!baseScrapView.isInBackStack())
67 | baseScrapView.setInBackStack(true);
68 | return super.add(baseScrapView);
69 | }
70 | @Override
71 | public void add(int index, BaseScrapView baseScrapView) {
72 | if(!baseScrapView.isInBackStack())
73 | baseScrapView.setInBackStack(true);
74 | super.add(index, baseScrapView);
75 | }
76 | };
77 | // set Comparator to prevent the same class
78 | mViewStack.setComparator(DEFAULT_COMPARATOR);
79 | mViewStack.setStackMode(StackMode.Normal);
80 | }
81 |
82 | /** restore the setting of back stack. */
83 | public void resetStackSetting(){
84 | if(mViewStack.getComparator() != DEFAULT_COMPARATOR){
85 | mViewStack.setComparator(DEFAULT_COMPARATOR);
86 | }
87 | if(mViewStack.getMode() != StackMode.Normal)
88 | mViewStack.setStackMode(StackMode.Normal);
89 | }
90 |
91 | public List getStackList() {
92 | return Collections.unmodifiableList(mViewStack);
93 | }
94 |
95 | /**
96 | * make the BaseScrapView in the cache for reuse.
97 | * @param key the key to find for resue.
98 | * @param view which view you want to cache
99 | */
100 | public CacheHelper cache(String key, BaseScrapView view){
101 | if(view == null)
102 | throw new NullPointerException();
103 | mCachedViewMap.put(key, view);
104 | return this;
105 | }
106 |
107 | /** default key is the view.getClass().getName()*/
108 | public CacheHelper cache(BaseScrapView view){
109 | return cache(view.getClass().getName(), view);
110 | }
111 |
112 | public BaseScrapView getCacheView(String key){
113 | return mCachedViewMap.get(key);
114 | }
115 |
116 | /** remove the mapping of the key
117 | * @param key */
118 | public BaseScrapView removeCacheView(String key){
119 | return mCachedViewMap.remove(key);
120 | }
121 |
122 | /**
123 | * add view to the top of stack. it means it will be first removed from next first back event.
124 | * @param view
125 | */
126 | public CacheHelper addToStackTop(BaseScrapView view){
127 | mViewStack.addLast(view);
128 | return this;
129 | }
130 | /**
131 | * add view to the bottom of stack. it means it will be last removed from back stack..
132 | * @param view
133 | */
134 | public CacheHelper addToStackBottom(BaseScrapView view){
135 | mViewStack.addFirst(view);
136 | return this;
137 | }
138 |
139 | /**
140 | * @return the size of back stack.
141 | */
142 | public int getStackSize(){
143 | return mViewStack.size();
144 | }
145 |
146 | public BaseScrapView pollStackTail(){
147 | BaseScrapView view = mViewStack.pollLast();
148 | view.setInBackStack(false);
149 | return view;
150 | }
151 |
152 | public BaseScrapView pollStackHead(){
153 | BaseScrapView view = mViewStack.pollFirst();
154 | view.setInBackStack(false);
155 | return view;
156 | }
157 |
158 | /** get the bottom of stack.*/
159 | public BaseScrapView getStackHead(){
160 | return mViewStack.getFirst();
161 | }
162 |
163 | public void clearStack(){
164 | mViewStack.clear();
165 | }
166 | public void clearCache(){
167 | mCachedViewMap.clear();
168 | }
169 |
170 | public void clearAll(){
171 | mCachedViewMap.clear();
172 | mViewStack.clear();
173 | }
174 | /**
175 | * add the view to stack befor or after the referencedView.
176 | * @param referencedView the view to referenced
177 | * @param target the target view to add
178 | * @param before true to make the view before referencedView.false to after it.
179 | * @throws NoSuchElementException if referencedView isn't in stack.
180 | */
181 | public void addToStack(BaseScrapView referencedView, BaseScrapView target,
182 | boolean before) {
183 | if(before)
184 | mViewStack.addBefore(referencedView, target);
185 | else
186 | mViewStack.addAfter(referencedView, target);
187 | }
188 | /**
189 | * add the view to stack befor or after the referencedView.
190 | * @param referencedClass the referencedClass of BaseScrapView
191 | * @param target the view to add
192 | * @param before true to make the view before referencedView.false to after it.
193 | * @throws NoSuchElementException if the referencedView isn't in stack.
194 | */
195 | /*public*/ void addToStack(Class extends BaseScrapView> referencedClass, BaseScrapView target,
196 | boolean before) {
197 | //create a simulate BaseScrapView to indexOf
198 | BaseScrapView referencedView = Reflector.from(referencedClass).constructor(Context.class)
199 | .newInstance(target.getContext());
200 | addToStack(referencedView, target, before);
201 | }
202 |
203 | public void onSaveInstanceState(Bundle out, int curIndex) {
204 | //save stack
205 | int size = mViewStack.size();
206 | out.putInt(KEY_STACK_PREFIX + KEY_SIZE, size);
207 | out.putInt(KEY_STACK_PREFIX + KEY_CUR_INDEX, curIndex);
208 | for (int i = 0 ; i < size ; i ++){
209 | BaseScrapView view = mViewStack.get(i);
210 | Bundle b = new Bundle();
211 | view.onSaveInstanceState(b);
212 | out.putBundle(KEY_STACK_PREFIX + KEY_DATA + i, b);
213 | out.putString(KEY_STACK_PREFIX + KEY_CLASS + i, view.getClass().getName());
214 | }
215 | //save cache
216 | size = mCachedViewMap.size();
217 | out.putInt(KEY_CACHE_PREFIX + KEY_SIZE, size);
218 | int i = 0;
219 | for (Map.Entry en : mCachedViewMap.entrySet()){
220 | BaseScrapView view = en.getValue();
221 |
222 | Bundle b = new Bundle();
223 | view.onSaveInstanceState(b);
224 | out.putBundle(KEY_CACHE_PREFIX + KEY_DATA + i, b);
225 | out.putString(KEY_CACHE_PREFIX + KEY_CLASS + i, view.getClass().getName());
226 | out.putString(KEY_CACHE_PREFIX + KEY_MAP_KEY + i, en.getKey());
227 | i ++;
228 | }
229 | }
230 | public int onRestoreInstanceState(Context context, Bundle in) {
231 | int curIndex = -2;
232 | if(in != null){
233 | int size = in.getInt(KEY_STACK_PREFIX + KEY_SIZE);
234 | curIndex = in.getInt(KEY_STACK_PREFIX + KEY_CUR_INDEX);
235 | mViewStack.clear();
236 | for (int i = 0 ; i < size ; i++){
237 | String cn = in.getString(KEY_STACK_PREFIX + KEY_CLASS + i);
238 | Bundle b = in.getBundle(KEY_STACK_PREFIX + KEY_DATA + i);
239 | try {
240 | BaseScrapView view = Reflector.from(Class.forName(cn)).constructor(Context.class).newInstance(context);
241 | view.onRestoreInstanceState(b);
242 | mViewStack.add(view);
243 | } catch (ClassNotFoundException e) {
244 | throw new IllegalStateException(e);
245 | }
246 | }
247 | //restore cache
248 | mCachedViewMap.clear();
249 | size = in.getInt(KEY_CACHE_PREFIX + KEY_SIZE);
250 | for (int i = 0 ; i < size ; i ++){
251 | Bundle b = in.getBundle(KEY_CACHE_PREFIX + KEY_DATA + i);
252 | String cn = in.getString(KEY_CACHE_PREFIX + KEY_CLASS + i);
253 | String mapKey = in.getString(KEY_CACHE_PREFIX + KEY_MAP_KEY + i);
254 |
255 | try {
256 | BaseScrapView view = Reflector.from(Class.forName(cn)).constructor(Context.class).newInstance(context);
257 | view.onRestoreInstanceState(b);
258 | mCachedViewMap.put(mapKey, view);
259 | } catch (ClassNotFoundException e) {
260 | throw new IllegalStateException(e);
261 | }
262 | }
263 | }
264 | return curIndex;
265 | }
266 | }
267 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/ExpandArrayList.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.core.oneac;
2 |
3 | import org.heaven7.scrap.util.ArrayList2;
4 |
5 | import java.io.IOException;
6 | import java.io.InvalidObjectException;
7 | import java.io.ObjectInputStream;
8 | import java.io.ObjectOutputStream;
9 | import java.util.Comparator;
10 |
11 | /**
12 | * an expand ArrayList2 . use {@link #setStackMode(StackMode)} and {@link #setComparator(Comparator)} will be useful to control how to add new E
13 | * and will effect add(E) , add(index,E)
14 | *
15 | * @param
16 | * @author heaven7
17 | * @see StackMode
18 | * @see ExpandArrayList#add(Object)
19 | * @see ExpandArrayList#add(int, Object)
20 | */
21 | /*public*/ class ExpandArrayList extends ArrayList2 {
22 | private static final long serialVersionUID = -8201458809772301953L;
23 |
24 | private StackMode mMode = StackMode.Normal;
25 | private Comparator mComparator;
26 |
27 | public StackMode getMode() {
28 | return mMode;
29 | }
30 |
31 | /**
32 | * set the mode which will effect the 'add(E)' and 'add(index,E)' operation.
33 | * default is {@link StackMode#Normal}
34 | *
35 | * @param mode can't be null
36 | */
37 | public void setStackMode(StackMode mode) {
38 | if (mode == null)
39 | throw new NullPointerException();
40 | this.mMode = mode;
41 | }
42 |
43 | public Comparator getComparator() {
44 | return mComparator;
45 | }
46 |
47 | /**
48 | * set the comparator , which will indicate how to find E. so effect {@link #indexOf(Object)} directly.
49 | * if {@link #getMode()} == {@link StackMode#Normal},this have no effect.
50 | */
51 | public void setComparator(Comparator c) {
52 | this.mComparator = c;
53 | }
54 |
55 | @Override
56 | public boolean add(E e) {
57 | if (e == null)
58 | throw new NullPointerException();
59 |
60 | switch (mMode) {
61 | case ClearPrevious:
62 | int index = indexOf(e);
63 | if (index != -1) {
64 | remove(index);
65 | }
66 | return super.add(e);
67 |
68 | case ReplacePrevious:
69 | int index2 = indexOf(e);
70 | if (index2 != -1) {
71 | set(index2, e);
72 | return true;
73 | }
74 | return super.add(e);
75 |
76 | case ReplacePreviousAndClearAfter:
77 | int index3 = indexOf(e);
78 | if (index3 != -1) {
79 | set(index3, e);
80 | clearAfter(index3);
81 | return true;
82 | }
83 | return super.add(e);
84 |
85 | case Normal:
86 | default:
87 | return super.add(e);
88 | }
89 | }
90 |
91 | @Override //index to add
92 | public void add(int index, E e) {
93 | if (e == null)
94 | throw new NullPointerException();
95 |
96 | switch (mMode) {
97 |
98 | case ClearPrevious:
99 | int oldIndex = indexOf(e);
100 | super.add(index, e);
101 | if (oldIndex == -1) {
102 | break;
103 | }
104 | //" oldIndex >= index " indicate the delete index after(>=) the added index
105 | final boolean after = oldIndex >= index;
106 | remove(after ? oldIndex + 1 : oldIndex);
107 | break;
108 |
109 | case ReplacePrevious:
110 | int index2 = indexOf(e);
111 | if (index2 != -1) {
112 | set(index2, e);
113 | break;
114 | }
115 | super.add(index, e);
116 | break;
117 |
118 | case ReplacePreviousAndClearAfter:
119 | int index3 = indexOf(e);
120 | if (index3 != -1) {
121 | set(index3, e);
122 | clearAfter(index3);
123 | break;
124 | }
125 | super.add(index, e);
126 | break;
127 |
128 | case Normal:
129 | default:
130 | super.add(index, e);
131 | }
132 | }
133 |
134 | /**
135 | * clear all element whose index after index
136 | */
137 | private void clearAfter(int index) {
138 | removeRange(index + 1, size()- 1);
139 | }
140 |
141 | @SuppressWarnings("unchecked")
142 | @Override
143 | public int indexOf(Object object) {
144 | if (object == null)
145 | return -1;
146 | E target = null;
147 | try {
148 | target = (E) object;
149 | } catch (ClassCastException e) {
150 | return -1;
151 | }
152 | final Comparator comparator = this.mComparator;
153 |
154 | final int size = size();
155 | int index = -1;
156 | for (int i = 0; i < size; i++) {
157 | E e = get(i);
158 | if (comparator == null) {
159 | if (e.equals(object)) {
160 | index = i;
161 | break;
162 | }
163 | } else if (comparator.compare(e, target) == 0) {
164 | index = i;
165 | break;
166 | }
167 | }
168 | return index;
169 | }
170 |
171 | private void writeObject(ObjectOutputStream stream) throws IOException {
172 | stream.defaultWriteObject();
173 | stream.writeInt(mMode.value);
174 |
175 | final int size = size();
176 | stream.writeInt(size);
177 | for (int i = 0; i < size; i++) {
178 | stream.writeObject(get(i));
179 | }
180 | }
181 |
182 | @SuppressWarnings("unchecked")
183 | private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
184 | stream.defaultReadObject();
185 | int modeVlue = stream.readInt();
186 | this.mMode = convertToMode(modeVlue);
187 |
188 | final int size = size();
189 | int cap = stream.readInt();
190 | if (cap < size) {
191 | throw new InvalidObjectException(
192 | "Capacity: " + cap + " < size: " + size);
193 | }
194 | clear();
195 | trimToSize();
196 | // array = (cap == 0 ? EmptyArray.OBJECT : new Object[cap]);
197 | for (int i = 0; i < size; i++) {
198 | //array[i] = stream.readObject();
199 | add((E) stream.readObject());
200 | }
201 | }
202 |
203 | public static StackMode convertToMode(int modeVlue) {
204 | switch (modeVlue) {
205 | case 1:
206 | return StackMode.Normal;
207 |
208 | case 2:
209 | return StackMode.ClearPrevious;
210 |
211 | case 3:
212 | return StackMode.ReplacePrevious;
213 |
214 | case 4:
215 | return StackMode.ReplacePreviousAndClearAfter;
216 |
217 | default:
218 | throw new IllegalStateException("wrong mode = " + modeVlue);
219 | }
220 | }
221 | }
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/IBackEventProcessor.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.core.oneac;
2 |
3 | /**
4 | * the back event handler
5 | * Created by heaven7 on 2015/8/3.
6 | */
7 | public interface IBackEventProcessor{
8 |
9 | /**
10 | * handle the back event .
11 | * @return true to consume the back event.
12 | */
13 | boolean handleBackEvent();
14 | }
15 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/IntentExecutor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015
3 | * heaven7(donshine723@gmail.com)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.heaven7.scrap.core.oneac;
18 |
19 | import android.content.Context;
20 |
21 | /**
22 | * Created by heaven7 on 2015/8/1.
23 | */
24 | public interface IntentExecutor {
25 | /**
26 | * start activity with the context
27 | * @param context the context
28 | */
29 | void startActivity(Context context);
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/LoadingParam.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.core.oneac;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * loading param , used for the loading view
8 | * Created by heaven7 on 2015/8/9.
9 | */
10 | public class LoadingParam implements Parcelable {
11 |
12 | public boolean showLoading;
13 | public boolean showTop;
14 | public boolean showBottom;
15 |
16 | // public boolean showMiddle;
17 | //content/middle is not show ,if showLoading = true
18 |
19 | /**
20 | * @param showLoading true to show loading
21 | * @param showTop true to show top while showLoading = true,
22 | * @param showBottom true to show bottom while showLoading = true;
23 | */
24 | public LoadingParam(boolean showLoading, boolean showTop, boolean showBottom) {
25 | set(showLoading,showTop,showBottom);
26 | }
27 |
28 | /**
29 | * @param showLoading true to show loading
30 | * @param showTop true to show top while showLoading = true,
31 | * @param showBottom true to show bottom while showLoading = true;
32 | */
33 | public void set(boolean showLoading, boolean showTop, boolean showBottom){
34 | this.showLoading = showLoading;
35 | this.showTop = showTop;
36 | this.showBottom = showBottom;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return "LoadingParam{" +
42 | "showLoading=" + showLoading +
43 | ", showTop=" + showTop +
44 | ", showBottom=" + showBottom +
45 | '}';
46 | }
47 |
48 | @Override
49 | public int describeContents() {
50 | return 0;
51 | }
52 |
53 | @Override
54 | public void writeToParcel(Parcel dest, int flags) {
55 | dest.writeByte(this.showLoading ? (byte) 1 : (byte) 0);
56 | dest.writeByte(this.showTop ? (byte) 1 : (byte) 0);
57 | dest.writeByte(this.showBottom ? (byte) 1 : (byte) 0);
58 | }
59 |
60 | protected LoadingParam(Parcel in) {
61 | this.showLoading = in.readByte() != 0;
62 | this.showTop = in.readByte() != 0;
63 | this.showBottom = in.readByte() != 0;
64 | }
65 |
66 | public static final Creator CREATOR = new Creator() {
67 | @Override
68 | public LoadingParam createFromParcel(Parcel source) {
69 | return new LoadingParam(source);
70 | }
71 |
72 | @Override
73 | public LoadingParam[] newArray(int size) {
74 | return new LoadingParam[size];
75 | }
76 | };
77 | }
78 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/ScrapHelper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015
3 | * heaven7(donshine723@gmail.com)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.heaven7.scrap.core.oneac;
18 |
19 | import android.os.Bundle;
20 |
21 | import org.heaven7.scrap.core.anim.AnimateExecutor;
22 | import org.heaven7.scrap.core.event.IActivityEventCallback;
23 | import org.heaven7.scrap.core.lifecycle.IActivityLifeCycleCallback;
24 |
25 | /**
26 | * a helpful util to use the 'OneActivity' framework.such as: jump to different page of {@linkplain BaseScrapView}
27 | * if you want more ,please see {@link ActivityController} and {@link ActivityViewController}.
28 | *
how to get them ?
29 | *
ActivityController controller = ActivityController.get();
30 | * ActivityViewController viewController = controller.getViewController();
31 | * ...// the more you want to do!
32 | *
33 | * @author heaven7
34 | * @see ActivityController
35 | * @see ActivityViewController
36 | * @see Transaction
37 | */
38 | public final class ScrapHelper {
39 |
40 | /** jump to the target view with no data. */
41 | public static void jumpTo(BaseScrapView view){
42 | ActivityController.get().jumpTo(view);
43 | }
44 |
45 | /**
46 | * jump to the target view with data. but not cache it or add to back stack.
47 | * if you want more . please use {@link #beginTransaction()}
48 | * @param view the view to jump
49 | * @param data the data to carry.
50 | * @see Transaction
51 | */
52 | public static void jumpTo(BaseScrapView view ,Bundle data){
53 | ActivityController.get().jumpTo(view, data);
54 | }
55 |
56 | /**
57 | * jump to the target view with data and animate executor.
58 | * @param target the target to jump
59 | * @param data the data to carry
60 | * @param executor the animate executor to perform this jump(only use once)
61 | */
62 | public static void jumpTo(BaseScrapView target,Bundle data,AnimateExecutor executor){
63 | getActivityViewController().jumpTo(target,data,executor);
64 | }
65 | /**
66 | * jump to the target view with animate executor.
67 | * @param target the target to jump
68 | * @param executor the animate executor to perform this jump(only use once)
69 | */
70 | public static void jumpTo(BaseScrapView target,AnimateExecutor executor){
71 | getActivityViewController().jumpTo(target,null,executor);
72 | }
73 |
74 | /**
75 | * open the transaction of {@link ActivityViewController}, this is very useful.
76 | * here is the sample code:
81 | * the more to see {@link Transaction}
82 | * @see Transaction
83 | */
84 | public static Transaction beginTransaction(){
85 | return ActivityController.get().beginTransaction();
86 | }
87 |
88 | /**
89 | * register Activity life cycle callback. which will be call in the Activity.
90 | * also you can use {@link org.heaven7.scrap.core.lifecycle.ActivityLifeCycleAdapter} ,it implement IActivityLifeCycleCallback
91 | * @param callbacks the callbacks
92 | * @see IActivityLifeCycleCallback
93 | * @see org.heaven7.scrap.core.lifecycle.ActivityLifeCycleAdapter
94 | * @see org.heaven7.scrap.core.lifecycle.ActivityLifeCycleDispatcher
95 | */
96 | public static void registerActivityLifeCycleCallback(IActivityLifeCycleCallback... callbacks){
97 | ActivityController.get().getLifeCycleDispatcher().registerActivityLifeCycleCallback(callbacks);
98 | }
99 |
100 | /**
101 | * unregister the activity life cycle callback. suach as: Activity_onResume(),Activity_onStop()
102 | * @param callbacks the callbacks
103 | * @see #registerActivityLifeCycleCallback(IActivityLifeCycleCallback...)
104 | */
105 | public static void unregisterActivityLifeCycleCallback(IActivityLifeCycleCallback...callbacks){
106 | ActivityController.get().getLifeCycleDispatcher().unregisterActivityLifeCycleCallback(callbacks);
107 | }
108 |
109 | /**
110 | * register the event callback of Activity.such as: key event(down/up...etc).touch event.
111 | * also use can use {@link org.heaven7.scrap.core.event.ActivityEventAdapter}
112 | * @param callbacks the callbacks
113 | * @see IActivityEventCallback
114 | * @see org.heaven7.scrap.core.event.ActivityEventAdapter
115 | */
116 | public static void registerActivityEventCallback(IActivityEventCallback ...callbacks){
117 | ActivityController.get().getEventListenerGroup().registerActivityEventListener(callbacks);
118 | }
119 |
120 | /**
121 | * unregister the event callback of activity.
122 | * @param callbacks the callbacks
123 | * @see #registerActivityEventCallback(IActivityEventCallback...)
124 | */
125 | public static void unregisterActivityEventCallback(IActivityEventCallback ...callbacks){
126 | ActivityController.get().getEventListenerGroup().unregisterActivityEventListener(callbacks);
127 | }
128 |
129 | /**
130 | * whether or not the target scarp view is at the top of back stack.
131 | *
head means it will be removed from back stack with the next first back event.
132 | * @param target the target view
133 | * @return true if the target is the head view of back stack.
134 | */
135 | public static boolean isScrapViewAtTop(BaseScrapView target){
136 | if(target == null)
137 | return false;
138 | return ActivityController.get().getViewController().getCurrentView() == target;
139 | }
140 | /**
141 | * whether or not the target scarp view is at the bottom of back stack.
142 | *
bottom means it will be last removed from back stack
143 | * @param target the target view
144 | * @return true if the target at the bottom view of back stack.
145 | * false if the target is null or it not add to the back stack.
146 | * @see #isScrapViewAtTop(BaseScrapView)
147 | * @see Transaction#addBackAsBottom()
148 | */
149 | public static boolean isScrapViewAtBottom(BaseScrapView target){
150 | return ActivityController.get().getViewController().isScrapViewAtBottom(target);
151 | }
152 |
153 | /** finish the current activity which is attached to {@link ActivityController} */
154 | public static void finishCurrentActivity(){
155 | ActivityController.get().finishActivity();
156 | }
157 |
158 | /**
159 | * get the activity's view controller
160 | */
161 | public static ActivityViewController getActivityViewController(){
162 | return ActivityController.get().getViewController();
163 | }
164 |
165 | /** set the visible of view .
166 | * @param visible true to visible,false to gone.
167 | * */
168 | public static void setVisibility(boolean visible){
169 | getActivityViewController().setVisibility(visible);
170 | }
171 |
172 | /**
173 | * toggle the visibility of view .
174 | */
175 | public static void toggleVisibility() {
176 | getActivityViewController().toggleVisibility();
177 | }
178 |
179 | /**
180 | * set the animate executor when jump from one ScrapView to another.
181 | * @note this animate executor is used as the global .
182 | * @param animateExecutor the animate executor
183 | * @see AnimateExecutor the animate executor
184 | */
185 | public static void setGlobalAnimateExecutor(AnimateExecutor animateExecutor) {
186 | ActivityController.get().setAnimateExecutor(animateExecutor);
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/core/oneac/StackMode.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.core.oneac;
2 |
3 |
4 | import org.heaven7.scrap.util.ArrayList2;
5 |
6 | import java.util.Comparator;
7 |
8 | /***
9 | * the mode of operate indicate how to effect {@link ExpandArrayList#add(Object)} or {@link ExpandArrayList#add(int, Object)}
10 | * if {@link ExpandArrayList#indexOf(Object)} != -1.
11 | * @author heaven7
12 | * @see ExpandArrayList#add(Object)
13 | * @see ExpandArrayList#add(int, Object)
14 | * @see #Normal
15 | * @see #ClearPrevious
16 | * @see #ReplacePrevious
17 | * @see #ReplacePreviousAndClearAfter
18 | */
19 | public enum StackMode {
20 |
21 | /**
22 | * have no effect. same to {@link ArrayList2}
23 | */
24 | Normal(1),
25 | /**
26 | * use {@link ExpandArrayList#indexOf(Object)} to search previous ( as this behaviour depend on the Comparator
27 | * which can through {@link ExpandArrayList#setComparator(Comparator)} to change it).
28 | * clear the previous E and put new E at the end or the target index.
29 | *
30 | * @see ExpandArrayList#add(int, Object)
31 | * @see ExpandArrayList#indexOf(Object)
32 | */
33 | ClearPrevious(2),
34 | /**
35 | * update the previous E to new E
36 | *
37 | * @see #ClearPrevious
38 | */
39 | ReplacePrevious(3),
40 | /**
41 | * update the previous E to new E,and the All E after it will be cleared.
42 | * this is similar to Activity.launch-mode = top
43 | *
44 | * @see #ClearPrevious
45 | */
46 | ReplacePreviousAndClearAfter(4);
47 |
48 | final int value;
49 |
50 | private StackMode(int value) {
51 | this.value = value;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/util/ArrayList2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015
3 | * heaven7(donshine723@gmail.com)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.heaven7.scrap.util;
18 |
19 | import java.util.ArrayList;
20 | import java.util.LinkedList;
21 | import java.util.NoSuchElementException;
22 | /**
23 | * a util similar to {@link ArrayList} help to use other feature. like {@link LinkedList}
24 | * and have another helpful methods.such as: {@link #addAfter(Object, Object)} and {@link #addBefore(Object, Object)}
25 | * @author heaven7
26 | * @param
27 | */
28 | public class ArrayList2 extends ArrayList {
29 |
30 | private static final long serialVersionUID = 894057356164202818L;
31 |
32 | @Override
33 | public boolean add(E e) {
34 | if(e == null)
35 | throw new NullPointerException("in ArrayList2 or child of it Null element is not permit.");
36 | return super.add(e);
37 | }
38 |
39 | /** add e to the first .same as: {@link LinkedList#addFirst(Object)} */
40 | public void addFirst(E e){
41 | add(0, e);
42 | }
43 | /** add e to the last .same as: {@link LinkedList#addLast(Object)} */
44 | public void addLast(E e){
45 | add(size(), e);
46 | }
47 | /**
48 | * add the element E after the element of index.
49 | * @param index must >=0
50 | */
51 | public void addAfter(int index, E e) {
52 | if(index < 0)
53 | throw new IllegalArgumentException("index is invalid(must >=0). index = " +index);
54 | add(index + 1, e);
55 | }
56 | /**
57 | * add an element after another element.
58 | * @param referenced the e to compare or refer.
59 | * @param e the e to add
60 | * @throws NoSuchElementException if the referenced e can't find.
61 | */
62 | public void addAfter(E referenced, E e) throws NoSuchElementException{
63 | int index = indexOf(referenced); //0 ~ size-1
64 | if(index == -1){
65 | throw new NoSuchElementException();
66 | }
67 | add(index + 1, e);
68 | }
69 | /**
70 | * add the element E before the element of index.
71 | * @param index must <= size() + 1
72 | */
73 | public void addBefore(int index, E e){
74 | if(index > size() + 1)//max = size+1
75 | throw new IllegalArgumentException("");
76 | add(index <=0 ? 0 : index-1 , e);
77 | }
78 | /**
79 | * add an element before another element.
80 | * @param referenced the e to compare or refer.
81 | * @param e the e to add
82 | * @throws NoSuchElementException if the referenced e can't find.
83 | */
84 | public void addBefore(E referenced, E e){
85 | int index = indexOf(referenced);
86 | if(index == -1){
87 | throw new NoSuchElementException();
88 | }
89 | addBefore(index, e);
90 | }
91 |
92 | /** get and remove last element may be null if list is empty. */
93 | public E pollLast() {
94 | int size = size();
95 | return size !=0 ? remove(size -1) : null;
96 | }
97 |
98 | /** get and remove first element may be null if list is empty. */
99 | public E pollFirst() {
100 | int size = size();
101 | return size !=0 ? remove(0) :null;
102 | }
103 |
104 | /** get first element but not remove from list, may be null if list is empty. */
105 | public E getFirst(){
106 | int size = size();
107 | return size !=0 ? get(0) :null;
108 | }
109 | /** get last element but not remove from list, may be null if list is empty. */
110 | public E getLast(){
111 | int size = size();
112 | return size !=0 ? get(size-1) :null;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/util/SpringUtil.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.util;
2 |
3 | public final class SpringUtil {
4 |
5 | /**
6 | * Map a value within a given range to another range.
7 | * @param value the value to map
8 | * @param fromLow the low end of the range the value is within
9 | * @param fromHigh the high end of the range the value is within
10 | * @param toLow the low end of the range to map to
11 | * @param toHigh the high end of the range to map to
12 | * @return the mapped value
13 | */
14 | public static double mapValueFromRangeToRange(
15 | double value,
16 | double fromLow,
17 | double fromHigh,
18 | double toLow,
19 | double toHigh) {
20 | double fromRangeSize = fromHigh - fromLow;
21 | double toRangeSize = toHigh - toLow;
22 | double valueScale = (value - fromLow) / fromRangeSize;
23 | return toLow + (valueScale * toRangeSize);
24 | }
25 |
26 | /**
27 | * Clamp a value to be within the provided range.
28 | * @param value the value to clamp
29 | * @param low the low end of the range
30 | * @param high the high end of the range
31 | * @return the clamped value
32 | */
33 | public static double clamp(double value, double low, double high) {
34 | return Math.min(Math.max(value, low), high);
35 | }
36 | }
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/java/org/heaven7/scrap/util/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015
3 | * heaven7(donshine723@gmail.com)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.heaven7.scrap.util;
18 |
19 | import android.content.Context;
20 | import android.content.res.Resources;
21 |
22 | import androidx.annotation.RestrictTo;
23 |
24 | import com.heaven7.core.util.ConfigUtil;
25 | import com.heaven7.core.util.DimenUtil;
26 | import com.heaven7.core.util.ResourceUtil;
27 |
28 | import java.util.Properties;
29 |
30 | @RestrictTo(RestrictTo.Scope.LIBRARY)
31 | public final class Utils {
32 |
33 | private static int sSystemUIHeight;
34 |
35 | /** load properties which is under the raw (exclude extension )*/
36 | public static Properties loadRawConfig(Context context,String rawResName) {
37 | int resId = ResourceUtil.getResId(context, rawResName, ResourceUtil.ResourceType.Raw);
38 | return ConfigUtil.loadRawConfig(context, resId);
39 | }
40 |
41 | public static int getSystemUIHeight(Context context) {
42 | if (0 == sSystemUIHeight) {
43 | Resources resources = context.getResources();
44 | int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
45 | if (resourceId > 0) {
46 | sSystemUIHeight = resources.getDimensionPixelSize(resourceId);
47 | } else {
48 | sSystemUIHeight = DimenUtil.dip2px(context, 56);
49 | }
50 | }
51 | return sSystemUIHeight;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/layout/lib_style_ac_container.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/layout/lib_style_ac_no_overlap.xml:
--------------------------------------------------------------------------------
1 |
4 |
10 |
11 |
18 |
19 |
20 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/layout/lib_style_ac_overlap.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
13 |
18 |
19 |
20 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/android-scrap/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android-Scrap
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/Android-Scrap/android-scrap/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android-Scrap/backup/ResourceHoldable.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.res;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 |
6 | public interface ResourceHoldable {
7 |
8 | Context getContext();
9 |
10 | CharSequence getText(String resName);
11 |
12 | Bitmap getBitmap(String resName);
13 |
14 | Bitmap getBitmap(String resName, int width, int height);
15 |
16 | int getId(String resName);
17 |
18 | int getStringId(String resName);
19 |
20 | int getLayoutId(String resName);
21 |
22 | int getDrawableId(String resName);
23 |
24 | int getStyleId(String resName);
25 |
26 | int getAnimId(String resName);
27 |
28 | int getColorId(String resName);
29 |
30 | int getDimenId(String resName);
31 |
32 | int getRawId(String resName);
33 |
34 | int getStringArrayId(String resName);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/Android-Scrap/backup/ResourceHolder.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.res;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 |
7 | import com.heaven7.core.util.ResourceUtil;
8 |
9 | public class ResourceHolder implements ResourceHoldable {
10 |
11 | private Context mContext;
12 |
13 | public ResourceHolder(Context context) {
14 | this.mContext = context;
15 | }
16 |
17 | @Override
18 | public CharSequence getText(String resName){
19 | return mContext.getResources().getText(getStringId(resName));
20 | }
21 |
22 | @Override
23 | public Bitmap getBitmap(String resName){
24 | return BitmapFactory.decodeResource(mContext.getResources(), getDrawableId(resName));
25 | }
26 |
27 | @Override
28 | public Bitmap getBitmap(String resName,int width,int height){
29 | Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), getDrawableId(resName));
30 | if(width <=0 || height<=0){
31 | return bitmap;
32 | }
33 | return Bitmap.createScaledBitmap(bitmap, width, height, true);
34 | }
35 |
36 | @Override
37 | public int getId(String resName){
38 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Id);
39 | }
40 |
41 | @Override
42 | public int getStringId(String resName){
43 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.String);
44 | }
45 |
46 | @Override
47 | public int getLayoutId(String resName){
48 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Layout);
49 | }
50 |
51 | @Override
52 | public int getDrawableId(String resName){
53 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Drawable);
54 | }
55 |
56 | @Override
57 | public int getStyleId(String resName){
58 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Style);
59 | }
60 |
61 | @Override
62 | public int getAnimId(String resName){
63 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Anim);
64 | }
65 |
66 | @Override
67 | public int getColorId(String resName){
68 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Color);
69 | }
70 | @Override
71 | public int getDimenId(String resName){
72 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Dimen);
73 | }
74 |
75 | @Override
76 | public int getRawId(String resName) {
77 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.Raw);
78 | }
79 |
80 | @Override
81 | public int getStringArrayId(String resName){
82 | return ResourceUtil.getResId(mContext, resName, ResourceUtil.ResourceType.StringArray);
83 | }
84 |
85 | @Override
86 | public Context getContext() {
87 | return mContext;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/Android-Scrap/bintrayUpload_backup.txt:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 | apply plugin: 'com.jfrog.bintray'
3 |
4 | // load properties
5 | Properties properties = new Properties()
6 | File localPropertiesFile = project.file("local.properties");
7 | if(localPropertiesFile.exists()){
8 | properties.load(localPropertiesFile.newDataInputStream())
9 | }
10 | File projectPropertiesFile = project.file("project.properties");
11 | if(projectPropertiesFile.exists()){
12 | properties.load(projectPropertiesFile.newDataInputStream())
13 | }
14 |
15 | // read properties
16 | def projectName = properties.getProperty("project.name")
17 | def projectGroupId = properties.getProperty("project.groupId")
18 | def projectArtifactId = properties.getProperty("project.artifactId")
19 | def projectVersionName = android.defaultConfig.versionName
20 | def projectPackaging = properties.getProperty("project.packaging")
21 | def projectSiteUrl = properties.getProperty("project.siteUrl")
22 | def projectGitUrl = properties.getProperty("project.gitUrl")
23 |
24 | def developerId = properties.getProperty("developer.id")
25 | def developerName = properties.getProperty("developer.name")
26 | def developerEmail = properties.getProperty("developer.email")
27 |
28 | def bintrayUser = properties.getProperty("bintray.user")
29 | def bintrayApikey = properties.getProperty("bintray.apikey")
30 |
31 | def javadocName = properties.getProperty("javadoc.name")
32 |
33 | group = projectGroupId
34 |
35 | // This generates POM.xml with proper parameters
36 | install {
37 | repositories.mavenInstaller {
38 | pom {
39 | project {
40 | name projectName
41 | groupId projectGroupId
42 | artifactId projectArtifactId
43 | version projectVersionName
44 | packaging projectPackaging
45 | url projectSiteUrl
46 | licenses {
47 | license {
48 | name 'The Apache Software License, Version 2.0'
49 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
50 | }
51 | }
52 | developers {
53 | developer {
54 | id developerId
55 | name developerName
56 | email developerEmail
57 | }
58 | }
59 | scm {
60 | connection projectGitUrl
61 | developerConnection projectGitUrl
62 | url projectSiteUrl
63 | }
64 | }
65 | }
66 | }
67 | }
68 |
69 | // This generates sources.jar
70 | task sourcesJar(type: Jar) {
71 | from android.sourceSets.main.java.srcDirs
72 | classifier = 'sources'
73 | }
74 |
75 | task javadoc(type: Javadoc) {
76 | source = android.sourceSets.main.java.srcDirs
77 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
78 | }
79 |
80 | // This generates javadoc.jar
81 | task javadocJar(type: Jar, dependsOn: javadoc) {
82 | classifier = 'javadoc'
83 | from javadoc.destinationDir
84 | }
85 |
86 | artifacts {
87 | archives javadocJar
88 | archives sourcesJar
89 | }
90 |
91 | // javadoc configuration
92 | javadoc {
93 | options{
94 | encoding "UTF-8"
95 | charSet 'UTF-8'
96 | author true
97 | version projectVersionName
98 | links "http://docs.oracle.com/javase/7/docs/api"
99 | title javadocName
100 | }
101 | }
102 |
103 | // bintray configuration
104 | bintray {
105 | user = bintrayUser
106 | key = bintrayApikey
107 | configurations = ['archives']
108 | pkg {
109 | repo = "maven"
110 | name = projectName
111 | websiteUrl = projectSiteUrl
112 | vcsUrl = projectGitUrl
113 | licenses = ["Apache-2.0"]
114 | publish = true
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/Android-Scrap/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.4.2'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
11 | //jcenter
12 | // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
13 | // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
14 | //classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
15 | //classpath 'com.github.dcendents:android-maven-plugin:1.2'
16 | // NOTE: Do not place your application dependencies here; they belong
17 | // in the individual module build.gradle files
18 | }
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | google()
24 | jcenter()
25 | maven { url "https://jitpack.io" }
26 | }
27 | }
28 | ext {
29 | compileSdkVersion = 28
30 | buildToolsVersion = "28.0.3"
31 |
32 | minSdkVersion = 19
33 | targetSdkVersion = 28
34 | }
--------------------------------------------------------------------------------
/Android-Scrap/common.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | def androidX_ver = '1.1.0'
3 |
4 | implementation "androidx.appcompat:appcompat:$androidX_ver"
5 | implementation "androidx.recyclerview:recyclerview:$androidX_ver"
6 |
7 | implementation 'com.heaven7.java.base:Java-base:1.2.1'
8 | implementation 'com.github.LightSun:Produce-consume:1.0.2-beta4'
9 | implementation 'com.heaven7.java.visitor:Visitor:1.3.5'
10 |
11 | implementation 'com.github.LightSun:android-ui:1.0.3-x'
12 | implementation 'com.github.LightSun:android-Component:1.1.7-x'
13 | implementation 'com.github.LightSun:Android-Download:1.0.0-beta-x'
14 | implementation 'com.heaven7.core.util:memory:1.0.5'
15 | implementation 'com.github.LightSun:Android-Common-Dialog:1.0.2-x'
16 | implementation 'com.github.LightSun:SuperAdapter:2.1.1-x'
17 | implementation('com.github.LightSun:util-v1:1.1.7-x') {
18 | exclude group: 'com.android.support'
19 | exclude module: 'android-component'
20 | }
21 | implementation('com.github.LightSun.Android-ImagePick:imagepick:2.0.0-beta-x') {
22 | exclude module: 'android-util2'
23 | }
24 | implementation('com.github.LightSun.Android-ImagePick:media:2.0.0-beta-x') {
25 | exclude module: 'android-util2'
26 | }
27 |
28 | implementation('com.github.LightSun:android-util2:1.2.0-x') {
29 | exclude group: "com.heaven7.core.adapter"
30 | exclude group: "com.heaven7.core.util"
31 | exclude module: 'android-component'
32 | }
33 | implementation('com.github.LightSun:android-PullRefreshView:1.1.1-x') {
34 | exclude group: "com.heaven7.core.adapter"
35 | exclude group: "com.heaven7.core.util"
36 | }
37 | implementation 'com.github.LightSun:common-view:1.2.4-x'
38 | }
39 |
--------------------------------------------------------------------------------
/Android-Scrap/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.useAndroidX=true
20 | # Automatically convert third-party libraries to use AndroidX
21 | android.enableJetifier=true
--------------------------------------------------------------------------------
/Android-Scrap/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Android-Scrap/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 01 15:07:23 CST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/Android-Scrap/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/Android-Scrap/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/Android-Scrap/lib.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | def androidX_ver = '1.1.0'
3 |
4 | implementation "androidx.appcompat:appcompat:$androidX_ver"
5 | implementation "androidx.recyclerview:recyclerview:$androidX_ver"
6 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
7 |
8 | implementation 'com.heaven7.java.base:Java-base:1.2.1'
9 | // implementation 'com.github.LightSun:Produce-consume:1.0.2-beta4'
10 | // implementation 'com.heaven7.java.visitor:Visitor:1.3.5'
11 |
12 | // implementation 'com.github.LightSun:android-ui:1.0.3-x'
13 | implementation 'com.github.LightSun:android-Component:1.1.7-x'
14 | // implementation 'com.github.LightSun:Android-Download:1.0.0-beta-x'
15 | implementation 'com.heaven7.core.util:memory:1.0.5'
16 | // implementation 'com.github.LightSun:Android-Common-Dialog:1.0.2-x'
17 | implementation 'com.github.LightSun:SuperAdapter:2.1.7-x'
18 | implementation('com.github.LightSun:util-v1:1.1.7-x') {
19 | exclude module: 'android-component'
20 | }
21 |
22 | implementation('com.github.LightSun:android-util2:1.2.0-x') {
23 | exclude group: "com.heaven7.core.adapter"
24 | exclude group: "com.heaven7.core.util"
25 | exclude module: 'android-component'
26 | }
27 | implementation('com.github.LightSun:android-PullRefreshView:1.1.1-x') {
28 | exclude group: "com.heaven7.core.adapter"
29 | exclude group: "com.heaven7.core.util"
30 | }
31 | implementation 'com.github.LightSun:common-view:1.2.4-x'
32 | }
33 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion "29.0.2"
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 19
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | def androidX_ver = '1.1.0'
31 | implementation "androidx.appcompat:appcompat:$androidX_ver"
32 | implementation "androidx.recyclerview:recyclerview:$androidX_ver"
33 | implementation 'com.github.LightSun:SuperAdapter:2.1.7-x'
34 | implementation('com.github.LightSun:util-v1:1.1.7-x') {
35 | exclude module: 'android-component'
36 | }
37 |
38 | implementation 'com.heaven7.java.base:Java-base:1.2.1'
39 |
40 | implementation project(":android-scrap")
41 | }
42 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/OnClickSampleItemListener.java:
--------------------------------------------------------------------------------
1 | package com.heaven7.android.style.libsample;
2 |
3 | import android.content.Context;
4 |
5 | import com.heaven7.android.style.libsample.module.SampleItem;
6 |
7 | public interface OnClickSampleItemListener {
8 |
9 | void onClickSample(Context context, SampleItem item);
10 | }
11 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/SampleConstants.java:
--------------------------------------------------------------------------------
1 | package com.heaven7.android.style.libsample;
2 |
3 | public interface SampleConstants {
4 |
5 | String KEY_LIST = "list";
6 | String KEY_ITEM_LISTENER = "item_listener";
7 | String KEY_TITLE = "title";
8 | }
9 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/module/SampleItem.java:
--------------------------------------------------------------------------------
1 | package com.heaven7.android.style.libsample.module;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import com.heaven7.adapter.BaseSelector;
7 |
8 | public class SampleItem extends BaseSelector implements Parcelable {
9 |
10 | private String text;
11 | private int id;
12 |
13 | public SampleItem(String text, int id) {
14 | this.text = text;
15 | this.id = id;
16 | }
17 |
18 | public SampleItem(String text) {
19 | this(text, 0);
20 | }
21 |
22 | public String getText() {
23 | return text;
24 | }
25 | public void setText(String text) {
26 | this.text = text;
27 | }
28 |
29 | public int getId() {
30 | return id;
31 | }
32 | public void setId(int id) {
33 | this.id = id;
34 | }
35 |
36 | @Override
37 | public int describeContents() {
38 | return 0;
39 | }
40 |
41 | @Override
42 | public void writeToParcel(Parcel dest, int flags) {
43 | dest.writeString(this.text);
44 | dest.writeInt(this.id);
45 | }
46 |
47 | protected SampleItem(Parcel in) {
48 | this.text = in.readString();
49 | this.id = in.readInt();
50 | }
51 |
52 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
53 | @Override
54 | public SampleItem createFromParcel(Parcel source) {
55 | return new SampleItem(source);
56 | }
57 |
58 | @Override
59 | public SampleItem[] newArray(int size) {
60 | return new SampleItem[size];
61 | }
62 | };
63 | }
64 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/java/com/heaven7/android/style/libsample/scrap/ListScrapView.java:
--------------------------------------------------------------------------------
1 | package com.heaven7.android.style.libsample.scrap;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 | import androidx.recyclerview.widget.LinearLayoutManager;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import com.heaven7.adapter.QuickRecycleViewAdapter;
11 | import com.heaven7.adapter.util.ViewHelper2;
12 | import com.heaven7.android.style.libsample.OnClickSampleItemListener;
13 | import com.heaven7.android.style.libsample.R;
14 | import com.heaven7.android.style.libsample.SampleConstants;
15 | import com.heaven7.android.style.libsample.module.SampleItem;
16 | import com.heaven7.java.base.util.Predicates;
17 | import com.heaven7.java.base.util.Reflector;
18 |
19 | import org.heaven7.scrap.core.oneac.BaseScrapView;
20 |
21 | import java.util.ArrayList;
22 |
23 | /**
24 | * need parameters
25 | * @see SampleConstants#KEY_LIST
26 | * @see SampleConstants#KEY_ITEM_LISTENER
27 | * @author heaven7
28 | */
29 | public class ListScrapView extends BaseScrapView {
30 |
31 | RecyclerView mRv;
32 |
33 | public ListScrapView(Context mContext) {
34 | super(mContext);
35 | }
36 |
37 | @Override
38 | protected int getLayoutId() {
39 | return R.layout.lib_sample_list;
40 | }
41 |
42 | @Override
43 | protected void onAttach() {
44 | super.onAttach();
45 | ArrayList items = getArguments().getParcelableArrayList(SampleConstants.KEY_LIST);
46 | String cn = getArguments().getString(SampleConstants.KEY_ITEM_LISTENER);
47 | String title = getArguments().getString(SampleConstants.KEY_TITLE);
48 | if(Predicates.isEmpty(items)){
49 | throw new IllegalStateException("must set sample items");
50 | }
51 | final OnClickSampleItemListener l;
52 | try {
53 | l = Reflector.from(Class.forName(cn)).newInstance();
54 | } catch (ClassNotFoundException e) {
55 | throw new RuntimeException(e);
56 | }
57 | TextView tv = getView(R.id.tv_title);
58 | tv.setText(title);
59 | if(title == null){
60 | tv.setVisibility(View.GONE);
61 | }
62 |
63 | mRv = getView(R.id.rv);
64 | mRv.setLayoutManager(new LinearLayoutManager(getContext()));
65 | mRv.setAdapter(new QuickRecycleViewAdapter(R.layout.lib_sample_item_button, items) {
66 | @Override
67 | protected void onBindData(Context context, int position, final SampleItem item, int itemLayoutId, ViewHelper2 helper) {
68 | helper.setText(R.id.bt, item.getText())
69 | .setRootOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View v) {
72 | l.onClickSample(getContext(), item);
73 | }
74 | });
75 | }
76 | });
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/res/layout/lib_sample_item_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/res/layout/lib_sample_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Android-Scrap/lib_sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | lib_sample
3 |
4 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply from: '../common.gradle'
3 |
4 | android {
5 | compileSdkVersion rootProject.ext.compileSdkVersion
6 | buildToolsVersion rootProject.ext.buildToolsVersion
7 |
8 | defaultConfig {
9 | applicationId "org.heaven7.scrap.sample"
10 | minSdkVersion rootProject.ext.minSdkVersion
11 | targetSdkVersion rootProject.ext.targetSdkVersion
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | compileOptions {
22 | sourceCompatibility JavaVersion.VERSION_1_8
23 | targetCompatibility JavaVersion.VERSION_1_8
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | //compile 'org.heaven7.scrap:android-scrap:1.1'
30 |
31 | implementation project(':android-scrap')
32 |
33 | api "com.github.bumptech.glide:glide:4.9.0"
34 | def butterknife = '10.0.0'
35 |
36 | implementation "com.jakewharton:butterknife:${butterknife}"
37 | annotationProcessor "com.jakewharton:butterknife-compiler:${butterknife}"
38 | }
39 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in I:\android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
18 |
19 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/MainScrapView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import com.heaven7.core.util.Toaster;
7 |
8 | import org.heaven7.scrap.core.oneac.BaseScrapView;
9 | import org.heaven7.scrap.core.oneac.ScrapHelper;
10 | import org.heaven7.scrap.sample.scrapview.TestTransitionScrapView_exit;
11 |
12 | /**
13 | * similar as the Main Activity: so this is used as the Splash scrap view.
14 | * but you must similar set res/raw/scrap_config.properties.
15 | * Created by heaven7 on 2015/8/8.
16 | */
17 | public class MainScrapView extends BaseScrapView {
18 |
19 | private long start;
20 |
21 | public MainScrapView(Context mContext) {
22 | super(mContext);
23 | }
24 |
25 | public void showToast(String msg) {
26 | Toaster.show(getContext(), msg);
27 | }
28 |
29 | @Override
30 | protected int getLayoutId() {
31 | return R.layout.scrap_main;
32 | }
33 |
34 | @Override
35 | protected boolean onBackPressed() {
36 | if (ScrapHelper.isScrapViewAtBottom(this)) {
37 | if(start == 0){
38 | start = System.currentTimeMillis();
39 | showToast("click again to exit MainScrapView!");
40 | return true;
41 | }
42 | long now = System.currentTimeMillis();
43 | if (now - start >= 500) {
44 | showToast("click again to exit MainScrapView!");
45 | start = now;
46 | } else {
47 | ScrapHelper.finishCurrentActivity();
48 | }
49 | return true;
50 | }
51 | return super.onBackPressed();
52 | }
53 |
54 | @Override
55 | protected void onAttach() {
56 | //after here i use volley to load image,so must init
57 |
58 | getView(R.id.bt).setOnClickListener(new View.OnClickListener() {
59 | @Override
60 | public void onClick(View v) {
61 | ScrapHelper.beginTransaction()
62 | .addBackAsTop(new TestTransitionScrapView_exit(v.getContext()))
63 | .jump()
64 | .commit();
65 | }
66 | });
67 |
68 | //String s = getResources().getDisplayMetrics().toString();
69 | // ScrapLog.i("getDisplayMetrics",s);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/ScrapApp.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample;
2 |
3 | import android.app.Application;
4 |
5 |
6 | public class ScrapApp extends Application {
7 |
8 | @Override
9 | public void onCreate() {
10 | super.onCreate();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/ScrapLog.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * Created by heaven7 on 2015/8/4.
7 | */
8 | public class ScrapLog {
9 |
10 | private static final String TAG = "ScrapLog";
11 |
12 | public static void i(String method,String msg){
13 | Log.i(TAG,"called [ "+method+" ]: "+msg);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/CommonView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.ImageView;
6 |
7 | import androidx.recyclerview.widget.LinearLayoutManager;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.heaven7.adapter.BaseSelector;
12 | import com.heaven7.adapter.QuickRecycleViewAdapter;
13 | import com.heaven7.adapter.util.ViewHelper2;
14 | import com.heaven7.core.util.Toaster;
15 |
16 | import org.heaven7.scrap.core.oneac.BaseScrapView;
17 | import org.heaven7.scrap.sample.R;
18 | import org.heaven7.scrap.util.ArrayList2;
19 |
20 | import java.util.List;
21 |
22 | import butterknife.ButterKnife;
23 | import butterknife.OnClick;
24 | import butterknife.Optional;
25 |
26 | /**
27 | * Created by heaven7 on 2015/8/3.
28 | */
29 | public class CommonView extends BaseScrapView {
30 |
31 |
32 | public CommonView(Context mContext) {
33 | super(mContext);
34 | }
35 |
36 | @Override
37 | protected int getLayoutId() {
38 | //TODO test KeyEvent. LifeCycle,
39 | return 0;
40 | }
41 |
42 | @Override
43 | protected void onAttach() {
44 | super.onAttach();
45 | ButterKnife.bind(this, getView());
46 | showToast("CommonView is attached");
47 | //set the list view's data
48 | //use QuickAdapter to fast set adapter.
49 | showGirl();
50 | }
51 | public void showToast(String msg) {
52 | Toaster.show(getContext(), msg);
53 | }
54 | @Optional
55 | @OnClick(R.id.iv_back)
56 | public void onClickBack(View view){
57 | onBackPressed();
58 | }
59 |
60 | protected void showGirl() {
61 | addGirlDatas();
62 |
63 | RecyclerView view = null; //getView(R.id.lv);
64 | view.setLayoutManager(new LinearLayoutManager(getContext()));
65 | view.setAdapter(new QuickRecycleViewAdapter(R.layout.item_girl,mGirlData) {
66 | @Override
67 | protected void onBindData(Context context, int position, GirlData item, int layoutId, ViewHelper2 viewHelper) {
68 | viewHelper.setText(R.id.tv,item.name);
69 | ImageView view = viewHelper.getView(R.id.eniv);
70 | Glide.with(view).load(item.imageUrl).into(view);
71 | }
72 |
73 | });
74 | }
75 |
76 | private void addGirlDatas() {
77 | String url = "http://images.ali213.net/picfile/pic/2012-06-18/927_h1ali213-page-34.jpg";
78 | mGirlData.add(new GirlData(url,"girl_1"));
79 | url = "http://www.2cto.com/uploadfile/2013/0407/20130407080828809.jpg";
80 | mGirlData.add(new GirlData(url,"girl_2"));
81 | url = "http://bagua.40407.com/uploads/allimg/130712/5-130G2141257.jpg";
82 | mGirlData.add(new GirlData(url,"girl_3"));
83 | url = "http://pic2.52pk.com/files/131213/1283314_094919_1430.jpg";
84 | mGirlData.add(new GirlData(url,"girl_4"));
85 | }
86 |
87 | private final List mGirlData = new ArrayList2<>();
88 |
89 | public static class GirlData extends BaseSelector {
90 | public String imageUrl;
91 | public String name;
92 |
93 | public GirlData(String imageUrl, String name) {
94 | this.imageUrl = imageUrl;
95 | this.name = name;
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/EntryScrapView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import com.heaven7.adapter.BaseSelector;
14 | import com.heaven7.adapter.QuickRecycleViewAdapter;
15 | import com.heaven7.adapter.util.ViewHelper2;
16 |
17 | import org.heaven7.scrap.core.anim.AnimateExecutor;
18 | import org.heaven7.scrap.core.oneac.BaseScrapView;
19 | import org.heaven7.scrap.core.oneac.ScrapHelper;
20 | import org.heaven7.scrap.core.oneac.StackMode;
21 | import org.heaven7.scrap.sample.R;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | import butterknife.BindView;
27 | import butterknife.ButterKnife;
28 |
29 | /**
30 | * Created by heaven7 on 2015/8/3.
31 | */
32 | public class EntryScrapView extends CommonView {
33 |
34 | // @BindView(R.id.tv_title)
35 | TextView mTv_title;
36 |
37 | /**
38 | * @param mContext the context
39 | */
40 | public EntryScrapView(Context mContext) {
41 | super(mContext);
42 | }
43 |
44 | @Override
45 | protected void onAttach() {
46 | ButterKnife.bind(this, getView());
47 |
48 | mTv_title.setText("Scrap_Demos");
49 |
50 | RecyclerView view = null;//TODO = getView(R.id.lv);
51 | view.setLayoutManager(new LinearLayoutManager(getContext()));
52 | view.setAdapter(new QuickRecycleViewAdapter(R.layout.item_demo, getDatas()) {
53 | @Override
54 | protected void onBindData(Context context, int position, ActionData item, int layoutId, ViewHelper2 helper) {
55 | helper.setText(R.id.bt_action, item.title)
56 | .setText(R.id.tv_desc, item.desc)
57 | .setTag(R.id.bt_action, item.id)
58 | .setOnClickListener(R.id.bt_action, mClickListener);
59 | }
60 |
61 | });
62 | }
63 |
64 | final View.OnClickListener mClickListener = new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | int id = (int) v.getTag();
68 | Context context = v.getContext();
69 | switch (id) {
70 | case 1:
71 | // use transaction to cache? , addback,and jump.
72 | /**
73 | * if you use the same class ScrapView.class to create multi view and want add all of
74 | * them to the default back stack, you must call changeBackStackMode(ArrayList2.
75 | * ExpandArrayList2.Mode.Normal) first.
76 | * Because default setting( contains mode ) of back stack only save
77 | * different view of BaseScrapView. and after call Transaction.commit().
78 | * the setting( contains mode ) will restore to the default.
79 | */
80 | Bundle b = new Bundle();
81 | b.putInt("id", 1);
82 | ScrapHelper.beginTransaction()
83 | .stackMode(StackMode.Normal)
84 | .addBackAsTop(new ScrapView(context))
85 | .arguments(b)
86 | .jump()
87 | .commit();
88 | // ScrapHelper.beginTransaction().cache() //if you want cache the view.
89 | break;
90 | case 2:
91 | ScrapHelper.jumpTo(new TestVisivilityScrapView(context));
92 | break;
93 | case 3:
94 | ScrapHelper.jumpTo(new TestLifeCycleScrapView(context));
95 | break;
96 | case 4:
97 |
98 | /**
99 | * if you want to set global animate executor, please use ScrapHelper.setAnimateExecutor(animateExecutor);
100 | */
101 | Bundle b2 = new Bundle();
102 | b2.putInt("id", 1);
103 | //also use can use #setBundle to carray data
104 | // view2.setBundle(data);
105 | ScrapHelper.beginTransaction()
106 | .stackMode(StackMode.Normal)
107 | .addBackAsTop(new ScrapView(context))
108 | .animateExecutor(animateExecutor)
109 | .arguments(b2)
110 | .jump()
111 | .commit();
112 | break;
113 | case 5:
114 | ScrapHelper.jumpTo(new TestKeyEventScrapView(context));
115 | break;
116 |
117 | case 6:
118 | // ScrapHelper.jumpTo(new TestLoadingScrapView(context));
119 | }
120 | }
121 | };
122 | // here use animator to perform animation between two ScrapViews.
123 | private final AnimateExecutor animateExecutor = new AnimateExecutor() {
124 | @Override//use animator
125 | protected byte getType(boolean enter, BaseScrapView previous, BaseScrapView current) {
126 | return TYPE_ANIMATOR;
127 | }
128 |
129 | @Override
130 | protected Animator prepareAnimator(View target, boolean enter, BaseScrapView previous, BaseScrapView current) {
131 | if (!enter) {
132 | //exit
133 | return ObjectAnimator.ofFloat(target, "translationX", 0, 200)
134 | .setDuration(2000);
135 | } else {
136 | // if it is the first BaseScrapView,return null to make it not to animate.
137 | if (previous == null)
138 | return null;
139 | //enter
140 | return ObjectAnimator.ofFloat(target, "translationX", 200, 0)
141 | .setDuration(2000);
142 | }
143 | // AnimatorInflater.loadAnimator(context, id)
144 | }
145 | };
146 |
147 | private List getDatas() {
148 | List datas = new ArrayList<>();
149 | String desc = "this is a sample tell you how to listen default back event. how to use Transaction" +
150 | "to cache, add back,jump to it.";
151 | datas.add(new ActionData("Back Stack and Transaction", desc, 1));
152 |
153 | desc = "this is a sample tell you how to hide or show or toogle visible of top/bottom/middle";
154 | datas.add(new ActionData("Visibility of ScrapPosition", desc, 2));
155 |
156 | desc = "this is a sample tell you how to use the Activity's lifecycle callback ";
157 | datas.add(new ActionData("Activity's life cycle", desc, 3));
158 |
159 | desc = "this is a sample tell you how to use the animation from one BaseScrapView to another. ";
160 | datas.add(new ActionData("ScrapView's Animation", desc, 4));
161 |
162 | desc = "this is a sample tell you how to register/unregiser the other key event of activity.";
163 | datas.add(new ActionData("Activity's other Key event", desc, 5));
164 |
165 | desc = "this is a sample tell you how to use the loading view...";
166 | datas.add(new ActionData("Loading View", desc, 6));
167 | return datas;
168 | }
169 |
170 | static class ActionData extends BaseSelector {
171 | public ActionData(String title, String desc, int id) {
172 | this.title = title;
173 | this.desc = desc;
174 | this.id = id;
175 | }
176 | String title;
177 | String desc;
178 | int id;
179 | }
180 | }
181 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/ScrapView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.TextView;
7 |
8 | import com.heaven7.core.util.ViewHelper;
9 |
10 | import org.heaven7.scrap.core.oneac.ScrapHelper;
11 | import org.heaven7.scrap.core.oneac.StackMode;
12 | import org.heaven7.scrap.sample.R;
13 | import org.heaven7.scrap.sample.ScrapLog;
14 |
15 | import butterknife.BindView;
16 | import butterknife.ButterKnife;
17 |
18 | /**
19 | * Created by heaven7 on 2015/8/3.
20 | */
21 | public class ScrapView extends CommonView {
22 |
23 | //@BindView(R.id.tv_title)
24 | TextView mTv_title;
25 | @BindView(R.id.tv_middle)
26 | TextView mTv_middle;
27 |
28 | @BindView(R.id.button)
29 | View mBtn;
30 |
31 | public int id;
32 | private boolean mIsLastScrapView;
33 |
34 | public ScrapView(Context mContext) {
35 | super(mContext);
36 | }
37 |
38 | public void setIsLastScrapView(boolean last){
39 | this.mIsLastScrapView = last;
40 | }
41 |
42 | @Override
43 | protected int getLayoutId() {
44 | return R.layout.scrap_middle_common;
45 | }
46 |
47 |
48 | @Override
49 | protected void onAttach() {
50 | ButterKnife.bind(this, getView());
51 |
52 | this.id = getArguments() == null ? 0 : getArguments().getInt("id");
53 | if(id == 4){
54 | setIsLastScrapView(true);
55 | }
56 |
57 | ScrapLog.i("ScrapView_onAttach","id = " + id);
58 |
59 | mTv_title.setText("ScrapView"+id);
60 |
61 | if(mIsLastScrapView){
62 | mTv_middle.setText(getResources().getText(R.string.test_back_please_click_back));
63 | mBtn.setVisibility(View.GONE);
64 | }else{
65 | mTv_middle.setText(getResources().getText(R.string.test_back_please_click_button));
66 | mBtn.setVisibility(View.VISIBLE);
67 | }
68 | mBtn.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | /*
72 | * if you use the same class ScrapView.class to create multi view and want add all of
73 | * them to the default back stack, you must call stackMode(StackMode) first.
74 | * Because default setting( contains mode ) of back stack only save
75 | * different view of BaseScrapView. and after call Transaction.commit().
76 | * the setting( contains mode ) will restore to the default.
77 | */
78 | Bundle b = new Bundle();
79 | b.putInt("id",id+1);
80 |
81 | ScrapHelper.beginTransaction().stackMode(StackMode.Normal)
82 | .addBackAsTop(new ScrapView(v.getContext()))
83 | .arguments(b).jump().commit();
84 | }
85 | });
86 | }
87 |
88 | @Override
89 | protected void onDetach() {
90 | showToast("ScrapView "+id+ " is detached!");
91 | }
92 |
93 | @Override
94 | public String toString() {
95 | return "ScrapView{" +
96 | "id=" + id +
97 | '}';
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestKeyEventScrapView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.content.Context;
4 | import android.view.KeyEvent;
5 | import android.view.MotionEvent;
6 |
7 | import org.heaven7.scrap.core.event.ActivityEventAdapter;
8 | import org.heaven7.scrap.core.event.IActivityEventCallback;
9 | import org.heaven7.scrap.core.oneac.ScrapHelper;
10 | import org.heaven7.scrap.sample.ScrapLog;
11 |
12 | /**
13 | * Created by heaven7 on 2015/8/4.
14 | */
15 | public class TestKeyEventScrapView extends CommonView {
16 |
17 | private IActivityEventCallback callback;
18 |
19 | public TestKeyEventScrapView(Context mContext) {
20 | super(mContext);
21 | }
22 |
23 | @Override
24 | protected void onAttach() {
25 | super.onAttach();
26 | callback = new ActivityEventAdapter() {
27 | @Override
28 | public boolean onKeyDown(int keyCode, KeyEvent event) {
29 | ScrapLog.i("callback onKeyDown","");
30 | return super.onKeyDown(keyCode, event);
31 | }
32 |
33 | @Override
34 | public boolean onBackPressed() {
35 | ScrapLog.i("callback onBackPressed","");
36 | return super.onBackPressed(); //if return true. the all BaseScrapView can't receive back event.
37 | }
38 |
39 | @Override
40 | public boolean onTouchEvent(MotionEvent event) {
41 | ScrapLog.i("callback onTouchEvent","");
42 | return super.onTouchEvent(event);
43 | }
44 | //...etc methods
45 | };
46 | ScrapHelper.registerActivityEventCallback(callback);
47 | }
48 |
49 | @Override
50 | protected void onDetach() {
51 | if(callback !=null){
52 | ScrapHelper.unregisterActivityEventCallback(callback);
53 | callback = null;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestLifeCycleScrapView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.widget.TextView;
9 |
10 | import org.heaven7.scrap.core.lifecycle.ActivityLifeCycleAdapter;
11 | import org.heaven7.scrap.core.lifecycle.IActivityLifeCycleCallback;
12 | import org.heaven7.scrap.core.oneac.ScrapHelper;
13 | import org.heaven7.scrap.sample.R;
14 | import org.heaven7.scrap.sample.ScrapLog;
15 | import org.heaven7.scrap.sample.util.DialogUtil;
16 |
17 | import java.util.Timer;
18 | import java.util.TimerTask;
19 |
20 | import butterknife.ButterKnife;
21 |
22 | /**
23 | * test the stand life cycle of activity.
24 | *
Note: Because this view is attached to the Activity. so activity is created.
25 | * some methods will not called.
26 | * if you want register global life cycle callback (.please use
27 | * {@link ScrapHelper#registerActivityLifeCycleCallback(IActivityLifeCycleCallback...)}
28 | * and {@link ScrapHelper#unregisterActivityLifeCycleCallback(IActivityLifeCycleCallback...)}
29 | * it has more methods.
30 | * Created by heaven7 on 2015/8/4.
31 | */
32 | public class TestLifeCycleScrapView extends CommonView {
33 |
34 | private IActivityLifeCycleCallback callback ;
35 |
36 | public TestLifeCycleScrapView(Context mContext) {
37 | super(mContext);
38 | }
39 |
40 | @Override
41 | protected void onPostInit() {
42 | // offen register it in onAttach. but here we want to see the life cycle . so register in init.
43 | callback = new ActivityLifeCycleAdapter() {
44 | @Override
45 | public void onActivityCreate(Activity activity, Bundle savedInstanceState) {
46 | ScrapLog.i("callback onActivityCreate","");
47 | }
48 |
49 | @Override
50 | public void onActivityPostCreate(Activity activity, Bundle savedInstanceState) {
51 | ScrapLog.i("callback onActivityPostCreate","");
52 | }
53 |
54 | @Override
55 | public void onActivityStart(Activity activity) {
56 | ScrapLog.i("callback onActivityStart","");
57 | }
58 |
59 | @Override
60 | public void onActivityResume(Activity activity) {
61 | ScrapLog.i("callback onActivityResume","");
62 | }
63 |
64 | @Override
65 | public void onActivityPause(Activity activity) {
66 | ScrapLog.i("callback onActivityPause","");
67 | }
68 |
69 | @Override
70 | public void onActivityStop(Activity activity) {
71 | ScrapLog.i("callback onActivityStop","");
72 | }
73 |
74 | @Override
75 | public void onActivityDestroy(Activity activity) {
76 | ScrapLog.i("callback onActivityDestroy","");
77 | }
78 | @Override
79 | public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
80 | ScrapLog.i("callback OnActivityResult","");
81 | }
82 | //....etc methods
83 | };
84 | // register global life cycle callback
85 | ScrapHelper.registerActivityLifeCycleCallback(callback);
86 | }
87 |
88 | @Override
89 | protected void onAttach() {
90 | // use dialog to help you test it, or else you will see nothing it this.
91 | /* TextView mBt1 = getView(R.id.bt_1);
92 | getView(R.id.bt_1).setOnClickListener(new View.OnClickListener() {
93 | @Override
94 | public void onClick(View v) {
95 | testLifeCycle();
96 | }
97 | });
98 |
99 | getView(R.id.bt_2).setVisibility(View.GONE);
100 | getView(R.id.bt_3).setVisibility(View.GONE);
101 | mBt1.setText("Click this button to show auto Dialog and test life cycle");*/
102 | }
103 |
104 | @Override
105 | protected void onDetach() {
106 | if(callback!=null) {
107 | ScrapHelper.unregisterActivityLifeCycleCallback(callback);
108 | callback = null;
109 | }
110 | }
111 |
112 | private void testLifeCycle() {
113 | DialogUtil.showProgressDialog((Activity) getContext());
114 | new Timer().schedule(new TimerTask() {
115 | @Override
116 | public void run() {
117 | DialogUtil.dismiss();
118 | }
119 | }, 2000);
120 | }
121 |
122 | @Override
123 | protected void onActivityCreate(Bundle saveInstanceState) {
124 | ScrapLog.i("onActivityCreate",saveInstanceState.toString());
125 | }
126 |
127 | @Override
128 | protected void onActivityPostCreate(Bundle saveInstanceState) {
129 | ScrapLog.i("onActivityPostCreate",saveInstanceState.toString());
130 | }
131 |
132 | @Override
133 | protected void onActivityStart() {
134 | ScrapLog.i("onActivityStart","");
135 | }
136 |
137 | @Override
138 | protected void onActivityResume() {
139 | ScrapLog.i("onActivityResume","");
140 | }
141 |
142 | @Override
143 | protected void onActivityPause() {
144 | ScrapLog.i("onActivityPause","");
145 | }
146 |
147 | @Override
148 | protected void onActivityStop() {
149 | ScrapLog.i("onActivityStop","");
150 | }
151 |
152 | @Override
153 | protected void onActivityDestroy() {
154 | ScrapLog.i("onActivityDestroy","");
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestTransitionScrapView_enter.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.content.Context;
4 |
5 | import org.heaven7.scrap.core.oneac.BaseScrapView;
6 | import org.heaven7.scrap.sample.R;
7 |
8 | public class TestTransitionScrapView_enter extends BaseScrapView {
9 |
10 | public TestTransitionScrapView_enter(Context mContext) {
11 | super(mContext);
12 | }
13 |
14 | @Override
15 | protected int getLayoutId() {
16 | return R.layout.scrap_test_transition_enter;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestTransitionScrapView_exit.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import org.heaven7.scrap.core.anim.TransitionAnimateExecutor;
7 | import org.heaven7.scrap.core.oneac.BaseScrapView;
8 | import org.heaven7.scrap.core.oneac.ScrapHelper;
9 | import org.heaven7.scrap.sample.R;
10 |
11 | public class TestTransitionScrapView_exit extends BaseScrapView {
12 |
13 | public TestTransitionScrapView_exit(Context mContext) {
14 | super(mContext);
15 | }
16 |
17 | @Override
18 | protected int getLayoutId() {
19 | return R.layout.scrap_test_transition_exit;
20 | }
21 |
22 | @Override
23 | protected void onAttach() {
24 | super.onAttach();
25 |
26 | getView(R.id.iv_trans).setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View v) {
29 | ScrapHelper.beginTransaction()
30 | .addBackAsTop(new TestTransitionScrapView_enter(getContext()))
31 | .animateExecutor(new TransitionAnimateExecutor(R.id.iv_trans))
32 | .jump()
33 | .commit();
34 | }
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/scrapview/TestVisivilityScrapView.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.scrapview;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 |
6 | import org.heaven7.scrap.core.oneac.ScrapHelper;
7 | import org.heaven7.scrap.sample.R;
8 |
9 | /**
10 | * this is sample to test visibility of view which is indicate by the ScrapPosition.
11 | * Created by heaven7 on 2015/8/4.
12 | */
13 | public class TestVisivilityScrapView extends CommonView {
14 |
15 | public TestVisivilityScrapView(Context mContext) {
16 | super(mContext);
17 | }
18 |
19 | @Override
20 | protected void onPostInit() {
21 | }
22 |
23 | @Override
24 | protected int getLayoutId() {
25 | return R.layout.scrap_middle_test_visibile;
26 | }
27 |
28 | @Override
29 |
30 | protected void onAttach() {
31 | getView(R.id.bt_test1).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View v) {
34 | ScrapHelper.setVisibility(true);
35 | }
36 | });
37 | getView(R.id.bt_test2).setOnClickListener(new View.OnClickListener() {
38 | @Override
39 | public void onClick(View v) {
40 | ScrapHelper.setVisibility(false);
41 | }
42 | });
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/java/org/heaven7/scrap/sample/util/DialogUtil.java:
--------------------------------------------------------------------------------
1 | package org.heaven7.scrap.sample.util;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.app.Dialog;
6 | import android.app.ProgressDialog;
7 | import android.content.Context;
8 | import android.content.DialogInterface;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.util.Log;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.WindowManager.BadTokenException;
15 | import android.widget.PopupWindow;
16 |
17 | public class DialogUtil {
18 |
19 | private static ProgressDialog sDialog;
20 | private static CharSequence sDefaultMsg;
21 |
22 | public static void dismiss(){
23 | if(sDialog!=null && sDialog.isShowing()){
24 | sDialog.dismiss();
25 | sDialog = null;
26 | }
27 | }
28 |
29 | public static void showProgressDialog(Activity activity){
30 | if(sDefaultMsg == null)
31 | sDefaultMsg = "loading";
32 | showProgressDialog(activity,sDefaultMsg);
33 | }
34 |
35 | public static void showProgressDialog(Activity activity,CharSequence content){
36 | showProgressDialog(activity,"",content);
37 | }
38 | public static void showProgressDialog(Activity activity,CharSequence title, CharSequence content){
39 | try{
40 | if(sDialog == null){
41 | sDialog = ProgressDialog.show(activity, title, content);
42 | sDialog.setCanceledOnTouchOutside(false);
43 | sDialog.setCancelable(false);
44 | sDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
45 | @Override
46 | public void onCancel(DialogInterface dialog) {
47 | sDialog = null;
48 | }
49 | });
50 | }else{
51 | if(sDialog.isShowing()){
52 | Log.w("showProgressDialog()", "dialog is showing...check?");
53 | return;
54 | }
55 | }
56 | }catch(BadTokenException e){
57 | e.printStackTrace();
58 | }
59 | }
60 |
61 | public static AlertDialog alert(Activity context,String title, String content,
62 | String leftStr,String rightStr,
63 | DialogInterface.OnClickListener leftBtnListener,
64 | DialogInterface.OnClickListener rightBtnListener){
65 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
66 | builder.setTitle(title);
67 | builder.setMessage(content);
68 | builder.setPositiveButton(leftStr, leftBtnListener);
69 | builder.setNegativeButton(rightStr, rightBtnListener);
70 | AlertDialog dialog = builder.create();
71 | dialog.setCanceledOnTouchOutside(false);
72 | dialog.setCancelable(false);
73 | dialog.show();
74 | return dialog;
75 | }
76 |
77 | //@TargetApi(Build.VERSION_CODES.HONEYCOMB)
78 | public static Dialog create(Activity context,int theme,View view){
79 | /*AlertDialog.Builder builder= null ;builder = new AlertDialog.Builder(context);
80 |
81 | if(view.getParent()!=null){ //be careful when you reuse this view
82 | ((ViewGroup)view.getParent()).removeView(view);
83 | }
84 | builder.setView(view);
85 | AlertDialog d = builder.create();
86 | d.setCanceledOnTouchOutside(false);*/
87 | Dialog d = new Dialog(context, theme);
88 | if(view.getParent()!=null){ //be careful when you reuse this view
89 | ((ViewGroup)view.getParent()).removeView(view);
90 | }
91 | d.setContentView(view);
92 | d.setCanceledOnTouchOutside(false);
93 | return d;
94 | }
95 |
96 | //遮罩实现类似dialog
97 | public static PopupWindow popup(Activity context,View view,int width,int height,int animStyle){
98 | PopupWindow pw = new PopupWindow(context);
99 | pw.setHeight(height);
100 | pw.setWidth(width);
101 | pw.setBackgroundDrawable(new ColorDrawable(0x88222222));
102 | pw.setOutsideTouchable(true);
103 | pw.setFocusable(true);
104 | pw.setAnimationStyle(animStyle);
105 | if(view.getParent()!=null)
106 | ((ViewGroup)view.getParent()).removeView(view);
107 | pw.setContentView(view);
108 | pw.showAtLocation(context.getWindow().getDecorView(), Gravity.LEFT|Gravity.TOP, 0, 0);
109 | return pw;
110 | }
111 |
112 | /**弹出有动画,自定义样式的dialog*/
113 | public static Dialog create(Context context,int theme,int animId,int layout){
114 | //if(layout.getParent()!=null)
115 | //((ViewGroup)layout.getParent()).removeView(layout);
116 | Dialog d = new Dialog(context, theme);
117 | d.getWindow().setWindowAnimations(animId);
118 | d.setContentView(layout);
119 | //d.findViewById(btnId)
120 | d.setCancelable(true);
121 | //d.show();
122 | return d;
123 | }
124 |
125 | public static void dismiss(Dialog d){
126 | if(d!=null && d.isShowing()){
127 | try{
128 | d.dismiss();
129 | }catch (BadTokenException e) {
130 | e.printStackTrace();
131 | }
132 | }
133 | }
134 |
135 | }
136 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/drawable-hdpi/ic_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/samples/src/main/res/drawable-hdpi/ic_back.png
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/feature.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/item_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/item_girl.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
13 |
14 |
21 |
22 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/scrap_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/scrap_middle_common.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/scrap_middle_test_visibile.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
21 |
28 |
29 |
37 |
38 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/scrap_test_transition_enter.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/layout/scrap_test_transition_exit.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
16 |
17 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/samples/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/samples/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/samples/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LightSun/android-style/82750321bdf6abbb5829bbb5d55367c100c24d10/Android-Scrap/samples/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/raw/scrap_config.properties:
--------------------------------------------------------------------------------
1 | #define the main scrap view
2 | scrap_view_main = org.heaven7.scrap.sample.MainScrapView
3 | #define the main scrap view whether add it to back stack or not.
4 | scrap_view_main_addBackStack = true
5 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/raw/scrap_data_binding_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
14 |
15 |
16 |
17 | @{user.username}
18 |
19 | @{user.isFriend ? handlers.onClickFriend : handlers.onClickEnemy}
20 |
21 |
22 | @{user.isAdult ? View.VISIBLE : View.GONE}
23 |
24 |
25 |
26 | @{ user.url }
27 | @{ user.url }
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Samples
3 |
4 | Hello world!
5 | Settings
6 |
7 | to test Back event, please click back image or back key.
8 | to test Back event, please click button to jump to the next.
9 |
10 | please click the below three buttons to test the visibility of bottom,
11 | b1 is visible , b2 is gone, b3 is toogle.
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Android-Scrap/samples/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Android-Scrap/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':android-scrap', ':samples', ':lib_sample'
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # android-scrap
2 | this is really One Activity Framework named android-scrap, a little like fragment.
3 | it helps you to reduce number of activities and avoid some problems of fragment.
4 | .
5 |
6 |
7 | ## Features
8 | - Really One Activity
9 | - Support animation(Animation or Animator or ViewPropertyAnimator) between two children of the 'BaseScrapView'.
10 | - Support cache BaseScrapView and add it to the back stack.
11 | - Support multi modes of back stack.
12 | - Support listen to Activity's Lifecycle and event.
13 | - Support fast set properties of view ,named 'ViewHelper'.
14 | - Support hide or show the loading view.
15 | - Support the entry of scrap view ( similar to the MainActivity).
16 | - Integreted google-Volley and expand it to support file upload and circle/round image. and you can see it in demo.
17 | - Integrated QuickAdapter and expand it to use easily and support multi item Adapter. based on [JoanZapata/base-adapter-helper](https://github.com/JoanZapata/base-adapter-helper) and thanks for him.
18 | - the more to see in demo or source code
19 |
20 |
21 | ## Changelog
22 | - # 1.0
23 | - support once animation when you jump, you can use it in Transaction.
24 | - # 1.1
25 | - Support hide or show the loading view, see it in 'TestLoadingScrapView'
26 | - Support the entry of scrap view ( similar to the MainActivity)
27 | - 1,create file 'scrap_config.properties' in res/raw like this.
28 |
29 | - define the main scrap view
30 | - scrap_view_main = org.heaven7.scrap.sample.MainScrapView
31 | - define the main scrap view whether add it to back stack or not.
32 | - scrap_view_main_addBackStack = true
33 |
34 | - 2, declear really main activity
35 | ``` java
36 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | ```
45 | - optimize code.
46 |
47 | ## TODO
48 | * other idea
49 | * Support databinding . wait for the databinding of google lib is stable .
50 |
51 | ## issue
52 | * if you have a good suggestion about this, please tell me. Thanks!
53 | * This is just a beginning, may have bugs , so if you have any question , please tell me . i will do my best to resolve it. Thanks !
54 |
55 | ## About me
56 | * heaven7
57 | * email: donshine723@gmail.com or 978136772@qq.com
58 |
59 | ## hope
60 | i like technology. especially the open-source technology.And previous i didn't contribute to it caused by i am a little lazy, but now i really want to do some for the open-source. So i hope to share and communicate with the all of you.
61 |
62 | ### How to use
63 | - in gradle of android studio:
64 | - add dependence ,
65 |
66 | ``` java
67 | dependencies {
68 | compile 'org.heaven7.scrap:android-scrap:1.1'
69 | }
70 | ```
71 |
72 | ## Demo
73 | in model [android-scrap/sample](https://github.com/LightSun/android-scrap/tree/master/Android-Scrap/samples).
74 |
75 |
76 |
77 | ``` java
78 | //[1], want jump to target ScrapView ( child of BaseScrapView)
79 | ScrapHelper.jumpTo(new EntryScrapView(MainActivity.this));
80 |
81 | //[2], want cache ,add back stack, and jump , with data and animation
82 | //this animate executor only use once .
83 | Bundle b = new Bundle();
84 | b.putInt("id",id+1);
85 |
86 | crapHelper.beginTransaction().changeBackStackMode(ArrayList2.ExpandArrayList2.Mode.Normal)
87 | .cache(new EntryScrapView(MainActivity.this)).addBackAsTop())
88 | .animateExecutor(animateExecutor).withExtras(b).jump().commit();
89 |
90 |
91 | //[3], animation between two children of the 'BaseScrapView'.
92 | // here use animator to perform animation between two ScrapViews.
93 | private AnimateExecutor animateExecutor = new AnimateExecutor() {
94 | @Override//use animator
95 | protected AnimateCategoryType getType(boolean enter, BaseScrapView previous, BaseScrapView current) {
96 | return AnimateCategoryType.Animator;
97 | }
98 |
99 | @Override
100 | protected Animator prepareAnimator(View target, boolean enter, BaseScrapView previous, BaseScrapView current) {
101 | if(!enter){
102 | //exit
103 | return ObjectAnimator.ofFloat(target, "translationX", 0, 200)
104 | .setDuration(2000);
105 | }else{
106 | // if it is the first BaseScrapView,return null to make it not to animate.
107 | if(previous == null)
108 | return null;
109 | //enter
110 | return ObjectAnimator.ofFloat(target,"translationX", 200, 0)
111 | .setDuration(2000);
112 | }
113 | // AnimatorInflater.loadAnimator(context, id)
114 | }
115 | };
116 |
117 | //set animate executor (it it the global's animate executor, it will be only used if
118 | // once animateExecutor is null )
119 |
120 | ScrapHelper.setAnimateExecutor(animateExecutor);
121 |
122 | //[4], event of activity
123 | callback = new ActivityEventAdapter() {
124 | @Override
125 | public boolean onKeyDown(int keyCode, KeyEvent event) {
126 | ScrapLog.i("callback onKeyDown","");
127 | return super.onKeyDown(keyCode, event);
128 | }
129 |
130 | @Override
131 | public boolean onBackPressed() {
132 | ScrapLog.i("callback onBackPressed","");
133 | return super.onBackPressed(); //if return true. the all BaseScrapView can't receive back event.
134 | }
135 |
136 | @Override
137 | public boolean onTouchEvent(MotionEvent event) {
138 | ScrapLog.i("callback onTouchEvent","");
139 | return super.onTouchEvent(event);
140 | }
141 | //...etc methods
142 | };
143 | // the callback is regist as the global. so if the ScrapView is detached and you don't need, don't forget to
144 | // unregister it.
145 | ScrapHelper.registerActivityEventCallback(callback);
146 |
147 | //[5],QuickAdapter and ViewHelper. in a child of 'BaseScrapView'
148 | @Override
149 | protected void onAttach() {
150 | super.onAttach();
151 | showToast("CommonView is attached");
152 | getViewHelper().setOnClickListener(R.id.iv_back, new View.OnClickListener() {
153 | @Override
154 | public void onClick(View v) {
155 | onBackPressed();
156 | }
157 | }).setOnClickListener(R.id.bt_1, new View.OnClickListener() {
158 | @Override
159 | public void onClick(View v) {
160 | showToast("button1 was clicked");
161 | }
162 | }).setOnClickListener(R.id.bt_2, new View.OnClickListener() {
163 | @Override
164 | public void onClick(View v) {
165 | showToast("button2 was clicked");
166 | }
167 | }).setOnClickListener(R.id.bt_3, new View.OnClickListener() {
168 | @Override
169 | public void onClick(View v) {
170 | showToast("button3 was clicked");
171 | }
172 | });
173 | //set the list view's data
174 | //use QuickAdapter to fast set adapter.
175 | addGirlDatas();
176 | getViewHelper().setAdapter(R.id.lv, new QuickAdapter(R.layout.item_girl,mGirlData) {
177 | @Override
178 | protected void convert(Context context, int position, ViewHelper viewHelper, GirlData item) {
179 | viewHelper.setText(R.id.tv,item.name);
180 | viewHelper.setImageUrl(R.id.eniv, item.imageUrl, new ImageParam.Builder()
181 | .placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).circle().create());
182 | }
183 | });
184 | }
185 |
186 | //[6], ....etc in demos
187 |
188 | ```
189 |
190 | ## License
191 |
192 | Copyright 2015
193 | heaven7(donshine723@gmail.com)
194 |
195 | Licensed under the Apache License, Version 2.0 (the "License");
196 | you may not use this file except in compliance with the License.
197 | You may obtain a copy of the License at
198 |
199 | http://www.apache.org/licenses/LICENSE-2.0
200 |
201 | Unless required by applicable law or agreed to in writing, software
202 | distributed under the License is distributed on an "AS IS" BASIS,
203 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
204 | See the License for the specific language governing permissions and
205 | limitations under the License.
206 |
--------------------------------------------------------------------------------
/release-notes.md:
--------------------------------------------------------------------------------
1 | ### release 1.0.0 log
2 |
3 | * the first version
4 |
5 | ## new Features
6 | - One Activity
7 | - Support animation between two children of the 'BaseScrapView'.
8 | - Support cache BaseScrapView and add it to the back stack.
9 | - Support listen to Activity's Lifecycle and event.
10 | - Support fast set properties of view ,named 'ViewHelper'.
11 | - Integreted google-Volley and expand it to support file upload and circle/round image. and you can see it in demo.
12 | - Integrated QuickAdapter and expand it to support multi item Adapter. based on [JoanZapata/base-adapter-helper](https://github.com/JoanZapata/base-adapter-helper) and thanks for him.
13 | - the more to see in demo or source code
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------