", "");
138 | webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "UTF-8", null);
139 | resultRepository.removeUpdatable(this);
140 | }
141 | });
142 | } else {
143 | webView.loadData(value.getBody(), "text/html", "utf-8");
144 | }
145 | }
146 | });
147 | }
148 | }
149 |
150 | class NewsDetailSupplier implements Supplier
> {
151 |
152 | String key;
153 |
154 | public void setKey(String key) {
155 | this.key = key;
156 |
157 | }
158 |
159 | @NonNull
160 | @Override
161 | public Result get() {
162 | NewsDetailResponse newsDetailResponse = null;
163 | try {
164 | newsDetailResponse = AppClient.httpService.getNewsDetail(key).execute().body();
165 | } catch (IOException e) {
166 | e.printStackTrace();
167 | }
168 | if (newsDetailResponse == null) {
169 | return Result.failure();
170 | } else {
171 | return Result.success(newsDetailResponse);
172 | }
173 | }
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/NewsDetailResponse.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by erfli on 6/16/16.
7 | */
8 | public class NewsDetailResponse {
9 | private String body;
10 |
11 | private String image_source;
12 |
13 | private String title;
14 |
15 | private String image;
16 |
17 | private String share_url;
18 |
19 | private List js ;
20 |
21 | private String ga_prefix;
22 |
23 | private List images ;
24 |
25 | private int type;
26 |
27 | private int id;
28 |
29 | private List css ;
30 |
31 | public void setBody(String body){
32 | this.body = body;
33 | }
34 | public String getBody(){
35 | return this.body;
36 | }
37 | public void setImage_source(String image_source){
38 | this.image_source = image_source;
39 | }
40 | public String getImage_source(){
41 | return this.image_source;
42 | }
43 | public void setTitle(String title){
44 | this.title = title;
45 | }
46 | public String getTitle(){
47 | return this.title;
48 | }
49 | public void setImage(String image){
50 | this.image = image;
51 | }
52 | public String getImage(){
53 | return this.image;
54 | }
55 | public void setShare_url(String share_url){
56 | this.share_url = share_url;
57 | }
58 | public String getShare_url(){
59 | return this.share_url;
60 | }
61 | public void setJs(List js){
62 | this.js = js;
63 | }
64 | public List getJs(){
65 | return this.js;
66 | }
67 | public void setGa_prefix(String ga_prefix){
68 | this.ga_prefix = ga_prefix;
69 | }
70 | public String getGa_prefix(){
71 | return this.ga_prefix;
72 | }
73 | public void setImages(List images){
74 | this.images = images;
75 | }
76 | public List getImages(){
77 | return this.images;
78 | }
79 | public void setType(int type){
80 | this.type = type;
81 | }
82 | public int getType(){
83 | return this.type;
84 | }
85 | public void setId(int id){
86 | this.id = id;
87 | }
88 | public int getId(){
89 | return this.id;
90 | }
91 | public void setCss(List css){
92 | this.css = css;
93 | }
94 | public List getCss(){
95 | return this.css;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/NewsListActivity.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.v4.app.ActivityCompat;
7 | import android.support.v4.app.ActivityOptionsCompat;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.DefaultItemAnimator;
10 | import android.support.v7.widget.LinearLayoutManager;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.support.v7.widget.Toolbar;
13 | import android.view.View;
14 |
15 | import com.aswifter.material.R;
16 | import com.aswifter.material.common.ThreadPool;
17 | import com.aswifter.material.widget.DividerItemDecoration;
18 | import com.aswifter.material.widget.DividerOffsetDecoration;
19 | import com.aswifter.material.widget.PullToRefreshLayout;
20 | import com.aswifter.material.widget.RecyclerItemClickListener;
21 | import com.aswifter.material.widget.RefreshLayout;
22 | import com.google.android.agera.Receiver;
23 | import com.google.android.agera.Repositories;
24 | import com.google.android.agera.Repository;
25 | import com.google.android.agera.Result;
26 | import com.google.android.agera.Updatable;
27 |
28 | import java.util.ArrayList;
29 | import java.util.Date;
30 | import java.util.List;
31 |
32 | public class NewsListActivity extends AppCompatActivity implements Updatable {
33 |
34 | Repository>> repository;
35 | NewsObservable newsObservable;
36 | Receiver> receiver;
37 | Receiver throwableReceiver;
38 | private RecyclerView mRecyclerView;
39 | private LinearLayoutManager mLayoutManager;
40 | private List myDataset;
41 | private NewsAdapter mAdapter;
42 | RefreshLayout refreshLayout;
43 |
44 | private int page = 0;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_recycler_view);
50 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
51 | toolbar.setTitle(R.string.latest_news);
52 | setSupportActionBar(toolbar);
53 | getSupportActionBar().setHomeButtonEnabled(true);
54 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
55 | toolbar.setNavigationOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View view) {
58 | onBackPressed();
59 | }
60 | });
61 | initRefreshView();
62 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
63 | // use a linear layout manager
64 | mLayoutManager = new LinearLayoutManager(this);
65 | mRecyclerView.setLayoutManager(mLayoutManager);
66 | // mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST).setmDivider(getResources().getDrawable(R.drawable.md_transparent)));
67 | mRecyclerView.addItemDecoration(new DividerOffsetDecoration());
68 | mRecyclerView.setItemAnimator(new DefaultItemAnimator());
69 | initData();
70 | }
71 |
72 | private void initRefreshView(){
73 | refreshLayout = (RefreshLayout) findViewById(R.id.refresh_layout);
74 | refreshLayout.setColorSchemeResources(R.color.google_blue,
75 | R.color.google_green,
76 | R.color.google_red,
77 | R.color.google_yellow);
78 | refreshLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
79 | @Override
80 | public void onRefresh() {
81 | getLatestData();
82 | }
83 | });
84 | refreshLayout.setOnLoadListener(new RefreshLayout.OnLoadListener() {
85 | @Override
86 | public void onLoad() {
87 | getHistoryData();
88 | }
89 | });
90 | }
91 |
92 | private void initData(){
93 | NewsSupplier newsSupplier = new NewsSupplier();
94 | newsObservable = new NewsObservable(newsSupplier);
95 | repository = Repositories.repositoryWithInitialValue(Result.>absent())
96 | .observe(newsObservable)
97 | .onUpdatesPerLoop()
98 | .goTo(ThreadPool.executor)
99 | .thenGetFrom(newsSupplier)
100 | .compile();
101 |
102 | receiver = new Receiver>() {
103 |
104 | @Override
105 | public void accept(@NonNull List value) {
106 | if(page > 1){
107 | mAdapter.addData(value);
108 | }else{
109 | mAdapter.updateData(value);
110 | }
111 | }
112 | };
113 |
114 | throwableReceiver = new Receiver() {
115 | @Override
116 | public void accept(@NonNull Throwable value) {
117 |
118 | }
119 | };
120 | myDataset = new ArrayList<>();
121 | mAdapter = new NewsAdapter(this, myDataset);
122 | mRecyclerView.setAdapter(mAdapter);
123 | mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {
124 | @Override
125 | public void onItemClick(View view, int position) {
126 | Intent intent = new Intent(NewsListActivity.this,NewsDetailActivity.class);
127 | ActivityOptionsCompat options =
128 | ActivityOptionsCompat.makeSceneTransitionAnimation(NewsListActivity.this,
129 | view.findViewById(R.id.news_image), getString(R.string.transition_news_img));
130 | intent.putExtra(NewsDetailActivity.NEWS, mAdapter.getItem(position));
131 | ActivityCompat.startActivity(NewsListActivity.this,intent, options.toBundle());
132 | }
133 | }));
134 | getLatestData();
135 | }
136 |
137 | @Override
138 | public void onResume() {
139 | super.onResume();
140 | repository.addUpdatable(this);
141 | }
142 |
143 |
144 | @Override
145 | public void onPause() {
146 | super.onPause();
147 | repository.removeUpdatable(this);
148 | }
149 |
150 | private void getLatestData() {
151 | newsObservable.refreshNews("");
152 | page = 0;
153 | }
154 |
155 | private void getHistoryData(){
156 | String time = getDateString(new Date());
157 | String key = String.valueOf(Long.valueOf(time) - page);
158 | newsObservable.refreshNews(key);
159 | page+=1;
160 | }
161 |
162 | @Override
163 | public void update() {
164 | refreshLayout.setRefreshing(false);
165 | repository.get().ifFailedSendTo(throwableReceiver).ifSucceededSendTo(receiver);
166 | }
167 |
168 | public static String getDateString(Date date){
169 | String year =(date.getYear()+1900)+"";
170 | String mm = (date.getMonth()+1)+"";
171 | if(Integer.valueOf(mm).intValue()<10){
172 | mm="0"+mm;
173 | }
174 | String day = date.getDate()+"";
175 | if(Integer.valueOf(day).intValue()<10)day="0"+day;
176 | return year+mm+day;
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/NewsObservable.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 | import com.google.android.agera.BaseObservable;
4 |
5 | /**
6 | * Created by erfli on 6/15/16.
7 | */
8 | public class NewsObservable extends BaseObservable{
9 |
10 | NewsSupplier supplier;
11 | public NewsObservable(NewsSupplier supplier){
12 | this.supplier = supplier;
13 | }
14 | public void refreshNews(String key){
15 | supplier.setNewsKey(key);
16 | dispatchUpdate();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/NewsResponse.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 | import java.util.List;
4 |
5 |
6 | public class NewsResponse{
7 | private List stories;
8 | private String date;
9 | public NewsResponse(){
10 |
11 | }
12 |
13 | public void setStories(List stories) {
14 | this.stories = stories;
15 | }
16 |
17 | public List getStories() {
18 | return stories;
19 | }
20 |
21 | public void setDate(String date) {
22 | this.date = date;
23 | }
24 |
25 | public String getDate() {
26 | return date;
27 | }
28 |
29 |
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/NewsSupplier.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.text.TextUtils;
5 |
6 | import com.aswifter.material.common.AppClient;
7 | import com.google.android.agera.Result;
8 | import com.google.android.agera.Supplier;
9 |
10 | import java.io.IOException;
11 | import java.util.List;
12 |
13 | /**
14 | * Created by erfli on 6/15/16.
15 | */
16 | public class NewsSupplier implements Supplier>> {
17 |
18 | private String newsKey = "latest";
19 | @NonNull
20 | @Override
21 | public Result> get() {
22 | List stories = getStoryList();
23 | if(stories == null){
24 | return Result.failure();
25 | }else{
26 | return Result.success(stories);
27 | }
28 | }
29 |
30 | private ListgetStoryList(){
31 | try {
32 | if(TextUtils.isEmpty(newsKey)){
33 | return AppClient.httpService.getLatestNews().execute().body().getStories();
34 | }else
35 | return AppClient.httpService.getHistoryNews(newsKey).execute().body().getStories();
36 | } catch (IOException e) {
37 | e.printStackTrace();
38 | return null;
39 | }
40 | }
41 |
42 | public void setNewsKey(@NonNull String key){
43 | if(TextUtils.isEmpty(key)){
44 | newsKey = "";
45 | }else {
46 | newsKey = key;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/Story.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import java.util.List;
7 |
8 |
9 | public class Story implements Parcelable{
10 |
11 | private static final String FIELD_TYPE = "type";
12 | private static final String FIELD_ID = "id";
13 | private static final String FIELD_GA_PREFIX = "ga_prefix";
14 | private static final String FIELD_IMAGES = "images";
15 | private static final String FIELD_TITLE = "title";
16 |
17 | private int type;
18 | private long id;
19 | private int gaPrefix;
20 | private List images;
21 | private String title;
22 |
23 | protected Story(Parcel in) {
24 | type = in.readInt();
25 | id = in.readLong();
26 | gaPrefix = in.readInt();
27 | images = in.createStringArrayList();
28 | title = in.readString();
29 | }
30 |
31 | public static final Creator CREATOR = new Creator() {
32 | @Override
33 | public Story createFromParcel(Parcel in) {
34 | return new Story(in);
35 | }
36 |
37 | @Override
38 | public Story[] newArray(int size) {
39 | return new Story[size];
40 | }
41 | };
42 |
43 | public void setType(int type) {
44 | this.type = type;
45 | }
46 |
47 | public int getType() {
48 | return type;
49 | }
50 |
51 | public void setId(long id) {
52 | this.id = id;
53 | }
54 |
55 | public long getId() {
56 | return id;
57 | }
58 |
59 | public void setGaPrefix(int gaPrefix) {
60 | this.gaPrefix = gaPrefix;
61 | }
62 |
63 | public int getGaPrefix() {
64 | return gaPrefix;
65 | }
66 |
67 | public void setImages(List images) {
68 | this.images = images;
69 | }
70 |
71 | public List getImages() {
72 | return images;
73 | }
74 |
75 | public void setTitle(String title) {
76 | this.title = title;
77 | }
78 |
79 | public String getTitle() {
80 | return title;
81 | }
82 |
83 | @Override
84 | public boolean equals(Object obj){
85 | if(obj instanceof Story){
86 | return ((Story) obj).getId() == id;
87 | }
88 | return false;
89 | }
90 |
91 | @Override
92 | public int hashCode(){
93 | return ((Long) id).hashCode();
94 | }
95 |
96 |
97 | @Override
98 | public int describeContents() {
99 | return 0;
100 | }
101 |
102 | @Override
103 | public void writeToParcel(Parcel dest, int flags) {
104 | dest.writeInt(type);
105 | dest.writeLong(id);
106 | dest.writeInt(gaPrefix);
107 | dest.writeStringList(images);
108 | dest.writeString(title);
109 | }
110 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/news/TopStory.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.news;
2 |
3 |
4 |
5 | public class TopStory{
6 |
7 | private static final String FIELD_TYPE = "type";
8 | private static final String FIELD_ID = "id";
9 | private static final String FIELD_GA_PREFIX = "ga_prefix";
10 | private static final String FIELD_TITLE = "title";
11 | private static final String FIELD_IMAGE = "image";
12 |
13 |
14 | private int mType;
15 | private long mId;
16 | private int mGaPrefix;
17 | private String mTitle;
18 | private String mImage;
19 |
20 |
21 | public TopStory(){
22 |
23 | }
24 |
25 | public void setType(int type) {
26 | mType = type;
27 | }
28 |
29 | public int getType() {
30 | return mType;
31 | }
32 |
33 | public void setId(long id) {
34 | mId = id;
35 | }
36 |
37 | public long getId() {
38 | return mId;
39 | }
40 |
41 | public void setGaPrefix(int gaPrefix) {
42 | mGaPrefix = gaPrefix;
43 | }
44 |
45 | public int getGaPrefix() {
46 | return mGaPrefix;
47 | }
48 |
49 | public void setTitle(String title) {
50 | mTitle = title;
51 | }
52 |
53 | public String getTitle() {
54 | return mTitle;
55 | }
56 |
57 | public void setImage(String image) {
58 | mImage = image;
59 | }
60 |
61 | public String getImage() {
62 | return mImage;
63 | }
64 |
65 | @Override
66 | public boolean equals(Object obj){
67 | if(obj instanceof TopStory){
68 | return ((TopStory) obj).getId() == mId;
69 | }
70 | return false;
71 | }
72 |
73 | @Override
74 | public int hashCode(){
75 | return ((Long)mId).hashCode();
76 | }
77 |
78 |
79 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/utils/DisplayUtil.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.utils;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 | import android.view.View;
6 | import android.view.WindowManager;
7 |
8 | public class DisplayUtil {
9 |
10 | public static int SCREEN_WIDTH_PIXELS;
11 | public static int SCREEN_HEIGHT_PIXELS;
12 | public static float SCREEN_DENSITY;
13 | public static int SCREEN_WIDTH_DP;
14 | public static int SCREEN_HEIGHT_DP;
15 |
16 | public static void init(Context context) {
17 | if (context == null) {
18 | return;
19 | }
20 | DisplayMetrics dm = new DisplayMetrics();
21 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
22 | wm.getDefaultDisplay().getMetrics(dm);
23 | SCREEN_WIDTH_PIXELS = dm.widthPixels;
24 | SCREEN_HEIGHT_PIXELS = dm.heightPixels;
25 | SCREEN_DENSITY = dm.density;
26 | SCREEN_WIDTH_DP = (int) (SCREEN_WIDTH_PIXELS / dm.density);
27 | SCREEN_HEIGHT_DP = (int) (SCREEN_HEIGHT_PIXELS / dm.density);
28 | }
29 |
30 | public static int dp2px(float dp) {
31 | final float scale = SCREEN_DENSITY;
32 | return (int) (dp * scale + 0.5f);
33 | }
34 |
35 | public static int designedDP2px(float designedDp) {
36 | if (SCREEN_WIDTH_DP != 320) {
37 | designedDp = designedDp * SCREEN_WIDTH_DP / 320f;
38 | }
39 | return dp2px(designedDp);
40 | }
41 |
42 | public static void setPadding(final View view, float left, float top, float right, float bottom) {
43 | view.setPadding(designedDP2px(left), dp2px(top), designedDP2px(right), dp2px(bottom));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/BackHandledFragment.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 |
6 | public abstract class BackHandledFragment extends Fragment {
7 | protected BackHandlerInterface backHandlerInterface;
8 |
9 | public abstract String getTagText();
10 |
11 | public abstract boolean onBackPressed();
12 |
13 | @Override
14 | public void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | if (!(getActivity() instanceof BackHandlerInterface)) {
17 | throw new ClassCastException("Hosting activity must implement BackHandlerInterface");
18 | } else {
19 | backHandlerInterface = (BackHandlerInterface) getActivity();
20 | }
21 | }
22 |
23 | @Override
24 | public void onStart() {
25 | super.onStart();
26 |
27 | // Mark this fragment as the selected Fragment.
28 | backHandlerInterface.setSelectedFragment(this);
29 | }
30 |
31 | public interface BackHandlerInterface {
32 | public void setSelectedFragment(BackHandledFragment backHandledFragment);
33 | }
34 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/CircleImageView.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.RadialGradient;
8 | import android.graphics.Shader;
9 | import android.graphics.drawable.ShapeDrawable;
10 | import android.graphics.drawable.shapes.OvalShape;
11 | import android.support.v4.view.ViewCompat;
12 | import android.view.animation.Animation;
13 | import android.widget.ImageView;
14 |
15 | /**
16 | * Private class created to work around issues with AnimationListeners being
17 | * called before the animation is actually complete and support shadows on older
18 | * platforms.
19 | *
20 | * @hide
21 | */
22 | class CircleImageView extends ImageView {
23 |
24 | private static final int KEY_SHADOW_COLOR = 0x1E000000;
25 | private static final int FILL_SHADOW_COLOR = 0x3D000000;
26 | // PX
27 | private static final float X_OFFSET = 0f;
28 | private static final float Y_OFFSET = 1.75f;
29 | private static final float SHADOW_RADIUS = 3.5f;
30 | private static final int SHADOW_ELEVATION = 4;
31 |
32 | private Animation.AnimationListener mListener;
33 | private int mShadowRadius;
34 |
35 | public CircleImageView(Context context, int color, final float radius) {
36 | super(context);
37 | final float density = getContext().getResources().getDisplayMetrics().density;
38 | final int diameter = (int) (radius * density * 2);
39 | final int shadowYOffset = (int) (density * Y_OFFSET);
40 | final int shadowXOffset = (int) (density * X_OFFSET);
41 |
42 | mShadowRadius = (int) (density * SHADOW_RADIUS);
43 |
44 | ShapeDrawable circle;
45 | if (elevationSupported()) {
46 | circle = new ShapeDrawable(new OvalShape());
47 | ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
48 | } else {
49 | OvalShape oval = new OvalShadow(mShadowRadius, diameter);
50 | circle = new ShapeDrawable(oval);
51 | ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, circle.getPaint());
52 | circle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
53 | KEY_SHADOW_COLOR);
54 | final int padding = mShadowRadius;
55 | // set padding so the inner image sits correctly within the shadow.
56 | setPadding(padding, padding, padding, padding);
57 | }
58 | circle.getPaint().setColor(color);
59 | setBackgroundDrawable(circle);
60 | }
61 |
62 | private boolean elevationSupported() {
63 | return android.os.Build.VERSION.SDK_INT >= 21;
64 | }
65 |
66 | @Override
67 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
68 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
69 | if (!elevationSupported()) {
70 | setMeasuredDimension(getMeasuredWidth() + mShadowRadius*2, getMeasuredHeight()
71 | + mShadowRadius*2);
72 | }
73 | }
74 |
75 | public void setAnimationListener(Animation.AnimationListener listener) {
76 | mListener = listener;
77 | }
78 |
79 | @Override
80 | public void onAnimationStart() {
81 | super.onAnimationStart();
82 | if (mListener != null) {
83 | mListener.onAnimationStart(getAnimation());
84 | }
85 | }
86 |
87 | @Override
88 | public void onAnimationEnd() {
89 | super.onAnimationEnd();
90 | if (mListener != null) {
91 | mListener.onAnimationEnd(getAnimation());
92 | }
93 | }
94 |
95 | /**
96 | * Update the background color of the circle image view.
97 | *
98 | * @param colorRes Id of a color resource.
99 | */
100 | public void setBackgroundColorRes(int colorRes) {
101 | setBackgroundColor(getContext().getResources().getColor(colorRes));
102 | }
103 |
104 | @Override
105 | public void setBackgroundColor(int color) {
106 | if (getBackground() instanceof ShapeDrawable) {
107 | ((ShapeDrawable) getBackground()).getPaint().setColor(color);
108 | }
109 | }
110 |
111 | private class OvalShadow extends OvalShape {
112 | private RadialGradient mRadialGradient;
113 | private Paint mShadowPaint;
114 | private int mCircleDiameter;
115 |
116 | public OvalShadow(int shadowRadius, int circleDiameter) {
117 | super();
118 | mShadowPaint = new Paint();
119 | mShadowRadius = shadowRadius;
120 | mCircleDiameter = circleDiameter;
121 | mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
122 | mShadowRadius, new int[] {
123 | FILL_SHADOW_COLOR, Color.TRANSPARENT
124 | }, null, Shader.TileMode.CLAMP);
125 | mShadowPaint.setShader(mRadialGradient);
126 | }
127 |
128 | @Override
129 | public void draw(Canvas canvas, Paint paint) {
130 | final int viewWidth = CircleImageView.this.getWidth();
131 | final int viewHeight = CircleImageView.this.getHeight();
132 | canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius),
133 | mShadowPaint);
134 | canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint);
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/DividerItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 |
12 | /*
13 | * Copyright (C) 2014 The Android Open Source Project
14 | *
15 | * Licensed under the Apache License, Version 2.0 (the "License");
16 | * you may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at
18 | *
19 | * http://www.apache.org/licenses/LICENSE-2.0
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an " IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | */
27 | public class DividerItemDecoration extends RecyclerView.ItemDecoration {
28 |
29 | private static final int[] ATTRS = new int[]{
30 | android.R.attr.listDivider
31 | };
32 |
33 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
34 |
35 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
36 |
37 | private Drawable mDivider;
38 |
39 | private int mOrientation;
40 |
41 | public DividerItemDecoration(Context context, int orientation) {
42 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
43 | mDivider = a.getDrawable(0);
44 | a.recycle();
45 | setOrientation(orientation);
46 | }
47 |
48 | public void setOrientation(int orientation) {
49 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
50 | throw new IllegalArgumentException("invalid orientation");
51 | }
52 | mOrientation = orientation;
53 | }
54 |
55 | public DividerItemDecoration setmDivider(Drawable mDivider) {
56 | this.mDivider = mDivider;
57 | return this;
58 | }
59 |
60 | @Override
61 | public void onDraw(Canvas c, RecyclerView parent) {
62 | if (mOrientation == VERTICAL_LIST) {
63 | drawVertical(c, parent);
64 | } else {
65 | drawHorizontal(c, parent);
66 | }
67 | }
68 |
69 | public void drawVertical(Canvas c, RecyclerView parent) {
70 | final int left = parent.getPaddingLeft();
71 | final int right = parent.getWidth() - parent.getPaddingRight();
72 |
73 | final int childCount = parent.getChildCount();
74 | for (int i = 0; i < childCount; i++) {
75 | final View child = parent.getChildAt(i);
76 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
77 | .getLayoutParams();
78 | final int top = child.getBottom() + params.bottomMargin;
79 | final int bottom = top + mDivider.getIntrinsicHeight();
80 | mDivider.setBounds(left, top, right, bottom);
81 | mDivider.draw(c);
82 | }
83 | }
84 |
85 | public void drawHorizontal(Canvas c, RecyclerView parent) {
86 | final int top = parent.getPaddingTop();
87 | final int bottom = parent.getHeight() - parent.getPaddingBottom();
88 |
89 | final int childCount = parent.getChildCount();
90 | for (int i = 0; i < childCount; i++) {
91 | final View child = parent.getChildAt(i);
92 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
93 | .getLayoutParams();
94 | final int left = child.getRight() + params.rightMargin;
95 | final int right = left + mDivider.getIntrinsicHeight();
96 | mDivider.setBounds(left, top, right, bottom);
97 | mDivider.draw(c);
98 | }
99 | }
100 |
101 | @Override
102 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
103 | if (mOrientation == VERTICAL_LIST) {
104 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
105 | } else {
106 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
107 | }
108 | }
109 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/DividerOffsetDecoration.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 |
12 | /*
13 | * Copyright (C) 2014 The Android Open Source Project
14 | *
15 | * Licensed under the Apache License, Version 2.0 (the "License");
16 | * you may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at
18 | *
19 | * http://www.apache.org/licenses/LICENSE-2.0
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an " IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | */
27 | public class DividerOffsetDecoration extends RecyclerView.ItemDecoration {
28 | @Override
29 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
30 | outRect.bottom = 30;
31 | }
32 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/ProgressWebView.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.webkit.WebChromeClient;
9 | import android.webkit.WebView;
10 | import android.webkit.WebViewClient;
11 |
12 |
13 | public class ProgressWebView extends WebView{
14 | private WebViewProgressBar progressBar;
15 | private Handler handler;
16 | private WebView _this;
17 | public ProgressWebView(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | progressBar = new WebViewProgressBar(context);
20 | progressBar.setLayoutParams(new ViewGroup.LayoutParams
21 | (ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
22 | progressBar.setVisibility(GONE);
23 | addView(progressBar);
24 | handler = new Handler();
25 | _this = this;
26 | setWebChromeClient(new MyWebChromeClient());
27 | setWebViewClient(new MyWebClient());
28 |
29 | }
30 |
31 | private class MyWebChromeClient extends WebChromeClient {
32 | @Override
33 | public void onProgressChanged(WebView view, int newProgress) {
34 | if(newProgress == 100){
35 | progressBar.setProgress(100);
36 | handler.postDelayed(runnable,200);
37 | }else if(progressBar.getVisibility() == GONE){
38 | progressBar.setVisibility(VISIBLE);
39 | }
40 | if(newProgress < 5){
41 | newProgress = 5;
42 | }
43 | progressBar.setProgress(newProgress);
44 | super.onProgressChanged(view, newProgress);
45 | }
46 | }
47 | private class MyWebClient extends WebViewClient {
48 | @Override
49 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
50 | _this.loadUrl(url);
51 | return true;
52 | }
53 | }
54 | private Runnable runnable = new Runnable() {
55 | @Override
56 | public void run() {
57 | progressBar.setVisibility(View.GONE);
58 | }
59 | };
60 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/RecyclerItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.GestureDetector;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 |
9 |
10 | public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
11 | private OnItemClickListener mListener;
12 |
13 | public interface OnItemClickListener {
14 | void onItemClick(View view, int position);
15 | }
16 |
17 | GestureDetector mGestureDetector;
18 |
19 | public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
20 | mListener = listener;
21 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
22 | @Override public boolean onSingleTapUp(MotionEvent e) {
23 | return true;
24 | }
25 | });
26 | }
27 |
28 | @Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
29 | View childView = view.findChildViewUnder(e.getX(), e.getY());
30 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
31 | mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
32 | }
33 | return false;
34 | }
35 |
36 | @Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }
37 |
38 | @Override public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
39 | // do nothing
40 | }
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/RefreshLayout.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.MotionEventCompat;
5 | import android.support.v4.view.ViewCompat;
6 | import android.util.AttributeSet;
7 | import android.view.MotionEvent;
8 | import android.view.ViewConfiguration;
9 | import android.view.animation.Animation;
10 |
11 | import com.aswifter.material.utils.DisplayUtil;
12 |
13 | public class RefreshLayout extends PullToRefreshLayout {
14 |
15 | private final int mTouchSlop;
16 | private OnLoadListener mOnLoadListener;
17 | private float mInitialDownY;
18 | private boolean mIsBeingDragged;
19 | private boolean isLoading = false;
20 |
21 | public RefreshLayout(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public RefreshLayout(Context context, AttributeSet attrs) {
26 | super(context, attrs);
27 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
28 | initListener();
29 | }
30 |
31 | private void initListener(){
32 | mRefreshListener = new Animation.AnimationListener() {
33 | @Override
34 | public void onAnimationStart(Animation animation) {
35 | }
36 |
37 | @Override
38 | public void onAnimationRepeat(Animation animation) {
39 | }
40 |
41 | @Override
42 | public void onAnimationEnd(Animation animation) {
43 | if(!isLoading){
44 | if (isRefreshing()) {
45 | // Make sure the progress view is fully visible
46 | mProgress.setAlpha(MAX_ALPHA);
47 | mProgress.start();
48 | if (mNotify) {
49 | if (mListener != null) {
50 | mListener.onRefresh();
51 | }
52 | }
53 | mCurrentTargetOffsetTop = mCircleView.getTop();
54 | } else {
55 | reset();
56 | }
57 | }else{
58 | if(mOnLoadListener != null){
59 | mOnLoadListener.onLoad();
60 | }
61 | }
62 | }
63 | };
64 | }
65 | @Override
66 | public boolean dispatchTouchEvent(MotionEvent ev) {
67 | final int action = MotionEventCompat.getActionMasked(ev);
68 |
69 | if (!isEnabled() || canChildScrollDown()) {
70 | // Fail fast if we're not in a state where a swipe is possible
71 | return super.dispatchTouchEvent(ev);
72 | }
73 | switch (action) {
74 | case MotionEvent.ACTION_DOWN:
75 | mIsBeingDragged = false;
76 | mInitialDownY = ev.getY();
77 | break;
78 |
79 | case MotionEvent.ACTION_MOVE: {
80 | final float y = ev.getY();
81 | final float overscrollTop = (mInitialDownY -y) * DRAG_RATE;
82 | if (overscrollTop > mTouchSlop) {
83 | mIsBeingDragged = true;
84 | if(!isLoading){
85 | isLoading = true;
86 | setProgressViewOffset(true, getBottom() - mCircleView.getHeight(), (int)(getBottom() - mCircleView.getHeight() - mTotalDragDistance));
87 | }
88 | moveSpinner(overscrollTop);
89 | return true;
90 | }
91 | break;
92 | }
93 | case MotionEventCompat.ACTION_POINTER_UP:
94 | case MotionEvent.ACTION_UP: {
95 | if (mIsBeingDragged) {
96 | final float y = ev.getY();
97 | final float overscrollTop = (mInitialDownY - y) * DRAG_RATE;
98 | mIsBeingDragged = false;
99 | finishSpinner(overscrollTop);
100 | return true;
101 | }
102 | }
103 | }
104 |
105 | return super.dispatchTouchEvent(ev);
106 | }
107 |
108 | private boolean canChildScrollDown() {
109 | return ViewCompat.canScrollVertically(mTarget, 1);
110 | }
111 |
112 | public void setLoading(boolean loading) {
113 | if (mTarget == null) return;
114 | isLoading = loading;
115 | if (loading) {
116 | if (isRefreshing()) {
117 | super.setRefreshing(true);
118 | }
119 | mOnLoadListener.onLoad();
120 | } else {
121 | super.setRefreshing(false);
122 | setProgressViewOffset(true,getTop(),(int)(DEFAULT_CIRCLE_TARGET * DisplayUtil.SCREEN_DENSITY));
123 | mInitialDownY = 0;
124 | }
125 | }
126 |
127 | @Override
128 | public void setRefreshing(boolean refreshing) {
129 | if(isLoading){
130 | setLoading(refreshing);
131 | }else{
132 | super.setRefreshing(refreshing);
133 | }
134 | if(!refreshing){
135 | setProgressViewOffset(true,-mCircleView.getHeight(), DEFAULT_CIRCLE_TARGET);
136 | }
137 | }
138 |
139 | public void setOnLoadListener(OnLoadListener loadListener) {
140 | mOnLoadListener = loadListener;
141 | }
142 |
143 | public interface OnLoadListener {
144 | public void onLoad();
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/app/src/main/java/com/aswifter/material/widget/WebViewProgressBar.java:
--------------------------------------------------------------------------------
1 | package com.aswifter.material.widget;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Paint;
6 | import android.util.AttributeSet;
7 | import android.view.View;
8 |
9 | import com.aswifter.material.R;
10 |
11 |
12 | public class WebViewProgressBar extends View {
13 | private int progress = 1;
14 | private final static int HEIGHT = 5;
15 | private Paint paint;
16 | private final static int colors[] = new int[]{};
17 | public WebViewProgressBar(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | }
20 |
21 | public WebViewProgressBar(Context context) {
22 | super(context);
23 | // LinearGradient shader = new LinearGradient(
24 | // 0, 0,
25 | // 100, HEIGHT,
26 | // colors,
27 | // null,
28 | // Shader.TileMode.MIRROR);
29 | paint=new Paint(Paint.DITHER_FLAG);
30 | paint.setStyle(Paint.Style.STROKE);
31 | paint.setStrokeWidth(HEIGHT);
32 | paint.setAntiAlias(true);
33 | paint.setColor(context.getResources().getColor(R.color.primary_light));
34 | // paint.setShader(shader);
35 | }
36 | public void setProgress(int progress){
37 | this.progress = progress;
38 | invalidate();
39 | }
40 |
41 | @Override
42 | protected void onDraw(Canvas canvas) {
43 | canvas.drawRect(0, 0, getWidth() * progress / 100, HEIGHT, paint);
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/res/color/tab_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/book1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/drawable-xxhdpi/book1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/book2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/drawable-xxhdpi/book2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/book3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/drawable-xxhdpi/book3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_favorite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/drawable-xxhdpi/ic_favorite.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_find_in_page_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/drawable-xxhdpi/ic_find_in_page_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/news_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_appbar_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
24 |
25 |
26 |
35 |
36 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
54 |
55 |
61 |
62 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_bottom_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
17 |
18 |
19 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_cardview.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
15 |
16 |
21 |
22 |
31 |
32 |
37 |
38 |
42 |
43 |
48 |
49 |
55 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
79 |
80 |
85 |
86 |
90 |
91 |
96 |
97 |
103 |
104 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
126 |
127 |
132 |
133 |
137 |
138 |
143 |
144 |
150 |
151 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_edittext_fl.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
26 |
27 |
33 |
34 |
35 |
36 |
37 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
13 |
14 |
17 |
18 |
19 |
26 |
27 |
28 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_news_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
27 |
28 |
29 |
38 |
39 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
59 |
62 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recycler_view.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
15 |
16 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/book_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
26 |
27 |
32 |
33 |
39 |
40 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/custom_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_about.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
16 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_blog.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_books.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
13 |
14 |
15 |
26 |
27 |
28 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_example.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_page.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/include_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
23 |
24 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/navigation_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 |
21 |
22 |
23 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/progress_bar.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
17 |
18 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/profile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/mipmap-hdpi/profile.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
28 |
29 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #009688
4 | #00897b
5 | #B2DFDB
6 | #ffb74d
7 | #212121
8 | #727272
9 | #FFFFFF
10 | #B6B6B6
11 | #E8E8E8
12 | #ffffff
13 |
14 | #FFF5F5F5
15 | #eeeeee
16 |
17 | #d62d20
18 | #0057e7
19 | #008744
20 | #ffa700
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 5dp
6 | 56dp
7 | 10dp>
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Material
3 |
4 | Settings
5 |
6 | 最新
7 |
8 | 用户登陆
9 | 用户名
10 | 密码
11 | 登 陆
12 |
13 |
14 | 例子
15 | 控件
16 | 博客
17 | 关于
18 |
19 |
20 | Open
21 | Close
22 | 再按一次退出程序
23 |
24 | 本APP用来演示Material Design控件的使用
25 | github地址:\nhttps://github.com/chenyangcun/MaterialDesignExample
26 |
27 | 书籍
28 |
29 | 失控
30 | 作者: [美] 凯文·凯利 \n副标题: 全人类的最终命运和结局 \n出版年: 2010-12 \n页数: 707 \n定价: 88.00元
31 |
32 | 黑客与画家
33 | 作者: [美] Paul Graham\n副标题: 硅谷创业之父Paul Graham文集\n出版年: 2011-4\n页数: 264\n定价: 49.00元
34 |
35 | 七周七语言
36 | 作者: Bruce A.Tate\n副标题: 理解多种编程范型\n出版年: 2012-5-8\n页数: 246\n定价: 59.00元
37 |
38 | 搜索
39 | 请输入关键字
40 |
41 | 花千骨
42 |
43 | Buttom Tab
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
27 |
28 |
29 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/values/transition.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | transition_book_img
4 | transition_news_img
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/values.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/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:2.3.2'
9 | classpath 'me.tatarka:gradle-retrolambda:3.2.5'
10 |
11 | //2. apt
12 | classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | maven { url "https://jitpack.io" }
20 | }
21 | }
22 |
23 | task wrapper(type: Wrapper) {
24 | gradleVersion = '2.6'
25 | }
--------------------------------------------------------------------------------
/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/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Aug 11 23:48:59 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | ssss=
4 | distributionPath=wrapper/dists
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
8 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/images/app-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/images/app-debug.apk
--------------------------------------------------------------------------------
/images/bookdetail.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/images/bookdetail.gif
--------------------------------------------------------------------------------
/images/cardview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/images/cardview.png
--------------------------------------------------------------------------------
/images/demo.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/images/demo.apk
--------------------------------------------------------------------------------
/images/pic1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/images/pic1.png
--------------------------------------------------------------------------------
/images/pic2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenyangcun/MaterialDesignExample/68438aa2ffa76520d9af35ad247e6414c49f9287/images/pic2.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
--------------------------------------------------------------------------------