44 | 关于GankDaily
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/GankApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio;
21 |
22 | import android.app.Application;
23 | import android.content.Context;
24 |
25 | import com.orhanobut.logger.LogLevel;
26 | import com.orhanobut.logger.Logger;
27 |
28 | /**
29 | * Created by GuDong on 10/14/15 23:42.
30 | * Contact with gudong.name@gmail.com.
31 | */
32 | public class GankApp extends Application {
33 | public static Context sContext;
34 | @Override
35 | public void onCreate() {
36 | super.onCreate();
37 | sContext = this;
38 | //只有调试模式下 才启用日志输出
39 | if(BuildConfig.DEBUG){
40 | Logger.init("Gank").hideThreadInfo().setMethodCount(0);
41 | }else{
42 | Logger.init("Gank").setLogLevel(LogLevel.NONE);
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/core/GankCategory.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.core;
21 |
22 | public enum GankCategory {
23 | 福利,
24 | iOS,
25 | Android,
26 | App,
27 | 拓展资源,
28 | 瞎推荐,
29 | 休息视频;
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/core/GuDong.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.core;
21 |
22 | import com.gudong.gankio.data.GankData;
23 | import com.gudong.gankio.data.PrettyGirlData;
24 | import com.gudong.gankio.data.RestData;
25 |
26 | import retrofit.http.GET;
27 | import retrofit.http.Path;
28 | import rx.Observable;
29 |
30 | /**
31 | * Created by GuDong on 9/27/15.
32 | * Contact with gudong.name@gmail.com
33 | */
34 | public interface GuDong {
35 |
36 | @GET("/data/福利/{pagesize}/{page}")
37 | Observable getPrettyGirlData(@Path("pagesize") int pagesize,@Path("page") int page);
38 |
39 | @GET("/data/休息视频/{pagesize}/{page}")
40 | Observable get休息视频Data(@Path("pagesize") int pagesize, @Path("page")int page);
41 |
42 | @GET("/day/{year}/{month}/{day}")
43 | Observable getGankData(@Path("year")int year,@Path("month")int month,@Path("day")int day);
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/core/MainFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.core;
21 |
22 | /**
23 | * Created by GuDong on 15/10/8.
24 | * Contact with gudong.name@gmail.com
25 | */
26 | public class MainFactory {
27 | /**
28 | * 数据主机地址
29 | */
30 | public static final String HOST = "http://gank.io/api";
31 |
32 | private static GuDong mGuDong;
33 |
34 | protected static final Object monitor = new Object();
35 |
36 | public static GuDong getGuDongInstance(){
37 | synchronized (monitor){
38 | if(mGuDong==null){
39 | mGuDong = new MainRetrofit().getService();
40 | }
41 | return mGuDong;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/core/MainRetrofit.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.core;
21 |
22 | import com.google.gson.Gson;
23 | import com.google.gson.GsonBuilder;
24 | import com.squareup.okhttp.OkHttpClient;
25 |
26 | import java.util.concurrent.TimeUnit;
27 |
28 | import retrofit.RestAdapter;
29 | import retrofit.client.OkClient;
30 | import retrofit.converter.GsonConverter;
31 |
32 | /**
33 | * Created by GuDong on 15/10/8.
34 | * Contact with gudong.name@gmail.com
35 | */
36 | public class MainRetrofit {
37 |
38 | final GuDong mService;
39 |
40 | final Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").serializeNulls().create();
41 |
42 | MainRetrofit() {
43 | OkHttpClient client = new OkHttpClient();
44 | client.setReadTimeout(21, TimeUnit.SECONDS);
45 | RestAdapter restAdapter = new RestAdapter.Builder()
46 | .setClient(new OkClient(client))
47 | .setEndpoint(MainFactory.HOST)
48 | .setConverter(new GsonConverter(gson))
49 | .setLogLevel(RestAdapter.LogLevel.FULL)
50 | .build();
51 | mService = restAdapter.create(GuDong.class);
52 | }
53 |
54 | public GuDong getService(){
55 | return mService;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/BaseData.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data;
21 |
22 | /**
23 | * Created by GuDong on 9/28/15.
24 | * Contact with gudong.name@gmail.com
25 | */
26 | public class BaseData {
27 | public boolean error;
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/GankData.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data;
21 |
22 | import com.gudong.gankio.data.entity.Gank;
23 | import com.google.gson.annotations.SerializedName;
24 |
25 | import java.util.List;
26 |
27 | /**
28 | * Created by GuDong on 10/9/15 22:20.
29 | * Contact with gudong.name@gmail.com.
30 | */
31 | public class GankData extends BaseData {
32 |
33 | public List category;
34 | public Result results;
35 |
36 | public class Result {
37 | @SerializedName("Android") public List androidList;
38 | @SerializedName("休息视频") public List 休息视频List;
39 | @SerializedName("iOS") public List iOSList;
40 | @SerializedName("福利") public List 妹纸List;
41 | @SerializedName("拓展资源") public List 拓展资源List;
42 | @SerializedName("瞎推荐") public List 瞎推荐List;
43 | @SerializedName("App") public List appList;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/PrettyGirlData.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data;
21 |
22 | import com.gudong.gankio.data.entity.Girl;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * 妹子数据集合对象
28 | * Created by GuDong on 9/28/15.
29 | * Contact with gudong.name@gmail.com
30 | */
31 | public class PrettyGirlData extends BaseData {
32 | public Listresults;
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/RestData.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data;
21 |
22 | import com.gudong.gankio.data.entity.Gank;
23 |
24 | import java.util.List;
25 |
26 | /**
27 | * Created by GuDong on 15/10/8.
28 | * Contact with gudong.name@gmail.com
29 | */
30 | public class RestData extends BaseData {
31 | public Listresults;
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/entity/Gank.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data.entity;
21 |
22 | import com.gudong.gankio.core.GankCategory;
23 |
24 | import java.io.Serializable;
25 | import java.util.Date;
26 |
27 | /**
28 | * Created by GuDong on 15/10/8.
29 | * Contact with gudong.name@gmail.com
30 | */
31 | public class Gank extends Soul implements Cloneable,Serializable{
32 |
33 | /**
34 | * createdAt : 2015-10-06T08:23:35.565Z
35 | * publishedAt : 2015-10-08T01:29:48.811Z
36 | * used : true
37 | * type : 休息视频
38 | * url : http://v.youku.com/v_show/id_XMTY4OTE3OTQ4.html
39 | * who : lxxself
40 | * desc : 耐克还有这广告,我良辰服气
41 | * updatedAt : 2015-10-08T01:29:49.219Z
42 | */
43 |
44 | public boolean used;
45 | public String type;
46 | public String url;
47 | public String who;
48 | public String desc;
49 | public Date updatedAt;
50 | public Date createdAt;
51 | public Date publishedAt;
52 |
53 | /**
54 | * this item is header type of gank or not,if true, this item will show category name
55 | */
56 | public boolean isHeader;
57 |
58 | public boolean is妹子(){
59 | return type.equals(GankCategory.福利.name());
60 | }
61 |
62 | @Override
63 | public Gank clone() {
64 | Gank gank = null;
65 | try{
66 | gank = (Gank)super.clone();
67 | }catch(CloneNotSupportedException e) {
68 | e.printStackTrace();
69 | }
70 | return gank;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/entity/Girl.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data.entity;
21 |
22 |
23 | import java.util.Date;
24 |
25 | /**
26 | * Created by GuDong on 15/10/8.
27 | * Contact with gudong.name@gmail.com
28 | */
29 | public class Girl extends Soul {
30 |
31 | /**
32 | * createdAt : 2015-10-07T05:42:23.910Z
33 | * publishedAt : 2015-10-08T01:29:48.812Z
34 | * used : true
35 | * type : 福利
36 | * url : http://ww4.sinaimg.cn/large/7a8aed7bgw1ewsip9thfoj20hs0qo774.jpg
37 | * who : 张涵宇
38 | * desc : 10.8
39 | * updatedAt : 2015-10-08T01:29:49.400Z
40 | */
41 |
42 | public boolean used;
43 | public String type;
44 | public String url;
45 | public String who;
46 | public String desc;
47 | public Date createdAt;
48 | public Date publishedAt;
49 | public Date updatedAt;
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/data/entity/Soul.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.data.entity;
21 |
22 | /**
23 | * Created by GuDong on 15/10/8.
24 | * Contact with gudong.name@gmail.com
25 | */
26 | public class Soul {
27 | protected long id;
28 | public String objectId;
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/presenter/BasePresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.presenter;
21 |
22 | import android.app.Activity;
23 |
24 | import com.gudong.gankio.core.GuDong;
25 | import com.gudong.gankio.core.MainFactory;
26 | import com.gudong.gankio.ui.view.IBaseView;
27 |
28 | /**
29 | * Created by GuDong on 10/29/15 14:08.
30 | * Contact with gudong.name@gmail.com.
31 | */
32 | public class BasePresenter {
33 |
34 | protected GV mView;
35 | /**
36 | * TODO 这里用是否用Activity待考证
37 | */
38 | protected Activity mContext;
39 |
40 | public static final GuDong mGuDong = MainFactory.getGuDongInstance();
41 |
42 | public BasePresenter(Activity context, GV view) {
43 | mContext = context;
44 | mView = view;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/presenter/CustomDialogPresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.presenter;
21 |
22 | import android.app.Activity;
23 | import android.content.DialogInterface;
24 | import android.graphics.Color;
25 | import android.os.Bundle;
26 | import android.support.v4.app.Fragment;
27 | import android.support.v7.app.AlertDialog;
28 | import android.view.View;
29 | import android.webkit.WebSettings;
30 | import android.webkit.WebView;
31 |
32 | import com.gudong.gankio.R;
33 | import com.gudong.gankio.ui.view.ICustomDialog;
34 | import com.gudong.gankio.ui.fragment.CustomWebViewDialog;
35 |
36 | import java.io.BufferedReader;
37 | import java.io.InputStream;
38 | import java.io.InputStreamReader;
39 |
40 | /**
41 | * Created by GuDong on 11/6/15 16:00.
42 | * Contact with gudong.name@gmail.com.
43 | */
44 | public class CustomDialogPresenter extends BasePresenter {
45 |
46 | private static final String EXTRA_DIALOG_TITLE = "DIALOG_TITLE";
47 | private static final String EXTRA_HTML_FILE_NAME = "HTML_FILE_NAME";
48 | private static final String EXTRA_ACCENT_COLOR = "ACCENT_COLOR";
49 |
50 | private static final String KEY_UTF_8 = "UTF_8";
51 |
52 | public CustomDialogPresenter(Activity context, ICustomDialog view) {
53 | super(context, view);
54 | }
55 |
56 | /**
57 | * create a custom dialog use web view load layout by html file
58 | * @param dialogTitle dialog title
59 | * @param htmlFileName html file name
60 | * @param accentColor accent color
61 | * @return a instance of CustomWebViewDialog
62 | */
63 | public static CustomWebViewDialog create(String dialogTitle, String htmlFileName, int accentColor) {
64 | CustomWebViewDialog dialog = new CustomWebViewDialog();
65 | Bundle args = new Bundle();
66 | args.putString(EXTRA_DIALOG_TITLE, dialogTitle);
67 | args.putString(EXTRA_HTML_FILE_NAME, htmlFileName);
68 | args.putInt(EXTRA_ACCENT_COLOR, accentColor);
69 | dialog.setArguments(args);
70 | return dialog;
71 | }
72 |
73 |
74 | public AlertDialog makeOkDialog(Fragment fragment, View customView) {
75 | String dialogTitle = fragment.getArguments().getString(EXTRA_DIALOG_TITLE);
76 | String htmlFileName = fragment.getArguments().getString(EXTRA_HTML_FILE_NAME);
77 | int accentColor = fragment.getArguments().getInt(EXTRA_ACCENT_COLOR);
78 |
79 | final WebView webView = (WebView) customView.findViewById(R.id.webview);
80 | setWebView(webView);
81 | loadData(webView, htmlFileName, accentColor);
82 |
83 | AlertDialog dialog = new AlertDialog.Builder(mContext)
84 | .setTitle(dialogTitle)
85 | .setView(customView)
86 | .setPositiveButton(android.R.string.ok, null)
87 | .show();
88 |
89 | return dialog;
90 | }
91 |
92 | /**
93 | * show positive na
94 | * @param fragment
95 | * @param customView
96 | * @return
97 | */
98 | public AlertDialog makeMulActionDialog(Fragment fragment, View customView,
99 | String ok, DialogInterface.OnClickListener okListener,
100 | String negative, DialogInterface.OnClickListener negativeListener,
101 | String neutral,DialogInterface.OnClickListener neutralListener) {
102 | String dialogTitle = fragment.getArguments().getString(EXTRA_DIALOG_TITLE);
103 | String htmlFileName = fragment.getArguments().getString(EXTRA_HTML_FILE_NAME);
104 | int accentColor = fragment.getArguments().getInt(EXTRA_ACCENT_COLOR);
105 |
106 | final WebView webView = (WebView) customView.findViewById(R.id.webview);
107 | setWebView(webView);
108 | loadData(webView, htmlFileName, accentColor);
109 |
110 | AlertDialog dialog = new AlertDialog.Builder(mContext)
111 | .setTitle(dialogTitle)
112 | .setView(customView)
113 | .setPositiveButton(ok, okListener)
114 | .setNegativeButton(negative,negativeListener)
115 | .setNeutralButton(neutral,neutralListener)
116 | .show();
117 |
118 | return dialog;
119 | }
120 |
121 | private void setWebView(WebView webView){
122 | WebSettings settings = webView.getSettings();
123 | settings.setDefaultTextEncodingName(KEY_UTF_8);
124 | settings.setJavaScriptEnabled(true);
125 | }
126 |
127 | private void loadData(WebView webView,String htmlFileName,int accentColor){
128 | try {
129 | StringBuilder buf = new StringBuilder();
130 | InputStream json = mContext.getAssets().open(htmlFileName);
131 | BufferedReader in = new BufferedReader(new InputStreamReader(json,KEY_UTF_8));
132 | String str;
133 | while ((str = in.readLine()) != null)
134 | buf.append(str);
135 | in.close();
136 |
137 | String formatLodString = buf.toString()
138 | .replace("{style-placeholder}", "body { background-color: #ffffff; color: #000; }")
139 | .replace("{link-color}", colorToHex(shiftColor(accentColor, true)))
140 | .replace("{link-color-active}", colorToHex(accentColor));
141 | webView.loadDataWithBaseURL(null, formatLodString, "text/html", KEY_UTF_8, null);
142 | } catch (Throwable e) {
143 | webView.loadData("
Unable to load
" + e.getLocalizedMessage() + "
", "text/html", KEY_UTF_8);
144 | }
145 | }
146 |
147 | private String colorToHex(int color) {
148 | return Integer.toHexString(color).substring(2);
149 | }
150 |
151 | private int shiftColor(int color, boolean up) {
152 | float[] hsv = new float[3];
153 | Color.colorToHSV(color, hsv);
154 | hsv[2] *= (up ? 1.1f : 0.9f); // value component
155 | return Color.HSVToColor(hsv);
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gudong/gankio/presenter/GirlFacePresenter.java:
--------------------------------------------------------------------------------
1 | /*
2 | *
3 | * Copyright (C) 2015 Drakeet
4 | * Copyright (C) 2015 GuDong
5 | *
6 | * Meizhi is free software: you can redistribute it and/or modify
7 | * it under the terms of the GNU General Public License as published by
8 | * the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * Meizhi is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | * GNU General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU General Public License
17 | * along with Meizhi. If not, see .
18 | */
19 |
20 | package com.gudong.gankio.presenter;
21 |
22 | import android.app.Activity;
23 | import android.content.Context;
24 | import android.content.Intent;
25 | import android.graphics.Bitmap;
26 | import android.net.Uri;
27 | import android.os.AsyncTask;
28 | import android.os.Environment;
29 | import android.provider.MediaStore;
30 | import android.text.TextUtils;
31 | import android.widget.ImageView;
32 |
33 | import com.bumptech.glide.Glide;
34 | import com.gudong.gankio.R;
35 | import com.gudong.gankio.ui.view.IGirlFaceView;
36 | import com.gudong.gankio.util.TaskUtils;
37 | import com.orhanobut.logger.Logger;
38 |
39 | import java.io.File;
40 | import java.io.FileNotFoundException;
41 | import java.io.FileOutputStream;
42 | import java.io.IOException;
43 | import java.util.concurrent.ExecutionException;
44 |
45 | /**
46 | * Created by GuDong on 11/2/15 18:22.
47 | * Contact with gudong.name@gmail.com.
48 | */
49 | public class GirlFacePresenter extends BasePresenter {
50 | public GirlFacePresenter(Activity context, IGirlFaceView view) {
51 | super(context, view);
52 | }
53 |
54 | public void saveFace(final String url, final ImageView ivGirlDetail) {
55 | if (!TextUtils.isEmpty(url)) {
56 | final String fileName = url.substring(url.lastIndexOf("/")+1);
57 |
58 | ivGirlDetail.post(new Runnable() {
59 | @Override
60 | public void run() {
61 | int width = ivGirlDetail.getWidth();
62 | int height = ivGirlDetail.getHeight();
63 | saveImageToSdCard(mContext, url, fileName,width,height);
64 | }
65 | });
66 | }
67 | }
68 |
69 | private void saveImageToSdCard(final Context context, final String url, final String title, final int w, final int h){
70 | TaskUtils.executeAsyncTask(new AsyncTask