package com.bigdo.app; import org.json.JSONException; import org.json.JSONObject; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.LinearInterpolator; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.ScrollView; import android.widget.TextView; import com.bigdo.common.BDSQLiteHelper; import com.bigdo.common.Login; import com.bigdo.common.RConfig; import com.bigdo.common.RState; import com.bigdo.common.User; import com.bigdo.util.WSCheck; import com.bigdo.util.WSHelper; import com.bigdo.util.WSResult; public class MainMeBll extends MainBaseBll { public static final int Ws_R_Code = 30000; TextView bd_login, bd_reg; LinearLayout bd_tab1, bd_tab2, bd_tab3; TextView bd_perInfor, bd_growth, bd_security, bd_suggest, bd_grade, bd_points, bd_order, bd_favorites, bd_playhistory, bd_needs; RelativeLayout tab1, tab2, tab3; View tab_line1, tab_line2, tab_line3; LinearLayout refurbishHost = null; Animation operatingAnim = null; TextView refurbish = null; boolean isGeting = false, isChecking = false; public MainMeBll(BaseActivity activity, View v, Handler handler) { super(activity, v, handler); // TODO Auto-generated constructor stub } @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub View com_title = host.findViewById(R.id.bd_title_host); refurbishHost = (LinearLayout) com_title .findViewById(R.id.top_tools_refurbish_host); refurbish = (TextView) com_title.findViewById(R.id.top_tools_refurbish); operatingAnim = AnimationUtils.loadAnimation(this.a, R.anim.ra_rotate); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); SwitchTab switchTab = new SwitchTab(); RelativeLayout tab1 = (RelativeLayout) host .findViewById(R.id.vdieo_tag_1); tab1.setTag(1); tab1.setOnClickListener(switchTab); RelativeLayout tab2 = (RelativeLayout) host .findViewById(R.id.vdieo_tag_2); tab2.setTag(2); tab2.setOnClickListener(switchTab); RelativeLayout tab3 = (RelativeLayout) host .findViewById(R.id.vdieo_tag_3); tab3.setTag(3); tab3.setOnClickListener(switchTab); tab_line1 = host.findViewById(R.id.vdieo_tag_1_vline); tab_line2 = host.findViewById(R.id.vdieo_tag_2_vline); tab_line3 = host.findViewById(R.id.vdieo_tag_3_vline); bd_tab1 = (LinearLayout) host.findViewById(R.id.bd_tab1); bd_tab2 = (LinearLayout) host.findViewById(R.id.bd_tab2); bd_tab3 = (LinearLayout) host.findViewById(R.id.bd_tab3); MyClickListener clicklistener = new MyClickListener(); bd_login = (TextView) host.findViewById(R.id.bd_login); bd_login.setTag(1); bd_login.setOnClickListener(clicklistener); bd_perInfor = (TextView) host.findViewById(R.id.bd_perInfor); bd_perInfor.setTag(11); bd_perInfor.setOnClickListener(clicklistener); bd_growth = (TextView) host.findViewById(R.id.bd_growth); bd_growth.setTag(12); bd_growth.setOnClickListener(clicklistener); bd_security = (TextView) host.findViewById(R.id.bd_security); bd_security.setTag(13); bd_security.setOnClickListener(clicklistener); bd_suggest = (TextView) host.findViewById(R.id.bd_suggest); bd_suggest.setTag(14); bd_suggest.setOnClickListener(clicklistener); TextView bd_clear = (TextView) host.findViewById(R.id.bd_clear); bd_clear.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { a.showProgress("清空缓冲中..."); new Thread(new Runnable() { @Override public void run() { BDSQLiteHelper.delAllData(a); if (handler != null) { Bundle b = new Bundle(); WSResult result = new WSResult(); result.RequestCode = MainMeBll.Ws_R_Code; result.RequestCode2 = -9999999; b.putParcelable(WSResult.ResultKey, result); Message msg = new Message(); msg.arg1 = RState.WSCall; msg.setData(b); handler.sendMessage(msg); a.broadcastClearData(); } } }).start(); } }); bd_grade = (TextView) host.findViewById(R.id.bd_grade); bd_grade.setTag(21); bd_grade.setOnClickListener(clicklistener); bd_points = (TextView) host.findViewById(R.id.bd_points); bd_points.setTag(22); bd_points.setOnClickListener(clicklistener); bd_order = (TextView) host.findViewById(R.id.bd_order); bd_order.setTag(23); bd_order.setOnClickListener(clicklistener); bd_favorites = (TextView) host.findViewById(R.id.bd_favorites); bd_favorites.setTag(31); bd_favorites.setOnClickListener(clicklistener); bd_playhistory = (TextView) host.findViewById(R.id.bd_playhistory); bd_playhistory.setTag(32); bd_playhistory.setOnClickListener(clicklistener); bd_needs = (TextView) host.findViewById(R.id.bd_needs); bd_needs.setTag(33); bd_needs.setOnClickListener(clicklistener); ImageView user_ico = (ImageView) host.findViewById(R.id.user_ico); user_ico.setTag(99); user_ico.setOnClickListener(clicklistener); TextView checkIn = (TextView) host.findViewById(R.id.checkIn); checkIn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { startCheckin(); } }); TextView bd_pay = (TextView) host.findViewById(R.id.bd_pay); bd_pay.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { goPay(); } }); setTab(1); } private void startCheckin() { User user = Login.get(this.a); if (user != null) { if (!isChecking) { try { JSONObject jparams = new JSONObject(); jparams.put("user", user.user); isChecking = true; this.a.showProgress("签到中..."); String url = RConfig.checkIn(this.a); String data = jparams.toString(); new WSHelper(this.a, "", false, handler, url, null, WSHelper.getStringEntity(data), Ws_R_Code, 2222, 0, 0, WSHelper.POST).start(); Log.e("startCheckin", url); Log.e("startCheckin_data", data); url = null; data = null; jparams = null; return; } catch (JSONException e) { isChecking = false; this.a.showInfo("签到时发生错误."); return; } } else { this.a.showInfo("签到已经开始."); } } else { this.a.showInfo("请先登录"); } } private void setTitleTools() { if (Login.isLogin(this.a)) { refurbishHost.setVisibility(LinearLayout.VISIBLE); refurbishHost.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getUserInfo(); } }); } else { refurbishHost.setVisibility(LinearLayout.INVISIBLE); } } private void getUserInfo() { if (!isGeting) { User user = Login.get(this.a); if (user != null) { try { JSONObject jparams = new JSONObject(); jparams.put("user", user.user); isGeting = true; refurbish.clearAnimation(); refurbish.startAnimation(operatingAnim); String url = RConfig.userInfo(this.a); String data = jparams.toString(); new WSHelper(this.a, "", false, handler, url, null, WSHelper.getStringEntity(data), Ws_R_Code, 9999, 0, 0, WSHelper.POST).start(); Log.e("startLogin", url); Log.e("startLogin_data", data); url = null; data = null; jparams = null; return; } catch (JSONException e) { isGeting = false; refurbish.clearAnimation(); this.a.showInfo("同步时发生错误."); return; } } refurbish.clearAnimation(); this.a.showInfo("请先登录."); } else { this.a.showInfo("同步已经开始."); } } private void goPay() { Intent i = new Intent(); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); i.setClass(a, PayActivity.class); a.startActivityForResult(i, 998877); } /** * 设置用户显示信息 */ private void setUserInfo() { LinearLayout bd_logined = (LinearLayout) host .findViewById(R.id.bd_logined); TextView checkIn = (TextView) host.findViewById(R.id.checkIn); LinearLayout bd_unlogin = (LinearLayout) host .findViewById(R.id.bd_unlogin); User user = Login.get(this.a); if (user != null) { bd_unlogin.setVisibility(LinearLayout.GONE); bd_logined.setVisibility(LinearLayout.VISIBLE); checkIn.setVisibility(TextView.VISIBLE); TextView user_name = (TextView) host .findViewById(R.id.ra_user_name); String name = user.alias; if (name == null || name.equals("")) { name = user.user; } user_name.setText(name); TextView score = (TextView) host.findViewById(R.id.ra_score); score.setText((user.score + user.score2) + ""); } else { bd_unlogin.setVisibility(LinearLayout.VISIBLE); bd_logined.setVisibility(LinearLayout.GONE); checkIn.setVisibility(TextView.GONE); } setTitleTools(); } @Override protected void onDestroy() { // TODO Auto-generated method stu } @Override protected boolean onHandler(WSResult result) { if (result != null) { if (result.RequestCode2 == 9999) { if (refurbish != null) { JSONObject json = WSCheck.Json(this.a, result, null); setLogin(json); refurbish.clearAnimation(); isGeting = false; } } else if (result.RequestCode2 == 2222) { JSONObject json = WSCheck.Json(this.a, result); checkinFinish(json); isChecking = false; this.a.hiddenProgress(); } else if (result.RequestCode2 == -9999999) { onClearData(); } } return false; } private void checkinFinish(JSONObject json) { if (json != null) { setLogin(json); boolean isok = false; try { isok = json.getBoolean("isok"); } catch (Exception e) { } if (isok) { this.a.messageBox("签到成功"); } else { this.a.messageBox("签到失败 或 今天您已经签到."); } } } private void setLogin(JSONObject json) { if (this.a != null) { if (json != null) { try { JSONObject user = json.getJSONObject("user"); if (user != null) { User ld = new User(); ld.iduser = user.getInt("iduser"); ld.user = user.getString("user"); ld.alias = user.getString("alias"); ld.sex = user.getInt("sex"); ld.birthday = user.getString("birthday"); ld.email = user.getString("email"); ld.company = user.getString("company"); ld.teamcount = user.getString("teamcount"); ld.level = user.getInt("level"); ld.score = user.getInt("score"); ld.score2 = user.getInt("score2"); ld.vip_stime = user.getString("vip_stime"); ld.vip_entime = user.getString("vip_entime"); if (Login.set(this.a, ld)) { this.a.showInfo("同步用户信息成功."); setUserInfo(); return; } else { this.a.showInfo("同步用户信息时缓存出错."); return; } } } catch (Exception e) { this.a.showInfo("同步用户信息时缓存出错."); return; } } this.a.showInfo("同步用户信息失败."); } } /** * 切换tab * * @author Administrator * */ public class SwitchTab implements View.OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub int tag = (Integer) v.getTag(); setTab(tag); } } private void setTab(int tag) { bd_tab1.setVisibility(View.GONE); bd_tab2.setVisibility(View.GONE); bd_tab3.setVisibility(View.GONE); switch (tag) { case 1: bd_tab1.setVisibility(ScrollView.VISIBLE); tab_line1.setBackgroundColor(0xffC0C280); tab_line2.setBackgroundColor(0x77cbcbcb); tab_line3.setBackgroundColor(0x77cbcbcb); break; case 2: bd_tab2.setVisibility(ScrollView.VISIBLE); tab_line1.setBackgroundColor(0x77cbcbcb); tab_line2.setBackgroundColor(0xffC0C280); tab_line3.setBackgroundColor(0x77cbcbcb); break; case 3: bd_tab3.setVisibility(ScrollView.VISIBLE); tab_line1.setBackgroundColor(0x77cbcbcb); tab_line2.setBackgroundColor(0x77cbcbcb); tab_line3.setBackgroundColor(0xffC0C280); break; default: break; } } /** * 点击列表item * * @author Administrator * */ public class MyClickListener implements View.OnClickListener { @Override public void onClick(View v) { // TODO Auto-generated method stub int tag = (Integer) v.getTag(); Intent i = new Intent(); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); if (Login.isLogin(a)) { switch (tag) { case 1: i.setClass(a, Login_Activity.class); break; case 2: i.setClass(a, Reg_Activityt.class); break; case 11: i.setClass(a, Me_PersonalInfor_Activity.class); break; case 12: i.setClass(a, Me_GrowthHistory_Activity.class); break; case 13: i.setClass(a, Me_SecurityCenter_Activity.class); break; case 14: i.setClass(a, Me_Suggest_Activity.class); break; case 21: i.setClass(a, Me_GradeManage_Activity.class); break; case 22: i.setClass(a, Me_PointsManage_Activity.class); break; case 23: i.setClass(a, Me_MyOrder.class); break; case 31: i.setClass(a, Me_Favorite_Activity.class); break; case 32: i.setClass(a, Me_PlayHistory_Activity.class); break; case 33: i.setClass(a, Me_MyNeeds_Activity.class); break; case 99: i.setClass(a, Me_PersonalInfor_Activity.class); break; default: return; } } else { i.setClass(a, Login_Activity.class); } a.startActivityForResult(i, tag); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub setUserInfo(); if (requestCode == 23 || requestCode == 998877) { getUserInfo(); } } @Override public void onShow() { // TODO Auto-generated method stub setUserInfo(); } @Override public void onClearData() { // TODO Auto-generated method stub a.hiddenProgress(); a.showInfo("清空完毕"); } }