@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(); }
/** 从数据库获取基本数据,并显示 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 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(); } }
/** * 账户头像上传到七牛服务器 * * @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); } }); }
/** 用户信息有变化的时候,保存用户信息 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(); } }); }