Java tutorial
package so.contacts.hub.basefunction.account.ui; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; import com.lives.depend.theme.dialog.CommonDialog; import com.lives.depend.theme.dialog.CommonDialogFactory; import com.lives.depend.theme.dialog.progress.AbstractProgressDialog; import com.lives.depend.utils.LogUtil; import com.putao.live.R; import com.qiniu.android.http.ResponseInfo; import com.qiniu.android.storage.UpCompletionHandler; import com.qiniu.android.storage.UploadManager; import com.qiniu.android.storage.UploadOptions; import android.R.integer; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.MediaStore; import android.provider.MediaStore.Images.Media; import android.text.TextUtils; import android.text.style.DynamicDrawableSpan; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import so.contacts.hub.BaseActivity; import so.contacts.hub.basefunction.account.adapter.WheelNumericAdapter; import so.contacts.hub.basefunction.account.adapter.WheelTextAdapter; import so.contacts.hub.basefunction.account.bean.BasicUserInfoBean; import so.contacts.hub.basefunction.account.manager.AccountManager; import so.contacts.hub.basefunction.config.Config; import so.contacts.hub.basefunction.imageloader.DataLoader; import so.contacts.hub.basefunction.imageloader.image.ImageLoaderFactory; import so.contacts.hub.basefunction.net.bean.RelateUser; import so.contacts.hub.basefunction.net.bean.UpLoadUserBasicInfoRequestData; import so.contacts.hub.basefunction.net.manager.IResponse; import so.contacts.hub.basefunction.net.manager.PTHTTPManager; import so.contacts.hub.basefunction.storage.db.CityListDB; import so.contacts.hub.basefunction.storage.db.PersonInfoDB; import so.contacts.hub.basefunction.utils.QiNiuCloudManager; import so.contacts.hub.basefunction.utils.SystemUtil; import so.contacts.hub.basefunction.widget.wheel.OnWheelChangedListener; import so.contacts.hub.basefunction.widget.wheel.WheelView; public class YellowpagePersonalInfoActivity extends BaseActivity implements OnClickListener, OnWheelChangedListener { private static final String TAG = "YellowpagePersonalInfoActivity"; private static final String IMAGE_FILE_NAME = "head_image.jpg"; private static final int CODE_GALLERY_REQUEST = 0xa0; private static final int CODE_CAMERA_REQUEST = 0xa1; private static final int CODE_RESULT_REQUEST = 0xa2; private static final int CODE_UPLOAD_SUCCESS = 0xa3; private static final int CODE_UPLOAD_FIAL = 0xa4; private static final int CODE_SHOW_WHEEL_CITY_DIALOG = 0xa5; private static final int CODE_INIT_BASIC_USER_DATA = 0xa6; // ===============================view start======================== // ??? private LinearLayout mDataHintLayout; // ?? private ImageView mHintDisappearImageView; private RelativeLayout mHeadDataLayout; // ? private ImageView mHeadImageView; private RelativeLayout mCityDataLayout; private CommonDialog mHeadImageDialog; // private TextView mCityTextView; private RelativeLayout mGenderLayout; private WheelView mProvinceWheelView; private WheelView mCityWheelView; private CommonDialog mCityDialog; // private TextView mGenderTextView; private RelativeLayout mBirthdayLayout; private CommonDialog mGenderDialog; // private TextView mBirthdayTextView; private RelativeLayout mCommInfoLayout; private CommonDialog mBirthdayDialog; private WheelView mYearWheelView; private int mCurrentYear; private WheelNumericAdapter mYearAdapter; private WheelView mMonthWheelView; private WheelNumericAdapter mMonthAdapter; private WheelView mDayWheelView; private int mMaxDay; private WheelNumericAdapter mDayAdapter; // ? private TextView mCommInfoTextView; private RelativeLayout mHomeAddressLayout; // ? private TextView mHomeAddressTextView; private RelativeLayout mCarInfoLayout; // ? private TextView mCarInfoTextView; // ? private TextView mBindPhoneTextView; // ? private RelativeLayout mSetPassWordLayout; // private TextView mNotSafeTextView; // private Button mLogOutButton; private CommonDialog mLogOutDialog; // ===============================view end======================== // ?? private boolean mChangeFlag = false; // ??(X)(Y),480 X 480 private static int output_X = 480; private static int output_Y = 480; // ??uri private Uri mHeadIconUri = null; // ? private DataLoader mImageLoader; // ??? private int mHasSetPassword; // ???? private String mHeadPicSTR; // private String mCitySTR; // private String mGenderSTR; // private String mBirthdaySTR; // ?? private PersonInfoDB mPersonInfoDB; // ? private LinkedList<String> mProvincesList = new LinkedList<String>(); // ?? private WheelTextAdapter mProvinceAdapter; // private LinkedList<String> mCitiesList = new LinkedList<String>(); // ? private WheelTextAdapter mCityAdapter; // ? private CityListDB mCityListDB; // ?? private LinkedList<ProvinceItem> mProvinceItems = new LinkedList<ProvinceItem>(); // ? private BasicUserInfoBean mBasicUserInfoBean; // private String male; // private String female; // handler private Handler mHandler = new Handler() { public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case CODE_UPLOAD_SUCCESS: dismissLoadingDialog(); if (mImageLoader != null) { mImageLoader.loadData(mHeadPicSTR, mHeadImageView); } break; case CODE_UPLOAD_FIAL: dismissLoadingDialog(); Toast.makeText(YellowpagePersonalInfoActivity.this, getString(R.string.putao_personal_data_upload_icon_fail), Toast.LENGTH_SHORT).show(); break; case CODE_SHOW_WHEEL_CITY_DIALOG: showWheelCityDialog(); case CODE_INIT_BASIC_USER_DATA: dismissLoadingDialog(); initBasicInfoData(); default: break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.putao_personal_data_layout); mHeadIconUri = Uri.fromFile(new File(getExternalCacheDir(), IMAGE_FILE_NAME)); mImageLoader = new ImageLoaderFactory(this).getStatusAvatarLoader(); mPersonInfoDB = Config.getDatabaseHelper().getPersonInfoDB(); mCityListDB = Config.getDatabaseHelper().getCityListDB(); initView(); } @Override protected void onResume() { super.onResume(); updateBasicInfoData(); initCommonInfoData(); } /** * ??? void */ private void updateBasicInfoData() { if (mBasicUserInfoBean == null) { showLoadingDialog(); } // 1.??? 2.handler??message? Config.execute(new Runnable() { @Override public void run() { mBasicUserInfoBean = mPersonInfoDB.queryData(); mHandler.sendEmptyMessage(CODE_INIT_BASIC_USER_DATA); } }); } /** * ?? void */ private void initBasicInfoData() { if (mBasicUserInfoBean == null) { return; } else { // ??? mHasSetPassword = mBasicUserInfoBean.getHas_set_password(); if (mHasSetPassword != 1) { findViewById(R.id.putao_not_safty).setVisibility(View.VISIBLE); } } // ? String imageUrl = mBasicUserInfoBean.getHead_pic(); if (!TextUtils.isEmpty(imageUrl) && mImageLoader != null) { mHeadPicSTR = imageUrl; mImageLoader.loadData(imageUrl, mHeadImageView); } else { mHeadImageView.setImageResource(R.drawable.putao_menu_acc_headimg_logined); } // String city = mBasicUserInfoBean.getCity(); if (!TextUtils.isEmpty(city)) { mCitySTR = city; } else { // ???mCitySTR } mCityTextView.setText(mCitySTR); // int gender = mBasicUserInfoBean.getGender(); if (gender == 0) { mGenderSTR = male; } else if (gender == 1) { mGenderSTR = female; } mGenderTextView.setText(mGenderSTR); // mBirthdaySTR = mBasicUserInfoBean.getBirthday(); if (!TextUtils.isEmpty(mBirthdaySTR)) { mBirthdayTextView.setText(mBirthdaySTR); } else { mBirthdayTextView.setText("1989-10-15"); } } @Override protected void onPause() { super.onPause(); // onpause????????????????1.?? // 2.??????? if (mChangeFlag) { saveUserBasicInfo(); } } /** * ???? void */ private void saveUserBasicInfo() { // ??? int sex = -1; if (!TextUtils.isEmpty(mGenderSTR)) { if (mGenderSTR.equals(male)) { sex = 0; } else if (mGenderSTR.equals(female)) { sex = 1; } else { sex = -1; } } // 1.??? final BasicUserInfoBean bean = new BasicUserInfoBean(0, mHeadPicSTR, mCitySTR, sex, null); // ???? Config.execute(new Runnable() { @Override public void run() { mPersonInfoDB.insertData(bean); } }); // 2.? UpLoadUserBasicInfoRequestData requestData = new UpLoadUserBasicInfoRequestData(this, mHeadPicSTR, mCitySTR, sex + "", mBirthdaySTR); PTHTTPManager.getHttp().asynPost(Config.UPLOAD_BASIC_INFO_URL, requestData, new IResponse() { @Override public void onSuccess(String content) { try { JSONObject object = new JSONObject(content); String ret_code = null; if (!object.isNull("ret_code")) { ret_code = object.getString("ret_code"); } if (!"0000".equals(ret_code)) { Toast.makeText(YellowpagePersonalInfoActivity.this, getString(R.string.putao_personal_edit_upload_fail), Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFail(int errorCode) { Toast.makeText(YellowpagePersonalInfoActivity.this, getString(R.string.putao_personal_edit_upload_fail), Toast.LENGTH_SHORT).show(); } }); } /** * ?? void */ private void initCommonInfoData() { // ?? String bindPhone = ""; RelateUser relateUser = AccountManager.getInstance().getRelateUser(RelateUser.TYPE_PHONE); if (relateUser != null) { bindPhone = AccountManager.getInstance().getDisplayName(relateUser); } mBindPhoneTextView.setText(bindPhone); } /** * ? void */ private void initView() { initTitleView(); initHeadImageView(); initCityInfoView(); initGenderInfoView(); initBirthdayInfoView(); initCommInfoView(); initSetPasswordView(); } /** * ?title void */ private void initTitleView() { setTitle(R.string.putao_personal_data_title); findViewById(R.id.back_layout).setOnClickListener(this); } /** * ?? void */ private void initSetPasswordView() { // ? mBindPhoneTextView = (TextView) findViewById(R.id.putao_personal_data_phone_number_tv); // ? mSetPassWordLayout = (RelativeLayout) findViewById(R.id.putao_set_password); mSetPassWordLayout.setOnClickListener(this); mNotSafeTextView = (TextView) findViewById(R.id.putao_not_safty); // mLogOutButton = (Button) findViewById(R.id.login_out_btn); mLogOutButton.setOnClickListener(this); } /** * ?? void */ private void initCommInfoView() { // ? mCommInfoLayout = (RelativeLayout) findViewById(R.id.putao_common_info); mCommInfoLayout.setOnClickListener(this); mCommInfoTextView = (TextView) findViewById(R.id.putao_common_info_hint_tv); // ? mHomeAddressLayout = (RelativeLayout) findViewById(R.id.putao_personal_data_home_address_rl); mHomeAddressLayout.setOnClickListener(this); mHomeAddressTextView = (TextView) findViewById(R.id.putao_personal_data_home_address_hint_tv); // ? mCarInfoLayout = (RelativeLayout) findViewById(R.id.putao_personal_data_license_number_rl); mCarInfoLayout.setOnClickListener(this); mCarInfoTextView = (TextView) findViewById(R.id.putao_personal_data_license_number_hint_tv); } /** * ?? void */ private void initBirthdayInfoView() { // mBirthdayLayout = (RelativeLayout) findViewById(R.id.putao_personal_data_birthday_ll); mBirthdayLayout.setOnClickListener(this); mBirthdayTextView = (TextView) findViewById(R.id.putao_personal_data_birthday_tv); } /** * ? void */ private void initGenderInfoView() { male = getString(R.string.putao_personal_data_male); female = getString(R.string.putao_personal_data_femel); // mGenderLayout = (RelativeLayout) findViewById(R.id.putao_personal_data_gender_ll); mGenderLayout.setOnClickListener(this); mGenderTextView = (TextView) findViewById(R.id.putao_personal_data_gender_tv); } /** * ? void */ private void initCityInfoView() { mCityDataLayout = (RelativeLayout) findViewById(R.id.putao_personal_data_city_ll); mCityDataLayout.setOnClickListener(this); mCityTextView = (TextView) findViewById(R.id.putao_personal_data_city_tv); } /** * ? void */ private void showCityDialog() { // ??,??? if (mProvinceItems.size() == 0 || mProvinceItems.isEmpty()) { showLoadingDialog(); Config.execute(new Runnable() { @Override public void run() { // ?? loadCityData(); // ??? mHandler.sendEmptyMessage(CODE_SHOW_WHEEL_CITY_DIALOG); } }); } else { showWheelCityDialog(); } } private void showWheelCityDialog() { dismissLoadingDialog(); if (mCityDialog == null) { mCityDialog = CommonDialogFactory.getDialog(this, R.style.Theme_Ptui_Dialog_Wheel); mCityDialog.setTitle(getString(R.string.putao_personal_data_area)); mCityDialog.setNegativeButton(getString(R.string.putao_cancel), new OnClickListener() { @Override public void onClick(View view) { mCityDialog.dismiss(); } }); mCityDialog.setPositiveButton(getString(R.string.putao_confirm), new OnClickListener() { @Override public void onClick(View view) { mCityDialog.dismiss(); mChangeFlag = true; // ???? ProvinceItem provinceItem = mProvinceItems.get(0); String city = ""; int provinceIndex = mProvinceWheelView.getCurrentItem(); if (provinceIndex >= 0 && provinceIndex < mProvinceItems.size()) { provinceItem = mProvinceItems.get(provinceIndex); mCitiesList.clear(); mCitiesList.addAll(provinceItem.cityList); int cityIndex = mCityWheelView.getCurrentItem(); if (cityIndex >= 0 && cityIndex < mCitiesList.size()) { city = mCitiesList.get(cityIndex); if ("---".equals(city)) { city = ""; } } StringBuilder sb = new StringBuilder(); sb.append(provinceItem.provinceName).append(" ").append(city); mCitySTR = sb.toString(); mCityTextView.setText(mCitySTR); } } }); LinearLayout wheelContainer = (LinearLayout) mCityDialog.getContainerLayout(); // ???wheelview wheelContainer.findViewById(R.id.wheel_center).setVisibility(View.GONE); mProvinceWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_left); mProvinceWheelView.setVisibleItems(3); mProvinceAdapter = new WheelTextAdapter(this, mProvincesList); mProvinceWheelView.setViewAdapter(mProvinceAdapter); mProvinceWheelView.addChangingListener(this); mCityWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_right); mCityWheelView.setVisibleItems(3); mCityAdapter = new WheelTextAdapter(this, mCitiesList); mCityWheelView.setViewAdapter(mCityAdapter); mCityWheelView.addChangingListener(this); } // if (!TextUtils.isEmpty(mCitySTR)) { // ?? String[] area = mCitySTR.split(" "); String province = ""; String city = ""; if (area.length > 0) { province = area[0]; } if (area.length > 1) { city = area[1]; } // ??? if (!mProvinceItems.isEmpty() && !TextUtils.isEmpty(province)) { for (int i = 0; i < mProvinceItems.size(); i++) { if (mProvinceItems.get(i).provinceName.equals(province)) { mProvinceWheelView.setCurrentItem(i); mCitiesList.clear(); mCitiesList.addAll(mProvinceItems.get(i).cityList); break; } } } // ?? if (!mCitiesList.isEmpty() && !TextUtils.isEmpty(city)) { for (int j = 0; j < mCitiesList.size(); j++) { if (mCitiesList.get(j).equals(city)) { mCityWheelView.setCurrentItem(j); break; } } } } else { mProvinceWheelView.setCurrentItem(0); mProvinceAdapter.setData(mProvincesList); mCityWheelView.setCurrentItem(0); mCityAdapter.setData(mCitiesList); } mCityDialog.show(); } /** * ?? void */ private void loadCityData() { if (mProvinceItems != null && !mProvinceItems.isEmpty()) { return; } LinkedList<String> provinceList = mCityListDB.getDistrictNameByParentId(this, 0); if (provinceList != null && provinceList.size() > 0) { mProvincesList.clear(); mProvincesList.addAll(provinceList); mProvinceItems.clear(); for (String province : provinceList) { ProvinceItem provinceItem = new ProvinceItem(); provinceItem.provinceName = province; // ?????id int provinceId = mCityListDB.getCityIdByCityName(province); // ??? LinkedList<String> cityList = mCityListDB.getDistrictNameByParentId(this, provinceId); if (cityList != null && cityList.size() > 0) { provinceItem.cityList.addAll(cityList); } // provinceItem.cityList.add("---"); mProvinceItems.add(provinceItem); } } } /** * ? void */ private void initHeadImageView() { // ??? mDataHintLayout = (LinearLayout) findViewById(R.id.putao_personal_data_hint_ll); mDataHintLayout.setOnClickListener(this); mHintDisappearImageView = (ImageView) findViewById(R.id.putao_personal_data_hint_disappear_iv); mHintDisappearImageView.setOnClickListener(this); // ? mHeadDataLayout = (RelativeLayout) findViewById(R.id.putao_personal_data_icon_rl); mHeadDataLayout.setOnClickListener(this); mHeadImageView = (ImageView) findViewById(R.id.putao_personal_data_icon_iv); } /** * ?? void */ protected void takePictureByCamera() { // sd? if (!SystemUtil.hasSdcard()) { return; } Intent intentByCapture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intentByCapture.putExtra(MediaStore.EXTRA_OUTPUT, mHeadIconUri); startActivityForResult(intentByCapture, CODE_CAMERA_REQUEST); } /** * ? void */ protected void chooseImageFromGallery() { Intent intentFromGallery = new Intent(); // intentFromGallery.setType("image/*"); intentFromGallery.setAction(Intent.ACTION_PICK); startActivityForResult(intentFromGallery, CODE_GALLERY_REQUEST); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_CANCELED) { return; } else if (resultCode == RESULT_OK) { switch (requestCode) { case CODE_GALLERY_REQUEST: Uri galleryUri = intent.getData(); cropRawPhoto(galleryUri); break; case CODE_CAMERA_REQUEST: cropRawPhoto(mHeadIconUri); break; case CODE_RESULT_REQUEST: if (mHeadIconUri != null) { Bitmap photo = null; try { photo = Media.getBitmap(getContentResolver(), mHeadIconUri); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (photo != null) { // ?? uploadImgFile(photo); } } break; default: break; } } } /** * ?? * * @param photo void */ private void uploadImgFile(final Bitmap photo) { if (mProgressDialog == null) { mProgressDialog = CommonDialogFactory.getProgressDialog(this, R.style.Theme_Ptui_Dialog_Progress); mProgressDialog.setMessage(getString(R.string.putao_personal_data_uploading_icon)); } mProgressDialog.show(); mChangeFlag = true; Config.execute(new Runnable() { @Override public void run() { if (photo == null) { if (mHandler != null) { mHandler.sendEmptyMessage(CODE_UPLOAD_FIAL); } } // photo? ByteArrayOutputStream stream = new ByteArrayOutputStream(); photo.compress(CompressFormat.JPEG, 100, stream); // ? byte[] data = stream.toByteArray(); // ? UploadManager uploadManager = new UploadManager(); Map<String, String> params = new HashMap<String, String>(); UploadOptions opt = new UploadOptions(params, null, true, null, null); // ???token String token = QiNiuCloudManager.getInstance() .getUploadToken(Config.YELLOW_PAGE_FEEDBACK_IMG_UPLOAD_TOKEN); if (TextUtils.isEmpty(token)) { if (mHandler != null) { mHandler.sendEmptyMessage(CODE_UPLOAD_FIAL); } } // ?key??? String key = QiNiuCloudManager.getInstance().getExpectKey(mHeadIconUri.toString()); // UpCompletionHandler upCompletionHandler = new UpCompletionHandler() { @Override public void complete(String key, ResponseInfo info, JSONObject res) { if (info.isOK()) { // ?,?? mHeadPicSTR = Config.BUCKET_NAME_URL + key; // handler??ui if (mHandler != null) { mHandler.sendEmptyMessage(CODE_UPLOAD_SUCCESS); } } else { if (mHandler != null) { mHandler.sendEmptyMessage(CODE_UPLOAD_FIAL); } } } }; // ? uploadManager.put(data, key, token, upCompletionHandler, null); } }); } /** * ? * * @param galleryUri void */ private void cropRawPhoto(Uri uri) { Intent intentCrop = new Intent("com.android.camera.action.CROP"); intentCrop.setDataAndType(uri, "image/*"); intentCrop.putExtra("crop", "true"); intentCrop.putExtra("aspectX", 1); intentCrop.putExtra("aspectY", 1); intentCrop.putExtra("outputX", output_X); intentCrop.putExtra("outputY", output_Y); intentCrop.putExtra("outputFormat", "JPEG"); intentCrop.putExtra("noFaceDetection", true); intentCrop.putExtra("return-data", false); intentCrop.putExtra(MediaStore.EXTRA_OUTPUT, mHeadIconUri); startActivityForResult(intentCrop, CODE_RESULT_REQUEST); } @Override protected void onDestroy() { super.onDestroy(); } @Override public void onClick(View view) { int id = view.getId(); switch (id) { case R.id.back_layout: onBackPressed(); break; case R.id.putao_personal_data_icon_rl: showHeadImageDialog(); break; case R.id.login_out_btn: showLogOutDialog(); break; case R.id.putao_personal_data_city_ll: showCityDialog(); break; case R.id.putao_personal_data_gender_ll: showGenderDialog(); break; case R.id.putao_personal_data_birthday_ll: showBirthdayDialog(); break; case R.id.putao_set_password: setPassWord(); break; default: break; } } /** * ? * void */ private void setPassWord() { Intent intent = new Intent(YellowpagePersonalInfoActivity.this, YellowpageModifyPasswordActivity.class); RelateUser relateUser = AccountManager.getInstance().getRelateUser(RelateUser.TYPE_PHONE); String showStr = relateUser.accName.substring(0, 3) + " " + relateUser.accName.substring(3, 7) + " " + relateUser.accName.substring(7); intent.putExtra("old_phone", showStr); startActivity(intent); } /** * * void */ private void showBirthdayDialog() { if (mBirthdayDialog == null) { mBirthdayDialog = CommonDialogFactory.getDialog(this, R.style.Theme_Ptui_Dialog_Wheel); mBirthdayDialog.setTitle(getString(R.string.putao_personal_data_birthday)); mBirthdayDialog.setNegativeButton(R.string.putao_cancel, new OnClickListener() { @Override public void onClick(View view) { mBirthdayDialog.dismiss(); } }); mBirthdayDialog.setPositiveButton(R.string.putao_confirm, new OnClickListener() { @Override public void onClick(View view) { mBirthdayDialog.dismiss(); mChangeFlag = true; int year = mYearWheelView.getCurrentItem() + mCurrentYear - 100; int month = mMonthWheelView.getCurrentItem() + 1; int day = mDayWheelView.getCurrentItem() + 1; StringBuilder sb = new StringBuilder(); sb.append(year).append("-").append(month).append("-").append(day); mBirthdaySTR = sb.toString(); mBirthdayTextView.setText(mBirthdaySTR); } }); LinearLayout wheelContainer = (LinearLayout) mBirthdayDialog.getContainerLayout(); // ?? Calendar calendar = Calendar.getInstance(); mCurrentYear = calendar.get(Calendar.YEAR); mYearWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_left); mYearWheelView.setVisibleItems(3); mYearAdapter = new WheelNumericAdapter(this, mCurrentYear - 100, mCurrentYear, getString(R.string.putao_personal_data_year)); mYearWheelView.setViewAdapter(mYearAdapter); // mMonthWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_center); mMonthWheelView.setVisibleItems(3); mMonthAdapter = new WheelNumericAdapter(this, 1, 12, getString(R.string.putao_personal_data_month)); mMonthWheelView.setViewAdapter(mMonthAdapter); // mDayWheelView = (WheelView) wheelContainer.findViewById(R.id.wheel_right); mDayWheelView.setVisibleItems(3); OnWheelChangedListener listener = new OnWheelChangedListener() { @Override public void onChanged(WheelView wheel, int oldValue, int newValue) { //????????? updateDays(mYearWheelView, mMonthWheelView, mDayWheelView); } }; mYearWheelView.addChangingListener(listener); mMonthWheelView.addChangingListener(listener); updateDays(mYearWheelView, mMonthWheelView, mDayWheelView); } //mBirthdaySTR? if (!TextUtils.isEmpty(mBirthdaySTR)) { try { String[] date = mBirthdaySTR.split("-"); String year = ""; String month = ""; String day = ""; if (date.length > 0) { year = date[0]; } // yearyear index if (!TextUtils.isEmpty(year)) { int yearIndex = Integer.parseInt(year) - (mCurrentYear - 100); mYearWheelView.setCurrentItem(yearIndex); } if (date.length > 1) { month = date[1]; } //monthmonth index if (!TextUtils.isEmpty(month)) { int monthIndex = Integer.parseInt(month) - 1; mMonthWheelView.setCurrentItem(monthIndex); } if (date.length > 2) { day = date[2]; } //dayday index if (!TextUtils.isEmpty(day)) { int dayIndex = Integer.parseInt(day) - 1; mDayWheelView.setCurrentItem(dayIndex); } } catch (Exception e) { LogUtil.w("YellowpagePersonalInfoActivity", "catch Exception throw by choosePicture", e); } } else { mYearWheelView.setCurrentItem(73); } mBirthdayDialog.show(); } /** * ?????????(2829) * * @param mYearWheelView2 * @param mMonthWheelView2 * @param mDayWheelView2 void */ private void updateDays(WheelView year, WheelView month, WheelView day) { // Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year.getCurrentItem()); calendar.set(Calendar.MONTH, month.getCurrentItem()); mMaxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); mDayAdapter = new WheelNumericAdapter(this, 1, mMaxDay, getString(R.string.putao_personal_data_day)); mDayWheelView.setViewAdapter(mDayAdapter); } /** * void */ private void showGenderDialog() { if (mGenderDialog == null) { mGenderDialog = CommonDialogFactory.getDialog(this, R.style.Theme_Ptui_Dialog_ListView); mGenderDialog.setTitle(getString(R.string.putao_personal_data_gender)); ArrayList<String> genderList = new ArrayList<String>(); genderList.add(male); genderList.add(female); mGenderDialog.setSingleChoiceListViewDatas(genderList); mGenderDialog.setListViewItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mGenderDialog.dismiss(); mChangeFlag = true; // 01 if (position == 0) { mGenderSTR = male; mGenderTextView.setText(male); } else if (position == 1) { mGenderSTR = female; mGenderTextView.setText(female); } } }); } //? if (!TextUtils.isEmpty(mGenderSTR)) { if (mGenderSTR.equals(male)) { mGenderDialog.getListView().setItemChecked(0, true); } else if (mGenderSTR.equals(female)) { mGenderDialog.getListView().setItemChecked(1, true); } } else { mGenderDialog.getListView().setItemChecked(0, true); } mGenderDialog.show(); } /** * ? void */ private void showHeadImageDialog() { mHeadImageDialog = CommonDialogFactory.getDialog(this, R.style.Theme_Ptui_Dialog_ListView); mHeadImageDialog.setTitle(R.string.putao_personal_data_icon); String[] imageList = new String[] { getString(R.string.putao_personal_data_get_icon_from_gallery), getString(R.string.putao_personal_data_get_icon_from_camera) }; mHeadImageDialog.setListViewDatas(imageList); mHeadImageDialog.setListViewItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mHeadImageDialog.dismiss(); // ?position??, if (position == 0) { // chooseImageFromGallery(); } else { // takePictureByCamera(); } } }); mHeadImageDialog.show(); } /** * :ptuser??? void */ private void showLogOutDialog() { mLogOutDialog = CommonDialogFactory.getDialog(YellowpagePersonalInfoActivity.this, R.style.Theme_Ptui_Dialog_OkCancel); mLogOutDialog.setTitle(R.string.putao_common_prompt); mLogOutDialog.setMessage(R.string.putao_msg_logout_dialog); mLogOutDialog.setPositiveButton(R.string.putao_confirm, new OnClickListener() { @Override public void onClick(View view) { mLogOutDialog.dismiss(); // showLoadingDialog(false); // ???? if (mChangeFlag) { saveUserBasicInfo(); mChangeFlag = false; } AccountManager.getInstance().logout(YellowpagePersonalInfoActivity.this); dismissLoadingDialog(); // menufragment setResult(RESULT_OK); finish(); } }); mLogOutDialog.setNegativeButton(R.string.putao_cancel, new OnClickListener() { @Override public void onClick(View view) { mLogOutDialog.dismiss(); } }); mLogOutDialog.show(); } @Override public void onChanged(WheelView wheel, int oldValue, int newValue) { if (wheel == mProvinceWheelView) { updateCities(); } else if (wheel == mCityWheelView) { // ?? } } /** * ??? void */ private void updateCities() { // ??? int currentIndex = mProvinceWheelView.getCurrentItem(); ProvinceItem currentProvince = mProvinceItems.get(currentIndex); LinkedList<String> cityList = currentProvince.cityList; // mCitiesList.clear(); if (cityList != null && cityList.size() > 0) { mCitiesList.addAll(cityList); } else { mCitiesList.add("---"); } mCityAdapter.setData(mCitiesList); mCityWheelView.setCurrentItem(0); } class ProvinceItem { private String provinceName = ""; private LinkedList<String> cityList = new LinkedList<String>(); } }