data) {
52 | super(context, layoutResId, data);
53 | }
54 |
55 | protected BaseAdapterHelper getAdapterHelper(int position, View convertView, ViewGroup parent) {
56 | return get(context, convertView, parent, layoutResId, position);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/java/com/cniao5/cwidgetutils/AutoGallery.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.cwidgetutils;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.KeyEvent;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 | import android.widget.Gallery;
9 |
10 | import java.util.Timer;
11 | import java.util.TimerTask;
12 |
13 |
14 | public class AutoGallery extends Gallery implements View.OnTouchListener {
15 | //画廊图片的数量
16 | private int length;
17 | //自动切换图片的时间
18 | private long delayMillis = 5000;
19 | //定时器
20 | private Timer timer = null;
21 |
22 | public AutoGallery(Context context) {
23 | super(context);
24 | setOnTouchListener(this);
25 | }
26 |
27 | public AutoGallery(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | setOnTouchListener(this);
30 | }
31 |
32 | public AutoGallery(Context context, AttributeSet attrs, int defStyle) {
33 | super(context, attrs, defStyle);
34 | setOnTouchListener(this);
35 | }
36 |
37 | public int getLength() {
38 | return this.length;
39 | }
40 |
41 | public void setLength(int length) {
42 | this.length = length;
43 | }
44 |
45 | public void setDelayMillis(long delayMillis) {
46 | this.delayMillis = delayMillis;
47 | }
48 |
49 | /**
50 | * 重写Galler中手指滑动的手势方法
51 | * @param e1
52 | * @param e2
53 | * @param velocityX
54 | * @param velocityY
55 | * @return
56 | */
57 | @Override
58 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
59 | float velocityY) {
60 | int kEvent;
61 | if (isScrollingLeft(e1, e2)) {
62 | kEvent = KeyEvent.KEYCODE_DPAD_LEFT; //设置手势滑动的方法 --向左
63 | } else {
64 | kEvent = KeyEvent.KEYCODE_DPAD_RIGHT; //设置手势滑动的方法--向右
65 | }
66 | onKeyDown(kEvent, null); //进行设置galler切换图片
67 | if (this.getSelectedItemPosition() == 0) {
68 | this.setSelection(length);
69 | }
70 | return false;
71 | }
72 |
73 | /**
74 | * 进行判断滑动方向
75 | * @param e1
76 | * @param e2
77 | * @return
78 | */
79 | private boolean isScrollingLeft(MotionEvent e1, MotionEvent e2) {
80 | return e2.getX() > e1.getX();
81 | }
82 |
83 | /**
84 | * 开启定时器
85 | */
86 | public void start() {
87 | if (length > 0&&timer == null) {
88 | timer = new Timer();
89 | //进行每个delayMillis时间gallery切换一张图片
90 | timer.scheduleAtFixedRate(new TimerTask() {
91 | @Override
92 | public void run() {
93 | if (length > 0) {
94 | onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
95 | }
96 | }
97 | }, delayMillis, delayMillis);
98 | }
99 | }
100 |
101 | /**
102 | * 关闭定时器
103 | */
104 | public void stop() {
105 | if (timer != null) {
106 | timer.cancel();
107 | timer = null;
108 | }
109 | }
110 |
111 | /**
112 | * 重写手指触摸的事件,当手指按下的时候,需要关闭gallery自动切换
113 | * 当手指抬开得时候 需要打开gallery自动切换功能
114 | * @param v
115 | * @param event
116 | * @return
117 | */
118 | @Override
119 | public boolean onTouch(View v, MotionEvent event) {
120 | switch (event.getAction()) {
121 | case MotionEvent.ACTION_DOWN:
122 | stop();
123 | break;
124 | case MotionEvent.ACTION_UP:
125 | case MotionEvent.ACTION_CANCEL:
126 | start();
127 | break;
128 | }
129 | return false;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/java/com/cniao5/cwidgetutils/FlowIndicator.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.cwidgetutils;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.graphics.Paint.Style;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.View;
13 |
14 |
15 | /**
16 | * 自动播放Gallery指示器
17 | * @author jiangqq
18 | *
19 | */
20 | public class FlowIndicator extends View {
21 | private static final String TAG_FLOWINDICATOR="FlowIndicator";
22 | private int count;
23 | private float space, radius;
24 | private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
25 | private Bitmap bmp_selected, bmp_normal;
26 | // 选中
27 | private int seleted = 0;
28 |
29 | public FlowIndicator(Context context, AttributeSet attrs) {
30 | super(context, attrs);
31 | TypedArray a = context.obtainStyledAttributes(attrs,
32 | R.styleable.FlowIndicator);
33 | //小圆点数量
34 | count = a.getInteger(R.styleable.FlowIndicator_count, 4);
35 | //每个小圆点间隔距离
36 | space = a.getDimension(R.styleable.FlowIndicator_space, 4);
37 | //小圆点半径
38 | radius = a.getDimension(R.styleable.FlowIndicator_radius, 7);
39 | //正常 没有选中的图片
40 | bmp_normal = BitmapFactory.decodeResource(getResources(),
41 | R.drawable.hui);
42 | //选中的图片
43 | bmp_selected = BitmapFactory.decodeResource(getResources(),
44 | R.drawable.lan);
45 | a.recycle();
46 | }
47 |
48 | //当前选中的索引,并且重绘指示器view
49 | public void setSeletion(int index) {
50 | this.seleted = index;
51 | invalidate();
52 | }
53 | //设置指示器的数量
54 | public void setCount(int count) {
55 | this.count = count;
56 | invalidate();
57 | }
58 | //设置指示器 下一个圆点
59 | public void next() {
60 | if (seleted < count - 1)
61 | seleted++;
62 | else
63 | seleted = 0;
64 | invalidate();
65 | }
66 | //设置指示器 前一个圆点
67 | public void previous() {
68 | if (seleted > 0)
69 | seleted--;
70 | else
71 | seleted = count - 1;
72 | invalidate();
73 | }
74 |
75 | /**
76 | * 重写绘制指示器view
77 | * @param canvas
78 | */
79 | @Override
80 | protected void onDraw(Canvas canvas) {
81 | super.onDraw(canvas);
82 | float width = (getWidth() - ((radius * 2 * count) + (space * (count - 1)))) / 2.f;
83 | Log.d(TAG_FLOWINDICATOR, "当前选中的为:" + this.seleted);
84 | for (int i = 0; i < count; i++) {
85 | if (i == seleted) {
86 | paint.setStyle(Style.FILL);
87 | canvas.drawBitmap(bmp_selected, 130+width + getPaddingLeft()
88 | + radius + i * (space + radius + radius), 0, null);
89 | } else {
90 | paint.setStyle(Style.FILL);
91 | canvas.drawBitmap(bmp_normal, 130+width + getPaddingLeft() + radius
92 | + i * (space + radius + radius), 0, null);
93 | }
94 | }
95 | }
96 |
97 | /**
98 | * 进行view大小的测量
99 | * @param widthMeasureSpec
100 | * @param heightMeasureSpec
101 | */
102 | @Override
103 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
104 | setMeasuredDimension(measureWidth(widthMeasureSpec),
105 | measureHeight(heightMeasureSpec));
106 | }
107 |
108 |
109 | private int measureWidth(int measureSpec) {
110 | int result = 0;
111 | int specMode = MeasureSpec.getMode(measureSpec);
112 | int specSize = MeasureSpec.getSize(measureSpec);
113 |
114 | if (specMode == MeasureSpec.EXACTLY) {
115 | result = specSize;
116 | } else {
117 | result = (int) (getPaddingLeft() + getPaddingRight()
118 | + (count * 2 * radius) + (count - 1) * radius + 1);
119 | if (specMode == MeasureSpec.AT_MOST) {
120 | result = Math.min(result, specSize);
121 | }
122 | }
123 | return result;
124 | }
125 |
126 | private int measureHeight(int measureSpec) {
127 | int result = 0;
128 | int specMode = MeasureSpec.getMode(measureSpec);
129 | int specSize = MeasureSpec.getSize(measureSpec);
130 |
131 | if (specMode == MeasureSpec.EXACTLY) {
132 | result = specSize;
133 | } else {
134 | result = (int) (2 * radius + getPaddingTop() + getPaddingBottom() + 1);
135 | if (specMode == MeasureSpec.AT_MOST) {
136 | result = Math.min(result, specSize);
137 | }
138 | }
139 | return result;
140 | }
141 | }
--------------------------------------------------------------------------------
/cwidgetutil/src/main/java/com/cniao5/cwidgetutils/PullToRefreshListView.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.cwidgetutils;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.Log;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.view.animation.LinearInterpolator;
10 | import android.view.animation.RotateAnimation;
11 | import android.widget.AbsListView;
12 | import android.widget.AbsListView.OnScrollListener;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 | import android.widget.ListView;
16 | import android.widget.ProgressBar;
17 | import android.widget.TextView;
18 |
19 |
20 | /**
21 | * 当前类注释:
22 | * ProjectName:App36Kr
23 | * Author:菜鸟窝
24 | * Description:
25 | * 菜鸟窝是一个只专注做Android开发技能的在线学习平台,课程以实战项目为主,对课程与服务”吹毛求疵”般的要求,
26 | * 打造极致课程,是菜鸟窝不变的承诺
27 | */
28 | public class PullToRefreshListView extends ListView implements OnScrollListener, OnClickListener {
29 | /**
30 | * 下拉状态
31 | */
32 | private static final int PULL_TO_REFRESH = 1; //下拉-默认为初始状态 准备下拉刷新
33 | private static final int RELEASE_TO_REFRESH = 2; //释放刷新
34 | private static final int REFRESHING = 3; //正在刷新
35 |
36 | private static final String TAG = "PullRefreshListView";
37 |
38 | private OnRefreshListener mOnRefreshListener;
39 |
40 | /**
41 | * 组件滑动监听器 scroll 当view在进行下拉滑动的时候,判断滑动的距离,
42 | * 如果达到可以进行刷新的临界点时候,回调当前接口中的方法
43 | * Listener that will receive notifications every time the list scrolls.
44 | */
45 | private OnScrollListener mOnScrollListener;
46 |
47 | //下拉刷新的的头部view
48 | private LinearLayout mRefreshView;
49 | private ImageView mRefreshViewImage;
50 | private ProgressBar mRefreshViewProgress;
51 | private TextView mRefreshViewText;
52 | private TextView mRefreshViewLastUpdated;
53 |
54 |
55 | private int mRefreshState;
56 | private int mCurrentScrollState;
57 |
58 | private RotateAnimation mFlipAnimation;
59 | private RotateAnimation mReverseFlipAnimation;
60 |
61 | private int mRefreshViewHeight;
62 | private int mRefreshOriginalTopPadding;
63 | private int mLastMotionY;
64 |
65 | public PullToRefreshListView(Context context) {
66 | super(context);
67 | init(context);
68 | }
69 |
70 | public PullToRefreshListView(Context context, AttributeSet attrs) {
71 | super(context, attrs);
72 | init(context);
73 | }
74 |
75 | private void init(Context context) {
76 | mFlipAnimation = new RotateAnimation(0, -180,
77 | RotateAnimation.RELATIVE_TO_SELF, 0.5f,
78 | RotateAnimation.RELATIVE_TO_SELF, 0.5f);
79 | mFlipAnimation.setInterpolator(new LinearInterpolator());
80 | mFlipAnimation.setDuration(250);
81 | mFlipAnimation.setFillAfter(true);
82 | mReverseFlipAnimation = new RotateAnimation(-180, 0,
83 | RotateAnimation.RELATIVE_TO_SELF, 0.5f,
84 | RotateAnimation.RELATIVE_TO_SELF, 0.5f);
85 | mReverseFlipAnimation.setInterpolator(new LinearInterpolator());
86 | mReverseFlipAnimation.setDuration(250);
87 | mReverseFlipAnimation.setFillAfter(true);
88 |
89 | mRefreshView = (LinearLayout) View.inflate(context, R.layout.pull_to_refresh_header, null);
90 | mRefreshViewText = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text);
91 | mRefreshViewImage = (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image);
92 | mRefreshViewProgress = (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress);
93 | mRefreshViewLastUpdated = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_updated_at);
94 |
95 | mRefreshState = PULL_TO_REFRESH;
96 | mRefreshViewImage.setMinimumHeight(50); //设置下拉最小的高度为50
97 |
98 | setFadingEdgeLength(0);
99 | setHeaderDividersEnabled(false);
100 |
101 | //把refreshview加入到listview的头部
102 | addHeaderView(mRefreshView);
103 | super.setOnScrollListener(this);
104 | mRefreshView.setOnClickListener(this);
105 |
106 | mRefreshView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
107 | mRefreshViewHeight = mRefreshView.getMeasuredHeight();
108 | mRefreshOriginalTopPadding = -mRefreshViewHeight;
109 |
110 | resetHeaderPadding();
111 | }
112 |
113 | /**
114 | * Set the listener that will receive notifications every time the list scrolls.
115 | *
116 | * @param l The scroll listener.
117 | */
118 | @Override
119 | public void setOnScrollListener(OnScrollListener l) {
120 | mOnScrollListener = l;
121 | }
122 |
123 | /**
124 | * 注册listview下拉刷新回到接口
125 | * Register a callback to be invoked when this list should be refreshed.
126 | *
127 | * @param onRefreshListener The callback to run.
128 | */
129 | public void setOnRefreshListener(OnRefreshListener onRefreshListener) {
130 | mOnRefreshListener = onRefreshListener;
131 | }
132 |
133 | /**
134 | * 进行设置设置上一次更新的时候
135 | *
136 | * Set a text to represent when the list was last updated.
137 | * @param lastUpdated Last updated at.
138 | */
139 | public void setLastUpdated(CharSequence lastUpdated) {
140 | if (lastUpdated != null) {
141 | mRefreshViewLastUpdated.setVisibility(View.VISIBLE);
142 | mRefreshViewLastUpdated.setText(lastUpdated);
143 | } else {
144 | mRefreshViewLastUpdated.setVisibility(View.GONE);
145 | }
146 | }
147 |
148 | /**
149 | * touch事件处理
150 | * @param event
151 | * @return
152 | */
153 | @Override
154 | public boolean onTouchEvent(MotionEvent event) {
155 | final int y = (int) event.getY();
156 | switch (event.getAction()) {
157 | case MotionEvent.ACTION_DOWN:
158 | mLastMotionY = y;
159 | break;
160 | case MotionEvent.ACTION_MOVE:
161 | int offsetY = (int) event.getY();
162 | int deltY = Math.round(offsetY - mLastMotionY);
163 | mLastMotionY = offsetY;
164 |
165 | if (getFirstVisiblePosition() == 0 && mRefreshState != REFRESHING) {
166 | deltY = deltY / 2;
167 | mRefreshOriginalTopPadding += deltY;
168 | if (mRefreshOriginalTopPadding < -mRefreshViewHeight) {
169 | mRefreshOriginalTopPadding = -mRefreshViewHeight;
170 | }
171 | resetHeaderPadding();
172 | }
173 | break;
174 | case MotionEvent.ACTION_UP:
175 | //当手指抬开得时候 进行判断下拉的距离 ,如果>=临界值,那么进行刷洗,否则回归原位
176 | if (!isVerticalScrollBarEnabled()) {
177 | setVerticalScrollBarEnabled(true);
178 | }
179 | if (getFirstVisiblePosition() == 0 && mRefreshState != REFRESHING) {
180 | if (mRefreshView.getBottom() >= mRefreshViewHeight
181 | && mRefreshState == RELEASE_TO_REFRESH) {
182 | //准备开始刷新
183 | prepareForRefresh();
184 | } else {
185 | // Abort refresh
186 | resetHeader();
187 | }
188 | }
189 | break;
190 | }
191 | return super.onTouchEvent(event);
192 | }
193 |
194 | @Override
195 | public void onScroll(AbsListView view, int firstVisibleItem,
196 | int visibleItemCount, int totalItemCount) {
197 | if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING) {
198 | if (firstVisibleItem == 0) {
199 | if ((mRefreshView.getBottom() >= mRefreshViewHeight)
200 | && mRefreshState != RELEASE_TO_REFRESH) {
201 | mRefreshViewText.setText(R.string.pull_to_refresh_release_label_it);
202 | mRefreshViewImage.clearAnimation();
203 | mRefreshViewImage.startAnimation(mFlipAnimation);
204 | mRefreshState = RELEASE_TO_REFRESH;
205 | } else if (mRefreshView.getBottom() < mRefreshViewHeight
206 | && mRefreshState != PULL_TO_REFRESH) {
207 | mRefreshViewText.setText(R.string.pull_to_refresh_pull_label_it);
208 | mRefreshViewImage.clearAnimation();
209 | mRefreshViewImage.startAnimation(mReverseFlipAnimation);
210 | mRefreshState = PULL_TO_REFRESH;
211 | }
212 | }
213 | }
214 |
215 | if (mOnScrollListener != null) {
216 | mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
217 | }
218 | }
219 |
220 | @Override
221 | public void onScrollStateChanged(AbsListView view, int scrollState) {
222 | mCurrentScrollState = scrollState;
223 |
224 | if (mOnScrollListener != null) {
225 | mOnScrollListener.onScrollStateChanged(view, scrollState);
226 | }
227 | }
228 |
229 | /**
230 | * Sets the header padding back to original size.
231 | */
232 | private void resetHeaderPadding() {
233 | mRefreshView.setPadding(
234 | mRefreshView.getPaddingLeft(),
235 | mRefreshOriginalTopPadding,
236 | mRefreshView.getPaddingRight(),
237 | mRefreshView.getPaddingBottom());
238 | }
239 |
240 | public void prepareForRefresh() {
241 | if (mRefreshState != REFRESHING) {
242 | mRefreshState = REFRESHING;
243 |
244 | mRefreshOriginalTopPadding = 0;
245 | resetHeaderPadding();
246 |
247 | mRefreshViewImage.clearAnimation();
248 | mRefreshViewImage.setVisibility(View.GONE);
249 | mRefreshViewProgress.setVisibility(View.VISIBLE);
250 | mRefreshViewText.setText(R.string.pull_to_refresh_refreshing_label_it);
251 |
252 | onRefresh();
253 | }
254 | }
255 |
256 | private void resetHeader() {
257 | mRefreshState = PULL_TO_REFRESH;
258 |
259 | mRefreshOriginalTopPadding = -mRefreshViewHeight;
260 | resetHeaderPadding();
261 |
262 | mRefreshViewImage.clearAnimation();
263 | mRefreshViewImage.setVisibility(View.VISIBLE);
264 | mRefreshViewProgress.setVisibility(View.GONE);
265 | mRefreshViewText.setText(R.string.pull_to_refresh_pull_label_it);
266 | }
267 |
268 | /**
269 | * 开始回调刷新
270 | */
271 | public void onRefresh() {
272 | Log.d(TAG, "onRefresh");
273 | if (mOnRefreshListener != null) {
274 | mOnRefreshListener.onRefresh();
275 | }
276 | }
277 |
278 | /**
279 | * Resets the list to a normal state after a refresh.
280 | */
281 | public void onRefreshComplete() {
282 | Log.d(TAG, "onRefreshComplete");
283 |
284 | resetHeader();
285 | }
286 |
287 | @Override
288 | public void onClick(View v) {
289 | Log.d(TAG, "onClick");
290 | }
291 |
292 | /**
293 | * Interface definition for a callback to be invoked when list should be
294 | * refreshed.
295 | */
296 | public interface OnRefreshListener {
297 | /**
298 | * Called when the list should be refreshed.
299 | *
300 | * A call to {@link PullToRefreshListView #onRefreshComplete()} is
301 | * expected to indicate that the refresh has completed.
302 | */
303 | public void onRefresh();
304 | }
305 | }
306 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/java/com/cniao5/utils/SharedPreferencesHelper.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.utils;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * 当前类注释:当前为SharedPerferences进行封装基本的方法,SharedPerferences已经封装成单例模式
8 | * 可以通过SharedPreferences sp=SharedPreferencesHelper.getInstances(FDApplication.getInstance())进行获取当前对象
9 | * sp.putStringValue(key,value)进行使用
10 | * 项目名:FastDev4Android
11 | * 包名:com.chinaztt.fda.spreference
12 | * 作者:江清清 on 15/10/22 09:25
13 | * 邮箱:jiangqqlmj@163.com
14 | * QQ: 781931404
15 | * 公司:江苏中天科技软件技术有限公司
16 | */
17 | public class SharedPreferencesHelper {
18 | private static final String SHARED_PATH = "fda_shared";
19 | private static SharedPreferencesHelper instance;
20 | private SharedPreferences sp;
21 | private SharedPreferences.Editor editor;
22 |
23 | public static SharedPreferencesHelper getInstance(Context context) {
24 | if (instance == null && context != null) {
25 | instance = new SharedPreferencesHelper(context);
26 | }
27 | return instance;
28 | }
29 |
30 | private SharedPreferencesHelper(Context context) {
31 | sp = context.getSharedPreferences(SHARED_PATH, Context.MODE_PRIVATE);
32 | editor = sp.edit();
33 | }
34 |
35 | public long getLongValue(String key) {
36 | if (key != null && !key.equals("")) {
37 | return sp.getLong(key, 0);
38 | }
39 | return 0;
40 | }
41 |
42 | public String getStringValue(String key) {
43 | if (key != null && !key.equals("")) {
44 | return sp.getString(key, null);
45 | }
46 | return null;
47 | }
48 |
49 | public int getIntValue(String key) {
50 | if (key != null && !key.equals("")) {
51 | return sp.getInt(key, 0);
52 | }
53 | return 0;
54 | }
55 |
56 | public int getIntValueByDefault(String key)
57 | {
58 | if (key != null && !key.equals("")) {
59 | return sp.getInt(key, 0);
60 | }
61 | return 0;
62 | }
63 | public boolean getBooleanValue(String key) {
64 | if (key != null && !key.equals("")) {
65 | return sp.getBoolean(key, false);
66 | }
67 | return true;
68 | }
69 |
70 | public float getFloatValue(String key) {
71 | if (key != null && !key.equals("")) {
72 | return sp.getFloat(key, 0);
73 | }
74 | return 0;
75 | }
76 |
77 | public void putStringValue(String key, String value) {
78 | if (key != null && !key.equals("")) {
79 | editor = sp.edit();
80 | editor.putString(key, value);
81 | editor.commit();
82 | }
83 | }
84 |
85 | public void putIntValue(String key, int value) {
86 | if (key != null && !key.equals("")) {
87 | editor = sp.edit();
88 | editor.putInt(key, value);
89 | editor.commit();
90 | }
91 | }
92 |
93 | public void putBooleanValue(String key, boolean value) {
94 | if (key != null && !key.equals("")) {
95 | editor = sp.edit();
96 | editor.putBoolean(key, value);
97 | editor.commit();
98 | }
99 | }
100 |
101 | public void putLongValue(String key, long value) {
102 | if (key != null && !key.equals("")) {
103 | editor = sp.edit();
104 | editor.putLong(key, value);
105 | editor.commit();
106 | }
107 | }
108 |
109 | public void putFloatValue(String key, Float value) {
110 | if (key != null && !key.equals("")) {
111 | editor = sp.edit();
112 | editor.putFloat(key, value);
113 | editor.commit();
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/java/com/cniao5/utils/SharedPreferencesTag.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.utils;
2 |
3 | /**
4 | * 当前类注释:当前类用户SharedPreferences进行save的时候 配置key常量
5 | * 项目名:FastDev4Android
6 | * 包名:com.chinaztt.fda.spreference
7 | * 作者:江清清 on 15/10/22 09:26
8 | * 邮箱:jiangqqlmj@163.com
9 | * QQ: 781931404
10 | * 公司:江苏中天科技软件技术有限公司
11 | */
12 | public class SharedPreferencesTag {
13 | public static final String DEMO_KEY="demo_key";
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/java/com/cniao5/utils/UIUtils.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 |
6 | import com.cniao5.cwidgetutils.PullToRefreshListView;
7 |
8 | import java.text.SimpleDateFormat;
9 | import java.util.Calendar;
10 |
11 | /**
12 | * 当前类注释:
13 | * ProjectName:App36Kr
14 | * Author:菜鸟窝
15 | * Description:
16 | * 菜鸟窝是一个只专注做Android开发技能的在线学习平台,课程以实战项目为主,对课程与服务”吹毛求疵”般的要求,
17 | * 打造极致课程,是菜鸟窝不变的承诺
18 | */
19 | public class UIUtils {
20 |
21 | /**
22 | * 设置上次更新数据时间
23 | * @param listView
24 | * @param key key表示具体某个列表
25 | */
26 | public static void setPullToRefreshLastUpdated(PullToRefreshListView listView, String key,Context pContext) {
27 | SharedPreferencesHelper spHelper = SharedPreferencesHelper.getInstance(pContext);
28 | long lastUpdateTimeStamp = spHelper.getLongValue(key);
29 | listView.setLastUpdated(getUpdateTimeString(lastUpdateTimeStamp));
30 | }
31 |
32 | /**
33 | * 保存更新数据时间
34 | * @param listView
35 | * @param key key表示具体某个列表
36 | */
37 | public static void savePullToRefreshLastUpdateAt(PullToRefreshListView listView, String key,Context pContext) {
38 | listView.onRefreshComplete();
39 | SharedPreferencesHelper spHelper = SharedPreferencesHelper.getInstance(pContext);
40 | long lastUpdateTimeStamp=System.currentTimeMillis();
41 | spHelper.putLongValue(key, lastUpdateTimeStamp);
42 | listView.setLastUpdated(getUpdateTimeString(lastUpdateTimeStamp));
43 | }
44 |
45 | /**
46 | * 更新时间字符串
47 | * @param timestamp
48 | * @return
49 | */
50 | @SuppressLint("SimpleDateFormat")
51 | public static String getUpdateTimeString(long timestamp) {
52 | if (timestamp <= 0) {
53 | return "上次更新时间:";
54 | } else {
55 | String textDate = "上次更新时间:";
56 | Calendar now = Calendar.getInstance();
57 | Calendar c = Calendar.getInstance();
58 | c.setTimeInMillis(timestamp);
59 | if (c.get(Calendar.YEAR) == now.get(Calendar.YEAR)
60 | && c.get(Calendar.MONTH) == now.get(Calendar.MONTH)
61 | && c.get(Calendar.DATE) == now.get(Calendar.DATE)) {
62 | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
63 | return textDate += sdf.format(c.getTime());
64 | } else if (c.get(Calendar.YEAR) == now.get(Calendar.YEAR)) {
65 | SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm");
66 | return textDate += sdf.format(c.getTime());
67 | } else {
68 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
69 | return textDate += sdf.format(c.getTime());
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/anim/ic_loading_refresh.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/drawable-hdpi/hui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/cwidgetutil/src/main/res/drawable-hdpi/hui.png
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/drawable-hdpi/ic_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/cwidgetutil/src/main/res/drawable-hdpi/ic_loading.png
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/drawable-hdpi/ic_refresh_down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/cwidgetutil/src/main/res/drawable-hdpi/ic_refresh_down.png
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/drawable-hdpi/lan.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/cwidgetutil/src/main/res/drawable-hdpi/lan.png
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/layout/pull_to_refresh_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
12 |
18 |
27 |
36 |
37 |
47 |
57 |
58 |
61 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/cwidgetutil/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CWidgetUtil
3 |
4 | 下拉可以刷新
5 | 松开即可刷新
6 | 正在刷新数据...
7 | 上次更新时间:%1$s
8 | 向下拉动可以刷新
9 | 松开可以刷新
10 | 加载中…
11 | 点击刷新
12 |
13 |
--------------------------------------------------------------------------------
/cwidgetutil/src/test/java/com/cniao5/cwidgetutils/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.cniao5.cwidgetutils;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 25 15:21:57 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.4-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 |
--------------------------------------------------------------------------------
/pull_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/pull_1.gif
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-07-12-35-53.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-07-12-35-53.png
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-07-12-36-11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-07-12-36-11.png
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-07-12-36-18.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-07-12-36-18.png
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-07-12-38-19.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-07-12-38-19.png
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-08-08-11-57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-08-08-11-57.png
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-08-08-12-03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-08-08-12-03.png
--------------------------------------------------------------------------------
/screenshot/Screenshot_2015-12-08-08-12-08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/Screenshot_2015-12-08-08-12-08.png
--------------------------------------------------------------------------------
/screenshot/cniaonews.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/cniaonews.gif
--------------------------------------------------------------------------------
/screenshot/pull_4 (2).gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yxs666/cniao5-news/b9d9ec83aa9869f99a77531a49ea2d15b462ebbf/screenshot/pull_4 (2).gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':cwidgetutil'
2 |
--------------------------------------------------------------------------------