admin
6 天以前 7f0825f8195a522ed7e8bcdb6347f3a719e06c74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.weikou.beibeivideo.util.ad;
 
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
 
import com.weikou.beibeivideo.entity.HomeAd;
import com.weikou.beibeivideo.ui.media.VideoDetailActivity2;
import com.weikou.beibeivideo.util.CustomShareDialog;
import com.weikou.beibeivideo.util.downutil.DownFiles;
 
import org.json.JSONObject;
 
import java.util.Iterator;
 
public class HomeAdUtil {
 
    public static void jump(HomeAd homeAd, Activity context) {
        Intent intent = null;
        if (homeAd.getLinkType() == 1) {
            intent = new Intent(context,
                    VideoDetailActivity2.class);
            intent.putExtra("video_info", homeAd
                    .getVideo());
            intent.putExtra("from", "homeAd");
        } else if (homeAd.getLinkType() == 5) {
            try {
                JSONObject object = new JSONObject(homeAd.getParams()
                        .replace("\\", ""));
                String thumb = object.optString("thumb");
                String title = object.optString("title");
                String desc = object.optString("desc");
                String path = object.optString("path");
                String username = object.optString("username");
                String url = object.optString("url");
 
                CustomShareDialog.Builder builder = new CustomShareDialog.Builder(context);
                builder.setMessage(desc);
                builder.setUrl(url);
                builder.setContentImage(thumb);
                builder.setTitle(title);
                builder.setPath(path);
                builder.setUserName(username);
                builder.setNegativeButton("取消分享", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                builder.create().show();
            } catch (Exception e) {
 
            }
 
        } else {
            try {
                intent = new Intent(context, Class
                        .forName(homeAd.getClazz()));
                JSONObject object = new JSONObject(homeAd.getParams()
                        .replace("\\", ""));
                if (homeAd.getClazz().contains("FXBrowserActivity") && object.optString("url").endsWith(".apk")) {
                    startDownLoadFile(context, object.optString("url"));
                    return;
                }
                if (homeAd.getParams() != null) {
                    @SuppressWarnings("unchecked")
                    Iterator<String> its = object.keys();
                    while (its.hasNext()) {
                        String key = its.next();
                        String value = object.optString(key);
                        intent.putExtra(key, value);
                        intent.putExtra("isPush", true);
                    }
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (context != null && intent != null)
            context.startActivity(intent);
    }
 
 
    private static void startDownLoadFile(Context context, String url) {
        new DownFiles(context, new DownFiles.IProgress() {
            @Override
            public void getProgress(int p) {
                //TODO 处理进度
            }
        }).execute(url);
    }
 
 
}