admin
2021-02-20 f8a5683d08f2e6f832578b2fd5c795888ddcae64
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.weikou.beibeivideo.ui.mine;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
 
import com.lcjian.library.DeviceUuidFactory;
import com.lcjian.library.util.common.StringUtils;
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
import com.weikou.beibeivideo.BeibeiVideoAPI;
import com.weikou.beibeivideo.R;
import com.weikou.beibeivideo.ui.BaseActivity;
 
public class DownLoadUrlActivity extends BaseActivity implements
        OnClickListener {
 
    private TextView tv_top_bar_left;
    private TextView tv_top_bar_middle;
 
    private EditText et_suggestion;
    private Button btn_watch, btn_copy;
 
    private ProgressDialog mProgressDialog;
 
    String url = "";
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.download_url_activity);
        initStatusBar();
        tv_top_bar_left = (TextView) findViewById(R.id.tv_top_bar_left);
        tv_top_bar_middle = (TextView) findViewById(R.id.tv_top_bar_middle);
        tv_top_bar_left.setText("返回");
        tv_top_bar_middle.setText(R.string.suggestion);
        tv_top_bar_middle.setText("下载链接");
 
        et_suggestion = (EditText) findViewById(R.id.et_url);
        et_suggestion.setEnabled(false);
        btn_watch = (Button) findViewById(R.id.btn_watch);
        btn_copy = (Button) findViewById(R.id.btn_copy);
 
        tv_top_bar_left.setOnClickListener(this);
        btn_watch.setOnClickListener(this);
        btn_copy.setOnClickListener(this);
 
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setCanceledOnTouchOutside(false);
        mProgressDialog.setMessage("获取链接...");
        init();
    }
 
    private void init() {
        SharedPreferences preferences = getSharedPreferences("user",
                Context.MODE_PRIVATE);
        url = preferences.getString("share_url", "");
        if (!StringUtils.isEmpty(url)) {
            et_suggestion.setText(url);
        } else {
            getUid();
        }
    }
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.tv_top_bar_left: {
            finish();
        }
            break;
        case R.id.btn_copy: {
            int sdkInt = Build.VERSION.SDK_INT;
            if (sdkInt > Build.VERSION_CODES.HONEYCOMB) {// api11
                ClipboardManager copy = (ClipboardManager) this
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                copy.setText(url);
                Toast.makeText(this, "链接复制成功", Toast.LENGTH_SHORT).show();
            } else if (sdkInt <= Build.VERSION_CODES.HONEYCOMB) {
                android.text.ClipboardManager copyq = (android.text.ClipboardManager) this
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                copyq.setText(url);
                Toast.makeText(this, "链接复制成功", Toast.LENGTH_SHORT).show();
            }
 
        }
            break;
        case R.id.btn_watch: {
            startActivity(new Intent(this, BrowserActivity.class).putExtra(
                    "url", url));
        }
            break;
        default:
            break;
        }
    }
 
    private String getChannel() throws NameNotFoundException {
        /*
         * ApplicationInfo appInfo = this.getPackageManager()
         * .getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
         * return appInfo.metaData.getString("UMENG_CHANNEL");
         */
        return "360";
    }
 
    private void getUid() {
        SharedPreferences preferences = getSharedPreferences("user",
                Context.MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        String channel = "";
        try {
            channel = getChannel();
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        BeibeiVideoAPI.getUid(this, channel, new DeviceUuidFactory(this)
                .getDeviceUuid().toString(), preferences.getString("imei", ""),
                preferences.getString("mac", ""), preferences.getString("lat",
                        ""), preferences.getString("lng", ""),
                new BasicTextHttpResponseHandler() {
                    @Override
                    public void onStart() {
                        mProgressDialog.show();
                    }
 
                    @Override
                    public void onSuccessPerfect(int statusCode,
                            Header[] headers, JSONObject jsonObject)
                            throws Exception {
                        if (jsonObject.getBoolean("IsPost")) {
                            url = jsonObject.getJSONObject("Data").getString(
                                    "ShareUrl");
                            et_suggestion.setText(jsonObject.getJSONObject(
                                    "Data").getString("ShareUrl"));
                        }
                    }
 
                    @Override
                    public void onFinish() {
                        mProgressDialog.dismiss();
                    }
                });
    }
 
}