implements Filterable,
53 | CursorFilter.CursorFilterClient {
54 | /**
55 | * Call when bind view with the cursor
56 | *
57 | * @param holder
58 | * @param cursor
59 | */
60 | public abstract void onBindViewHolder(VH holder, Cursor cursor);
61 |
62 | /**
63 | * This field should be made private, so it is hidden from the SDK.
64 | * {@hide}
65 | */
66 | protected boolean mDataValid;
67 |
68 | /**
69 | * The current cursor
70 | */
71 | protected Cursor mCursor;
72 |
73 | /**
74 | * This field should be made private, so it is hidden from the SDK.
75 | * {@hide}
76 | */
77 | protected Context mContext;
78 |
79 | /**
80 | * The row id column
81 | */
82 | protected int mRowIDColumn;
83 |
84 | /**
85 | * This field should be made private, so it is hidden from the SDK.
86 | * {@hide}
87 | */
88 | protected ChangeObserver mChangeObserver;
89 | /**
90 | * This field should be made private, so it is hidden from the SDK.
91 | * {@hide}
92 | */
93 | protected DataSetObserver mDataSetObserver;
94 |
95 | /**
96 | * This field should be made private, so it is hidden from the SDK.
97 | * {@hide}
98 | */
99 | protected CursorFilter mCursorFilter;
100 |
101 | /**
102 | * This field should be made private, so it is hidden from the SDK.
103 | * {@hide}
104 | */
105 | protected FilterQueryProvider mFilterQueryProvider;
106 |
107 | /**
108 | * If set the adapter will register a content observer on the cursor and will call
109 | * {@link #onContentChanged()} when a notification comes in. Be careful when
110 | * using this flag: you will need to unset the current Cursor from the adapter
111 | * to avoid leaks due to its registered observers. This flag is not needed
112 | * when using a CursorAdapter with a
113 | * {@link android.content.CursorLoader}.
114 | */
115 | public static final int FLAG_REGISTER_CONTENT_OBSERVER = 0x02;
116 |
117 | /**
118 | * Recommended constructor.
119 | *
120 | * @param c The cursor from which to get the data.
121 | * @param context The context
122 | * @param flags Flags used to determine the behavior of the adapter;
123 | * Currently it accept {@link #FLAG_REGISTER_CONTENT_OBSERVER}.
124 | */
125 | public BaseAbstractRecycleCursorAdapter(Context context, Cursor c, int flags) {
126 | init(context, c, flags);
127 | }
128 |
129 | void init(Context context, Cursor c, int flags) {
130 | boolean cursorPresent = c != null;
131 | mCursor = c;
132 | mDataValid = cursorPresent;
133 | mContext = context;
134 | mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
135 | if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) {
136 | mChangeObserver = new ChangeObserver();
137 | mDataSetObserver = new MyDataSetObserver();
138 | } else {
139 | mChangeObserver = null;
140 | mDataSetObserver = null;
141 | }
142 |
143 | if (cursorPresent) {
144 | if (mChangeObserver != null) c.registerContentObserver(mChangeObserver);
145 | if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver);
146 | }
147 | setHasStableIds(true);
148 | }
149 |
150 | /**
151 | * Returns the cursor.
152 | *
153 | * @return the cursor.
154 | */
155 | @Override
156 | public Cursor getCursor() {
157 | return mCursor;
158 | }
159 |
160 | /**
161 | * @see android.support.v7.widget.RecyclerView.Adapter#getItemCount()
162 | */
163 | @Override
164 | public int getItemCount() {
165 | if (mDataValid && mCursor != null) {
166 | return mCursor.getCount();
167 | } else {
168 | return 0;
169 | }
170 | }
171 |
172 | /**
173 | * @param position Adapter position to query
174 | * @return
175 | * @see android.support.v7.widget.RecyclerView.Adapter#getItemId(int)
176 | */
177 | @Override
178 | public long getItemId(int position) {
179 | if (mDataValid && mCursor != null) {
180 | if (mCursor.moveToPosition(position)) {
181 | return mCursor.getLong(mRowIDColumn);
182 | } else {
183 | return 0;
184 | }
185 | } else {
186 | return 0;
187 | }
188 | }
189 |
190 | @Override
191 | public void onBindViewHolder(VH holder, int position) {
192 | if (!mDataValid) {
193 | throw new IllegalStateException("this should only be called when the cursor is valid");
194 | }
195 | if (!mCursor.moveToPosition(position)) {
196 | throw new IllegalStateException("couldn't move cursor to position " + position);
197 | }
198 | onBindViewHolder(holder, mCursor);
199 | }
200 |
201 | /**
202 | * Change the underlying cursor to a new cursor. If there is an existing cursor it will be
203 | * closed.
204 | *
205 | * @param cursor The new cursor to be used
206 | */
207 | public void changeCursor(Cursor cursor) {
208 | Cursor old = swapCursor(cursor);
209 | if (old != null) {
210 | old.close();
211 | }
212 | }
213 |
214 | /**
215 | * Swap in a new Cursor, returning the old Cursor. Unlike
216 | * {@link #changeCursor(android.database.Cursor)}, the returned old Cursor is not
217 | * closed.
218 | *
219 | * @param newCursor The new cursor to be used.
220 | * @return Returns the previously set Cursor, or null if there wasa not one.
221 | * If the given new Cursor is the same instance is the previously set
222 | * Cursor, null is also returned.
223 | */
224 | public Cursor swapCursor(Cursor newCursor) {
225 | if (newCursor == mCursor) {
226 | return null;
227 | }
228 | Cursor oldCursor = mCursor;
229 | if (oldCursor != null) {
230 | if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver);
231 | if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver);
232 | }
233 | mCursor = newCursor;
234 | if (newCursor != null) {
235 | if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver);
236 | if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver);
237 | mRowIDColumn = newCursor.getColumnIndexOrThrow("_id");
238 | mDataValid = true;
239 | // notify the observers about the new cursor
240 | notifyDataSetChanged();
241 | } else {
242 | mRowIDColumn = -1;
243 | mDataValid = false;
244 | // notify the observers about the lack of a data set
245 | notifyDataSetChanged();
246 | }
247 | return oldCursor;
248 | }
249 |
250 | /**
251 | * Converts the cursor into a CharSequence. Subclasses should override this
252 | * method to convert their results. The default implementation returns an
253 | * empty String for null values or the default String representation of
254 | * the value.
255 | *
256 | * @param cursor the cursor to convert to a CharSequence
257 | * @return a CharSequence representing the value
258 | */
259 | public CharSequence convertToString(Cursor cursor) {
260 | return cursor == null ? "" : cursor.toString();
261 | }
262 |
263 | /**
264 | * Runs a query with the specified constraint. This query is requested
265 | * by the filter attached to this adapter.
266 | *
267 | * The query is provided by a
268 | * {@link android.widget.FilterQueryProvider}.
269 | * If no provider is specified, the current cursor is not filtered and returned.
270 | *
271 | * After this method returns the resulting cursor is passed to {@link #changeCursor(android.database.Cursor)}
272 | * and the previous cursor is closed.
273 | *
274 | * This method is always executed on a background thread, not on the
275 | * application's main thread (or UI thread.)
276 | *
277 | * Contract: when constraint is null or empty, the original results,
278 | * prior to any filtering, must be returned.
279 | *
280 | * @param constraint the constraint with which the query must be filtered
281 | * @return a Cursor representing the results of the new query
282 | * @see #getFilter()
283 | * @see #getFilterQueryProvider()
284 | * @see #setFilterQueryProvider(android.widget.FilterQueryProvider)
285 | */
286 | public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
287 | if (mFilterQueryProvider != null) {
288 | return mFilterQueryProvider.runQuery(constraint);
289 | }
290 |
291 | return mCursor;
292 | }
293 |
294 | public Filter getFilter() {
295 | if (mCursorFilter == null) {
296 | mCursorFilter = new CursorFilter(this);
297 | }
298 | return mCursorFilter;
299 | }
300 |
301 | /**
302 | * Returns the query filter provider used for filtering. When the
303 | * provider is null, no filtering occurs.
304 | *
305 | * @return the current filter query provider or null if it does not exist
306 | * @see #setFilterQueryProvider(android.widget.FilterQueryProvider)
307 | * @see #runQueryOnBackgroundThread(CharSequence)
308 | */
309 | public FilterQueryProvider getFilterQueryProvider() {
310 | return mFilterQueryProvider;
311 | }
312 |
313 | /**
314 | * Sets the query filter provider used to filter the current Cursor.
315 | * The provider's
316 | * {@link android.widget.FilterQueryProvider#runQuery(CharSequence)}
317 | * method is invoked when filtering is requested by a client of
318 | * this adapter.
319 | *
320 | * @param filterQueryProvider the filter query provider or null to remove it
321 | * @see #getFilterQueryProvider()
322 | * @see #runQueryOnBackgroundThread(CharSequence)
323 | */
324 | public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider) {
325 | mFilterQueryProvider = filterQueryProvider;
326 | }
327 |
328 | /**
329 | * Called when the {@link android.database.ContentObserver} on the cursor receives a change notification.
330 | * The default implementation provides the auto-requery logic, but may be overridden by
331 | * sub classes.
332 | *
333 | * @see android.database.ContentObserver#onChange(boolean)
334 | */
335 | protected abstract void onContentChanged();
336 |
337 | private class ChangeObserver extends ContentObserver {
338 | public ChangeObserver() {
339 | super(new Handler());
340 | }
341 |
342 | @Override
343 | public boolean deliverSelfNotifications() {
344 | return true;
345 | }
346 |
347 | @Override
348 | public void onChange(boolean selfChange) {
349 | onContentChanged();
350 | }
351 | }
352 |
353 | private class MyDataSetObserver extends DataSetObserver {
354 | @Override
355 | public void onChanged() {
356 | mDataValid = true;
357 | notifyDataSetChanged();
358 | }
359 |
360 | @Override
361 | public void onInvalidated() {
362 | mDataValid = false;
363 | notifyDataSetChanged();
364 | }
365 | }
366 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/adapter/BaseRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 |
7 | import com.ithooks.android.xreap.log.LogUtils;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Author: ZhuWenWu
14 | * Version V1.0
15 | * Date: 15/4/11 15:18
16 | * Description: RecyclerView 适配器基类
17 | * Modification History:
18 | * Date Author Version Description
19 | * -----------------------------------------------------------------------------------
20 | * 15/4/11 ZhuWenWu 1.0 1.0
21 | * Why & What is modified:
22 | */
23 | public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter {
24 | protected final String TAG = getClass().getSimpleName();
25 | protected final Context mContext;
26 | protected final LayoutInflater mLayoutInflater;
27 |
28 | protected List mDataList = new ArrayList<>();
29 |
30 | public BaseRecyclerAdapter(Context context) {
31 | mContext = context;
32 | mLayoutInflater = LayoutInflater.from(context);
33 | }
34 |
35 | public List getDataList() {
36 | return mDataList;
37 | }
38 |
39 | public T getItemData(int position) {
40 | return position < mDataList.size() ? mDataList.get(position) : null;
41 | }
42 |
43 | @Override
44 | public int getItemCount() {
45 | return mDataList == null ? 0 : mDataList.size();
46 | }
47 |
48 | /**
49 | * 移除某一条记录
50 | *
51 | * @param position 移除数据的position
52 | */
53 | public void removeItem(int position) {
54 | if (position < mDataList.size()) {
55 | mDataList.remove(position);
56 | notifyItemRemoved(position);
57 | }
58 | }
59 |
60 | /**
61 | * 添加一条记录
62 | *
63 | * @param data 需要加入的数据结构
64 | * @param position 插入位置
65 | */
66 | public void addItem(T data, int position) {
67 | if (position <= mDataList.size()) {
68 | mDataList.add(position, data);
69 | notifyItemInserted(position);
70 | }
71 | }
72 |
73 | /**
74 | * 添加一条记录
75 | *
76 | * @param data 需要加入的数据结构
77 | */
78 | public void addItem(T data) {
79 | addItem(data, mDataList.size());
80 | }
81 |
82 | /**
83 | * 移除所有记录
84 | */
85 | public void clearItems() {
86 | int size = mDataList.size();
87 | if (size > 0) {
88 | mDataList.clear();
89 | LogUtils.d(TAG, "clearItems --> ");
90 | notifyItemRangeRemoved(0, size);
91 | }
92 | }
93 |
94 | /**
95 | * 批量添加记录
96 | *
97 | * @param data 需要加入的数据结构
98 | * @param position 插入位置
99 | */
100 | public void addItems(List data, int position) {
101 | if (position <= mDataList.size() && data != null && data.size() > 0) {
102 | LogUtils.d(TAG, "addItems --> position" + position);
103 | mDataList.addAll(position, data);
104 | notifyItemRangeChanged(position, data.size());
105 | }
106 | }
107 |
108 | /**
109 | * 批量添加记录
110 | *
111 | * @param data 需要加入的数据结构
112 | */
113 | public void addItems(List data) {
114 | addItems(data, mDataList.size());
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/adapter/BaseRecyclerMultipleItemAdapter.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.ViewGroup;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 15/4/11 15:23
13 | * Description:有头和尾的 RecyclerView 适配器基类
14 | * Modification History:
15 | * Date Author Version Description
16 | * -----------------------------------------------------------------------------------
17 | * 15/4/11 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public abstract class BaseRecyclerMultipleItemAdapter extends BaseRecyclerAdapter {
21 | public static enum ITEM_TYPE {
22 | ITEM_TYPE_HEADER,
23 | ITEM_TYPE_CONTENT,
24 | ITEM_TYPE_BOTTOM
25 | }
26 |
27 | protected int mHeaderCount;//头部View个数
28 | protected int mBottomCount;//底部View个数
29 |
30 | public BaseRecyclerMultipleItemAdapter(Context context) {
31 | super(context);
32 | }
33 |
34 | public void setHeaderCount(int headerCount) {
35 | this.mHeaderCount = headerCount;
36 | }
37 |
38 | public void setBottomCount(int bottomCount) {
39 | this.mBottomCount = bottomCount;
40 | }
41 |
42 | public boolean isHeaderView(int position) {
43 | return mHeaderCount != 0 && position < mHeaderCount;
44 | }
45 |
46 | public boolean isBottomView(int position) {
47 | return mBottomCount != 0 && position >= (mHeaderCount + getContentItemCount());
48 | }
49 |
50 | @Override
51 | public T getItemData(int position) {
52 | int index = position - mHeaderCount;
53 | if (index >= super.getItemCount()) {
54 | return null;
55 | }
56 | return super.getItemData(index);
57 | }
58 |
59 | /**
60 | * 移除某一条记录
61 | *
62 | * @param position 移除数据的position 如果有Header需要减去Header数量
63 | */
64 | public void removeItem(int position) {
65 | if (position < mDataList.size()) {
66 | mDataList.remove(position);
67 | notifyItemRemoved(mHeaderCount + position);
68 | }
69 | }
70 |
71 | /**
72 | * 添加一条记录
73 | *
74 | * @param data 需要加入的数据结构
75 | * @param position 插入数据的位置 如果有Header需要减去Header数量
76 | */
77 | public void addItem(T data, int position) {
78 | if (position <= mDataList.size()) {
79 | mDataList.add(position, data);
80 | notifyItemInserted(mHeaderCount + position);
81 | }
82 | }
83 |
84 | /**
85 | * 移除所有记录
86 | */
87 | public void clearItems() {
88 | int size = mDataList.size();
89 | if (size > 0) {
90 | mDataList.clear();
91 | notifyItemRangeRemoved(mHeaderCount, size);
92 | }
93 | }
94 |
95 | /**
96 | * 批量添加记录
97 | *
98 | * @param data 需要加入的数据结构
99 | * @param position 插入数据的位置 如果有Header需要减去Header数量
100 | */
101 | public void addItems(List data, int position) {
102 | if (position <= mDataList.size() && data != null && data.size() > 0) {
103 | mDataList.addAll(position, data);
104 | notifyItemRangeChanged(mHeaderCount + position, data.size());
105 | }
106 | }
107 |
108 | @Override
109 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
110 | if (viewType == ITEM_TYPE.ITEM_TYPE_HEADER.ordinal()) {
111 | return onCreateHeaderView(parent);
112 | } else if (viewType == ITEM_TYPE.ITEM_TYPE_CONTENT.ordinal()) {
113 | return onCreateContentView(parent);
114 | } else if (viewType == ITEM_TYPE.ITEM_TYPE_BOTTOM.ordinal()) {
115 | return onCreateBottomView(parent);
116 | }
117 | return null;
118 | }
119 |
120 | @Override
121 | public int getItemViewType(int position) {
122 | int dataItemCount = getContentItemCount();
123 | if (mHeaderCount != 0 && position < mHeaderCount) {//头部View
124 | return ITEM_TYPE.ITEM_TYPE_HEADER.ordinal();
125 | } else if (mBottomCount != 0 && position >= (mHeaderCount + dataItemCount)) {//底部View
126 | return ITEM_TYPE.ITEM_TYPE_BOTTOM.ordinal();
127 | } else {
128 | return ITEM_TYPE.ITEM_TYPE_CONTENT.ordinal();
129 | }
130 | }
131 |
132 | @Override
133 | public int getItemCount() {
134 | return mHeaderCount + getContentItemCount() + mBottomCount;
135 | }
136 |
137 | public abstract RecyclerView.ViewHolder onCreateHeaderView(ViewGroup parent);//创建头部View
138 |
139 | public abstract RecyclerView.ViewHolder onCreateContentView(ViewGroup parent);//创建中间内容View
140 |
141 | public abstract RecyclerView.ViewHolder onCreateBottomView(ViewGroup parent);//创建底部View
142 |
143 | public abstract int getContentItemCount();//获取中间内容个数
144 | }
145 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/adapter/CursorFilter.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.adapter;
2 |
3 | import android.database.Cursor;
4 | import android.widget.Filter;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 2014/12/30 17:15.
10 | * Description: 数据库Cursor筛选
11 | * Modification History:
12 | * Date Author Version Description
13 | * -----------------------------------------------------------------------------------
14 | * 2014/12/30 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class CursorFilter extends Filter {
18 | CursorFilterClient mClient;
19 |
20 | interface CursorFilterClient {
21 | CharSequence convertToString(Cursor cursor);
22 | Cursor runQueryOnBackgroundThread(CharSequence constraint);
23 | Cursor getCursor();
24 | void changeCursor(Cursor cursor);
25 | }
26 |
27 | CursorFilter(CursorFilterClient client) {
28 | mClient = client;
29 | }
30 |
31 | @Override
32 | public CharSequence convertResultToString(Object resultValue) {
33 | return mClient.convertToString((Cursor) resultValue);
34 | }
35 |
36 | @Override
37 | protected FilterResults performFiltering(CharSequence constraint) {
38 | Cursor cursor = mClient.runQueryOnBackgroundThread(constraint);
39 |
40 | FilterResults results = new FilterResults();
41 | if (cursor != null) {
42 | results.count = cursor.getCount();
43 | results.values = cursor;
44 | } else {
45 | results.count = 0;
46 | results.values = null;
47 | }
48 | return results;
49 | }
50 |
51 | @Override
52 | protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
53 | Cursor oldCursor = mClient.getCursor();
54 |
55 | if (results.values != null && results.values != oldCursor) {
56 | mClient.changeCursor((Cursor) results.values);
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/app/AppApiContact.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-11-22 14:10
7 | * Description: APP API常量工具类
8 | * Modification History:
9 | * Date Author Version Description
10 | * -----------------------------------------------------------------------------------
11 | * 14-11-22 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppApiContact {
15 | // public static final String API_HOST = "http://";//API Host
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/app/AppApplication.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.app;
2 |
3 | import android.content.Context;
4 | import android.support.multidex.MultiDexApplication;
5 |
6 | import com.google.gson.Gson;
7 | import com.google.gson.GsonBuilder;
8 | import com.google.gson.internal.bind.DateTypeAdapter;
9 | import com.ithooks.android.xreap.BuildConfig;
10 | import com.ithooks.android.xreap.network.http.AppApiService;
11 | import com.ithooks.android.xreap.utils.SharedPreferencesHelper;
12 | import com.squareup.okhttp.OkHttpClient;
13 |
14 | import java.util.Date;
15 | import java.util.concurrent.TimeUnit;
16 |
17 | import retrofit.RestAdapter;
18 | import retrofit.client.OkClient;
19 | import retrofit.converter.GsonConverter;
20 |
21 | /**
22 | * Author: ZhuWenWu
23 | * Version V1.0
24 | * Date: 14-11-22 13:30
25 | * Description:
26 | * Modification History:
27 | * Date Author Version Description
28 | * -----------------------------------------------------------------------------------
29 | * 14-11-22 ZhuWenWu 1.0 1.0
30 | * Why & What is modified:
31 | */
32 | public class AppApplication extends MultiDexApplication {
33 | private static Context sContext;
34 | private static AppApiService sAppApiService;//API 请求Service对象
35 |
36 | @Override
37 | public void onCreate() {
38 | super.onCreate();
39 |
40 | sContext = getApplicationContext();
41 |
42 | setUpSharedPreferencesHelper(getApplicationContext());//初始化SharedPreferences
43 | setUpApiService();//初始化APP API
44 | }
45 |
46 | private void setUpApiService() {
47 | Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateTypeAdapter()).create();
48 | OkHttpClient okHttpClient = new OkHttpClient();
49 | okHttpClient.setConnectTimeout(15, TimeUnit.SECONDS);
50 | RestAdapter restAdapter = new RestAdapter.Builder()
51 | .setEndpoint(BuildConfig.API_HOST)
52 | .setConverter(new GsonConverter(gson))
53 | .setClient(new OkClient(okHttpClient))
54 | .build();
55 | sAppApiService = restAdapter.create(AppApiService.class);
56 | }
57 |
58 | /**
59 | * 初始化SharedPreferences
60 | *
61 | * @param context 上下文
62 | */
63 | private void setUpSharedPreferencesHelper(Context context) {
64 | SharedPreferencesHelper.getInstance().Builder(context);
65 | }
66 |
67 | public static Context getContext() {
68 | return sContext;
69 | }
70 |
71 | public static AppApplication getInstance() {
72 | return (AppApplication) sContext;
73 | }
74 |
75 | public static AppApiService getAppApiService() {
76 | return sAppApiService;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/app/AppContact.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-11-22 14:10
7 | * Description: APP常量工具类
8 | * Modification History:
9 | * Date Author Version Description
10 | * -----------------------------------------------------------------------------------
11 | * 14-11-22 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppContact {
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/app/AppParamContact.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-11-22 14:12
7 | * Description: APP Intent 常量工具类
8 | * Modification History:
9 | * Date Author Version Description
10 | * -----------------------------------------------------------------------------------
11 | * 14-11-22 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppParamContact {
15 | public static final String PARAM_KEY_ID = "id";//ID
16 | public static final String PARAM_KEY_TITLE = "title";//Title
17 | public static final String PARAM_KEY_DATA = "data";//Object 序列化以后的数据
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/app/AppSpContact.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.app;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-11-22 14:11
7 | * Description: APP SharedPreferences KEY 常量工具类
8 | * Modification History:
9 | * Date Author Version Description
10 | * -----------------------------------------------------------------------------------
11 | * 14-11-22 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class AppSpContact {
15 | public static final String SP_KEY_NAME = "name";
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/BaseAbstractActionBarActivity.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 |
6 | import com.ithooks.android.xreap.R;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-11-22 15:13
12 | * Description: Fragment Activity 基类
13 | * Modification History:
14 | * Date Author Version Description
15 | * -----------------------------------------------------------------------------------
16 | * 14-11-22 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public abstract class BaseAbstractActionBarActivity extends BaseActionBarActivity {
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_fragment_base);
24 | if (savedInstanceState == null) {
25 | getSupportFragmentManager().beginTransaction()
26 | .add(R.id.container, getFragment())
27 | .commit();
28 | }
29 | }
30 |
31 | public abstract Fragment getFragment();
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/BaseActionBarActivity.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.app.ActionBar;
4 | import android.os.Bundle;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.view.MenuItem;
7 |
8 | import com.ithooks.android.xreap.utils.SharedPreferencesHelper;
9 |
10 | /**
11 | * Author: ZhuWenWu
12 | * Version V1.0
13 | * Date: 14-11-22 13:31
14 | * Description: Activity 基类
15 | * Modification History:
16 | * Date Author Version Description
17 | * -----------------------------------------------------------------------------------
18 | * 14-11-22 ZhuWenWu 1.0 1.0
19 | * Why & What is modified:
20 | */
21 | public class BaseActionBarActivity extends FragmentActivity {
22 | protected final String TAG = getClass().getSimpleName();
23 | protected ActionBar mActionBar;
24 | protected SharedPreferencesHelper mSharedPreferencesHelper;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | mActionBar = getActionBar();
30 | mSharedPreferencesHelper = SharedPreferencesHelper.getInstance();
31 | }
32 |
33 | protected void showActionBar() {
34 | if (mActionBar != null) {
35 | mActionBar.setDisplayShowCustomEnabled(false);
36 | mActionBar.setDisplayHomeAsUpEnabled(true);
37 | }
38 | }
39 |
40 | @Override
41 | public boolean onOptionsItemSelected(MenuItem item) {
42 | int id = item.getItemId();
43 | if (id == android.R.id.home) {
44 | finish();
45 | return true;
46 | }
47 | return super.onOptionsItemSelected(item);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/BaseCursorFragment.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.database.Cursor;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.LoaderManager;
7 | import android.support.v4.content.Loader;
8 | import android.view.View;
9 |
10 | import com.ithooks.android.xreap.adapter.BaseAbstractCursorAdapter;
11 |
12 | /**
13 | * Author: ZhuWenWu
14 | * Version V1.0
15 | * Date: 14-11-22 18:48
16 | * Description: DB配合LoaderManager加载数据
17 | * Modification History:
18 | * Date Author Version Description
19 | * -----------------------------------------------------------------------------------
20 | * 14-11-22 ZhuWenWu 1.0 1.0
21 | * Why & What is modified:
22 | */
23 | public abstract class BaseCursorFragment extends PullToRefreshBaseFragment implements LoaderManager.LoaderCallbacks {
24 | protected BaseAbstractCursorAdapter mCursorAdapter;
25 |
26 | @Override
27 | public void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | }
30 |
31 | @Override
32 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
33 | super.onViewCreated(view, savedInstanceState);
34 | setUpCursorAdapter();
35 | }
36 |
37 | @Override
38 | public Loader onCreateLoader(int i, Bundle bundle) {
39 | return createCursorLoader();
40 | }
41 |
42 | @Override
43 | public void onLoadFinished(Loader loader, Cursor cursor) {
44 | if (mCursorAdapter != null) {
45 | mCursorAdapter.changeCursor(cursor);
46 | }
47 | }
48 |
49 | @Override
50 | public void onLoaderReset(Loader loader) {
51 | if (mCursorAdapter != null) {
52 | mCursorAdapter.changeCursor(null);
53 | }
54 | }
55 |
56 | protected abstract void setUpCursorAdapter();
57 |
58 | protected abstract Loader createCursorLoader();
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.ithooks.android.xreap.utils.SharedPreferencesHelper;
10 |
11 | import butterknife.ButterKnife;
12 |
13 | /**
14 | * Author: ZhuWenWu
15 | * Version V1.0
16 | * Date: 14-11-22 15:19
17 | * Description: Fragment 基类
18 | * Modification History:
19 | * Date Author Version Description
20 | * -----------------------------------------------------------------------------------
21 | * 14-11-22 ZhuWenWu 1.0 1.0
22 | * Why & What is modified:
23 | */
24 | public abstract class BaseFragment extends Fragment {
25 | protected final String TAG = getClass().getSimpleName();
26 | protected SharedPreferencesHelper mSharedPreferencesHelper;
27 |
28 | @Override
29 | public void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | mSharedPreferencesHelper = SharedPreferencesHelper.getInstance();
32 | }
33 |
34 | @Override
35 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
36 | View rootView = inflater.inflate(getLayoutResId(), container, false);
37 | ButterKnife.inject(this, rootView);
38 | return rootView;
39 | }
40 |
41 | protected abstract int getLayoutResId();
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/BaseRecycleCursorFragment.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.database.Cursor;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.LoaderManager;
7 | import android.support.v4.content.Loader;
8 | import android.view.View;
9 |
10 | import com.ithooks.android.xreap.adapter.BaseAbstractRecycleCursorAdapter;
11 |
12 | /**
13 | * Author: ZhuWenWu
14 | * Version V1.0
15 | * Date: 14-11-22 18:48
16 | * Description: DB配合LoaderManager加载数据
17 | * Modification History:
18 | * Date Author Version Description
19 | * -----------------------------------------------------------------------------------
20 | * 14-11-22 ZhuWenWu 1.0 1.0
21 | * Why & What is modified:
22 | */
23 | public abstract class BaseRecycleCursorFragment extends RecycleRefreshBaseFragment implements LoaderManager.LoaderCallbacks {
24 | protected BaseAbstractRecycleCursorAdapter mCursorAdapter;
25 |
26 | @Override
27 | public void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | }
30 |
31 | @Override
32 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
33 | super.onViewCreated(view, savedInstanceState);
34 | setUpCursorAdapter();
35 | }
36 |
37 | @Override
38 | public Loader onCreateLoader(int id, Bundle bundle) {
39 | return createCursorLoader();
40 | }
41 |
42 | @Override
43 | public void onLoadFinished(Loader loader, Cursor cursor) {
44 | if (mCursorAdapter != null) {
45 | mCursorAdapter.changeCursor(cursor);
46 | }
47 | }
48 |
49 | @Override
50 | public void onLoaderReset(Loader loader) {
51 | if (mCursorAdapter != null) {
52 | mCursorAdapter.changeCursor(null);
53 | }
54 | }
55 |
56 | protected abstract void setUpCursorAdapter();
57 |
58 | protected abstract Loader createCursorLoader();
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/PullToRefreshBaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.ithooks.android.xreap.R;
11 | import com.ithooks.android.xreap.view.PageListView;
12 |
13 | import butterknife.ButterKnife;
14 | import butterknife.InjectView;
15 |
16 | /**
17 | * Author: ZhuWenWu
18 | * Version V1.0
19 | * Date: 14-11-22 16:33
20 | * Description: PullToRefreshList Fragment 基类
21 | * Modification History:
22 | * Date Author Version Description
23 | * -----------------------------------------------------------------------------------
24 | * 14-11-22 ZhuWenWu 1.0 1.0
25 | * Why & What is modified:
26 | */
27 | public abstract class PullToRefreshBaseFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener {
28 | @InjectView(R.id.swipe_container)
29 | SwipeRefreshLayout mSwipeContainer;
30 | @InjectView(R.id.page_list_view)
31 | PageListView mPageListView;
32 |
33 | @Override
34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
35 | View rootView = inflater.inflate(R.layout.fragment_pull_to_refresh_base_view, container, false);
36 | ButterKnife.inject(this, rootView);
37 | return rootView;
38 | }
39 |
40 | @Override
41 | protected int getLayoutResId() {
42 | return 0;//不调用父类布局,所以返回0
43 | }
44 |
45 | @Override
46 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
47 | super.onViewCreated(view, savedInstanceState);
48 | mSwipeContainer.setOnRefreshListener(this);
49 | mSwipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright,
50 | android.R.color.holo_green_light, android.R.color.holo_orange_light,
51 | android.R.color.holo_red_light);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/base/RecycleRefreshBaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.widget.SwipeRefreshLayout;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.ithooks.android.xreap.R;
11 | import com.malinskiy.superrecyclerview.OnMoreListener;
12 | import com.malinskiy.superrecyclerview.SuperRecyclerView;
13 |
14 | import butterknife.InjectView;
15 |
16 | /**
17 | * Author: ZhuWenWu
18 | * Version V1.0
19 | * Date: 2014/12/30 15:28.
20 | * Description: RecycleRefresh 基类
21 | * Modification History:
22 | * Date Author Version Description
23 | * -----------------------------------------------------------------------------------
24 | * 2014/12/30 ZhuWenWu 1.0 1.0
25 | * Why & What is modified:
26 | */
27 | public abstract class RecycleRefreshBaseFragment extends BaseFragment {
28 | @InjectView(R.id.recycle_view)
29 | protected SuperRecyclerView mRecycleView;
30 |
31 | @Override
32 | protected int getLayoutResId() {
33 | return R.layout.fragment_recycle_refresh_base;
34 | }
35 |
36 | @Override
37 | public void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | }
40 |
41 | @Override
42 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
43 | return super.onCreateView(inflater, container, savedInstanceState);
44 | }
45 |
46 | @Override
47 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
48 | super.onViewCreated(view, savedInstanceState);
49 | setUpRecycleView();
50 | }
51 |
52 | private void setUpRecycleView() {
53 | mRecycleView.setRefreshingColorResources(android.R.color.holo_blue_bright,
54 | android.R.color.holo_green_light, android.R.color.holo_orange_light,
55 | android.R.color.holo_red_light);
56 |
57 | mRecycleView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
58 | @Override
59 | public void onRefresh() {
60 | onDataRefresh();
61 | }
62 | });
63 | mRecycleView.setupMoreListener(new OnMoreListener() {
64 | @Override
65 | public void onMoreAsked(int numberOfItems, int numberBeforeMore, int currentItemPos) {
66 | onDataMore();
67 | }
68 | }, 1);
69 | }
70 |
71 | public abstract void onDataRefresh();
72 |
73 | public abstract void onDataMore();
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/dao/DataProvider.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.dao;
2 |
3 | import android.content.ContentProvider;
4 | import android.content.ContentUris;
5 | import android.content.ContentValues;
6 | import android.content.Context;
7 | import android.content.UriMatcher;
8 | import android.database.Cursor;
9 | import android.database.SQLException;
10 | import android.database.sqlite.SQLiteDatabase;
11 | import android.database.sqlite.SQLiteOpenHelper;
12 | import android.database.sqlite.SQLiteQueryBuilder;
13 | import android.net.Uri;
14 | import android.provider.BaseColumns;
15 | import android.support.annotation.NonNull;
16 |
17 | import com.ithooks.android.xreap.app.AppApplication;
18 |
19 | /**
20 | * Author: ZhuWenWu
21 | * Version V1.0
22 | * Date: 14-11-22 14:25
23 | * Description:
24 | * Modification History:
25 | * Date Author Version Description
26 | * -----------------------------------------------------------------------------------
27 | * 14-11-22 ZhuWenWu 1.0 1.0
28 | * Why & What is modified:
29 | */
30 | public class DataProvider extends ContentProvider {
31 | public static final Object obj = new Object();
32 | public static final String AUTHORITY = "com.ithooks.android.xreap";
33 | public static final String SCHEME = "content://";
34 |
35 | private static DBHelper mDBHelper;
36 |
37 | public static DBHelper getDBHelper() {
38 | if (mDBHelper == null) {
39 | mDBHelper = new DBHelper(AppApplication.getContext());
40 | }
41 | return mDBHelper;
42 | }
43 |
44 | @Override
45 | public boolean onCreate() {
46 | return true;
47 | }
48 |
49 | @Override
50 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
51 | synchronized (obj) {
52 | SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
53 | queryBuilder.setTables(matchTable(uri));
54 |
55 | SQLiteDatabase db = getDBHelper().getReadableDatabase();
56 | Cursor cursor = queryBuilder.query(db,
57 | projection,
58 | selection,
59 | selectionArgs,
60 | null,
61 | null,
62 | sortOrder);
63 | cursor.setNotificationUri(getContext().getContentResolver(), uri);
64 | return cursor;
65 | }
66 | }
67 |
68 | private static final UriMatcher sUriMATCHER = new UriMatcher(UriMatcher.NO_MATCH) {{
69 |
70 | }};
71 |
72 | private String matchTable(Uri uri) {
73 | String table = null;
74 | switch (sUriMATCHER.match(uri)) {
75 | default:
76 | throw new IllegalArgumentException("Unknown Uri" + uri);
77 | }
78 | // return table;
79 | }
80 |
81 | @Override
82 | public String getType(Uri uri) {
83 | switch (sUriMATCHER.match(uri)) {
84 | default:
85 | throw new IllegalArgumentException("Unknown Uri" + uri);
86 | }
87 | }
88 |
89 | @Override
90 | public Uri insert(Uri uri, ContentValues values) {
91 | synchronized (obj) {
92 | SQLiteDatabase db = getDBHelper().getWritableDatabase();
93 | long rowId = 0;
94 | db.beginTransaction();
95 | try {
96 | rowId = db.insert(matchTable(uri), null, values);
97 | db.setTransactionSuccessful();
98 | } catch (Exception e) {
99 | e.printStackTrace();
100 | } finally {
101 | db.endTransaction();
102 | }
103 | if (rowId > 0) {
104 | Uri returnUri = ContentUris.withAppendedId(uri, rowId);
105 | getContext().getContentResolver().notifyChange(uri, null);
106 | return returnUri;
107 | }
108 | throw new SQLException("Failed to insert row into " + uri);
109 | }
110 | }
111 |
112 | @Override
113 | public int bulkInsert(Uri uri, @NonNull ContentValues[] values) {
114 | synchronized (obj) {
115 | SQLiteDatabase db = getDBHelper().getWritableDatabase();
116 | db.beginTransaction();
117 | try {
118 | for (ContentValues contentValues : values) {
119 | db.insertWithOnConflict(matchTable(uri), BaseColumns._ID, contentValues, SQLiteDatabase.CONFLICT_IGNORE);
120 | }
121 | db.setTransactionSuccessful();
122 | getContext().getContentResolver().notifyChange(uri, null);
123 | return values.length;
124 | } catch (Exception e) {
125 | e.printStackTrace();
126 | } finally {
127 | db.endTransaction();
128 | }
129 | throw new SQLException("Failed to insert row into " + uri);
130 | }
131 | }
132 |
133 | @Override
134 | public int delete(Uri uri, String selection, String[] selectionArgs) {
135 | synchronized (obj) {
136 | SQLiteDatabase db = getDBHelper().getWritableDatabase();
137 | int count = 0;
138 | db.beginTransaction();
139 | try {
140 | count = db.delete(matchTable(uri), selection, selectionArgs);
141 | db.setTransactionSuccessful();
142 | } finally {
143 | db.endTransaction();
144 | }
145 | getContext().getContentResolver().notifyChange(uri, null);
146 | return count;
147 | }
148 | }
149 |
150 | public static void clearDBCache() {
151 | synchronized (DataProvider.obj) {
152 | DataProvider.DBHelper mDBHelper = DataProvider.getDBHelper();
153 | SQLiteDatabase db = mDBHelper.getWritableDatabase();
154 | }
155 | }
156 |
157 | @Override
158 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
159 | synchronized (obj) {
160 | SQLiteDatabase db = getDBHelper().getWritableDatabase();
161 | int count;
162 | db.beginTransaction();
163 | try {
164 | count = db.update(matchTable(uri), values, selection, selectionArgs);
165 | db.setTransactionSuccessful();
166 | } finally {
167 | db.endTransaction();
168 | }
169 | getContext().getContentResolver().notifyChange(uri, null);
170 | return count;
171 | }
172 | }
173 |
174 | public static class DBHelper extends SQLiteOpenHelper {
175 |
176 | private static final String DB_NAME = "xx.db";
177 |
178 | private static final int DB_VERSION = 1;
179 |
180 | private DBHelper(Context context) {
181 | super(context, DB_NAME, null, DB_VERSION);
182 | }
183 |
184 | @Override
185 | public void onCreate(SQLiteDatabase db) {
186 | }
187 |
188 | @Override
189 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
190 | }
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/dao/database/Column.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.dao.database;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-11-22 14:31
7 | * Description:
8 | * Modification History:
9 | * Date Author Version Description
10 | * -----------------------------------------------------------------------------------
11 | * 14-11-22 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public class Column {
15 | public static enum Constraint {
16 | UNIQUE("UNIQUE"), NOT("NOT"), NULL("NULL"), CHECK("CHECK"), FOREIGN_KEY("FOREIGN KEY"), PRIMARY_KEY(
17 | "PRIMARY KEY");
18 |
19 | private String value;
20 |
21 | private Constraint(String value) {
22 | this.value = value;
23 | }
24 |
25 | @Override
26 | public String toString() {
27 | return value;
28 | }
29 | }
30 |
31 | public static enum DataType {
32 | NULL, INTEGER, REAL, TEXT, BLOB
33 | }
34 |
35 | private String mColumnName;
36 |
37 | private Constraint mConstraint;
38 |
39 | private DataType mDataType;
40 |
41 | public Column(String columnName, Constraint constraint, DataType dataType) {
42 | mColumnName = columnName;
43 | mConstraint = constraint;
44 | mDataType = dataType;
45 | }
46 |
47 | public String getColumnName() {
48 | return mColumnName;
49 | }
50 |
51 | public Constraint getConstraint() {
52 | return mConstraint;
53 | }
54 |
55 | public DataType getDataType() {
56 | return mDataType;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/dao/database/SQLiteTable.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.dao.database;
2 |
3 | import android.database.sqlite.SQLiteDatabase;
4 | import android.provider.BaseColumns;
5 |
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-11-22 14:31
12 | * Description:
13 | * Modification History:
14 | * Date Author Version Description
15 | * -----------------------------------------------------------------------------------
16 | * 14-11-22 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class SQLiteTable {
20 | String mTableName;
21 |
22 | ArrayList mColumnsDefinitions = new ArrayList();
23 |
24 | public String getTableName() {
25 | return mTableName;
26 | }
27 |
28 | /**
29 | * 会自动添加主键 BaseColumns._ID
30 | *
31 | * @param tableName 表名
32 | */
33 | public SQLiteTable(String tableName) {
34 | mTableName = tableName;
35 | mColumnsDefinitions.add(new Column(BaseColumns._ID, Column.Constraint.PRIMARY_KEY,
36 | Column.DataType.INTEGER));
37 | }
38 |
39 | public SQLiteTable addColumn(Column columnsDefinition) {
40 | mColumnsDefinitions.add(columnsDefinition);
41 | return this;
42 | }
43 |
44 | public SQLiteTable addColumn(String columnName, Column.DataType dataType) {
45 | mColumnsDefinitions.add(new Column(columnName, null, dataType));
46 | return this;
47 | }
48 |
49 | public SQLiteTable addColumn(String columnName, Column.Constraint constraint,
50 | Column.DataType dataType) {
51 | mColumnsDefinitions.add(new Column(columnName, constraint, dataType));
52 | return this;
53 | }
54 |
55 | public void create(SQLiteDatabase db) {
56 | String formatter = " %s";
57 | StringBuilder stringBuilder = new StringBuilder();
58 | stringBuilder.append("CREATE TABLE IF NOT EXISTS ");
59 | stringBuilder.append(mTableName);
60 | stringBuilder.append("(");
61 | int columnCount = mColumnsDefinitions.size();
62 | int index = 0;
63 | for (Column columnsDefinition : mColumnsDefinitions) {
64 | stringBuilder.append(columnsDefinition.getColumnName()).append(
65 | String.format(formatter, columnsDefinition.getDataType().name()));
66 | Column.Constraint constraint = columnsDefinition.getConstraint();
67 |
68 | if (constraint != null) {
69 | stringBuilder.append(String.format(formatter, constraint.toString()));
70 | }
71 | if (index < columnCount - 1) {
72 | stringBuilder.append(",");
73 | }
74 | index++;
75 | }
76 | stringBuilder.append(");");
77 | db.execSQL(stringBuilder.toString());
78 | }
79 |
80 | public void delete(final SQLiteDatabase db) {
81 | db.execSQL("DROP TABLE IF EXISTS " + mTableName);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/dao/datahelper/BaseDataHelper.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.dao.datahelper;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.net.Uri;
7 | import android.support.v4.content.CursorLoader;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-11-22 14:29
13 | * Description: 数据库帮助类基类
14 | * Modification History:
15 | * Date Author Version Description
16 | * -----------------------------------------------------------------------------------
17 | * 14-11-22 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public abstract class BaseDataHelper {
21 | private Context mContext;
22 |
23 | protected abstract Uri getContentUri();
24 | protected abstract String getTableName();
25 |
26 | public BaseDataHelper(Context context) {
27 | mContext = context;
28 | }
29 |
30 | public Context getContext() {
31 | return mContext;
32 | }
33 |
34 | public void notifyChange() {
35 | mContext.getContentResolver().notifyChange(getContentUri(), null);
36 | }
37 |
38 | protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
39 | return mContext.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
40 | }
41 |
42 | protected final Cursor query(String[] projection, String selection, String[] selectionArgs, String sortOrder) {
43 | return mContext.getContentResolver().query(getContentUri(), projection, selection, selectionArgs, sortOrder);
44 | }
45 |
46 | protected final Uri insert(ContentValues values) {
47 | return mContext.getContentResolver().insert(getContentUri(), values);
48 | }
49 |
50 | protected final int bulkInsert(ContentValues[] values) {
51 | return mContext.getContentResolver().bulkInsert(getContentUri(), values);
52 | }
53 |
54 | protected final int update(ContentValues values, String where, String[] whereArgs) {
55 | return mContext.getContentResolver().update(getContentUri(), values, where, whereArgs);
56 | }
57 |
58 | protected final int delete(String where, String[] selectionArgs) {
59 | return mContext.getContentResolver().delete(getContentUri(), where, selectionArgs);
60 | }
61 |
62 | public CursorLoader getCursorLoader(Context context) {
63 | return getCursorLoader(context, null, null, null, null);
64 | }
65 |
66 | public CursorLoader getCursorLoader(Context context, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
67 | return new CursorLoader(context, getContentUri(), projection, selection, selectionArgs, sortOrder);
68 | }
69 |
70 | protected final Cursor getList(String[] projection, String selection, String[] selectionArgs, String sortOrder) {
71 | return mContext.getContentResolver().query(getContentUri(), projection, selection, selectionArgs, sortOrder);
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/dao/datahelper/DBInterface.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.dao.datahelper;
2 |
3 | import android.content.ContentValues;
4 |
5 | import java.util.List;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-11-22 19:25
11 | * Description: DB操作接口类
12 | * Modification History:
13 | * Date Author Version Description
14 | * -----------------------------------------------------------------------------------
15 | * 14-11-22 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public interface DBInterface {
19 | /**
20 | * 查询某一条记录
21 | *
22 | * @param id ID
23 | * @return T 返回查询到得第一条记录
24 | */
25 | public T query(String id);
26 |
27 | /**
28 | * 删除所有数据
29 | *
30 | * @return count 本次操作的条数
31 | */
32 | public int clearAll();
33 |
34 | /**
35 | * 批量插入数据
36 | *
37 | * @param listData 需要插入的数据列表
38 | */
39 | public void bulkInsert(List listData);
40 |
41 | public ContentValues getContentValues(T data);
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/log/LogUtils.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.log;
2 |
3 | import com.ithooks.android.xreap.BuildConfig;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-11-22 14:09
9 | * Description:Log 控制工具类
10 | * Modification History:
11 | * Date Author Version Description
12 | * -----------------------------------------------------------------------------------
13 | * 14-11-22 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class LogUtils {
17 | public static void v(String tag, String msg, Throwable tr) {
18 | if (BuildConfig.LOG_DEBUG) {
19 | android.util.Log.v(tag, msg, tr);
20 | }
21 | }
22 |
23 | public static void d(String tag, String msg) {
24 | if (BuildConfig.LOG_DEBUG) {
25 | android.util.Log.d(tag, msg);
26 | }
27 | }
28 |
29 | public static void d(String tag, String msg, Throwable tr) {
30 | if (BuildConfig.LOG_DEBUG) {
31 | android.util.Log.d(tag, msg, tr);
32 | }
33 | }
34 |
35 | public static void i(String tag, String msg) {
36 | if (BuildConfig.LOG_DEBUG) {
37 | android.util.Log.i(tag, msg);
38 | }
39 | }
40 |
41 | public static void i(String tag, String msg, Throwable tr) {
42 | if (BuildConfig.LOG_DEBUG) {
43 | android.util.Log.i(tag, msg, tr);
44 | }
45 | }
46 |
47 | public static void w(String tag, String msg, Throwable tr) {
48 | if (BuildConfig.LOG_DEBUG) {
49 | android.util.Log.w(tag, msg, tr);
50 | }
51 | }
52 |
53 | public static void w(String tag, Throwable tr) {
54 | if (BuildConfig.LOG_DEBUG) {
55 | android.util.Log.w(tag, tr);
56 | }
57 | }
58 |
59 | public static void e(String tag, String msg, Throwable tr) {
60 | if (BuildConfig.LOG_DEBUG) {
61 | android.util.Log.e(tag, msg, tr);
62 | }
63 | }
64 |
65 | public static void e(String tag, String msg) {
66 | if (BuildConfig.LOG_DEBUG) {
67 | android.util.Log.e(tag, msg);
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/model/BaseModel.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.model;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import com.google.gson.Gson;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-11-22 14:45
12 | * Description: Model 基类
13 | * Modification History:
14 | * Date Author Version Description
15 | * -----------------------------------------------------------------------------------
16 | * 14-11-22 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class BaseModel implements Parcelable {
20 | public String toJson() {
21 | return new Gson().toJson(this);
22 | }
23 |
24 | @Override
25 | public int describeContents() {
26 | return 0;
27 | }
28 |
29 | @Override
30 | public void writeToParcel(Parcel dest, int flags) {
31 | }
32 |
33 | public BaseModel() {
34 | }
35 |
36 | private BaseModel(Parcel in) {
37 | }
38 |
39 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
40 | public BaseModel createFromParcel(Parcel source) {
41 | return new BaseModel(source);
42 | }
43 |
44 | public BaseModel[] newArray(int size) {
45 | return new BaseModel[size];
46 | }
47 | };
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/network/AppNetworkInfo.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.network;
2 |
3 | import android.content.Context;
4 | import android.net.ConnectivityManager;
5 | import android.net.NetworkInfo;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-11-22 13:27
11 | * Description:手机网络资源工具类
12 | * Modification History:
13 | * Date Author Version Description
14 | * -----------------------------------------------------------------------------------
15 | * 14-11-22 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class AppNetworkInfo {
19 | /**
20 | * 网络是否可用
21 | *
22 | * @param context 上下文
23 | * @return true 可用 false 不可用
24 | */
25 | public static boolean isNetworkAvailable(Context context) {
26 | if (context != null) {
27 | ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
28 | NetworkInfo[] info = mgr.getAllNetworkInfo();
29 | if (info != null) {
30 | for (NetworkInfo anInfo : info) {
31 | if (anInfo.getState() == NetworkInfo.State.CONNECTED) {
32 | return true;
33 | }
34 | }
35 | }
36 | }
37 | return false;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/network/callback/HttpBaseCallBack.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.network.callback;
2 |
3 | import com.ithooks.android.xreap.log.LogUtils;
4 |
5 | import retrofit.Callback;
6 | import retrofit.RetrofitError;
7 | import retrofit.client.Response;
8 |
9 | /**
10 | * Author: ZhuWenWu
11 | * Version V1.0
12 | * Date: 14-11-22 14:55
13 | * Description: Http 数据请求 CallBack
14 | * Modification History:
15 | * Date Author Version Description
16 | * -----------------------------------------------------------------------------------
17 | * 14-11-22 ZhuWenWu 1.0 1.0
18 | * Why & What is modified:
19 | */
20 | public class HttpBaseCallBack implements Callback {
21 | protected String TAG = HttpBaseCallBack.class.getSimpleName();
22 |
23 | @Override
24 | public void success(T data, Response response) {
25 | LogUtils.d(TAG, "success--> url = " + response.getUrl());
26 | }
27 |
28 | @Override
29 | public void failure(RetrofitError retrofitError) {
30 | LogUtils.e(TAG, "failure--> url = " + retrofitError.getUrl());
31 | retrofitError.printStackTrace();
32 | }
33 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/network/callback/UiDisplayListener.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.network.callback;
2 |
3 | import retrofit.RetrofitError;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-11-22 15:06
9 | * Description: HTTP 请求刷新UI回调接口
10 | * Modification History:
11 | * Date Author Version Description
12 | * -----------------------------------------------------------------------------------
13 | * 14-11-22 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public interface UiDisplayListener {
17 | /**
18 | * HTTP请求成功回调
19 | *
20 | * @param data GSON解析之后的数据model
21 | */
22 | public void onSuccessDisplay(T data);
23 |
24 | /**
25 | * HTTP请求失败回调
26 | */
27 | public void onFailDisplay(RetrofitError retrofitError);
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/network/controller/BaseHttpController.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.network.controller;
2 |
3 | import com.ithooks.android.xreap.app.AppApplication;
4 | import com.ithooks.android.xreap.network.AppNetworkInfo;
5 | import com.ithooks.android.xreap.network.callback.UiDisplayListener;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-11-22 13:28
11 | * Description:网络请求控制类父类
12 | * Modification History:
13 | * Date Author Version Description
14 | * -----------------------------------------------------------------------------------
15 | * 14-11-22 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public abstract class BaseHttpController {
19 | protected UiDisplayListener uiDisplayListener;
20 |
21 | public BaseHttpController() {
22 | }
23 |
24 | public BaseHttpController(UiDisplayListener uiDisplayListener) {
25 | this.uiDisplayListener = uiDisplayListener;
26 | }
27 |
28 | public void setUiDisplayListener(UiDisplayListener uiDisplayListener) {
29 | this.uiDisplayListener = uiDisplayListener;
30 | }
31 |
32 | public void loadData() {
33 | if (AppNetworkInfo.isNetworkAvailable(AppApplication.getContext())) {//没有网络时直接调用失败接口
34 | getNetData();
35 | } else {
36 | if (uiDisplayListener != null) {
37 | uiDisplayListener.onFailDisplay(null);
38 | }
39 | }
40 | }
41 |
42 | /**
43 | * 获取网络数据
44 | */
45 | protected abstract void getNetData();
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/network/http/AppApiService.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.network.http;
2 |
3 | /**
4 | * Author: ZhuWenWu
5 | * Version V1.0
6 | * Date: 14-11-22 14:39
7 | * Description: Retrofit 注解API接口
8 | * Modification History:
9 | * Date Author Version Description
10 | * -----------------------------------------------------------------------------------
11 | * 14-11-22 ZhuWenWu 1.0 1.0
12 | * Why & What is modified:
13 | */
14 | public interface AppApiService {
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/ui/HomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.ui;
2 |
3 | import android.app.Fragment;
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.ithooks.android.xreap.R;
12 | import com.ithooks.android.xreap.base.BaseActionBarActivity;
13 |
14 |
15 | public class HomeActivity extends BaseActionBarActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_home);
21 | if (savedInstanceState == null) {
22 | getFragmentManager().beginTransaction()
23 | .add(R.id.container, new PlaceholderFragment())
24 | .commit();
25 | }
26 | }
27 |
28 |
29 | @Override
30 | public boolean onCreateOptionsMenu(Menu menu) {
31 | // Inflate the menu; this adds items to the action bar if it is present.
32 | getMenuInflater().inflate(R.menu.menu_home, menu);
33 | return true;
34 | }
35 |
36 | @Override
37 | public boolean onOptionsItemSelected(MenuItem item) {
38 | // Handle action bar item clicks here. The action bar will
39 | // automatically handle clicks on the Home/Up button, so long
40 | // as you specify a parent activity in AndroidManifest.xml.
41 | int id = item.getItemId();
42 |
43 | //noinspection SimplifiableIfStatement
44 | if (id == R.id.action_settings) {
45 | return true;
46 | }
47 |
48 | return super.onOptionsItemSelected(item);
49 | }
50 |
51 | /**
52 | * A placeholder fragment containing a simple view.
53 | */
54 | public static class PlaceholderFragment extends Fragment {
55 |
56 | public PlaceholderFragment() {
57 | }
58 |
59 | @Override
60 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
61 | Bundle savedInstanceState) {
62 | View rootView = inflater.inflate(R.layout.fragment_home, container, false);
63 | return rootView;
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/utils/Md5EncryptionHelper.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.utils;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-11-22 22:48
10 | * Description: MD5加密工具类
11 | * Modification History:
12 | * Date Author Version Description
13 | * -----------------------------------------------------------------------------------
14 | * 14-11-22 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class Md5EncryptionHelper {
18 | /**
19 | * 获取MD5字符串
20 | * @param content 需要转换的字符串
21 | * @return String
22 | */
23 | public static String getMD5(String content) {
24 | try {
25 | MessageDigest digest = MessageDigest.getInstance("MD5");
26 | digest.update(content.getBytes());
27 | return getHashString(digest);
28 |
29 | } catch (NoSuchAlgorithmException e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 |
35 | private static String getHashString(MessageDigest digest) {
36 | StringBuilder builder = new StringBuilder();
37 | for (byte b : digest.digest()) {
38 | builder.append(Integer.toHexString((b >> 4) & 0xf));
39 | builder.append(Integer.toHexString(b & 0xf));
40 | }
41 | return builder.toString();
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/utils/SharedPreferencesHelper.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.os.Environment;
8 | import android.preference.PreferenceManager;
9 | import android.text.TextUtils;
10 | import android.util.Log;
11 |
12 | import java.io.File;
13 | import java.io.FileOutputStream;
14 | import java.io.IOException;
15 | import java.io.OutputStream;
16 | import java.util.ArrayList;
17 | import java.util.Arrays;
18 | import java.util.Map;
19 |
20 | /**
21 | * Author: ZhuWenWu
22 | * Version V1.0
23 | * Date: 14-11-22 14:14
24 | * Description: SharedPreferences 帮助类
25 | * Modification History:
26 | * Date Author Version Description
27 | * -----------------------------------------------------------------------------------
28 | * 14-11-22 ZhuWenWu 1.0 1.0
29 | * Why & What is modified:
30 | */
31 | public class SharedPreferencesHelper {
32 | private static SharedPreferences sPreferences = null;
33 | private String DEFAULT_APP_IMAGE_DATA_DIRECTORY;
34 | public static String lastImagePath = "";
35 |
36 | private SharedPreferencesHelper() {
37 | }
38 |
39 | private static class SharedPreferencesHelperHolder {
40 | private static SharedPreferencesHelper appSharedPreferencesHelper = new SharedPreferencesHelper();
41 | }
42 |
43 | public static SharedPreferencesHelper getInstance() {
44 | return SharedPreferencesHelperHolder.appSharedPreferencesHelper;
45 | }
46 |
47 | public void Builder(Context context) {
48 | if (sPreferences == null) {
49 | sPreferences = PreferenceManager.getDefaultSharedPreferences(context);
50 | }
51 | }
52 |
53 | public Bitmap getImage(String path) {
54 | Bitmap theGottenBitmap = null;
55 | try {
56 | theGottenBitmap = BitmapFactory.decodeFile(path);
57 | } catch (Exception e) {
58 | e.printStackTrace();
59 | }
60 | return theGottenBitmap;
61 | }
62 |
63 | /**
64 | * Returns the String path of the last image that was saved with this Object
65 | *
66 | */
67 | public String getSavedImagePath() {
68 | return lastImagePath;
69 | }
70 |
71 | /**
72 | * Returns the String path of the last image that was saved with this FullPath
73 | *
74 | * @param theFolder String
75 | * the theFolder - the folder path dir you want to save it to e.g
76 | * "DropBox/WorkImages"
77 | * @param theImageName String
78 | * the theImageName - the name you want to assign to the image file e.g
79 | * "MeAtlunch.png"
80 | */
81 | public String putImagePNG(String theFolder, String theImageName,
82 | Bitmap theBitmap) {
83 | this.DEFAULT_APP_IMAGE_DATA_DIRECTORY = theFolder;
84 | String mFullPath = setupFolderPath(theImageName);
85 | saveBitmapPNG(mFullPath, theBitmap);
86 | lastImagePath = mFullPath;
87 | return mFullPath;
88 | }
89 |
90 | private String setupFolderPath(String imageName) {
91 | File filePath = Environment.getExternalStorageDirectory();
92 | File mFolder = new File(filePath, DEFAULT_APP_IMAGE_DATA_DIRECTORY);
93 | if (!mFolder.exists()) {
94 | if (!mFolder.mkdirs()) {
95 | Log.e("While creating save path",
96 | "Default Save Path Creation Error");
97 | }
98 | }
99 | return mFolder.getPath() + '/' + imageName;
100 | }
101 |
102 | private boolean saveBitmapPNG(String strFileName, Bitmap bitmap) {
103 | if (strFileName == null || bitmap == null)
104 | return false;
105 | boolean bSuccess1 = false;
106 | boolean bSuccess2;
107 | boolean bSuccess3;
108 | File saveFile = new File(strFileName);
109 |
110 | if (saveFile.exists()) {
111 | if (!saveFile.delete())
112 | return false;
113 | }
114 |
115 | try {
116 | bSuccess1 = saveFile.createNewFile();
117 | } catch (IOException e1) {
118 | e1.printStackTrace();
119 | }
120 |
121 | OutputStream out = null;
122 | try {
123 | out = new FileOutputStream(saveFile);
124 | bSuccess2 = bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
125 | } catch (Exception e) {
126 | e.printStackTrace();
127 | bSuccess2 = false;
128 | }
129 | try {
130 | if (out != null) {
131 | out.flush();
132 | out.close();
133 | bSuccess3 = true;
134 | } else
135 | bSuccess3 = false;
136 |
137 | } catch (IOException e) {
138 | e.printStackTrace();
139 | bSuccess3 = false;
140 | } finally {
141 | if (out != null) {
142 | try {
143 | out.close();
144 | } catch (IOException e) {
145 | e.printStackTrace();
146 | }
147 | }
148 | }
149 |
150 | return (bSuccess1 && bSuccess2 && bSuccess3);
151 | }
152 |
153 | public int getInt(String key) {
154 | return sPreferences.getInt(key, 0);
155 | }
156 |
157 | public long getLong(String key) {
158 | return sPreferences.getLong(key, 0l);
159 | }
160 |
161 | public String getString(String key) {
162 | return sPreferences.getString(key, "");
163 | }
164 |
165 | public String getString(String key, String defaultValue) {
166 | return sPreferences.getString(key, defaultValue);
167 | }
168 |
169 | public double getDouble(String key) {
170 | String number = getString(key);
171 | try {
172 | return Double.parseDouble(number);
173 | } catch (NumberFormatException e) {
174 | return 0;
175 | }
176 | }
177 |
178 | public void putInt(String key, int value) {
179 | SharedPreferences.Editor editor = sPreferences.edit();
180 | editor.putInt(key, value);
181 | editor.apply();
182 | }
183 |
184 | public void putLong(String key, long value) {
185 | SharedPreferences.Editor editor = sPreferences.edit();
186 | editor.putLong(key, value);
187 | editor.apply();
188 | }
189 |
190 | public void putDouble(String key, double value) {
191 | putString(key, String.valueOf(value));
192 | }
193 |
194 | public void putString(String key, String value) {
195 |
196 | SharedPreferences.Editor editor = sPreferences.edit();
197 | editor.putString(key, value);
198 | editor.apply();
199 | }
200 |
201 | public void putList(String key, ArrayList array) {
202 |
203 | SharedPreferences.Editor editor = sPreferences.edit();
204 | String[] lists = array.toArray(new String[array.size()]);
205 | // the comma like character used below is not a comma it is the SINGLE
206 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for
207 | // seprating the items in the list
208 | editor.putString(key, TextUtils.join("‚‗‚", lists));
209 | editor.apply();
210 | }
211 |
212 | public ArrayList getList(String key) {
213 | // the comma like character used below is not a comma it is the SINGLE
214 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for
215 | // seprating the items in the list
216 | String[] lists = TextUtils.split(sPreferences.getString(key, ""), "‚‗‚");
217 | return new ArrayList(Arrays.asList(lists));
218 | }
219 |
220 | public void putListInt(String key, ArrayList array,
221 | Context context) {
222 | SharedPreferences.Editor editor = sPreferences.edit();
223 | Integer[] lists = array.toArray(new Integer[array.size()]);
224 | // the comma like character used below is not a comma it is the SINGLE
225 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for
226 | // seprating the items in the list
227 | editor.putString(key, TextUtils.join("‚‗‚", lists));
228 | editor.apply();
229 | }
230 |
231 | public ArrayList getListInt(String key,
232 | Context context) {
233 | // the comma like character used below is not a comma it is the SINGLE
234 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for
235 | // seprating the items in the list
236 | String[] mylist = TextUtils.split(sPreferences.getString(key, ""), "‚‗‚");
237 | ArrayList gottenlist = new ArrayList(Arrays.asList(mylist));
238 | ArrayList gottenlist2 = new ArrayList();
239 | for (String data : gottenlist) {
240 | gottenlist2.add(Integer.parseInt(data));
241 | }
242 |
243 | return gottenlist2;
244 | }
245 |
246 | public void putListBoolean(String key, ArrayList marray) {
247 | ArrayList origList = new ArrayList();
248 | for (Boolean b : marray) {
249 | if (b) {
250 | origList.add("true");
251 | } else {
252 | origList.add("false");
253 | }
254 | }
255 | putList(key, origList);
256 | }
257 |
258 | public ArrayList getListBoolean(String key) {
259 | ArrayList origList = getList(key);
260 | ArrayList mBools = new ArrayList();
261 | for (String b : origList) {
262 | if (b.equals("true")) {
263 | mBools.add(true);
264 | } else {
265 | mBools.add(false);
266 | }
267 | }
268 | return mBools;
269 | }
270 |
271 | public void putBoolean(String key, boolean value) {
272 | SharedPreferences.Editor editor = sPreferences.edit();
273 | editor.putBoolean(key, value);
274 | editor.apply();
275 | }
276 |
277 | public boolean getBoolean(String key) {
278 | return sPreferences.getBoolean(key, false);
279 | }
280 |
281 | public boolean getBoolean(String key, boolean defaultValue) {
282 | return sPreferences.getBoolean(key, defaultValue);
283 | }
284 |
285 | public void putFloat(String key, float value) {
286 | SharedPreferences.Editor editor = sPreferences.edit();
287 | editor.putFloat(key, value);
288 | editor.apply();
289 | }
290 |
291 | public float getFloat(String key) {
292 | return sPreferences.getFloat(key, 0f);
293 | }
294 |
295 | public void remove(String key) {
296 | SharedPreferences.Editor editor = sPreferences.edit();
297 | editor.remove(key);
298 | editor.apply();
299 | }
300 |
301 | public void clear() {
302 | SharedPreferences.Editor editor = sPreferences.edit();
303 | editor.clear();
304 | editor.apply();
305 | }
306 |
307 | public Map getAll() {
308 | return sPreferences.getAll();
309 | }
310 |
311 | public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
312 | sPreferences.registerOnSharedPreferenceChangeListener(listener);
313 | }
314 |
315 | public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
316 | sPreferences.unregisterOnSharedPreferenceChangeListener(listener);
317 | }
318 | }
319 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/utils/StringHelper.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.utils;
2 |
3 | import android.widget.EditText;
4 | import android.widget.TextView;
5 |
6 | /**
7 | * Author: ZhuWenWu
8 | * Version V1.0
9 | * Date: 14-11-22 14:32
10 | * Description: 字符串帮助类
11 | * Modification History:
12 | * Date Author Version Description
13 | * -----------------------------------------------------------------------------------
14 | * 14-11-22 ZhuWenWu 1.0 1.0
15 | * Why & What is modified:
16 | */
17 | public class StringHelper {
18 | public static String getStr(String str) {
19 | return isEmpty(str) ? "" : str;
20 | }
21 |
22 | public static String getEditTextContent(EditText edt) {
23 | return edt.getText().toString().trim();
24 | }
25 |
26 | public static boolean isEmpty(String str) {
27 | return str == null || str.equals("null") || str.equals("");
28 | }
29 |
30 | public static boolean isEditTextEmpty(EditText edt) {
31 | return isEmpty(getEditTextContent(edt));
32 | }
33 |
34 | public static boolean isPhoneEditTextEmpty(EditText edt) {
35 | return isEmpty(getEditTextContent(edt)) || getEditTextContent(edt).length() != 11;
36 | }
37 |
38 | public static boolean notEmpty(String str) {
39 | return !isEmpty(str);
40 | }
41 |
42 | public static String getTextViewContent(TextView tv) {
43 | return tv.getText().toString().trim();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/utils/ToastHelper.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.utils;
2 |
3 | import android.app.Activity;
4 | import android.view.Gravity;
5 |
6 | import com.devspark.appmsg.AppMsg;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-11-22 14:34
12 | * Description: 弹出信息工具类
13 | * Modification History:
14 | * Date Author Version Description
15 | * -----------------------------------------------------------------------------------
16 | * 14-11-22 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class ToastHelper {
20 | public static void showInfo(Activity context, String msg) {
21 | AppMsg.makeText(context, msg, AppMsg.STYLE_INFO).show();
22 | }
23 |
24 | public static void showInfo(Activity context, int resId) {
25 | AppMsg.makeText(context, resId, AppMsg.STYLE_INFO).show();
26 | }
27 |
28 | public static void showBottomInfo(Activity context, String msg) {
29 | AppMsg.makeText(context, msg, AppMsg.STYLE_INFO).setLayoutGravity(Gravity.BOTTOM).show();
30 | }
31 |
32 | public static void showBottomInfo(Activity context, int resId) {
33 | AppMsg.makeText(context, resId, AppMsg.STYLE_INFO).setLayoutGravity(Gravity.BOTTOM).show();
34 | }
35 |
36 | public static void showAlert(Activity context, String msg) {
37 | AppMsg.makeText(context, msg, AppMsg.STYLE_ALERT).show();
38 | }
39 |
40 | public static void showAlert(Activity context, int resId) {
41 | AppMsg.makeText(context, resId, AppMsg.STYLE_ALERT).show();
42 | }
43 |
44 | public static void showBottomAlert(Activity context, String msg) {
45 | AppMsg.makeText(context, msg, AppMsg.STYLE_ALERT).setLayoutGravity(Gravity.BOTTOM).show();
46 | }
47 |
48 | public static void showBottomAlert(Activity context, int resId) {
49 | AppMsg.makeText(context, resId, AppMsg.STYLE_ALERT).setLayoutGravity(Gravity.BOTTOM).show();
50 | }
51 |
52 | public static void showConfirm(Activity context, String msg) {
53 | AppMsg.makeText(context, msg, AppMsg.STYLE_CONFIRM).show();
54 | }
55 |
56 | public static void showConfirm(Activity context, int resId) {
57 | AppMsg.makeText(context, resId, AppMsg.STYLE_CONFIRM).show();
58 | }
59 |
60 | public static void showBottomConfirm(Activity context, String msg) {
61 | AppMsg.makeText(context, msg, AppMsg.STYLE_CONFIRM).setLayoutGravity(Gravity.BOTTOM).show();
62 | }
63 |
64 | public static void showBottomConfirm(Activity context, int resId) {
65 | AppMsg.makeText(context, resId, AppMsg.STYLE_CONFIRM).setLayoutGravity(Gravity.BOTTOM).show();
66 | }
67 |
68 |
69 | public static void showMsg(Activity context, String msg, AppMsg.Style style) {
70 | AppMsg.makeText(context, msg, style).show();
71 | }
72 |
73 | public static void showMsg(Activity context, int resId, AppMsg.Style style) {
74 | AppMsg.makeText(context, resId, style).show();
75 | }
76 |
77 | public static void showMsg(Activity context, String msg, AppMsg.Style style, int gravity) {
78 | AppMsg.makeText(context, msg, style).setLayoutGravity(gravity).show();
79 | }
80 |
81 | public static void showMsg(Activity context, int resId, AppMsg.Style style, int gravity) {
82 | AppMsg.makeText(context, resId, style).setLayoutGravity(gravity).show();
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/utils/ViewHelper.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.utils;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Author: ZhuWenWu
7 | * Version V1.0
8 | * Date: 14-11-22 14:35
9 | * Description: View 帮助类
10 | * Modification History:
11 | * Date Author Version Description
12 | * -----------------------------------------------------------------------------------
13 | * 14-11-22 ZhuWenWu 1.0 1.0
14 | * Why & What is modified:
15 | */
16 | public class ViewHelper {
17 | /**
18 | * 设置View 是否显示
19 | *
20 | * @param view 需要设置的View对象
21 | * @param isGone 是否隐藏
22 | * @param V
23 | * @return V 当前View
24 | */
25 | public static V setGone(V view, boolean isGone) {
26 | if (view != null) {
27 | if (isGone) {
28 | if (View.GONE != view.getVisibility())
29 | view.setVisibility(View.GONE);
30 | } else {
31 | if (View.VISIBLE != view.getVisibility())
32 | view.setVisibility(View.VISIBLE);
33 | }
34 | }
35 | return view;
36 | }
37 |
38 | /**
39 | * 多个view隐藏或显示
40 | *
41 | * @param gone true 隐藏;false 显示
42 | * @param views 多个view对象
43 | */
44 | public static void setViewsGone(boolean gone, View... views) {
45 | for (View view : views) {
46 | setGone(view, gone);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/view/FixedRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 |
6 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView;
7 |
8 | /**
9 | * Author: ZhuWenWu
10 | * Version V1.0
11 | * Date: 14-12-14 23:48
12 | * Description: fixed RecyclerView and SwipeRefreshLayout BUG
13 | * Modification History:
14 | * Date Author Version Description
15 | * -----------------------------------------------------------------------------------
16 | * 14-12-14 ZhuWenWu 1.0 1.0
17 | * Why & What is modified:
18 | */
19 | public class FixedRecyclerView extends ObservableRecyclerView {
20 | public FixedRecyclerView(Context context) {
21 | this(context, null);
22 | }
23 |
24 | public FixedRecyclerView(Context context, AttributeSet attrs) {
25 | this(context, attrs, 0);
26 | }
27 |
28 | public FixedRecyclerView(Context context, AttributeSet attrs, int defStyle) {
29 | super(context, attrs, defStyle);
30 | }
31 |
32 | @Override
33 | public boolean canScrollVertically(int direction) {
34 | if (direction < 1) {
35 | boolean original = super.canScrollVertically(direction);
36 | return !original && getChildAt(0) != null && getChildAt(0).getTop() < 0 || original;
37 | }
38 | return super.canScrollVertically(direction);
39 | }
40 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/view/FullyExpandedListView.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ListView;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-11-22 16:47
11 | * Description: 默认全部展开的ListView
12 | * Modification History:
13 | * Date Author Version Description
14 | * -----------------------------------------------------------------------------------
15 | * 14-11-22 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class FullyExpandedListView extends ListView {
19 | public FullyExpandedListView(Context context) {
20 | super(context);
21 | }
22 |
23 | public FullyExpandedListView(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public FullyExpandedListView(Context context, AttributeSet attrs, int defStyle) {
28 | super(context, attrs, defStyle);
29 | }
30 |
31 | @Override
32 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
33 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
34 | super.onMeasure(widthMeasureSpec, expandSpec);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/view/PageListView.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.AbsListView;
6 |
7 | /**
8 | * Author: ZhuWenWu
9 | * Version V1.0
10 | * Date: 14-11-22 16:41
11 | * Description: 分页加载的自定义ListView
12 | * Modification History:
13 | * Date Author Version Description
14 | * -----------------------------------------------------------------------------------
15 | * 14-11-22 ZhuWenWu 1.0 1.0
16 | * Why & What is modified:
17 | */
18 | public class PageListView extends StatusListView implements AbsListView.OnScrollListener {
19 | private OnLoadNextListener mLoadNextListener;
20 | private boolean isLoadMoreEnable;
21 | private PageListViewState mStatus;
22 |
23 | public static enum PageListViewState {
24 | Idle, TheEnd, Loading
25 | }
26 |
27 | public PageListView(Context context) {
28 | this(context, null);
29 | }
30 |
31 | public PageListView(Context context, AttributeSet attrs) {
32 | this(context, attrs, 0);
33 | }
34 |
35 | public PageListView(Context context, AttributeSet attrs, int defStyle) {
36 | super(context, attrs, defStyle);
37 | setOnScrollListener(this);
38 | }
39 |
40 | public void setLoadMoreEnable(boolean isLoadMoreEnable) {
41 | this.isLoadMoreEnable = isLoadMoreEnable;
42 | }
43 |
44 | @Override
45 | public void onScrollStateChanged(AbsListView absListView, int scrollState) {
46 |
47 | }
48 |
49 | @Override
50 | public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
51 | if (mStatus == PageListViewState.Loading
52 | || mStatus == PageListViewState.TheEnd || !isLoadMoreEnable) {
53 | return;
54 | }
55 |
56 | if (firstVisibleItem + visibleItemCount >= totalItemCount
57 | && totalItemCount != 0
58 | && totalItemCount != getHeaderViewsCount()
59 | + getFooterViewsCount() && mLoadNextListener != null) {
60 | setState(PageListViewState.Loading);
61 | mLoadNextListener.onLoadNext();
62 | }
63 | }
64 |
65 | public void setState(PageListViewState status) {
66 | mStatus = status;
67 | }
68 |
69 | public void setLoadNextListener(OnLoadNextListener listener) {
70 | mLoadNextListener = listener;
71 | }
72 |
73 | public interface OnLoadNextListener {
74 | public void onLoadNext();
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/ithooks/android/xreap/view/StatusListView.java:
--------------------------------------------------------------------------------
1 | package com.ithooks.android.xreap.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.util.AttributeSet;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.AbsListView;
10 | import android.widget.Button;
11 | import android.widget.FrameLayout;
12 | import android.widget.ListView;
13 | import android.widget.TextView;
14 |
15 | import com.ithooks.android.xreap.R;
16 |
17 | /**
18 | * Author: ZhuWenWu
19 | * Version V1.0
20 | * Date: 14-11-22 16:41
21 | * Description: 不同状态的自定义ListView empty / loading / error
22 | * Modification History:
23 | * Date Author Version Description
24 | * -----------------------------------------------------------------------------------
25 | * 14-11-22 ZhuWenWu 1.0 1.0
26 | * Why & What is modified:
27 | */
28 | public class StatusListView extends ListView {
29 | private static final String VIEW_TAG = "tag";
30 | private LayoutInflater mLayoutInflater;
31 | private View mLoadingView;
32 | private View mEmptyView;
33 | private View mErrorView;
34 | private TextView mEmptyMsgView;
35 | private Button mEmptyButton;
36 | private TextView mErrorMsgView;
37 | private Button mErrorButton;
38 | private boolean isInitViews = true;
39 | private boolean isInvalidateView;
40 |
41 | public StatusListView(Context context) {
42 | this(context, null);
43 | }
44 |
45 | public StatusListView(Context context, AttributeSet attrs) {
46 | this(context, attrs, 0);
47 | }
48 |
49 | public StatusListView(Context context, AttributeSet attrs, int defStyle) {
50 | super(context, attrs, defStyle);
51 | init(attrs);
52 | }
53 |
54 | private void init(AttributeSet attrs) {
55 | if (attrs != null) {
56 | //初始化状态View
57 | mLayoutInflater = LayoutInflater.from(getContext());
58 |
59 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StatusListView);
60 |
61 | int loadingViewResId = a.getResourceId(R.styleable.StatusListView_loadingView, 0);
62 | if (loadingViewResId > 0) {
63 | mLoadingView = mLayoutInflater.inflate(loadingViewResId, null);
64 | }
65 |
66 | int emptyViewResId = a.getResourceId(R.styleable.StatusListView_emptyView, 0);
67 | if (emptyViewResId > 0) {
68 | mEmptyView = mLayoutInflater.inflate(emptyViewResId, null);
69 | mEmptyMsgView = (TextView) mEmptyView.findViewById(R.id.tv_list_empty);
70 | mEmptyButton = (Button) mEmptyView.findViewById(R.id.btn_list_empty);
71 | }
72 |
73 | int errorViewResId = a.getResourceId(R.styleable.StatusListView_errorView, 0);
74 | if (errorViewResId > 0) {
75 | mErrorView = mLayoutInflater.inflate(errorViewResId, null);
76 | mErrorMsgView = (TextView) mErrorView.findViewById(R.id.tv_list_error);
77 | mErrorButton = (Button) mErrorView.findViewById(R.id.btn_list_error);
78 | }
79 | a.recycle();
80 | }
81 | }
82 |
83 | public static class Builder {
84 |
85 | private Context mContext;
86 | private LayoutInflater mLayoutInflater;
87 |
88 | private View mLoadingView;
89 | private View mEmptyView;
90 | private View mErrorView;
91 |
92 | public Builder(Context context) {
93 | if (context == null) {
94 | throw new IllegalArgumentException("Context must not be null.");
95 | }
96 | mContext = context;
97 | mLayoutInflater = LayoutInflater.from(context);
98 | }
99 |
100 | public Builder loadingView(View view) {
101 | if (view == null) {
102 | throw new IllegalArgumentException("View must not be null.");
103 | }
104 | mLoadingView = view;
105 | return this;
106 | }
107 |
108 | public Builder loadingView(View view, OnClickListener clickListener) {
109 | if (view == null) {
110 | throw new IllegalArgumentException("View must not be null.");
111 | }
112 | mLoadingView = view;
113 | mLoadingView.setOnClickListener(clickListener);
114 | return this;
115 | }
116 |
117 | public Builder loadingView(int resId) {
118 | if (resId <= 0) {
119 | throw new IllegalArgumentException("View resource id must be greater than 0.");
120 | }
121 | mLoadingView = mLayoutInflater.inflate(resId, null);
122 | return this;
123 | }
124 |
125 | public Builder emptyView(View view) {
126 | if (view == null) {
127 | throw new IllegalArgumentException("View must not be null.");
128 | }
129 | mEmptyView = view;
130 | return this;
131 | }
132 |
133 | public Builder emptyView(View view, OnClickListener clickListener) {
134 | if (view == null) {
135 | throw new IllegalArgumentException("View must not be null.");
136 | }
137 | mEmptyView = view;
138 | mEmptyView.setOnClickListener(clickListener);
139 | return this;
140 | }
141 |
142 | public Builder emptyView(int resId) {
143 | if (resId <= 0) {
144 | throw new IllegalArgumentException("View resource id must be greater than 0.");
145 | }
146 | mEmptyView = mLayoutInflater.inflate(resId, null);
147 | return this;
148 | }
149 |
150 | public Builder errorView(View view) {
151 | if (view == null) {
152 | throw new IllegalArgumentException("View must not be null.");
153 | }
154 | mErrorView = view;
155 | return this;
156 | }
157 |
158 | public Builder errorView(View view, OnClickListener clickListener) {
159 | if (view == null) {
160 | throw new IllegalArgumentException("View must not be null.");
161 | }
162 | mErrorView = view;
163 | mErrorView.setOnClickListener(clickListener);
164 | return this;
165 | }
166 |
167 | public Builder errorView(int resId) {
168 | if (resId <= 0) {
169 | throw new IllegalArgumentException("View resource id must be greater than 0.");
170 | }
171 | mErrorView = mLayoutInflater.inflate(resId, null);
172 | return this;
173 | }
174 |
175 | public StatusListView build() {
176 | return new StatusListView(mContext);
177 | }
178 | }
179 |
180 | //================================================================================
181 | // Getters
182 | //================================================================================
183 |
184 | public View getLoadingView() {
185 | return mLoadingView;
186 | }
187 |
188 | @Override
189 | public View getEmptyView() {
190 | return mEmptyView;
191 | }
192 |
193 | public View getErrorView() {
194 | return mErrorView;
195 | }
196 |
197 | public TextView getEmptyTextView() {
198 | return mEmptyMsgView;
199 | }
200 |
201 | public TextView getErrorTextView() {
202 | return mErrorMsgView;
203 | }
204 | //================================================================================
205 | // Setters
206 | //================================================================================
207 |
208 | public void setLoadingView(View view) {
209 | setLoadingView(view, false);
210 | }
211 |
212 | public void setLoadingView(View view, boolean invalidateView) {
213 | if (view == null) {
214 | throw new IllegalArgumentException("View must not be null.");
215 | }
216 | mLoadingView = view;
217 | isInvalidateView = invalidateView;
218 | }
219 |
220 | public void setLoadingView(int resId) {
221 | setLoadingView(resId, false);
222 | }
223 |
224 | public void setLoadingView(int resId, boolean invalidateView) {
225 | if (resId <= 0) {
226 | throw new IllegalArgumentException("View resource id must be greater than 0.");
227 | }
228 | mLoadingView = mLayoutInflater.inflate(resId, null);
229 | isInvalidateView = invalidateView;
230 | }
231 |
232 | public void setLoadingView(View view, OnClickListener clickListener) {
233 | setLoadingView(view, clickListener, false);
234 | }
235 |
236 | public void setLoadingView(View view, OnClickListener clickListener, boolean invalidateView) {
237 | if (view == null) {
238 | throw new IllegalArgumentException("View must not be null.");
239 | }
240 | mLoadingView = view;
241 | mLoadingView.setOnClickListener(clickListener);
242 | isInvalidateView = invalidateView;
243 | }
244 |
245 | public void setLoadingView(int resId, OnClickListener clickListener) {
246 | setLoadingView(resId, clickListener, false);
247 | }
248 |
249 | public void setLoadingView(int resId, OnClickListener clickListener, boolean invalidateView) {
250 | if (resId <= 0) {
251 | throw new IllegalArgumentException("View resource id must be greater than 0.");
252 | }
253 | mLoadingView = mLayoutInflater.inflate(resId, null);
254 | mLoadingView.setOnClickListener(clickListener);
255 | isInvalidateView = invalidateView;
256 | }
257 |
258 | public void setLoadingViewClickListener(OnClickListener clickListener) {
259 | if (mLoadingView == null) {
260 | throw new IllegalStateException("Loading view is null. Cannot set click listener.");
261 | }
262 | mLoadingView.setOnClickListener(clickListener);
263 | }
264 |
265 | @Override
266 | public void setEmptyView(View view) {
267 | setEmptyView(view, false);
268 | }
269 |
270 | public void setEmptyView(View view, boolean invalidateView) {
271 | if (view == null) {
272 | throw new IllegalArgumentException("View must not be null.");
273 | }
274 | mEmptyView = view;
275 | isInvalidateView = invalidateView;
276 | }
277 |
278 | public void setEmptyView(int resId) {
279 | setEmptyView(resId, false);
280 | }
281 |
282 | public void setEmptyView(int resId, boolean invalidateView) {
283 | if (resId <= 0) {
284 | throw new IllegalArgumentException("View resource id must be greater than 0.");
285 | }
286 | mEmptyView = mLayoutInflater.inflate(resId, null);
287 | isInvalidateView = invalidateView;
288 | }
289 |
290 | public void setEmptyView(View view, OnClickListener clickListener) {
291 | setEmptyView(view, clickListener, false);
292 | }
293 |
294 | public void setEmptyView(View view, OnClickListener clickListener, boolean invalidateView) {
295 | if (view == null) {
296 | throw new IllegalArgumentException("View must not be null.");
297 | }
298 | mEmptyView = view;
299 | mEmptyView.setOnClickListener(clickListener);
300 | isInvalidateView = invalidateView;
301 | }
302 |
303 | public void setEmptyView(int resId, OnClickListener clickListener) {
304 | setEmptyView(resId, clickListener, false);
305 | }
306 |
307 | public void setEmptyView(int resId, OnClickListener clickListener, boolean invalidateView) {
308 | if (resId <= 0) {
309 | throw new IllegalArgumentException("View resource id must be greater than 0.");
310 | }
311 | mEmptyView = mLayoutInflater.inflate(resId, null);
312 | mEmptyView.setOnClickListener(clickListener);
313 | isInvalidateView = invalidateView;
314 | }
315 |
316 | public void setEmptyViewClickListener(OnClickListener clickListener) {
317 | if (mEmptyView == null) {
318 | throw new IllegalStateException("Empty view is null. Cannot set click listener.");
319 | }
320 | mEmptyView.setOnClickListener(clickListener);
321 | }
322 |
323 | public void setErrorView(View view) {
324 | setErrorView(view, false);
325 | }
326 |
327 | public void setErrorView(View view, boolean invalidateView) {
328 | if (view == null) {
329 | throw new IllegalArgumentException("View must not be null.");
330 | }
331 | mErrorView = view;
332 | isInvalidateView = invalidateView;
333 | }
334 |
335 | public void setErrorView(int resId) {
336 | setErrorView(resId, false);
337 | }
338 |
339 | public void setErrorView(int resId, boolean invalidateView) {
340 | if (resId <= 0) {
341 | throw new IllegalArgumentException("View resource id must be greater than 0.");
342 | }
343 | mErrorView = mLayoutInflater.inflate(resId, null);
344 | isInvalidateView = invalidateView;
345 | }
346 |
347 | public void setErrorView(View view, OnClickListener clickListener) {
348 | setErrorView(view, clickListener, false);
349 | }
350 |
351 | public void setErrorView(View view, OnClickListener clickListener, boolean invalidateView) {
352 | if (view == null) {
353 | throw new IllegalArgumentException("View must not be null.");
354 | }
355 | mErrorView = view;
356 | mErrorView.setOnClickListener(clickListener);
357 | isInvalidateView = invalidateView;
358 | }
359 |
360 | public void setErrorView(int resId, OnClickListener clickListener) {
361 | setErrorView(resId, clickListener, false);
362 | }
363 |
364 | public void setErrorView(int resId, OnClickListener clickListener, boolean invalidateView) {
365 | if (resId <= 0) {
366 | throw new IllegalArgumentException("View resource id must be greater than 0.");
367 | }
368 | mErrorView = mLayoutInflater.inflate(resId, null);
369 | mErrorView.setOnClickListener(clickListener);
370 | isInvalidateView = invalidateView;
371 | }
372 |
373 | public void setErrorViewClickListener(OnClickListener clickListener) {
374 | if (mErrorView == null) {
375 | throw new IllegalStateException("Error view is null. Cannot set click listener.");
376 | }
377 | mErrorView.setOnClickListener(clickListener);
378 | }
379 |
380 | //================================================================================
381 | // State Handling
382 | //================================================================================
383 |
384 | public static enum State {
385 | LOADING,
386 | EMPTY,
387 | ERROR
388 | }
389 |
390 | public void showLoadingView() {
391 | showView(State.LOADING);
392 | }
393 |
394 | public void showEmptyView() {
395 | showView(State.EMPTY);
396 | }
397 |
398 | public void showErrorView() {
399 | showView(State.ERROR);
400 | }
401 |
402 | public void showView(State state) {
403 | if (isInitViews || isInvalidateView) {
404 | initViews();
405 | isInitViews = isInvalidateView = false;
406 | }
407 |
408 | boolean showLoadingView = false;
409 | boolean showEmptyView = false;
410 | boolean showErrorView = false;
411 |
412 | switch (state) {
413 | case LOADING:
414 | showLoadingView = true;
415 | break;
416 | case EMPTY:
417 | showEmptyView = true;
418 | break;
419 | case ERROR:
420 | showErrorView = true;
421 | break;
422 | }
423 |
424 | if (mLoadingView != null) {
425 | mLoadingView.setVisibility(showLoadingView ? View.VISIBLE : View.GONE);
426 | }
427 |
428 | if (mEmptyView != null) {
429 | mEmptyView.setVisibility(showEmptyView ? View.VISIBLE : View.GONE);
430 | }
431 |
432 | if (mErrorView != null) {
433 | mErrorView.setVisibility(showErrorView ? View.VISIBLE : View.GONE);
434 | }
435 | }
436 |
437 | private void initViews() {
438 | ViewGroup parent = (ViewGroup) getParent();
439 | if (parent == null) {
440 | throw new IllegalStateException(getClass().getSimpleName() + " is not attached to parent view.");
441 | }
442 |
443 | ViewGroup container = getContainerView(parent);
444 | container.removeAllViews();
445 |
446 | parent.removeView(container);
447 | parent.addView(container);
448 |
449 | if (mLoadingView != null) {
450 | container.addView(mLoadingView);
451 | }
452 |
453 | if (mEmptyView != null) {
454 | container.addView(mEmptyView);
455 | }
456 |
457 | if (mErrorView != null) {
458 | container.addView(mErrorView);
459 | }
460 |
461 | super.setEmptyView(container);
462 | }
463 |
464 | private ViewGroup getContainerView(ViewGroup parent) {
465 | ViewGroup container = findContainerView(parent);
466 | if (container == null) {
467 | container = createContainerView();
468 | }
469 | return container;
470 | }
471 |
472 | private ViewGroup findContainerView(ViewGroup parent) {
473 | return (ViewGroup) parent.findViewWithTag(VIEW_TAG);
474 | }
475 |
476 | private ViewGroup createContainerView() {
477 | AbsListView.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
478 | FrameLayout container = new FrameLayout(getContext());
479 | container.setTag(VIEW_TAG);
480 | container.setLayoutParams(lp);
481 | return container;
482 | }
483 |
484 | public void setEmptyViewMsg(String msg) {
485 | if (mEmptyMsgView != null) {
486 | mEmptyMsgView.setText(msg);
487 | }
488 | }
489 |
490 | public void setEmptyViewMsg(int resId) {
491 | if (mEmptyMsgView != null) {
492 | mEmptyMsgView.setText(resId);
493 | }
494 | }
495 |
496 | public void setErrorViewMsg(String msg) {
497 | if (mErrorMsgView != null) {
498 | mErrorMsgView.setText(msg);
499 | }
500 | }
501 |
502 | public void setErrorViewMsg(int resId) {
503 | if (mErrorMsgView != null) {
504 | mErrorMsgView.setText(resId);
505 | }
506 | }
507 |
508 | public void setEmptyButtonListener(OnClickListener listener) {
509 | if (mEmptyButton != null) {
510 | mEmptyButton.setOnClickListener(listener);
511 | }
512 | }
513 |
514 | public void setErrorButtonListener(OnClickListener listener) {
515 | if (mErrorButton != null) {
516 | mErrorButton.setOnClickListener(listener);
517 | }
518 | }
519 |
520 | }
521 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_fragment_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_home.xml:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_pull_to_refresh_base_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_recycle_refresh_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_empty_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_error_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_loading_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_home.xml:
--------------------------------------------------------------------------------
1 |
3 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #E91E63
5 | #C2185B
6 | #F8BBD0
7 | #536dfe
8 | #ff3e5efe
9 | #212121
10 | #727272
11 | #FFFFFF
12 | #B6B6B6
13 |
14 | #ffffffff
15 | #ff000000
16 | #ffffff
17 | #eeffffff
18 | #B2000000
19 |
20 | #ff00ddff
21 | #ff99cc00
22 | #ffffbb33
23 | #ffff4444
24 |
25 | #00000000
26 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 掌上eap
5 | Hello world!
6 | Settings
7 | 没有数据
8 | 重试
9 | 服务器或网络错误
10 | 正在加载..
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
16 |
17 |
21 |
22 |
27 |
28 |
33 |
34 |
38 |
39 |
43 |
44 |
48 |
49 |
57 |
58 |
67 |
68 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/art/art.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/art/art.jpg
--------------------------------------------------------------------------------
/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 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/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_BUILD_COMPILE_SDK_VERSION=21
20 | ANDROID_BUILD_TARGET_SDK_VERSION=21
21 | ANDROID_BUILD_TOOLS_VERSION=22.0.1
22 | MIN_SDK_VERSION=14
23 | TARGET_SDK_VERSION=21
24 | VERSION_CODE=100
25 | VERSION_NAME=1.0.0
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jan 05 14:14:51 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-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------