package com.partynetwork.iparty.iparty;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.partynetwork.iparty.R;
import com.partynetwork.iparty.app.common.BitmapManager;
import com.partynetwork.iparty.info.IpartyFreeComboInfo;
import com.partynetwork.myview.myimageview.ImagePicker;
import com.partynetwork.myview.wheelview.ArrayWheelAdapter;
import com.partynetwork.myview.wheelview.NumericWheelAdapter;
import com.partynetwork.myview.wheelview.WheelAdapter;
import com.partynetwork.myview.wheelview.WheelPicker;
import com.partynetwork.myview.wheelview.WheelView;
import com.partynetwork.myview.wheelview.WheelPicker.WheelListener;
import com.baidu.mobstat.StatService;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
public class IpartyPublishComboFreeInfoActivity extends Activity {
public static final int COMBO_FREE_INFO_REQUEST_CODE = 20;
public static final String COMBO_FREE_INFO = "free_combo_info";
private static final int NEED_PHOTO_YES = 1;
private static final int NEED_PHOTO_NO = 0;
// public static final String OTHER_STR = "other_str";
@ViewInject(R.id.menu_head_left)
private LinearLayout back;
/**
* 免费参加人数
*/
@ViewInject(R.id.number)
private EditText number;
/**
* 性别条件
*/
@ViewInject(R.id.sex)
private TextView sex;
/**
* 最小年龄
*/
@ViewInject(R.id.min_age)
private TextView minAge;
/**
* 最大年龄
*/
@ViewInject(R.id.max_age)
private TextView maxAge;
/**
* 备注
*/
@ViewInject(R.id.mark)
private EditText mark;
/**
* 需要照片
*/
@ViewInject(R.id.need_photo_yes)
private TextView needPhotoYes;
/**
* 不需要照片
*/
@ViewInject(R.id.need_photo_no)
private TextView needPhotoNo;
/**
* 用作单选的List
*/
private List<TextView> needPhotoList = new ArrayList<TextView>();
/**
* 回报
*/
@ViewInject(R.id.in_return)
private EditText reciprocation;
/**
* 初始选择图片的布局
*/
@ViewInject(R.id.choose_photo_rl)
private RelativeLayout choosePhoto;
/**
* 图片显示的区域
*/
@ViewInject(R.id.choose_photo_content)
private RelativeLayout choosePhotoContent;
/**
* 显示的回报图片
*/
@ViewInject(R.id.content_photo_iv)
private ImageView photo;
/**
* 文件存放路径
*/
private String file;
/**
* 照片选择对象
*/
private ImagePicker imagePicker;
/**
* 免费套餐对象
*/
private IpartyFreeComboInfo info;
/**
* 是否需要提交真实照片 0:不需要 ; 1:需要
*/
private int needPhoto;
/** 滚轮弹窗 */
private WheelPicker sexPicker;
private WheelPicker agePicker;
private BitmapManager bitmapManager;
/**
*
* 覆盖方法
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.iparty_publish_combo_free_info);
ViewUtils.inject(this);
init();
}
/**
* 初始化数据、控件
*/
private void init() {
bitmapManager=new BitmapManager();
imagePicker = new ImagePicker(this, false);
needPhotoList.add(needPhotoNo);
needPhotoList.add(needPhotoYes);
try {
info = getIntent().getParcelableExtra(COMBO_FREE_INFO);
setInfo(info);
} catch (Exception e) {
info = new IpartyFreeComboInfo();
}
sexPicker = new WheelPicker(this,1, new ArrayWheelAdapter<String>(
new String[] { "男", "女", "其他", "不限" }), sexWheelListener);
agePicker=new WheelPicker(this, 2, new NumericWheelAdapter(18, 100),
ageWheelListener);
}
/**
* 根据数据对象生成布局
*
* @param info
*/
private void setInfo(IpartyFreeComboInfo info) {
// 设置套餐数量
this.number.setText(info.getMaxNum() + "");
// 设置性别要求
switch (info.getSex()) {
case 0:
this.sex.setText("男");
break;
case 1:
this.sex.setText("女");
break;
case 2:
this.sex.setText("其他");
break;
case 3:
this.sex.setText("不限");
break;
default:
break;
}
this.minAge.setText(info.getMinAge() + "");
this.maxAge.setText(info.getMaxAge() + "");
this.mark.setText(info.getRemark());
choose(info.getNeedPhoto());
this.reciprocation.setText(info.getIntroduce());
file = info.getComboPhotoUrl();
if (file != null && !file.equals("")) {
choosePhoto.setVisibility(View.GONE);
choosePhotoContent.setVisibility(View.VISIBLE);
bitmapManager.loadBitmap(file, photo);
}
}
/**
* 设置监听
*
* @param view
*/
@OnClick({ R.id.menu_head_left, R.id.menu_head_right, R.id.choose_photo_rl,
R.id.delete_tv, R.id.change_photo_tv, R.id.need_photo_yes,
R.id.need_photo_no, R.id.sex, R.id.min_age, R.id.max_age })
public void onClick(View view) {
switch (view.getId()) {
case R.id.menu_head_left:
// 返回
finish();
break;
case R.id.menu_head_right:
// 完成
getInfo();
Intent intent = new Intent();
intent.putExtra(COMBO_FREE_INFO, info);
this.setResult(COMBO_FREE_INFO_REQUEST_CODE, intent);
finish();
break;
case R.id.choose_photo_rl:
// 选择图片
imagePicker.show(back);
break;
case R.id.delete_tv:
// 删除图片
choosePhoto.setVisibility(View.VISIBLE);
choosePhotoContent.setVisibility(View.GONE);
break;
case R.id.change_photo_tv:
// 更改图片
imagePicker.show(back);
break;
case R.id.need_photo_yes:
// 需要照片
choose(NEED_PHOTO_YES);
break;
case R.id.need_photo_no:
// 不需要照片
choose(NEED_PHOTO_NO);
break;
case R.id.sex:
// 性别
sexPicker.showAt(back);
break;
case R.id.min_age:
case R.id.max_age:
// 年龄
agePicker.showAt(back);
break;
default:
break;
}
}
/**
* 性别监听对象
*/
private WheelListener sexWheelListener = new WheelListener() {
public WheelAdapter onChange(WheelView wheel, int oldValue, int newValue) {
return null;
}
public void confirm(String str) {
IpartyPublishComboFreeInfoActivity.this.sex.setText(str);
}
public void cancel() {
}
};
/**
* 年龄滚轮的监听
*/
private WheelListener ageWheelListener = new WheelListener() {
@Override
public WheelAdapter onChange(WheelView wheel, int oldValue, int newValue) {
return new NumericWheelAdapter(Integer.parseInt(wheel
.getTextItem(wheel.getCurrentItem())), 100);
}
@Override
public void confirm(String str) {
String[] strs = str.split("-");
if (strs != null && strs.length >= 2) {
minAge.setText(strs[0]);
maxAge.setText(strs[1]);
}
}
@Override
public void cancel() {
}
};
/**
* 获得免费参加套餐对象
*/
private void getInfo() {
String number = this.number.getText().toString();
String sex = this.sex.getText().toString();
String minAge = this.minAge.getText().toString();
String maxAge = this.maxAge.getText().toString();
String mark = this.mark.getText().toString();
String reciprocation = this.reciprocation.getText().toString();
// 设置套餐内容文本
info.setIntroduce(reciprocation);
// 设置备注
info.setRemark(mark);
// 设置最大年龄
if (maxAge != null && !maxAge.equals("")) {
info.setMaxAge(Integer.valueOf(maxAge));
}else{
info.setMaxAge(100);
}
// 设置最小年龄
if (minAge != null && !minAge.equals("")) {
info.setMinAge(Integer.valueOf(minAge));
}
// 设置套餐数量
if (number != null && !number.equals("")) {
info.setMaxNum(Integer.valueOf(number));
}
// 设置性别
if (sex == null || sex.equals("")) {
info.setSex(0);
} else if (sex.equals("男")) {
info.setSex(0);
} else if (sex.equals("女")) {
info.setSex(1);
} else if (sex.equals("其他")) {
info.setSex(2);
} else if (sex.equals("不限")) {
info.setSex(3);
}
// 是否需要提交真实照片
info.setNeedPhoto(needPhoto);
// 设置回报图片
info.setComboPhotoUrl(file);
}
/**
* 选择是否需要提交照片
*
* @param needPhoto
*/
private void choose(int needPhoto) {
this.needPhoto = needPhoto;
for (int i = 0; i < needPhotoList.size(); i++) {
if (i == needPhoto) {
Drawable left = this.getResources().getDrawable(
R.drawable.contacts_selected);
left.setBounds(0, 0, left.getMinimumWidth(),
left.getMinimumHeight());
needPhotoList.get(i).setCompoundDrawables(left, null, null,
null);
} else {
Drawable left = this.getResources().getDrawable(
R.drawable.contacts_normal);
left.setBounds(0, 0, left.getMinimumWidth(),
left.getMinimumHeight());
needPhotoList.get(i).setCompoundDrawables(left, null, null,
null);
}
}
}
/**
* 覆盖方法
*
* @see android.app.Activity#onActivityResult(int, int,
* android.content.Intent)
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
file = imagePicker.onActivityResult(requestCode, resultCode, data);
if (file != null && !file.equals("")) {
choosePhoto.setVisibility(View.GONE);
choosePhotoContent.setVisibility(View.VISIBLE);
bitmapManager.loadBitmap(file, photo);
}
}
@Override
protected void onResume() {
StatService.onResume(this);
super.onResume();
}
@Override
protected void onPause() {
StatService.onPause(this);
super.onPause();
}
}