Java tutorial
/** * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.grass.caishi.cc.activity; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Map; import org.apache.http.Header; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.provider.MediaStore; import android.text.InputType; import android.text.method.NumberKeyListener; import android.view.Gravity; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.EditText; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.easemob.util.DeviceUuidFactory; import com.grass.caishi.cc.Constant; import com.grass.caishi.cc.R; import com.grass.caishi.cc.activity.main.MainActivity; import com.grass.caishi.cc.utils.CommonUtils; import com.grass.caishi.cc.utils.HttpRestClient; import com.grass.caishi.cc.utils.ImageUtils; import com.grass.caishi.cc.utils.JsonToMapList; import com.grass.caishi.cc.utils.MyLogger; import com.grass.caishi.cc.utils.PreferenceUtils; import com.grass.caishi.cc.win.MyAddressView; import com.grass.caishi.cc.win.MyAddressView.OnAddressCheckListener; import com.grass.view.ActionSheetDialog; import com.grass.view.ActionSheetDialog.OnSheetItemClickListener; import com.grass.view.ActionSheetDialog.SheetItemColor; import com.loopj.android.http.RequestParams; import com.loopj.android.http.TextHttpResponseHandler; import com.nostra13.universalimageloader.utils.StorageUtils; /** * ? * * @author Administrator * */ public class SettingUserActivity extends BaseActivity implements OnClickListener { /* * private String = "shared_key_setting_user_pic"; private String = "shared_key_setting_user_sex"; private String = "shared_key_setting_user_age"; private String = "shared_key_setting_user_area"; private String = "shared_key_setting_user_zaina"; */ private static MyLogger Log = MyLogger.yLog(); /********************************** ? *****************************************/ /** * ? */ private RelativeLayout rl_user_pic; /** * */ private RelativeLayout rl_user_nicheng; /** * */ private RelativeLayout rl_user_xingbie; /** * */ // private RelativeLayout rl_user_nianling; /** * */ private RelativeLayout rl_user_chengshi; /** * ? */ // private RelativeLayout rl_user_zhiye; /** * ?? */ private RelativeLayout rl_user_qianming; /** * ? */ private RelativeLayout rl_user_zainadongtai; /** * ?imageView */ private ImageView iv_user_photo; /** * */ private TextView tv_user_nicheng; /** * */ private TextView tv_user_xingbie; /** * */ private TextView tv_user_nianling; /** * */ private TextView tv_user_chengshi; /** * ? */ // private TextView tv_user_zhiye; /** * ?? */ private TextView tv_user_qianming; /** * ? */ public TextView tv_user_zainadongtai; private String UserPic = null; private String UserNickName = null; private int UserSex = 1; // private String UserAge = null; private String UserAdd = null; private String UserAge = null; // private String UserZhiye = null; private String UserQianming = null; private boolean isRefresh = false; // /******************************************************************************/ // /** // * ? // */ // private RelativeLayout rl_switch_notification; // /** // * // */ // private RelativeLayout rl_switch_sound; // /** // * // */ // private RelativeLayout rl_switch_vibrate; // /** // * // */ // private RelativeLayout rl_switch_speaker; // // /** // * ?imageView // */ // private ImageView iv_switch_open_notification; // /** // * ?imageview // */ // private ImageView iv_switch_close_notification; // /** // * ??imageview // */ // private ImageView iv_switch_open_sound; // /** // * ??imageview // */ // private ImageView iv_switch_close_sound; // /** // * ??? // */ // private ImageView iv_switch_open_vibrate; // /** // * ??? // */ // private ImageView iv_switch_close_vibrate; // /** // * // */ // private ImageView iv_switch_open_speaker; // /** // * // */ // private ImageView iv_switch_close_speaker; // // /** // * ? // */ // private TextView textview1, textview2; // // private LinearLayout blacklistContainer; // // /** // * // */ // private Button logoutBtn; // // private Button exit; // private EMChatOptions chatOptions; /************* * ?? */ private MyAddressView address_view; private TextHttpResponseHandler responseHandler; private File cameraFile;// ? // private File cutFile;//? // ?uri private static String IMAGE_FILE_LOCATION = null; private Uri imageUri = null; private static final String IMAGE_FILE_LOCATION_TEAST = "file:///sdcard/lehu/temp.jpg";// temp // file Uri imageUritest = Uri.parse(IMAGE_FILE_LOCATION_TEAST);// The Uri to store // the big bitmap // private Uri imageUri = null;//Uri.parse(IMAGE_FILE_LOCATION);//The Uri to // store the big bitmap public static final int USERPIC_REQUEST_CODE_LOCAL = 101; public static final int USERPIC_REQUEST_CODE_LOCAL_19 = 101; public static final int USERPIC_REQUEST_CODE_CAMERA = 102; public static final int USERPIC_REQUEST_CODE_CUT = 103; // private ProgressDialog pd; // id private static String uid = null; private String userInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings_user_main); DeviceUuidFactory uuid = new DeviceUuidFactory(this); uid = uuid.getDeviceUuid().toString(); dialog.setMessage("??..."); /*************** ? **************/ rl_user_pic = (RelativeLayout) findViewById(R.id.rl_user_pic); rl_user_nicheng = (RelativeLayout) findViewById(R.id.rl_user_nicheng); rl_user_xingbie = (RelativeLayout) findViewById(R.id.rl_user_xingbie); rl_user_chengshi = (RelativeLayout) findViewById(R.id.rl_user_chengshi); rl_user_qianming = (RelativeLayout) findViewById(R.id.rl_user_qianming); // ? iv_user_photo = (ImageView) findViewById(R.id.iv_user_photo); tv_user_nicheng = (TextView) findViewById(R.id.tv_user_nicheng); tv_user_xingbie = (TextView) findViewById(R.id.tv_user_xingbie); tv_user_chengshi = (TextView) findViewById(R.id.tv_user_chengshi); tv_user_qianming = (TextView) findViewById(R.id.tv_user_qianming); tv_user_nianling = (TextView) findViewById(R.id.tv_user_nianling); // ?? UserPic = PreferenceUtils.getInstance(this).getSettingUserLogo(); UserNickName = PreferenceUtils.getInstance(this).getSettingUserNick(); UserSex = PreferenceUtils.getInstance(this).getSettingUserSex(); UserAdd = PreferenceUtils.getInstance(this).getSettingUserCity(); UserAge = PreferenceUtils.getInstance(this).getSettingUserAge() + ""; UserQianming = PreferenceUtils.getInstance(this).getSettingUserQianming(); // tv_user_chengshi.setText(PreferenceUtils.getInstance(SettingUserActivity.this).getSettingUserCity()); // ? // iv_user_photo ImageUtils.LoadThumbImage(iv_user_photo, UserPic); tv_user_nicheng.setText(UserNickName); if (UserSex == 1) { tv_user_xingbie.setText(""); } else { tv_user_xingbie.setText(""); } tv_user_nianling.setText(UserAge); tv_user_chengshi.setText(UserAdd); tv_user_qianming.setText(UserQianming); /*************** ? **************/ /********** ***********/ rl_user_pic.setOnClickListener(this); rl_user_nicheng.setOnClickListener(this); rl_user_xingbie.setOnClickListener(this); rl_user_chengshi.setOnClickListener(this); rl_user_qianming.setOnClickListener(this); tv_user_nianling.setOnClickListener(this); /*********** **********/ /************************* http? ***********************/ responseHandler = new TextHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { // TODO Auto-generated method stub isRefresh = true; dialog.dismiss(); if (CommonUtils.isNullOrEmpty(responseString)) { Toast.makeText(SettingUserActivity.this, "?,?", 0).show(); return; } Map<String, Object> lm = JsonToMapList.getMap(responseString); if (lm != null && lm.get("ok").toString() != null && lm.get("ok").toString().equals("1")) { Toast.makeText(SettingUserActivity.this, "?", Toast.LENGTH_SHORT).show(); Log.d("message==" + lm.get("data").toString()); if (!CommonUtils.isNullOrEmpty(lm.get("data").toString())) { userInfo = lm.get("data").toString(); Map<String, Object> lmres = JsonToMapList.getMap(userInfo); String nickname = lmres.get("user_nick").toString(); int age = Integer.valueOf(lmres.get("user_age").toString()); String sex = lmres.get("user_sex").toString(); String logo = lmres.get("user_logo").toString(); String add_code = lmres.get("user_add_code").toString(); String add_name = lmres.get("user_add_name").toString(); // String qianming = lmres.get("qianming").toString(); if (!CommonUtils.isNullOrEmpty(nickname)) { tv_user_nicheng.setText(nickname); PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserNick(nickname); } if (!CommonUtils.isNullOrEmpty(sex)) { int se = Integer.valueOf(sex); if (se == 1) { tv_user_xingbie.setText(""); } else { tv_user_xingbie.setText(""); } PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserSex(se); } else if (!CommonUtils.isNullOrEmpty(logo)) { // tv_user_xingbie.setText(sex); // ? ImageUtils.LoadThumbImage(iv_user_photo, logo); // ImageLoader.getInstance().displayImage(headurl, // iv_user_photo); // ImageLoader.getInstance().notify(); PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserLogo(logo); // PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserLogo(logo); } else if (!CommonUtils.isNullOrEmpty(add_code)) {// ? // int se = Integer.valueOf(add_code); tv_user_chengshi.setText(add_name); PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserCity(add_name); PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserCityCode(add_code); } else if (!CommonUtils.isNullOrEmpty(age)) { tv_user_nianling.setText(age + ""); PreferenceUtils.getInstance(SettingUserActivity.this).setSettingUserAge(age); } } } } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { // TODO Auto-generated method stub dialog.dismiss(); } }; address_view = new MyAddressView(this); address_view.setOnAddressCheckListener(new OnAddressCheckListener() { @Override public void onCheck(int add_code, String add_name) { // TODO Auto-generated method stub // addcode = add_code; // addname = add_name; tv_user_chengshi.setText(add_name); RequestParams params = new RequestParams(); params.put("add_code", add_code); params.put("add_name", add_name); params.put("type", "add_code"); HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler); dialog.show(); } }); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.rl_user_pic: // startActivity(new Intent(this, // BlacklistActivity.class)); // ? change_logo(); break; case R.id.rl_user_nicheng: // startActivity(new Intent(this, // BlacklistActivity.class)); // change_nickname("" + tv_user_nicheng.getText().toString().trim()); break; case R.id.rl_user_xingbie: // // change_sex(); break; case R.id.rl_user_nianling: // change_age("" + tv_user_nianling.getText().toString().trim()); case R.id.rl_user_chengshi: // change_add_do(); break; case R.id.rl_user_zhiye: // ? // change_zhiye(); break; case R.id.rl_user_qianming: // ?? Intent it = new Intent(SettingUserActivity.this, EditPasswordActivity.class); startActivityForResult(it, MainActivity.MAIN_MESSAGE_LOGIN_OUT); break; default: break; } } // /** // * ?? // */ // private void change_qianming(String qianming) { // // TODO Auto-generated method stub // final EditText texta = new EditText(this); // texta.setText(qianming); // new AlertDialog.Builder(this).setTitle("??").setIcon(android.R.drawable.ic_dialog_info).setView(texta).setPositiveButton("", new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialogg, int which) { // String nickname = texta.getEditableText().toString(); // RequestParams params = new RequestParams(); // // params.add("user", MyApplication.getInstance().getUser()); // params.add("qianming", nickname); // params.add("param", "qianming"); // params.add("uid", uid); // // HttpRestClient.get(Constant.UPDATE_USER_URL, params, // // responseHandler); // dialog.show(); // dialogg.dismiss(); // // ? // } // }).setNegativeButton("?", null).show(); // } /** * */ public void change_age(String age) { final EditText texta = new EditText(this); texta.setText(age); // EditText texta.setKeyListener(new NumberKeyListener() { public int getInputType() { return InputType.TYPE_CLASS_PHONE; } @Override protected char[] getAcceptedChars() { // TODO Auto-generated method stub char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; return numbers; } }); new AlertDialog.Builder(this).setTitle("").setIcon(android.R.drawable.ic_dialog_info) .setView(texta).setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogg, int which) { String age = texta.getEditableText().toString(); RequestParams params = new RequestParams(); params.add("age", age); params.add("type", "age"); HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler); dialog.show(); dialogg.dismiss(); // ? } }).setNegativeButton("?", null).show(); // return true; } /** * */ public void change_nickname(String nickname) { final EditText texta = new EditText(this); texta.setText(nickname); new AlertDialog.Builder(this).setTitle("").setIcon(android.R.drawable.ic_dialog_info) .setView(texta).setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogg, int which) { String nickname = texta.getEditableText().toString(); RequestParams params = new RequestParams(); params.add("nick", nickname); params.add("type", "nick"); HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler); dialog.show(); dialogg.dismiss(); // ? } }).setNegativeButton("?", null).show(); // return true; } /** * ? */ public void change_add_do() { address_view.show(); } /** * */ public void change_sex() { new ActionSheetDialog(this).builder().setCancelable(true).setCanceledOnTouchOutside(true) .addSheetItem("", SheetItemColor.Blue, new OnSheetItemClickListener() { @Override public void onClick(int which) { change_sex_do(1); } }).addSheetItem("", SheetItemColor.Blue, new OnSheetItemClickListener() { @Override public void onClick(int which) { change_sex_do(2); } }).show(); } public void change_sex_do(int sex) { RequestParams params = new RequestParams(); params.put("sex", sex); params.put("type", "sex"); HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler); dialog.show(); } /** * ? */ public void change_logo() { /* * //SDcard if(Environment.getExternalStorageState().equals(Environment .MEDIA_MOUNTED)){ //SDcardTestSyncListView IMAGE_FILE_LOCATION = Environment.getExternalStorageDirectory()+Constant .CACHE_DIR_IMAGE+"/temp.jpg"; imageUri = Uri.parse(IMAGE_FILE_LOCATION); //File cutFile = new File(Constant.CACHE_DIR_IMAGE,"temp.jpg"); //cutFile.getParentFile().mkdirs(); File dir = new File(IMAGE_FILE_LOCATION); if (!dir.exists()) { try { // dir.createNewFile(); } catch (Exception e) { //println(e); } } * * }else{ Toast.makeText(this, "SD????", 0).show(); return; } */ /* -? */ if (!CommonUtils.isExitsSdcard()) { Toast.makeText(this, "SD????", 0).show(); return; } cameraFile = new File(StorageUtils.getOwnCacheDirectory(this, Constant.CACHE_DIR_IMAGE), System.currentTimeMillis() + ".jpg"); if (cameraFile == null && !cameraFile.exists()) {// ? cameraFile.getParentFile().mkdirs(); } new ActionSheetDialog(this).builder().setCancelable(true).setCanceledOnTouchOutside(true) .addSheetItem("??", SheetItemColor.Blue, new OnSheetItemClickListener() { @Override public void onClick(int which) { selectPicFromCamera(); } }).addSheetItem("?", SheetItemColor.Blue, new OnSheetItemClickListener() { @Override public void onClick(int which) { selectPicFromLocal(); } }).show(); } /** * ? */ public void selectPicFromLocal() { Intent intent; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); // Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); /* * intent.setType("image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", 600); intent.putExtra("outputY", 600); intent.putExtra("scale", true); intent.putExtra("return-data", false); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUritest); intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); intent.putExtra("noFaceDetection", true); // no face detection */ // startActivityForResult(intent, CHOOSE_BIG_PICTURE); } else { intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); // startActivityForResult(intent, USERPIC_REQUEST_CODE_LOCAL_19); } startActivityForResult(intent, USERPIC_REQUEST_CODE_LOCAL); } /** * ? */ public void selectPicFromCamera() { // cameraFile = new File(PathUtil.getInstance().getImagePath(), // DemoApplication.getInstance().getUserName() startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)), USERPIC_REQUEST_CODE_CAMERA); } /** * onActivityResult */ public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == USERPIC_REQUEST_CODE_CAMERA) { // ? if (cameraFile != null && cameraFile.exists()) { Log.d("cameraFile" + cameraFile.getAbsolutePath()); // ?uri imageUri = Uri.fromFile(cameraFile); cropImageUri(Uri.fromFile(cameraFile), 300, 300, USERPIC_REQUEST_CODE_CUT); } } else if (requestCode == USERPIC_REQUEST_CODE_LOCAL) { // ? if (data != null) { Uri selectedImage = data.getData(); if (selectedImage != null) { cropImageUri(selectedImage, 300, 300, USERPIC_REQUEST_CODE_CUT); // Log.d("log","selectedImage"+selectedImage); } } } else if (requestCode == USERPIC_REQUEST_CODE_CUT) {// ? // ? if (data != null) { Bitmap bitmap = data.getParcelableExtra("data"); iv_user_photo.setImageBitmap(bitmap); File file = saveJPGE_After(bitmap, cameraFile); // ???? RequestParams params = new RequestParams(); if (file.exists()) { try { dialog.show(); params.put("logo", file, "image/jpeg"); // params.put("user", // MyApplication.getInstance().getUser()); params.put("type", "logo"); // params.add("uid", uid); HttpRestClient.post(Constant.UPDATE_USER_INFO_DO, params, responseHandler); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Toast toast = Toast.makeText(this, "?SD??", Toast.LENGTH_SHORT); } } else { // Log.e(TAG, "CHOOSE_SMALL_PICTURE: data = " + data); } } else if (resultCode == MainActivity.MAIN_MESSAGE_LOGIN_OUT) { setResult(resultCode); finish(); } } // uri bitmap private Bitmap decodeUriAsBitmap(Uri uri) { Bitmap bitmap = null; try { bitmap = BitmapFactory.decodeStream(this.getContentResolver().openInputStream(uri)); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return bitmap; } /** * ?uri?? * * @param selectedImage */ private File Uritofile(Uri selectedImage) { File file = null; Cursor cursor = this.getContentResolver().query(selectedImage, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex("_data"); String picturePath = cursor.getString(columnIndex); cursor.close(); cursor = null; if (picturePath == null || picturePath.equals("null")) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return null; } file = new File(picturePath); // sendPicture(picturePath); } else { file = new File(selectedImage.getPath()); if (!file.exists()) { Toast toast = Toast.makeText(this, "?", Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); return null; } } return file; } /** * ? * * @param uri * @param outputX * @param outputY * @param requestCode */ private void cropImageUri(Uri uri, int outputX, int outputY, int requestCode) { /* * Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); //aspectX aspectY intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); // outputX outputY ? intent.putExtra("outputX", outputX); intent.putExtra("outputY", outputY); intent.putExtra("scale", true); intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); intent.putExtra("return-data", false); intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); intent.putExtra("noFaceDetection", true); // no face detection startActivityForResult(intent, requestCode); */ Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", outputX); intent.putExtra("outputY", outputY); intent.putExtra("scale", true); intent.putExtra("return-data", true); intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); intent.putExtra("noFaceDetection", true); // no face detection startActivityForResult(intent, requestCode); } /** * ?Bitmap * * @param baseBitmap */ public void save(Bitmap baseBitmap) { try { /* * BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(cutFile)); baseBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); bos.flush(); bos.close(); */ OutputStream stream = new FileOutputStream(Uritofile(imageUri)); baseBitmap.compress(CompressFormat.JPEG, 100, stream); stream.close(); /* * // sdcard Intent intent = new Intent(); intent.setAction(Intent.ACTION_MEDIA_MOUNTED); intent.setData(Uri.fromFile(Environment .getExternalStorageDirectory())); sendBroadcast(intent); */ Toast.makeText(this, "??", 0).show(); } catch (Exception e) { Toast.makeText(this, "?", 0).show(); e.printStackTrace(); } } /** * bitmap file ?JPEG * * @param bitmap * @param cameraFile2 */ public File saveJPGE_After(Bitmap bitmap, File cameraFile2) { // File file = new File(cameraFile2); try { FileOutputStream out = new FileOutputStream(cameraFile2); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) { out.flush(); out.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return cameraFile2; } /** * ?? * * @param oldPath * String c:/fqf.txt * @param newPath * String ?? f:/fqf.txt * @return boolean */ public void copyFile(String oldPath, String newPath) { try { int bytesum = 0; int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { // InputStream inStream = new FileInputStream(oldPath); // FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[1444]; int length; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; // ? // Log.d("log",bytesum); fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { Log.d("???"); e.printStackTrace(); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { // ? if (isRefresh) { Intent it = new Intent(); it.putExtra("info", userInfo); setResult(888, it); finish(); } } return super.onKeyDown(keyCode, event); } }