package com.partynetwork.iparty.assistant; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.baidu.mobstat.StatService; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; import com.partynetwork.dataprovider.DataProvider.IJsonResultListener; import com.partynetwork.dataprovider.json.NetworkEntity; import com.partynetwork.dataprovider.json.struct.Assistant_getAssistantRequest; import com.partynetwork.dataprovider.json.struct.Assistant_getAssistantResponse; import com.partynetwork.iparty.R; import com.partynetwork.iparty.app.AppContext; import com.partynetwork.iparty.app.common.BitmapManager; import com.partynetwork.iparty.flipmenu.BaseSlidingPage; import com.partynetwork.iparty.helper.IntentHelper; import com.partynetwork.iparty.info.AssistantInfo; import com.partynetwork.myview.myimageview.CircularImage; /** * 助手页面 * * @author 沈跃双 Create at 2014-2-28 下午1:46:25 */ @SuppressLint("ValidFragment") public class AssistantPage extends BaseSlidingPage implements IJsonResultListener, OnClickListener { public static final int PARTICIPANT = 0; public static final int INITIATOR = 1; private TextView orgTv; private TextView parTv; private LinearLayout orgLL; private LinearLayout parLL; private CircularImage head; private TextView title; private LinearLayout titleLl; private TextView leftNumber; private TextView leftTitle; private TextView rightNumber; private TextView rightTitle; private AssistantInfo info; private int userType = PARTICIPANT; private Activity mActivity; public AssistantPage(SlidingMenu menu) { super(menu); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mActivity = getActivity(); init(); } private void init() { initView(); initData(); } private void initView() { orgTv = (TextView) mActivity.findViewById(R.id.bottom_org_tv); parTv = (TextView) mActivity.findViewById(R.id.bottom_par_tv); orgLL = (LinearLayout) mActivity.findViewById(R.id.body_org_ll); parLL = (LinearLayout) mActivity.findViewById(R.id.body_par_ll); head = (CircularImage) mActivity.findViewById(R.id.head); head.setOnClickListener(this); title = (TextView) mActivity.findViewById(R.id.title_tv); titleLl = (LinearLayout) mActivity.findViewById(R.id.title_ll); leftNumber = (TextView) mActivity.findViewById(R.id.left_number_tv); leftTitle = (TextView) mActivity.findViewById(R.id.left_title_tv); rightNumber = (TextView) mActivity.findViewById(R.id.right_number_tv); rightTitle = (TextView) mActivity.findViewById(R.id.right_title_tv); mActivity.findViewById(R.id.menu_head_left).setOnClickListener(this); mActivity.findViewById(R.id.bottom_org_rl).setOnClickListener(this); mActivity.findViewById(R.id.bottom_par_rl).setOnClickListener(this); mActivity.findViewById(R.id.left_title_ll).setOnClickListener(this); mActivity.findViewById(R.id.right_title_ll).setOnClickListener(this); mActivity.findViewById(R.id.body_par_like_ll).setOnClickListener(this); mActivity.findViewById(R.id.body_par_back_ll).setOnClickListener(this); mActivity.findViewById(R.id.body_org_scan_ll).setOnClickListener(this); mActivity.findViewById(R.id.body_org_free_ll).setOnClickListener(this); } private void sendRequest() { AppContext context = (AppContext) mActivity.getApplicationContext(); Assistant_getAssistantRequest request = new Assistant_getAssistantRequest(); request.setUserId(context.getLoginUid()); AppContext.getInstance().getmDataProvider() .getJsonFromNetwork(request, this); } private void initData() { AppContext context = (AppContext) mActivity.getApplicationContext(); new BitmapManager().loadBitmap(context.getLoginInfo().getFace(), this.head); cutover(userType); } public void onClick(View v) { switch (v.getId()) { case R.id.menu_head_left: if (slidingMenu == null) { return; } if (slidingMenu.isMenuShowing()) { slidingMenu.showContent(); } else { slidingMenu.showMenu(); } break; case R.id.head: AppContext context = (AppContext) mActivity.getApplicationContext(); IntentHelper.goPersonalCenterActivity(mActivity, context.getLoginUid()); break; case R.id.bottom_org_rl: cutover(INITIATOR); break; case R.id.bottom_par_rl: cutover(PARTICIPANT); break; case R.id.left_title_ll: if (userType == PARTICIPANT) { goAssistantInfoPage(AssistantInfoActivity.PARTY_WAIT); } else { goAssistantInfoPage(AssistantInfoActivity.PARTY_PARTING); } break; case R.id.right_title_ll: if (userType == PARTICIPANT) { goAssistantInfoPage(AssistantInfoActivity.PARTY_EVALUATE); } else { goAssistantInfoPage(AssistantInfoActivity.PARTY_CLOSE); } break; case R.id.body_par_like_ll: goAssistantInfoPage(AssistantInfoActivity.PARTY_INTERESTED); break; case R.id.body_par_back_ll: goAssistantInfoPage(AssistantInfoActivity.PARTY_REFUND); break; case R.id.body_org_scan_ll: IntentHelper.goCaptureActivity(mActivity); break; case R.id.body_org_free_ll: Intent intent = new Intent(mActivity, FreeOrderActivity.class); mActivity.startActivity(intent); break; default: break; } } private void goAssistantInfoPage(int partyType) { Intent intent = new Intent(mActivity, AssistantInfoActivity.class); intent.putExtra(AssistantInfoActivity.PARTY_TYPE, partyType); mActivity.startActivity(intent); } private void cutover(int i) { userType = i; Resources res = mActivity.getResources(); titleLl.removeAllViews(); if (i == PARTICIPANT) { Drawable left1 = res .getDrawable(R.drawable.assistant_participant_seleted); left1.setBounds(0, 0, left1.getMinimumWidth(), left1.getMinimumHeight()); parTv.setCompoundDrawables(left1, null, null, null); parTv.setTextColor(res.getColor(R.color.blue_text)); Drawable left2 = res .getDrawable(R.drawable.assistant_organizers_normal); left2.setBounds(0, 0, left2.getMinimumWidth(), left2.getMinimumHeight()); orgTv.setCompoundDrawables(left2, null, null, null); orgTv.setTextColor(res.getColor(R.color.gray)); parLL.setVisibility(View.VISIBLE); orgLL.setVisibility(View.GONE); title.setText("参加者信用级别:"); leftTitle.setText("待参加的Party"); rightTitle.setText("待评价的Party"); if (info == null) { return; } titleLl.addView(getGradeLayout(mActivity, info.getParticipantsCreditRating(), PARTICIPANT)); leftNumber.setText(info.getParticipateNumber() + ""); rightNumber.setText(info.getEvaluatedNumber() + ""); } else { Drawable left1 = res .getDrawable(R.drawable.assistant_participant_normal); left1.setBounds(0, 0, left1.getMinimumWidth(), left1.getMinimumHeight()); parTv.setCompoundDrawables(left1, null, null, null); Drawable left2 = res .getDrawable(R.drawable.assistant_organizers_seleted); left2.setBounds(0, 0, left2.getMinimumWidth(), left2.getMinimumHeight()); orgTv.setCompoundDrawables(left2, null, null, null); parTv.setTextColor(res.getColor(R.color.gray)); orgTv.setTextColor(res.getColor(R.color.red)); parLL.setVisibility(View.GONE); orgLL.setVisibility(View.VISIBLE); title.setText("发起人信用级别:"); leftTitle.setText("发布中的Party"); rightTitle.setText("已结束的Party"); if (info == null) { return; } titleLl.addView(getGradeLayout(mActivity, info.getOrganizersCreditRating(), INITIATOR)); leftNumber.setText(info.getReleaseNumber() + ""); rightNumber.setText(info.getFinishNumber() + ""); } } protected int initPage() { return R.layout.assistant; } public static View getGradeLayout(Context context, int grade, int userType) { int[] resArray = null; if (userType == PARTICIPANT) { resArray = new int[] { R.drawable.grade_participant_0, R.drawable.grade_participant_1, R.drawable.grade_participant_2, R.drawable.grade_participant_3, R.drawable.grade_participant_4 }; } else { resArray = new int[] { R.drawable.grade_initiator_0, R.drawable.grade_initiator_1, R.drawable.grade_initiator_2, R.drawable.grade_initiator_3, R.drawable.grade_initiator_4 }; } int res = 0; int num = 0; if (grade > 0 && grade < 16) { res = resArray[((grade - 1) / 4) + 1]; num = grade % 4; if (num == 0) { num = 4; } } else if (grade == 0) { res = resArray[1]; num = 1; } else if (grade < 0) { res = resArray[0]; num = 1; } else { res = resArray[4]; num = 4; } LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i < num; i++) { ImageView image = new ImageView(context); image.setImageResource(res); layout.addView(image); } return layout; } @Override public void onNetworkRequest() { } @Override public void onResultSuccess(NetworkEntity entity) { if (entity.getRequest().getAction() .equals(new Assistant_getAssistantRequest().getAction())) { Assistant_getAssistantResponse aResponse = (Assistant_getAssistantResponse) entity .getResponse(); info = aResponse.getDetails(); initData(); } } @Override public void onResultFail(String result) { } @Override public void onResume() { super.onResume(); StatService.onPageStart(mActivity, "AssistantPage"); sendRequest(); } @Override public void onPause() { super.onResume(); StatService.onPageEnd(mActivity, "AssistantPage"); } }