admin
2021-02-18 7641351b4b4d59a35dad924079f13cfa1fb15e02
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package com.weikou.beibeivideo.ui.dialog;
 
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.androidquery.AQuery;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMWeb;
import com.weikou.beibeivideo.R;
 
/**
 * 用户协议弹框
 */
public class ShareAPPDialog extends Dialog {
 
    private static String TAG = ShareAPPDialog.class.getName();
 
    public ShareAPPDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public ShareAPPDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
 
    public static class Builder {
 
 
        private Activity context;
 
        public Builder(Activity context) {
            this.context = context;
        }
 
        private View.OnClickListener closeListener;
 
        private View.OnClickListener upgradeListener;
 
 
        public Builder setCloseListener(View.OnClickListener listener) {
            this.closeListener = listener;
            return this;
        }
 
        public Builder setUpgradeListener(View.OnClickListener listener) {
            this.upgradeListener = listener;
            return this;
        }
 
        private String getShareUrl() {
            SharedPreferences preferences = context.getSharedPreferences("user",
                    Context.MODE_PRIVATE);
            return preferences.getString("share_url", "http://yy.umgotv.com");
        }
 
        private String getShareContent() {
            SharedPreferences preferences = context.getSharedPreferences(
                    "user", Context.MODE_PRIVATE);
            String shareContent = preferences.getString(
                    "share_content",
                    "牛逼的APP,什么样的新片,大片,电视剧都有---"
                            + context.getResources().getString(
                            R.string.app_name))
                    + getShareUrl();
            return shareContent;
        }
 
        private void share(SHARE_MEDIA media) {
            String shareContent = getShareContent();
            UMWeb web = new UMWeb(getShareUrl());
            String shareTitle = context.getResources().getString(R.string.app_name);
            web.setTitle(shareTitle);
            web.setDescription(shareContent);
            new ShareAction(context).withText(shareContent).setPlatform(media).withMedia(web).share();
        }
 
        public ShareAPPDialog create() {
 
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final ShareAPPDialog dialog = new ShareAPPDialog(context, R.style.Dialog);
            dialog.setCanceledOnTouchOutside(true);
            final View layout = inflater.inflate(R.layout.dialog_share_app, null);
            AQuery aQuery = new AQuery(layout);
 
            aQuery.id(R.id.ll_qq).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    share(SHARE_MEDIA.QQ);
 
                }
            });
            aQuery.id(R.id.ll_wx).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    share(SHARE_MEDIA.WEIXIN);
                }
            });
 
            aQuery.id(R.id.ll_weibo).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    share(SHARE_MEDIA.SINA);
                }
            });
 
            aQuery.id(R.id.tv_cancel).clicked(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (dialog.isShowing()) {
                        dialog.dismiss();
                    }
                }
            });
 
 
            dialog.setContentView(layout);
 
            WindowManager.LayoutParams params = dialog.getWindow()
                    .getAttributes();
            params.width = WindowManager.LayoutParams.MATCH_PARENT;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.gravity = Gravity.BOTTOM;
            dialog.getWindow().setAttributes(params);
            return dialog;
        }
    }
 
    public interface MeasureCallBack {
        public void onMeasure(int height);
    }
}