package com.hjx.personalcenter.activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.app.FragmentActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.facebook.drawee.view.SimpleDraweeView; import com.hjx.personalcenter.R; import com.hjx.personalcenter.adapter.AccountChildsAdapter; import com.hjx.personalcenter.customdialog.RecyclerViewSpaceItem; import com.hjx.personalcenter.db.Content; import com.hjx.personalcenter.db.SaveParam; import com.hjx.personalcenter.http.HttpCode; import com.hjx.personalcenter.http.HttpManager; import com.hjx.personalcenter.model.ChildsInfo; import com.hjx.personalcenter.util.AlertUtils; import com.hjx.personalcenter.util.GetDevicesUtil; import java.util.ArrayList; import java.util.List; /** * 账户管理 熊巍 * Created by h on 2017/8/12. */ public class AccountManagementActivity extends FragmentActivity implements View.OnClickListener { private TextView changbangding, changpassword, usernames, tv_username, tv_grade, tv_school, tv_adress, tv_changzhu; private ImageView iv_useing, cancel; private SimpleDraweeView mSimpleDraweeView; private RecyclerView listview; private LinearLayout add_accunt, ll_zhu_backgrangd; private AccountChildsAdapter childsAdapter; private ArrayList data = new ArrayList<>(); private String subAccountId = null; Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case HttpCode.CHILDS_SUCESS: ChildsInfo childsInfo = new ChildsInfo(); if (childsInfo.getStatus()==1000) { String names =SaveParam.getInstance().getLoginParam(AccountManagementActivity.this, SaveParam.USERNAME); String adress =SaveParam.getInstance().getLoginParam(AccountManagementActivity.this, SaveParam.ADRESS); String grades =SaveParam.getInstance().getLoginParam(AccountManagementActivity.this, SaveParam.GRADES); String schools =SaveParam.getInstance().getLoginParam(AccountManagementActivity.this, SaveParam.SCHOOL); tv_username.setText(names); tv_grade.setText(grades); tv_school.setText(schools); tv_adress.setText(adress); tv_changzhu.setText("使用中"); tv_changzhu.setEnabled(false); iv_useing.setVisibility(View.VISIBLE); ll_zhu_backgrangd.setBackgroundResource(R.drawable.corcle_blue_bg); //mSimpleDraweeView.setImageURI(phote); } else { String name = null; String grade = null; String school = null; String addr = null; String phote = null; List childList = new ArrayList<>(); List list = (List) msg.obj; for (int i = 0; i < list.size(); i++) { int type = list.get(i).getType(); if (type == 1) { name = list.get(i).getName(); grade = list.get(i).getGrade(); school = list.get(i).getSchool(); addr = list.get(i).getRegion(); phote = list.get(i).getImage(); subAccountId = list.get(i).getGradeId(); } else if (type == 2) { childList.add(list.get(i)); } } tv_username.setText(name); tv_grade.setText(grade); tv_school.setText(school); tv_adress.setText(addr); mSimpleDraweeView.setImageURI(phote); data.clear(); data.addAll(childList); childsAdapter.notifyDataSetChanged(); } break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_account_management); initView(); initData(); initLister(); } private void initView() { changbangding = (TextView) findViewById(R.id.changBangding); changpassword = (TextView) findViewById(R.id.changpassword); usernames = (TextView) findViewById(R.id.cunt_username); tv_username = (TextView) findViewById(R.id.tv_account_name); tv_grade = (TextView) findViewById(R.id.tv_account_grade); tv_school = (TextView) findViewById(R.id.tv_account_school); tv_adress = (TextView) findViewById(R.id.tv_account_adress); mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.tv_account_head); iv_useing = (ImageView) findViewById(R.id.iv_shiyongzhong); cancel = (ImageView) findViewById(R.id.cancel); ll_zhu_backgrangd = (LinearLayout) findViewById(R.id.ll_zhu_backgrangd); tv_changzhu = (TextView) findViewById(R.id.change_zhu_account); listview = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal); } private void initData() { String cunt_username = SaveParam.getInstance().getLoginParam(this, "username"); String account = SaveParam.getInstance().getCustomizeParam(this, SaveParam.ACCOUNT); usernames.setText(cunt_username); if (account.equals("1")) { tv_changzhu.setText("使用中"); tv_changzhu.setEnabled(false); iv_useing.setVisibility(View.VISIBLE); ll_zhu_backgrangd.setBackgroundResource(R.drawable.corcle_blue_bg); } else { tv_changzhu.setText("切换主账户"); tv_changzhu.setEnabled(true); iv_useing.setVisibility(View.GONE); ll_zhu_backgrangd.setBackgroundResource(R.drawable.corcle_black_bg); } LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); listview.setLayoutManager(linearLayoutManager); childsAdapter = new AccountChildsAdapter(data, this); listview.addItemDecoration(new RecyclerViewSpaceItem(10)); listview.setAdapter(childsAdapter); childsAdapter.setOnItemClickListener(new AccountChildsAdapter.OnItemClickListener() { @Override public void onItemClick(View view, int position) { AlertUtils.showToast(AccountManagementActivity.this, "你点击了" + data.get(position)); } }); } private void initLister() { changbangding.setOnClickListener(this); changpassword.setOnClickListener(this); cancel.setOnClickListener(this); tv_changzhu.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.changBangding: Content.authcodeflag = 1; Intent changebangding = new Intent(); changebangding.setClass(AccountManagementActivity.this, ElectronicCardValidationActivity.class); startActivity(changebangding); overridePendingTransition(R.anim.rightin, R.anim.rightout); break; case R.id.changpassword: Intent changpwd = new Intent(); changpwd.setClass(AccountManagementActivity.this, ChangePasswordActivity.class); startActivity(changpwd); overridePendingTransition(R.anim.rightin, R.anim.rightout); break; case R.id.change_zhu_account: Content.changgeaccountflag = 1; String userID = SaveParam.getInstance().getLoginParam(this, "userId"); SaveParam.getInstance().saveCustomizeParam(this, SaveParam.ACCOUNT, "1"); String devicenumber = GetDevicesUtil.getDevicesInfo(this).getDeviceNumber(); //String ss = SaveParam.getInstance().getLoginParam(AccountManagementActivity.this, SaveParam.GRADENS); String zizhuanhui = SaveParam.getInstance().getCustomizeParam(AccountManagementActivity.this, SaveParam.CHILDSGRADENSss); try { long auserID = Long.parseLong(userID); int zhugrade = Integer.parseInt(subAccountId); int zigrade = Integer.parseInt(zizhuanhui); Log.i("---", "发送完了"+zhugrade+"ddd"+zhugrade); // if ((zhugrade < 8)&&(zigrade>=8)||(zhugrade >= 8)&&(zigrade<8)) { // Intent intentbroad = new Intent(); // intentbroad.putExtra("info", "小学"); // //4、定义广播发送的action // intentbroad.setAction("com.ozing.launcher.SWITCH_GRADE"); // //5、发送广播 // sendBroadcast(intentbroad); // Log.i("---", "发送完了"); // } HttpManager.getInstance().Accountinfo(AccountManagementActivity.this, auserID, devicenumber, 1); } catch (NumberFormatException e) { e.printStackTrace(); } break; case R.id.cancel: finish(); break; } } @Override protected void onResume() { super.onResume(); String userID = SaveParam.getInstance().getLoginParam(this, "userId"); String devicenumber = GetDevicesUtil.getDevicesInfo(this).getDeviceNumber(); String cunt_username = SaveParam.getInstance().getLoginParam(this, "username"); usernames.setText(cunt_username); try { long auserID = Long.parseLong(userID); HttpManager.getInstance().getchildAccountinfo(this, auserID, devicenumber, handler); } catch (NumberFormatException e) { e.printStackTrace(); } } }