|
package com.electric.chargingpile.activity;
import android.Manifest;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import com.amap.api.services.weather.LocalDayWeatherForecast;
import com.amap.api.services.weather.LocalWeatherForecast;
import com.amap.api.services.weather.LocalWeatherForecastResult;
import com.amap.api.services.weather.LocalWeatherLive;
import com.amap.api.services.weather.LocalWeatherLiveResult;
import com.amap.api.services.weather.WeatherSearch;
import com.amap.api.services.weather.WeatherSearchQuery;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.electric.chargingpile.R;
import com.electric.chargingpile.application.MainApplication;
import com.electric.chargingpile.manager.ProfileManager;
import com.electric.chargingpile.util.DES3;
import com.electric.chargingpile.util.JsonUtils;
import com.electric.chargingpile.util.NetUtil;
import com.electric.chargingpile.util.OkHttpUtil;
import com.electric.chargingpile.util.PicassoUtil;
import com.electric.chargingpile.util.Util;
import com.electric.chargingpile.view.ObservableScrollView;
import com.electric.chargingpile.view.RoundImageView;
import com.electric.chargingpile.view.ScrollViewListener;
import com.electric.chargingpile.view.SignInDialog;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.picasso.Picasso;
import com.umeng.analytics.MobclickAgent;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;
import com.zhy.http.okhttp.request.RequestCall;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;
import okhttp3.Call;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;
//import cn.sharesdk.framework.Platform;
//import cn.sharesdk.framework.PlatformActionListener;
//import cn.sharesdk.framework.ShareSDK;
//import cn.sharesdk.onekeyshare.OnekeyShare;
public class UserCenterActivity extends Activity implements View.OnClickListener,
ScrollViewListener, WeatherSearch.OnWeatherSearchListener, EasyPermissions.PermissionCallbacks {
private static final String TAG = "UserCenterActivity";
private IntentFilter intentFilter;
private Bitmap download_bmp;
private NetworkChangeReceiver networkChangeReceiver;
private ImageView iv_back, iv_message, iv_qiandao, iv_share_prompt, iv_find, iv_main, iv_screening, iv_point;
private RelativeLayout rl_addZhan, rl_collection, rl_more,
rl_offline, rl_shop, rl_message, rl_feedback, rl_shareNo, rl_offline_upload, rl_chongzhi, rl_myaccount, rl_yue, rl_chongdianbi, rl_hongbao;
private ToggleButton mTogBtn;
private TextView tv_exit, userLogin, userRegister, chongdianbi, yue, hongbao, tv_our;
private LinearLayout ll_userLogin;
private RelativeLayout ll_noLogin, rl_myaq, ll_tab_find;
private TextView show_userPoints, show_userName, tv_msg_num, tv_msg_num1;
private ImageView iv_gift, usermore, bg_icon, default_icon, iv_rank, iv_tishi, iv_usermore, iv_yue, iv_hongbao, iv_chongdianbi, iv_paihang, iv_qiandao_default, iv_paihang_default;
private RoundImageView userIcon;
private RelativeLayout llPerson, rl_sirenzhuang;
private String integral, integral2;
private LinearLayout tab_main, tab_hot, tab_claim, tab_me, tab_scan, tab_qa;
static Bitmap bitmap = null;
private Bitmap bm = null;
private FrameLayout fl_icon;
private long exitTime = 0;
private String shareNo;
private RelativeLayout ll_btn, rl_shezhi;
private ObservableScrollView sv;
private Activity activity;
private int zhanMessageNum = 0, commentNum = 0;
String name;
Bitmap target;
private ImageView iv_our;
private WeatherSearchQuery mquery;
private WeatherSearchQuery mquery1;
private WeatherSearch mweathersearch;
private WeatherSearch mweathersearch1;
private String now_temperature = "", now_weather = "", temperature = "";
// String imageUrl = MainApplication.userIcon;
Bitmap usericonbt;
private TextView tv_qaNum, tv_messageNum;
private static final int RC_CAMERA_PERM = 123;
private Handler handler = new Handler() {
// 主线程通过这个方法处理消息
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 3:
Toast.makeText(getApplication(), "服务器处理错误", Toast.LENGTH_SHORT).show();
break;
case 17:
try {
JSONObject jsonObject = new JSONObject(msg.obj.toString());
String pingLunNum = jsonObject.getString("rtnMsg");
Log.d("pingLunNum+++", pingLunNum);
MainMapActivity.have_pinglun = Integer.parseInt(pingLunNum);
Log.d("pinglun===yonghu", MainMapActivity.have_message + "");
// if (MainMapActivity.have_message == 0 && MainMapActivity.have_pinglun == 0) {
//// ivRight.setImageResource(R.drawable.icon_user2_0);
//// iv_havemessage.setVisibility(View.GONE);
// iv_message.setVisibility(View.INVISIBLE);
// if (MainApplication.festival_time.equals("1")){
// iv_our.setImageResource(R.drawable.icon_cj4);
// }else if (MainApplication.festival_time.equals("2")){
// iv_our.setImageResource(R.drawable.icon_yx4);
// }else {
// iv_our.setImageResource(R.drawable.tab_our_selected);
// }
//// iv_our.setImageResource(R.drawable.tab_our_selected);
// } else if (MainMapActivity.have_message == 1) {
// if (MainApplication.festival_time.equals("1")){
// iv_our.setImageResource(R.drawable.icon_cjh4);
// }else if (MainApplication.festival_time.equals("2")){
// iv_our.setImageResource(R.drawable.icon_yxh4);
// }else {
// iv_our.setImageResource(R.drawable.tab_our_selected_h);
// }
//// iv_our.setImageResource(R.drawable.tab_our_selected_h);
//// iv_havemessage.setVisibility(View.VISIBLE);
// iv_message.setVisibility(View.VISIBLE);
// } else if (MainMapActivity.have_pinglun > 0) {
//// iv_havemessage.setVisibility(View.VISIBLE);
// iv_message.setVisibility(View.VISIBLE);
// if (MainApplication.festival_time.equals("1")){
// iv_our.setImageResource(R.drawable.icon_cjh4);
// }else if (MainApplication.festival_time.equals("2")){
// iv_our.setImageResource(R.drawable.icon_yxh4);
// }else {
// }
// iv_our.setImageResource(R.drawable.tab_our_selected_h);
// }
// }
} catch (JSONException e) {
e.printStackTrace();
}
break;
// case 5:
//// Log.e("log",msg.obj.toString());
// try {
// JSONArray jsonArray = new JSONArray(msg.obj.toString());
// Log.e("???",jsonArray.length()+"");
// Log.e("???",msg.obj.toString());
// if (jsonArray.length() == 0){
// Log.e("!!!",jsonArray.length()+"");
// iv_message.setVisibility(View.INVISIBLE);
// have_message = 0;
// }else{
// Log.e("@@@",jsonArray.length()+"");
// iv_message.setVisibility(View.VISIBLE);
// have_message = 1;
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
//// if (msg.obj.toString() == null || msg.obj.toString().equals("") ||msg.obj.toString().equals("null")){
//// iv_message.setVisibility(View.INVISIBLE);
//// }
// break;
default:
break;
}
}
};
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
private ImageView chat_share_bar;
//把一个url的网络图片变成一个本地的BitMap
public Bitmap returnBitMap(final String url) {
new Thread(new Runnable() {
@Override
public void run() {
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
return bitmap;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_center);
intentFilter = new IntentFilter();
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
networkChangeReceiver = new NetworkChangeReceiver();
registerReceiver(networkChangeReceiver, intentFilter);
//透明状态栏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//透明导航栏
// getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
initView();
activity = this;
if (MainApplication.isLogin()) {
getPingLun();
}
// getMessage();
// getIntegration();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
Handler hand = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 2:
try {
saveBitmap(bm);
setIcon();
} catch (Exception e) {
e.printStackTrace();
}
// saveBitmap(bm);
break;
default:
break;
}
}
;
};
private void initView() {
mquery = new WeatherSearchQuery(MainMapActivity.location_city, WeatherSearchQuery.WEATHER_TYPE_FORECAST);
mweathersearch = new WeatherSearch(this);
mweathersearch.setOnWeatherSearchListener(this);
mweathersearch.setQuery(mquery);
mweathersearch.searchWeatherAsyn(); //异步搜索
mquery1 = new WeatherSearchQuery(MainMapActivity.location_city, WeatherSearchQuery.WEATHER_TYPE_LIVE);
mweathersearch1 = new WeatherSearch(this);
mweathersearch1.setOnWeatherSearchListener(this);
mweathersearch1.setQuery(mquery1);
mweathersearch1.searchWeatherAsyn(); //异步搜索
sv = (ObservableScrollView) findViewById(R.id.sv);
sv.setScrollViewListener(this);
iv_qiandao = (ImageView) findViewById(R.id.iv_qiandao);
iv_qiandao.setOnClickListener(this);
rl_shezhi = findViewById(R.id.rl_shezhi);
int statusBarHeight = BarUtils.getStatusBarHeight();
rl_shezhi.setTranslationY(statusBarHeight);
tv_qaNum = (TextView) findViewById(R.id.tv_qaNum);
tv_messageNum = (TextView) findViewById(R.id.tv_messageNum);
tab_qa = (LinearLayout) findViewById(R.id.tab_qa);
tab_qa.setOnClickListener(this);
iv_qiandao_default = (ImageView) findViewById(R.id.iv_qiandao_default);
iv_gift = (ImageView) findViewById(R.id.iv_gift);
iv_qiandao_default.setOnClickListener(this);
iv_gift.setOnClickListener(this);
iv_paihang = (ImageView) findViewById(R.id.iv_paihang);
iv_paihang.setOnClickListener(this);
iv_paihang_default = (ImageView) findViewById(R.id.iv_paihang_default);
iv_paihang_default.setOnClickListener(this);
rl_sirenzhuang = (RelativeLayout) findViewById(R.id.rl_sirenzhuang);
rl_sirenzhuang.setOnClickListener(this);
iv_share_prompt = (ImageView) findViewById(R.id.iv_share_prompt);
tv_msg_num = (TextView) findViewById(R.id.tv_msg_num);
rl_myaq = (RelativeLayout) findViewById(R.id.rl_myaq);
rl_myaq.setOnClickListener(this);
iv_yue = (ImageView) findViewById(R.id.iv_yue);
iv_hongbao = (ImageView) findViewById(R.id.iv_hongbao);
iv_chongdianbi = (ImageView) findViewById(R.id.iv_chongdianbi);
yue = (TextView) findViewById(R.id.tv_yue);
// iv_message = (ImageView) findViewById(R.id.iv_message);
iv_message = (ImageView) findViewById(R.id.iv_have_message);
ll_tab_find = (RelativeLayout) findViewById(R.id.ll_tab_find);
ll_tab_find.setOnClickListener(this);
chongdianbi = (TextView) findViewById(R.id.tv_chongdianbi);
hongbao = (TextView) findViewById(R.id.tv_hongbao);
ll_btn = (RelativeLayout) findViewById(R.id.ll_btn);
iv_point = findViewById(R.id.iv_point);
iv_our = (ImageView) findViewById(R.id.iv_our);
// if (MainMapActivity.have_message == 1) {
// Log.e("userCenter==",MainMapActivity.have_message+"");
// iv_message.setVisibility(View.VISIBLE);
// } else {
// iv_message.setVisibility(View.INVISIBLE);
// }
// iv_havemessage = (ImageView) findViewById(R.id.iv_havemessage);
// if (MainFragment.have_message == 1){
// iv_havemessage.setVisibility(View.VISIBLE);
// }else if(MainFragment.have_message == 0){
// iv_havemessage.setVisibility(View.GONE);
// }
// if (have_message == 1){
// iv_message.setVisibility(View.VISIBLE);
// }else{
// iv_message.setVisibility(View.INVISIBLE);
// }
rl_collection = (RelativeLayout) findViewById(R.id.rl_collection);
rl_collection.setOnClickListener(this);
// rl_more = (RelativeLayout) findViewById(R.id.rl_more);
// rl_more.setOnClickListener(this);
rl_message = (RelativeLayout) findViewById(R.id.rl_message);
rl_message.setOnClickListener(this);
rl_shareNo = (RelativeLayout) findViewById(R.id.rl_shareNo);
rl_shareNo.setOnClickListener(this);
rl_offline_upload = (RelativeLayout) findViewById(R.id.rl_offline_upload);
rl_offline_upload.setOnClickListener(this);
chat_share_bar = findViewById(R.id.chat_share_bar);
chat_share_bar.setOnClickListener(this);
rl_chongzhi = (RelativeLayout) findViewById(R.id.rl_chongzhi);
rl_chongzhi.setOnClickListener(this);
rl_myaccount = (RelativeLayout) findViewById(R.id.rl_myaccount);
rl_myaccount.setOnClickListener(this);
rl_chongdianbi = (RelativeLayout) findViewById(R.id.rl_chongdianbi);
rl_chongdianbi.setOnClickListener(this);
rl_hongbao = (RelativeLayout) findViewById(R.id.rl_hongbao);
rl_hongbao.setOnClickListener(this);
rl_yue = (RelativeLayout) findViewById(R.id.rl_yue);
rl_yue.setOnClickListener(this);
// mTogBtn = (ToggleButton) findViewById(R.id.iosbutton); // 获取到控件
// if (MainApplication.userTpye == "1") {
// mTogBtn.setChecked(false);
// } else if (MainApplication.userTpye == "2") {
// mTogBtn.setChecked(true);
// }
//
// mTogBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//
// @Override
// public void onCheckedChanged(CompoundButton buttonView,
// boolean isChecked) {
// // TODO Auto-generated method stub
// if (isChecked) {
// MainApplication.userTpye = "2";
// Log.e("suit_car", "特斯拉");
// MainFragment.firstSelect();
// } else {
// MainApplication.userTpye = "1";
// Log.e("suit_car", "国标");
// MainFragment.firstSelect();
// }
// }
// });
tab_main = (LinearLayout) findViewById(R.id.tab_main);
tab_main.setOnClickListener(this);
tab_hot = (LinearLayout) findViewById(R.id.tab_hot);
tab_hot.setOnClickListener(this);
tab_claim = (LinearLayout) findViewById(R.id.tab_claim);
tab_claim.setOnClickListener(this);
tab_scan = (LinearLayout) findViewById(R.id.tab_screening);
tab_scan.setOnClickListener(this);
iv_find = (ImageView) findViewById(R.id.iv_find);
iv_main = (ImageView) findViewById(R.id.iv_main);
iv_screening = (ImageView) findViewById(R.id.iv_screening);
tv_our = (TextView) findViewById(R.id.tv_our);
//整个用户banner布局
llPerson = (RelativeLayout) findViewById(R.id.ll_person);
llPerson.setOnClickListener(this);
//退出登录按钮
// tv_exit = (TextView) findViewById(R.id.tv_exit);
// tv_exit.setOnClickListener(this);
//登陆按钮
userLogin = (TextView) findViewById(R.id.userLogin);
userLogin.setOnClickListener(this);
//注册按钮
userRegister = (TextView) findViewById(R.id.userRegister);
userRegister.setOnClickListener(this);
//包含登陆按钮和注册按钮的线性布局
ll_userLogin = (LinearLayout) findViewById(R.id.ll_userLogin);
//未登录状态头像显示
ll_noLogin = (RelativeLayout) findViewById(R.id.ll_noLogin);
//显示用户积分
// show_userPoints = (TextView) findViewById(R.id.show_userPoints);
//显示用户名
show_userName = (TextView) findViewById(R.id.show_username);
//用户详情信息图标
usermore = (ImageView) findViewById(R.id.iv_usermore);
//用户头像
userIcon = (RoundImageView) findViewById(R.id.user);
// if (!MainApplication.userIcon.equals("")) {
// PicassoUtil.loadingNetImage(getApplication(), MainApplication.userIcon, userIcon);
// }
bg_icon = (ImageView) findViewById(R.id.bg_icon);
// iv_rank = (ImageView) findViewById(R.id.iv_rank);
iv_usermore = (ImageView) findViewById(R.id.iv_usermore);
iv_usermore.setOnClickListener(this);
if (MainMapActivity.total_unread > 0) {
tv_msg_num.setVisibility(View.VISIBLE);
tv_msg_num.setText(MainMapActivity.total_unread + "");
if (MainMapActivity.question_unread > 0) {
tv_qaNum.setVisibility(View.VISIBLE);
tv_qaNum.setText(MainMapActivity.question_unread + "");
} else {
tv_qaNum.setVisibility(View.GONE);
}
if (MainMapActivity.system_unread + MainMapActivity.comment_unread > 0) {
tv_messageNum.setVisibility(View.VISIBLE);
tv_messageNum.setText(MainMapActivity.system_unread + MainMapActivity.comment_unread + "");
} else {
tv_messageNum.setVisibility(View.GONE);
}
} else {
tv_msg_num.setVisibility(View.GONE);
tv_qaNum.setVisibility(View.GONE);
tv_messageNum.setVisibility(View.GONE);
}
// iv_tishi = (ImageView) findViewById(R.id.iv_tishi);
// iv_tishi.setOnClickListener(this);
//默认头像
// setIcon();
// PicassoUtil.loadingNetImage(UserCenterActivity.this, MainApplication.userIcon, userIcon);
set_loginShow();
}
private void getSharePrompt(String user_id) {
OkHttpUtils.get().url("http://123.57.6.131/zhannew/basic/web/index.php/present/index")
.addParams("user_id", user_id)
.build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
String status = JsonUtils.getKeyResult(response, "status");
// Log.e("status===",status);
if (status.equals("1")) {
iv_share_prompt.setVisibility(View.VISIBLE);
} else {
iv_share_prompt.setVisibility(View.GONE);
}
}
});
}
private void setIcon() {
// if (!MainApplication.userIcon.equals("")&&!MainApplication.userIcon.equals("V")){
// new Thread(new Runnable() {
// @Override
// public void run() {
// Log.e("1234","22222222");
// bm = ImageLoader.getInstance().loadImageSync(MainApplication.userIcon);
// if (bm != null) {
// Message mes = new Message();
// mes.obj = bm;
// mes.what = 2;
// hand.sendMessage(mes);
// }
// }
// }).start();
// }
if (MainApplication.userIcon.equals("V")) {
// Log.e("1111", "11111");
usericonbt = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + File.separator + "d1ev/usericon");
userIcon.setImageBitmap(usericonbt);
} else if (MainApplication.userIcon.equals("")) {
// Log.e("2222", "22222");
userIcon.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon_face2_0));
} else {
// Log.e("3333", "33333");
// userIcon.setImageBitmap(bm);
if (!MainApplication.userIcon.equals("")) {
// Glide.with(MainApplication.context)
// .load(MainApplication.userIcon)
// .error(R.drawable.icon_face2_0)
// .placeholder(R.drawable.icon_face2_0)
// .into(userIcon);
PicassoUtil.loadingNetImage(getApplication(), MainApplication.userIcon, userIcon);
}
}
}
public void saveBitmap(Bitmap mBitmap) {
String dir_path = Environment.getExternalStorageDirectory() + File.separator + "d1ev/";
File directory = new File(dir_path);
File f = new File(dir_path, "usericon");
try {
if (!directory.exists()) {
directory.mkdir();//没有目录先创建目录
}
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
}
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (Exception e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
if ((System.currentTimeMillis() - exitTime) > 2000) {
Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
exitTime = System.currentTimeMillis();
} else {
if (MainMapActivity.mainMapActivity != null) {
MainMapActivity.mainMapActivity.finish();
}
SharedPreferences mySharedPreferences = getSharedPreferences("showdialog",
Activity.MODE_PRIVATE);
SharedPreferences.Editor editor1 = mySharedPreferences.edit();
editor1.clear();
ProfileManager.getInstance().setSearchAddress(this, "");
ActivityUtils.finishAllActivities();
// finish();
// System.exit(0);
Process.killProcess(Process.myPid());
}
return true;
}
return super.onKeyDown(keyCode, event);
}
// public void saveBitmap() {
// Log.e("@@@", "保存图片");
// File f = new File("/sdcard/d1ev/", "usericon");
// if (f.exists()) {
// f.delete();
// }
// try {
// FileOutputStream out = new FileOutputStream(f);
// bm.compress(Bitmap.CompressFormat.PNG, 90, out);
// out.flush();
// out.close();
// Log.i("@@@", "已经保存");
// } catch (FileNotFoundException e) {
//// TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
//// TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
private void set_loginShow() {
if (MainApplication.isLogin()) {
// if (!MainApplication.userIcon.equals("")){
// PicassoUtil.loadingNetImage(UserCenterActivity.this, MainApplication.userIcon, userIcon);
// }else {
//
// SharedPreferences sharedPreferences= getSharedPreferences("userInfo",
// Activity.MODE_PRIVATE);
//
// String userphoto = sharedPreferences.getString("userphoto","");
// Log.e("!!!",userphoto);
// userIcon.setImageBitmap(base64ToBitmap(userphoto));
// }
////
setIcon();
// bg_icon.setVisibility(View.VISIBLE);
// iv_tishi.setVisibility(View.VISIBLE);
// createCircleImage(returnBitMap(imageUrl),15);
// userIcon.setImageBitmap(target);
userIcon.setVisibility(View.VISIBLE);
// fl_icon.setVisibility(View.VISIBLE);
ll_btn.setVisibility(View.VISIBLE);
ll_btn.setEnabled(true);
ll_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MobclickAgent.onEvent(getApplicationContext(), "0802");
// startActivity(new Intent(getApplicationContext(), PersonalPageActivity.class));
// startActivity(new Intent(getApplicationContext(), UserInfoActivity.class));
startActivity(new Intent(getApplicationContext(), UserPageActivity.class));
}
});
ll_userLogin.setVisibility(View.INVISIBLE);
ll_noLogin.setVisibility(View.INVISIBLE);
iv_yue.setVisibility(View.GONE);
iv_chongdianbi.setVisibility(View.GONE);
iv_hongbao.setVisibility(View.GONE);
yue.setVisibility(View.VISIBLE);
hongbao.setVisibility(View.VISIBLE);
chongdianbi.setVisibility(View.VISIBLE);
show_userName.setVisibility(View.VISIBLE);
// iv_rank.setVisibility(View.GONE);
if (!ProfileManager.getInstance().getNickname(getApplication()).equals("")) {
sp();
MainApplication.userNickname = ProfileManager.getInstance().getNickname(getApplication());
show_userName.setText(MainApplication.userNickname);
} else {
show_userName.setText(Util.handlePhone(ProfileManager.getInstance()
.getUsername(getApplication())));
}
// show_userPoints.setVisibility(View.VISIBLE);
// default_icon.setVisibility(View.GONE);
// usermore.setVisibility(View.VISIBLE);
// tv_exit.setVisibility(View.VISIBLE);
MainApplication.userPhone = ProfileManager.getInstance().getUsername(getApplication());
MainApplication.userId = ProfileManager.getInstance().getUserid(getApplication());
// MainApplication.userIcon = ProfileManager.getInstance().getUsericon(getApplication());
} else {
iv_gift.setImageResource(R.drawable.icon_qiandaohavegift);
ll_btn.setVisibility(View.GONE);
llPerson.setEnabled(false);
ll_userLogin.setVisibility(View.VISIBLE);
ll_noLogin.setVisibility(View.VISIBLE);
iv_yue.setVisibility(View.VISIBLE);
iv_hongbao.setVisibility(View.VISIBLE);
iv_chongdianbi.setVisibility(View.VISIBLE);
yue.setVisibility(View.INVISIBLE);
hongbao.setVisibility(View.INVISIBLE);
chongdianbi.setVisibility(View.INVISIBLE);
show_userName.setVisibility(View.INVISIBLE);
// show_userPoints.setVisibility(View.INVISIBLE);
// usermore.setVisibility(View.INVISIBLE);
// iv_rank.setVisibility(View.GONE);
// tv_exit.setVisibility(View.GONE);
// iv_tishi.setVisibility(View.GONE);
// default_icon.setVisibility(View.VISIBLE);
bg_icon.setVisibility(View.INVISIBLE);
userIcon.setVisibility(View.GONE);
// fl_icon.setVisibility(View.GONE);
}
}
private void sp() {
SharedPreferences mySharedPreferences = getSharedPreferences("userInfo",
Activity.MODE_PRIVATE);
name = mySharedPreferences.getString("nickname", "");
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.rl_myaq:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
MobclickAgent.onEvent(getApplicationContext(), "0812");
startActivityForResult(new Intent(getApplicationContext(), MyQAActivity.class), 2);
}
break;
case R.id.iv_qiandao:
MobclickAgent.onEvent(getApplicationContext(), "0803");
startActivity(new Intent(getApplication(), MemberCenterActivity.class));
break;
case R.id.iv_qiandao_default:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
}
break;
case R.id.iv_gift:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
MobclickAgent.onEvent(getApplicationContext(), "0805");
// startActivity(new Intent(getApplication(), WebQianDaoActivity.class));
// MobclickAgent.onEvent(getApplicationContext(), "0015");
signIn();
}
break;
case R.id.ll_tab_find:
MobclickAgent.onEvent(getApplicationContext(), "0105");
Intent intent = new Intent(getApplication(), FindActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
overridePendingTransition(0, 0);
break;
case R.id.tab_main:
Intent ii = new Intent(getApplication(), MainMapActivity.class);
ii.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(ii);
MobclickAgent.onEvent(getApplicationContext(), "0118");
finish();
overridePendingTransition(0, 0);
break;
case R.id.tab_screening:
if (!MainApplication.isLogin()) {
startActivity(new Intent(getApplication(), LoginActivity.class));
} else if (!cameraTask()) {
EasyPermissions.requestPermissions(
this,
"该功能需要开启摄像头权限,是否前往开启?",
RC_CAMERA_PERM,
Manifest.permission.CAMERA);
} else {
Intent iintent = new Intent(getApplicationContext(), com.google.zxing.client.android.CaptureActivity.class);
iintent.putExtra("url", MainApplication.url);
iintent.putExtra("user_id", MainApplication.userId);
iintent.putExtra("user_password", MainApplication.userPassword);
iintent.putExtra("user_phone", MainApplication.userPhone);
iintent.putExtra("cha", MainMapActivity.cha);
iintent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(iintent);
overridePendingTransition(0, 0);
MobclickAgent.onEvent(getApplicationContext(), "0104");
}
break;
case R.id.tab_qa:
MobclickAgent.onEvent(getApplicationContext(), "0103");
Intent intent7 = new Intent(getApplication(), ChatActivity.class);
intent7.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent7);
finish();
overridePendingTransition(0, 0);
break;
case R.id.iv_back:
// finish();
break;
case R.id.iv_paihang:
startActivity(new Intent(getApplicationContext(), RankingListActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0804");
break;
case R.id.iv_paihang_default:
startActivity(new Intent(getApplicationContext(), RankingListActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0804");
break;
// case R.id.iv_tishi:
// startActivity(new Intent(getApplication(),IntegralDescriptionActivity.class));
//// Toast.makeText(UserCenterActivity.this,"还没有跳转界面",Toast.LENGTH_SHORT).show();
// break;
case R.id.rl_shareNo:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
Intent intent4 = new Intent(getApplication(), MyWebViewActivity.class);
intent4.putExtra("url", "http://evcharge.cc/cdz/yqm.html?code=" +
getShareNo(Integer.parseInt(MainApplication.userId)) + "&phone=" + MainApplication.userPhone + "&ver=" + Math.random());
startActivity(intent4);
MobclickAgent.onEvent(getApplicationContext(), "0811");
// startActivity(new Intent(getApplicationContext(),MemberGetCoinActivity.class));
// startActivity(new Intent(getApplicationContext(),MemberCenterActivity.class));
}
break;
case R.id.rl_collection:
// startActivity(new Intent(getApplication(), MyFeedbackActivity.class));
startActivity(new Intent(getApplication(), MyCollectActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0815");
break;
case R.id.rl_chongzhi:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
startActivity(new Intent(getApplication(), AccountRechargeActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0810");
}
break;
case R.id.rl_hongbao:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
long appTime4 = System.currentTimeMillis() / 1000;
long updatetime4 = appTime4 - MainMapActivity.cha - 1;
String token4 = String.valueOf(updatetime4);
Intent intent4 = new Intent(getApplication(), MyWebViewActivity.class);
String web1 = null;
try {
web1 = MainApplication.url + "/zhannew/basic/web/index.php/discount/redlist?userid=" + MainApplication.userId + "&token=" + URLEncoder.encode(DES3.encode(token4));
} catch (Exception e) {
e.printStackTrace();
}
intent4.putExtra("url", web1);
startActivity(intent4);
MobclickAgent.onEvent(getApplicationContext(), "0808");
}
break;
case R.id.rl_chongdianbi:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
startActivity(new Intent(getApplication(), ChargingCoinsActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0809");
}
break;
case R.id.rl_yue:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
startActivity(new Intent(getApplication(), MyBalanceActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0807");
}
break;
case R.id.rl_myaccount:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
startActivity(new Intent(getApplication(), MyAccountActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0806");
}
break;
case R.id.rl_feedback:
startActivity(new Intent(getApplication(), FeedbackActivity.class));
break;
case R.id.rl_message:
// if (!MainApplication.isLogin()) {
// Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
// startActivity(new Intent(getApplication(), LoginActivity.class));
//// finish();
// } else {
startActivityForResult(new Intent(getApplication(), MyMessageActivity.class), 1);
// finish();
MobclickAgent.onEvent(getApplicationContext(), "0814");
// }
// startActivity(new Intent(getApplication(), MessageActivity.class));
break;
case R.id.rl_offline_upload:
startActivity(new Intent(getApplication(), OfflineMapActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0816");
break;
case R.id.chat_share_bar: // 聊聊入口
Intent i = new Intent(getApplicationContext(), ChatActivity.class);//聊聊页面
i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(i);
break;
case R.id.iv_usermore:
startActivity(new Intent(getApplication(), UserCenterMoreActivity.class));
MobclickAgent.onEvent(getApplicationContext(), "0817");
// startActivityForResult(new Intent(getApplication(), UserInfoActivity.class), 3);
// startActivity(new Intent(getApplication(),UserInfoActivity.class));
break;
case R.id.userLogin:
startActivity(new Intent(getApplication(), LoginActivity.class));
// finish();
break;
case R.id.userRegister:
startActivity(new Intent(getApplication(), RegisterActivity.class));
// finish();
break;
// case R.id.rl_more:
// startActivity(new Intent(getApplication(), UserCenterMoreActivity.class));
// break;
case R.id.rl_sirenzhuang:
if (!MainApplication.isLogin()) {
Toast.makeText(getApplication(), "请先登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplication(), LoginActivity.class));
} else {
MobclickAgent.onEvent(getApplicationContext(), "0813");
startActivity(new Intent(this, PrivateZhaungListActivity.class));
}
break;
}
}
private Bitmap createCircleImage(Bitmap source, int min) {
final Paint paint = new Paint();
paint.setAntiAlias(true);
target = Bitmap.createBitmap(min, min, Bitmap.Config.ARGB_8888);
/**
* 产生一个同样大小的画布
*/
Canvas canvas = new Canvas(target);
/**
* 首先绘制圆形
*/
canvas.drawCircle(min / 2, min / 2, min / 2, paint);
/**
* 使用SRC_IN,参考上面的说明
*/
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
/**
* 绘制图片
*/
canvas.drawBitmap(source, 0, 0, paint);
return target;
}
private void getIntegration() {
if (!NetUtil.CheckNetwork(this)) {
Toast.makeText(this, "请检查网络", Toast.LENGTH_SHORT).show();
return;
}
new Thread(new Runnable() {
@Override
public void run() {
// String url = "https://192.168.1.131/t.php";
String url = "";
// OkHttpUtils.get("https://www.baidu.com",new OkHttpUtils.)
// OkHttpUtils
// .get()
// .url(url)
//// .addParams("username", "hyman")
//// .addParams("password", "123")
// .build()
// .execute(new StringCallback()
// {
//
// @Override
// public void onError(Call call, Exception e) {
// }
//
// @Override
// public void onResponse(String response)
// {
// Log.e("@!#",response);
// }
// });
try {
url = MainApplication.url + "/zhannew/basic/web/index.php/tpmember/getintegral_v2?" +
"user_id=" + MainApplication.userId + "&password=" + URLEncoder.encode(MainApplication.userPassword);
// Log.d("url=====",url);
// OkHttpUtils.get()
// .url(url)
// .build()
// .execute(new StringCallback() {
// @Override
// public void onError(Call call, Exception e) {
//
// }
//
// @Override
// public void onResponse(String response) {
// Log.e("===",response);
// }
// });
} catch (Exception e) {
e.printStackTrace();
}
submit(url);
}
}).start();
}
private void submit(String sms) {
// Log.e("url", sms);
Request request = new Request.Builder().url(sms).build();
Response response = null;
try {
if (request == null) {
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
return;
}
response = OkHttpUtil.execute(request);
if (response.code() == 200) {
String json = "";
try {
json = response.body().string();
Message msg = new Message();
msg.obj = json;
msg.what = 2;
handler.sendMessage(msg);
// Log.e("url!!!", json);
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//先判断是哪个页面返回过来的
switch (requestCode) {
case 3:
//再判断返回过来的情况,是成功还是失败还是其它的什么……
// switch (resultCode) {
// case UserInfoActivity.RESULT_SUCCESS:
// //成功了
//// String nickname = getIntent().getStringExtra("nickname");
//// show_userName.setText(nickname);
//
//// MainApplication.isLogin();
//// set_loginShow();
// break;
// }
// break;
case 1:
// Log.e(TAG, "aaa onActivityResult 1" );
getMessageNum();
break;
case 2:
// Log.e(TAG, "aaa onActivityResult 2" );
getMessageNum();
break;
}
}
private void getMessageNum() {
long appTime1 = System.currentTimeMillis() / 1000;
String token = String.valueOf(appTime1);
if (MainApplication.msgTime.equals("0")) {
MainApplication.firstOpenTime = token;
ProfileManager.getInstance().setFirstOpenTime(getApplicationContext(), token);
MainApplication.msgTime = token;
ProfileManager.getInstance().setSystemMsgTime(getApplicationContext(), token);
}
String url = MainApplication.url + "/zhannew/basic/web/index.php/question/center?user_id=" +
MainApplication.userId + "&timer=" + MainApplication.msgTime + "&phone=" + MainApplication.userPhone
+ "&password=" + MainApplication.userPassword;
OkHttpUtils.get().url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
// Log.e(TAG, "onResponse: "+response );
String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
if ("01".equals(rtnCode)) {
String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
MainMapActivity.question_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg, "question_unread"));
MainMapActivity.comment_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg, "comment_unread"));
MainMapActivity.system_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg, "system_unread"));
MainMapActivity.total_unread = MainMapActivity.question_unread + MainMapActivity.comment_unread + MainMapActivity.system_unread;
if (MainMapActivity.total_unread > 0) {
tv_msg_num.setVisibility(View.VISIBLE);
tv_msg_num.setText(MainMapActivity.total_unread + "");
if (MainMapActivity.question_unread > 0) {
tv_qaNum.setVisibility(View.VISIBLE);
tv_qaNum.setText(MainMapActivity.question_unread + "");
} else {
tv_qaNum.setVisibility(View.GONE);
}
if (MainMapActivity.system_unread + MainMapActivity.comment_unread > 0) {
tv_messageNum.setVisibility(View.VISIBLE);
tv_messageNum.setText(MainMapActivity.system_unread + MainMapActivity.comment_unread + "");
} else {
tv_messageNum.setVisibility(View.GONE);
}
} else {
tv_msg_num.setVisibility(View.GONE);
tv_qaNum.setVisibility(View.GONE);
tv_messageNum.setVisibility(View.GONE);
}
}
}
});
}
@Override
protected void onResume() {
if (FindActivity.haveFindMessage == true) {
iv_point.setVisibility(View.VISIBLE);
} else {
iv_point.setVisibility(View.GONE);
}
set_loginShow();
if (MainApplication.isLogin()) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getUserIntegral();
}
}, 300);
}
super.onResume();
MobclickAgent.onResume(this);
if (MainApplication.isLogin()) {
if (!"".equals(MainApplication.userIcon)) {
Picasso.with(UserCenterActivity.this)
.load(MainApplication.userIcon)
.placeholder(R.drawable.icon_face2_0)
.error(R.drawable.icon_face2_0)
.into(userIcon);
} else {
userIcon.setImageResource(R.drawable.icon_face2_0);
}
}
}
@Override
public void onWeatherLiveSearched(LocalWeatherLiveResult localWeatherLiveResult, int rCode) {
if (rCode == 1000) {
if (localWeatherLiveResult != null & localWeatherLiveResult.getLiveResult() != null) {
LocalWeatherLive weatherlive = localWeatherLiveResult.getLiveResult();
// Log.e(TAG, "onWeatherLiveSearched: " + "-------" + weatherlive.getCity() + "-------" + weatherlive.getAdCode()
// + "-------" + weatherlive.getHumidity() + "-------" + weatherlive.getProvince() + "-------" + weatherlive.getReportTime()
// + "-------" + weatherlive.getTemperature() + "-------" + weatherlive.getWeather() + "-------" + weatherlive.getWindDirection()
// + "-------" + weatherlive.getWindPower());
now_temperature = weatherlive.getTemperature();
} else {
// ToastUtil.show(WeatherSearchActivity.this, R.string.no_result);
}
} else {
// ToastUtil.showToast(UserCenterActivity.this, rCode + "", Toast.LENGTH_SHORT);
}
}
@Override
public void onWeatherForecastSearched(LocalWeatherForecastResult localWeatherForecastResult, int i) {
if (i == 1000) {
if (localWeatherForecastResult != null & localWeatherForecastResult.getForecastResult() != null) {
LocalWeatherForecast weatherlive = localWeatherForecastResult.getForecastResult();
// Log.e(TAG, "onWeatherLiveSearched: " + "-------" + weatherlive.getCity() + "-------" + weatherlive.getAdCode()
// + "-------" + weatherlive.getWeatherForecast().get(1)..getWeatherForecast() + "-------" + weatherlive.getProvince() + "-------" + weatherlive.getReportTime());
List<LocalDayWeatherForecast> list = weatherlive.getWeatherForecast();
if (list.size() > 1) {
temperature = list.get(0).getDayTemp() + "~" + list.get(0).getNightTemp();
if (list.get(0).getNightWeather().equals(list.get(0).getDayWeather())) {
now_weather = list.get(0).getDayWeather();
} else {
now_weather = list.get(0).getDayWeather() + "转" + list.get(0).getNightWeather();
}
}
// for (int a = 0; a < list.size(); a++) {
// Log.e(TAG, "onWeatherForecastSearched: " + list.get(a).getDate());
// Log.e(TAG, "onWeatherForecastSearched: " + list.get(a).getDayTemp());
// Log.e(TAG, "onWeatherForecastSearched: " + list.get(a).getDayWeather());
// Log.e(TAG, "onWeatherForecastSearched: " + list.get(a).getNightTemp());
// Log.e(TAG, "onWeatherForecastSearched: " + list.get(a).getNightWeather());
//
// }
// reporttime1.setText(weatherlive.getReportTime()+"发布");
// weather.setText(weatherlive.getWeather());
// Temperature.setText(weatherlive.getTemperature()+"°");
// wind.setText(weatherlive.getWindDirection()+"风 "+weatherlive.getWindPower()+"级");
// humidity.setText("湿度 "+weatherlive.getHumidity()+"%");
} else {
// ToastUtil.show(WeatherSearchActivity.this, R.string.no_result);
}
} else {
// ToastUtil.showToast(MainMapActivity.this, rCode+"",Toast.LENGTH_SHORT);
}
}
private void getPingLun() {
// if (!NetUtil.CheckNetwork(getApplication())) {
// Toast.makeText(this, "请检查网络", Toast.LENGTH_SHORT).show();
// return;
// }
new Thread(new Runnable() {
@Override
public void run() {
String url = null;
try {
url = MainApplication.url + "/zhannew/basic/web/index.php/tpmember/commentcount?userid=" + MainApplication.userId;
} catch (Exception e) {
e.printStackTrace();
}
submitPingLun(url);
// long appTime1 = System.currentTimeMillis() / 1000;
// String token = String.valueOf(appTime1);
// MainApplication.messageToken = token;
// ProfileManager.getInstance().setMessageToken(UserCenterActivity.this, token);
// Log.e("token",MainApplication.messageToken);
}
}).start();
}
private void submitPingLun(String sms) {
// Log.e("url", sms);
Request request = new Request.Builder().url(sms).build();
Response response = null;
try {
if (request == null) {
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
return;
}
response = OkHttpUtil.execute(request);
if (response.code() == 200) {
String json = "";
try {
json = response.body().string();
Message msg = new Message();
msg.obj = json;
msg.what = 17;
handler.sendMessage(msg);
// Log.e("url", json);
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
} catch (Exception e) {
e.printStackTrace();
Message msg = new Message();
msg.what = 3;
handler.sendMessage(msg);
}
}
@Override
protected void onPause() {
super.onPause();
MobclickAgent.onPause(this);
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"UserCenter Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.electric.chargingpile/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"UserCenter Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.electric.chargingpile/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
public static String getShareNo(int no) {
final int wordsLength = 26;
int sus = no;// 商
int mo;// 模
int i = 1;// 循环的次数
StringBuilder sb = new StringBuilder();
char[] array = new char[]{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z'};
while (sus > 0) {
System.out.println();
mo = sus % wordsLength;
sus = sus / wordsLength;
System.err.println("第" + i + "次循环, " + "商sus= " + sus
+ " 模 mo= " + mo);
sb.append(array[mo]);
i++;
}
System.err.println(sb.toString());
// tv_shareno.setText(sb.toString());
return sb.toString();
}
@Override
public void onScrollChanged(ObservableScrollView scrollView, int x, int y, int oldx, int oldy) {
if (scrollView == sv) {
// Toast.makeText(getApplicationContext(),"开始滑动",Toast.LENGTH_SHORT).show();
} else {
}
}
@Override
public void onPermissionsGranted(int requestCode, List<String> perms) {
Intent iintent = new Intent(getApplicationContext(), com.google.zxing.client.android.CaptureActivity.class);
iintent.putExtra("url", MainApplication.url);
iintent.putExtra("user_id", MainApplication.userId);
iintent.putExtra("user_password", MainApplication.userPassword);
iintent.putExtra("user_phone", ProfileManager.getInstance().getUsername(getApplicationContext()));
iintent.putExtra("cha", MainMapActivity.cha);
iintent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(iintent);
overridePendingTransition(0, 0);
}
@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
new AppSettingsDialog.Builder(UserCenterActivity.this,
"该功能需要开启摄像头权限,是否前往开启??").build().show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}
private boolean hasCameraPermission() {
return EasyPermissions.hasPermissions(this, Manifest.permission.CAMERA);
}
@AfterPermissionGranted(RC_CAMERA_PERM)
public boolean cameraTask() {
if (hasCameraPermission()) {
// Have permission, do the thing!
// Toast.makeText(this, "TODO: Camera things", Toast.LENGTH_LONG).show();
return true;
} else {
// Ask for one permission
// EasyPermissions.requestPermissions(
// this,
// "该功能需要开启摄像头权限,是否前往开启?",
// RC_CAMERA_PERM,
// Manifest.permission.CAMERA);
return false;
}
}
class NetworkChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (null != networkInfo && networkInfo.isAvailable()) {
} else {
Toast.makeText(context, "当前网络不可用", Toast.LENGTH_SHORT).show();
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(networkChangeReceiver);
}
private void getUserIntegral() {
String replace = null;
try {
long appTime1 = System.currentTimeMillis() / 1000;
long updatetime = appTime1 - MainMapActivity.cha - 3;
String token = String.valueOf(updatetime);
String encode_token = DES3.encode(token);
replace = URLEncoder.encode(encode_token);
} catch (Exception e) {
e.printStackTrace();
}
String url = MainApplication.url + "/zhannew/basic/web/index.php/member/get-score?id=" + MainApplication.userId +
"&phone=" + MainApplication.userPhone + "&password=" + URLEncoder.encode(MainApplication.userPassword) + "&token=" + replace;
RequestCall call = OkHttpUtils.get().url(url).build();
call.execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
// Log.e(TAG, "onResponse:getUserIntegral= "+response );
String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
if (null != rtnCode && rtnCode.equals("01")) {
String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
String count_score = JsonUtils.getKeyResult(rtnMsg, "count_score");
String money = JsonUtils.getKeyResult(rtnMsg, "money");
String hongbao1 = JsonUtils.getKeyResult(rtnMsg, "hongbao");
String sign = JsonUtils.getKeyResult(rtnMsg, "sign");
if (sign.equals("01")) {
iv_gift.setImageResource(R.drawable.icon_signined);
} else {
iv_gift.setImageResource(R.drawable.icon_qiandaohavegift);
}
if (null != count_score && !count_score.equals("")) {
chongdianbi.setText(count_score);
}
if (null != money && !money.equals("")) {
yue.setText(money);
}
if (null != hongbao1 && !hongbao1.equals("")) {
hongbao.setText(hongbao1);
}
String grow_score_info = JsonUtils.getKeyResult(rtnMsg, "grow_score_info");
String name = JsonUtils.getKeyResult(grow_score_info, "name");
if (name != null) {
if (name.equals("普通")) {
iv_qiandao.setImageResource(R.drawable.icon_center_putong);
} else if (name.equals("青铜")) {
iv_qiandao.setImageResource(R.drawable.icon_center_qingtong);
} else if (name.equals("白银")) {
iv_qiandao.setImageResource(R.drawable.icon_center_baiyin);
} else if (name.equals("黄金")) {
iv_qiandao.setImageResource(R.drawable.icon_center_huangjin);
} else if (name.equals("铂金")) {
iv_qiandao.setImageResource(R.drawable.icon_senter_bojin);
} else if (name.equals("钻石")) {
iv_qiandao.setImageResource(R.drawable.icon_center_zuanshi);
}
}
} else {
ProfileManager.getInstance().setUsername(getApplicationContext(), "");
MainApplication.userPhone = "";
Toast.makeText(getApplicationContext(), "登录已失效,请重新登录", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
}
}
});
}
private void signIn() {
String replace = null;
try {
long appTime1 = System.currentTimeMillis() / 1000;
long updatetime = appTime1 - MainMapActivity.cha - 3;
String token = String.valueOf(updatetime);
String encode_token = DES3.encode(token);
replace = URLEncoder.encode(encode_token);
} catch (Exception e) {
e.printStackTrace();
}
String url = MainApplication.url + "/zhannew/basic/web/index.php/checkin/sign?phone=" + MainApplication.userPhone +
"&password=" + URLEncoder.encode(MainApplication.userPassword) + "&token=" + replace + "&city=" + MainMapActivity.location_city;
OkHttpUtils.get().url(url).build().execute(new StringCallback() {
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(String response) {
// Log.e(TAG, "onResponse: signIn "+response );
// {"rtnCode":"01","rtnMsg":{"score":"10","log_day":"1"}}
String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
if (rtnCode.equals("01")) {
getUserIntegral();
iv_gift.setImageResource(R.drawable.icon_signined);
String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
String log_day = JsonUtils.getKeyResult(rtnMsg, "log_day");
String score = JsonUtils.getKeyResult(rtnMsg, "plusScore");
String third = "", second = "", first = "";
int length = log_day.length();
char words[] = log_day.toCharArray();
if (length == 1) {
third = "";
second = "";
first = String.valueOf(words[0]);
} else if (length == 2) {
third = "";
second = String.valueOf(words[0]);
first = String.valueOf(words[1]);
} else if (length == 3) {
third = String.valueOf(words[0]);
second = String.valueOf(words[1]);
first = String.valueOf(words[2]);
}
// String weather = JsonUtils.getKeyResult(rtnMsg,"weather");
//// Log.e(TAG, "onResponse: weather="+weather );
// String status = JsonUtils.getKeyResult(weather,"status");
//// Log.e(TAG, "onResponse: status="+status );
// String results = JsonUtils.getKeyResult(weather,"results");
//// Log.e(TAG, "onResponse: results="+results );
// try {
// JSONArray jsArray = new JSONArray(results);
//// if (jsArray.length() >1) {
// String s = jsArray.getString(0);
// Log.e(TAG, "onResponse: s=" + s);
// String pm25 = JsonUtils.getKeyResult(s, "pm25");//*
// Log.e(TAG, "onResponse: pm25=" + pm25);
// String weather_data = JsonUtils.getKeyResult(s, "weather_data");
// Log.e(TAG, "onResponse: weather_data=" + weather_data);
// List<WeatherResults.WeatherDataBean> list = JsonUtils.parseToObjectList(weather_data, WeatherResults.WeatherDataBean.class);
// String now_weather = list.get(0).getWeather();//*
// String temperature = list.get(0).getTemperature();//*
// temperature = temperature.replace(" ", "");
// temperature = temperature.substring(0, temperature.length() - 1);
// String date = list.get(0).getDate();
// String now_temperature = date.substring(date.length() - 4, date.length() - 2);//*
// Log.e(TAG, "onResponse: now_weather=" + now_weather + "--temperature=" + temperature + "--now_temperature=" + now_temperature);
if (activity == null || activity.isFinishing()) {
return;
} else {
showDialog(third, second, first, score, now_temperature, now_weather, temperature, MainMapActivity.location_city);
}
}
}
});
}
private void showDialog(String third, String second, String first, String score, String now_temperature, String now_weather, String temperature, String city) {
SignInDialog signInDialog = new SignInDialog(this);
signInDialog.builder()
.setCancelable(true)
.setTitle(third, second, first, score, city)
.setWeatherUI(now_temperature, now_weather, temperature)
.show();
}
}
|