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();
|
}
|
});
|
}
|
|
}
|