package com.mobileclient.activity;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import com.mobileclient.util.HttpUtil;
import com.mobileclient.util.ImageService;
import com.mobileclient.domain.Hourse;
import com.mobileclient.service.HourseService;
import com.mobileclient.domain.BuildingInfo;
import com.mobileclient.service.BuildingInfoService;
import com.mobileclient.domain.HourseType;
import com.mobileclient.service.HourseTypeService;
import com.mobileclient.domain.PriceRange;
import com.mobileclient.service.PriceRangeService;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.Spinner;
import android.widget.Toast;
public class HourseEditActivity extends Activity {
// 声明确定添加按钮
private Button btnUpdate;
// 声明房屋编号TextView
private TextView TV_hourseId;
// 声明房屋名称输入框
private EditText ET_hourseName;
// 声明所在楼盘下拉框
private Spinner spinner_buildingObj;
private ArrayAdapter<String> buildingObj_adapter;
private static String[] buildingObj_ShowText = null;
private List<BuildingInfo> buildingInfoList = null;
/*所在楼盘管理业务逻辑层*/
private BuildingInfoService buildingInfoService = new BuildingInfoService();
// 声明房屋图片图片框控件
private ImageView iv_housePhoto;
private Button btn_housePhoto;
protected int REQ_CODE_SELECT_IMAGE_housePhoto = 1;
private int REQ_CODE_CAMERA_housePhoto = 2;
// 声明房屋类型下拉框
private Spinner spinner_hourseTypeObj;
private ArrayAdapter<String> hourseTypeObj_adapter;
private static String[] hourseTypeObj_ShowText = null;
private List<HourseType> hourseTypeList = null;
/*房屋类型管理业务逻辑层*/
private HourseTypeService hourseTypeService = new HourseTypeService();
// 声明价格范围下拉框
private Spinner spinner_priceRangeObj;
private ArrayAdapter<String> priceRangeObj_adapter;
private static String[] priceRangeObj_ShowText = null;
private List<PriceRange> priceRangeList = null;
/*价格范围管理业务逻辑层*/
private PriceRangeService priceRangeService = new PriceRangeService();
// 声明面积输入框
private EditText ET_area;
// 声明租金(元/月)输入框
private EditText ET_price;
// 声明楼层/总楼层输入框
private EditText ET_louceng;
// 声明装修输入框
private EditText ET_zhuangxiu;
// 声明朝向输入框
private EditText ET_caoxiang;
// 声明建筑年代输入框
private EditText ET_madeYear;
// 声明联系人输入框
private EditText ET_connectPerson;
// 声明联系电话输入框
private EditText ET_connectPhone;
// 声明详细信息输入框
private EditText ET_detail;
// 声明地址输入框
private EditText ET_address;
protected String carmera_path;
/*要保存的房屋信息信息*/
Hourse hourse = new Hourse();
/*房屋信息管理业务逻辑层*/
private HourseService hourseService = new HourseService();
private int hourseId;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去除title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//去掉Activity上面的状态栏
getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN);
// 设置当前Activity界面布局
setContentView(R.layout.hourse_edit);
ImageView search = (ImageView) this.findViewById(R.id.search);
search.setVisibility(View.GONE);
TextView title = (TextView) this.findViewById(R.id.title);
title.setText("编辑房屋信息信息");
ImageView back = (ImageView) this.findViewById(R.id.back_btn);
back.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
finish();
}
});
TV_hourseId = (TextView) findViewById(R.id.TV_hourseId);
ET_hourseName = (EditText) findViewById(R.id.ET_hourseName);
spinner_buildingObj = (Spinner) findViewById(R.id.Spinner_buildingObj);
// 获取所有的所在楼盘
try {
buildingInfoList = buildingInfoService.QueryBuildingInfo(null);
} catch (Exception e1) {
e1.printStackTrace();
}
int buildingInfoCount = buildingInfoList.size();
buildingObj_ShowText = new String[buildingInfoCount];
for(int i=0;i<buildingInfoCount;i++) {
buildingObj_ShowText[i] = buildingInfoList.get(i).getBuildingName();
}
// 将可选内容与ArrayAdapter连接起来
buildingObj_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, buildingObj_ShowText);
// 设置图书类别下拉列表的风格
buildingObj_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 将adapter 添加到spinner中
spinner_buildingObj.setAdapter(buildingObj_adapter);
// 添加事件Spinner事件监听
spinner_buildingObj.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
hourse.setBuildingObj(buildingInfoList.get(arg2).getBuildingId());
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
// 设置默认值
spinner_buildingObj.setVisibility(View.VISIBLE);
iv_housePhoto = (ImageView) findViewById(R.id.iv_housePhoto);
/*单击图片显示控件时进行图片的选择*/
iv_housePhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setClass(HourseEditActivity.this,photoListActivity.class);
startActivityForResult(intent,REQ_CODE_SELECT_IMAGE_housePhoto);
}
});
btn_housePhoto = (Button) findViewById(R.id.btn_housePhoto);
btn_housePhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
carmera_path = HttpUtil.FILE_PATH + "/carmera_housePhoto.bmp";
File out = new File(carmera_path);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
startActivityForResult(intent, REQ_CODE_CAMERA_housePhoto);
}
});
spinner_hourseTypeObj = (Spinner) findViewById(R.id.Spinner_hourseTypeObj);
// 获取所有的房屋类型
try {
hourseTypeList = hourseTypeService.QueryHourseType(null);
} catch (Exception e1) {
e1.printStackTrace();
}
int hourseTypeCount = hourseTypeList.size();
hourseTypeObj_ShowText = new String[hourseTypeCount];
for(int i=0;i<hourseTypeCount;i++) {
hourseTypeObj_ShowText[i] = hourseTypeList.get(i).getTypeName();
}
// 将可选内容与ArrayAdapter连接起来
hourseTypeObj_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, hourseTypeObj_ShowText);
// 设置图书类别下拉列表的风格
hourseTypeObj_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 将adapter 添加到spinner中
spinner_hourseTypeObj.setAdapter(hourseTypeObj_adapter);
// 添加事件Spinner事件监听
spinner_hourseTypeObj.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public vo