First, the business scene
1, chat interface to send pictures ==> multiple selection + have the top right corner "send" + picture preview ==> Picture Preview support the top right corner "send" logic
2, published dynamic ==> multiple selection + top right Corner "complete" + Picture preview ==> Picture Preview support the top right corner "complete" logic
3, Personal data change Avatar ==> single point selection + Picture preview screenshot ==> picture preview screenshot Support "use" logic in upper right corner
second, the intent parameter design; (Intent principle: Try not to use custom type-specific parameters)
1, the most basic parameter transfer (the maximum number of optional pictures, the title in the top right corner, the radio mode or the multiple selection mode, return the results of the parameters)
/** maximum picture selection times, int type, default 9 *
/public static final String Extra_select_count = "Max_select_count";
/** send button title such as Complete or send * * public
static final String extra_submit_title = "Extra_submit_title";
/** picture selection mode, the default multiple select
/public static final String Extra_select_mode = "Select_count_mode";
/** Select result, return to arraylist<string> picture path set
/public static final String Extra_result = "Select_result";
2, extended part of the parameter transfer (Picture selection interface of the first item whether to display the camera function, the activity of the preview supports the "Check Cancel" check button)
/** whether the camera is displayed, the default display *
/public static final String Extra_show_camera = "Show_camera";
/** whether to jump to imagedetailcheckpicsact
/public static final String extra_jumptocheckpics = "Is_jumpto_checkpics";
3, in the "Publish Dynamic Selection" has selected 5 pictures, and then to choose Pictures-image browser needs to select the selected picture Check status set to tick
/** default has been selected Set *
/public static final String extra_default_selected_list = "Default_list";
4, screenshot function (in the single selection mode, if the start screenshot mode, then jump screenshot after selection interface)
/** whether the original image return or first jump screenshot after return * * public
static final String resizebit = "Resizebit";
/** screenshot Save Path * * Public
static final String result = "Resultpath";
/** whether the screenshot/public
static final String Mode_scale_boolean = "Mode_scale_boolean";
/** Single screenshot area blue box width, unit DP/public
static final String Scalew = "Scalew";
/** Single screenshot area blue box high, unit DP/public
static final String Scaleh = "Scaleh";
/** the image saved pixel width after the single screenshot, the unit SP/public
static final String LIMITW = "Limitwidth";
/** the image saved after a single screenshot of the high pixel, the unit SP/public
static final String Limith = "Limithight";
/** the saved path of the screenshot of the radio
/public static final String Mode_scale_path = "Mode_scale_path";
Third, the design after clear requirements
omitted here; shared code implements functionality that has not been designed to optimize the code for poor readability
Code Project GitHub Address Imalbum
Four, code use method
public static void Jumptoselectpics (Activity mcontext, Boolean isshowcamera, int selectmaxcount, int selectmode, S Tring Submitbtnstr, Boolean isjumptocheckpics, arraylist<string> hasselectlist) {Intent Intent = new Intent (mCo
ntext, multiimageselectoractivity.class);
Whether show camera Intent.putextra (Multiimageselectoractivity.extra_show_camera, Isshowcamera);
String of Submit button Intent.putextra (Multiimageselectoractivity.extra_submit_title, SUBMITBTNSTR);
String of Submit button Intent.putextra (Multiimageselectorfragment.extra_jumptocheckpics, isjumptocheckpics);
Max Select Image Amount Intent.putextra (Multiimageselectoractivity.extra_select_count, Selectmaxcount); Select mode (multiimageselectoractivity.mode_single OR multiimageselectoractivity.mode_multi) Intent.putExtra (
Multiimageselectoractivity.extra_select_mode, SelectMode);
Extra_default_selected_list if (hasselectlist!= null) { Intent.putstringarraylistextra (Multiimageselectoractivity.extra_default_selected_list, hasSelectList);
}//Mcontext.startactivityforresult (Intent, request_image); /** * Picture format JPEG * @param picresultpath image to be saved address * @param the width of the Scalew screenshot area DP * @param scaleh the height of the screenshot area Unit DP * @param the width of the graph cropped by the limtwidth * @param the height of the limithight cropped graph * @param isscaleimg is in accordance with Limtwidth, Limithight ratio * @description: * @author Zhangjianlin (990996641) * @date June 11, 2015 afternoon 4:25:00/public static Voi D jumptoselecandcropimg (Activity mcontext, String picresultpath, int scalew, int scaleh, int limtwidth, int limithig
HT, Boolean isscaleimg) {Intent Intent = new Intent (Mcontext, Multiimageselectoractivity.class);
Whether show camera Intent.putextra (Multiimageselectoractivity.extra_show_camera, false);
Max Select Image Amount Intent.putextra (Multiimageselectoractivity.extra_select_count, 1); Select Mode (MulTiimageselectoractivity.mode_single OR Multiimageselectoractivity.mode_multi) Intent.putextra (
Multiimageselectoractivity.extra_select_mode, Multiimageselectoractivity.mode_single);
Intent.putextra (Multiimageselectoractivity.extra_default_crop_camera, isscaleimg);
Intent.putextra (Cropimageact.resizebit, isscaleimg);
Intent.putextra (Cropimageact.result, Picresultpath);
Intent.putextra (Cropimageact.scalew, Scalew);
Intent.putextra (Cropimageact.scaleh, Scaleh);
Intent.putextra (CROPIMAGEACT.LIMITW, limtwidth);
Intent.putextra (Cropimageact.limith, limithight);
Mcontext.startactivityforresult (Intent, request_cropimage);
/** * @Description: Select single picture does not cut * return value ArrayList switch (requestcode) {case Intentutils.request_image: if (data!= null) {arraylist<string> resultlist = data. Getstringarraylistextra (Multiima
Geselectoractivity.extra_result);
} break;
* @param mcontext * * public static void Jumptoselectnocropimg (activity mcontext) {Jumptoselectpics (Mcontext, False, 2, Multiimageselector
Activity.mode_single);
}
V, baseselectactivity class
/** @Override public void onconfigurationchanged (Configuration newconfig) {super.onconfigurationchanged (Newcon
FIG); } <activity android:name= "com.huika.huixin.control.me.activity.PersonalInfoAct" android:launchmode= "Singletask "Android:configchanges=" Orientation|keyboardhidden|screensize > </activity> * @Descriptio N: Select the act * @author zhangjianlin * @date 2015-9-24 PM 2:06:28 * * Public abstract class Baseselectpicact extends Activi
ty {private final int cropcamara_takephoto = 1003;
Private final int cropcamara_selectfromalbum = 1004;
/** from the photo selection * * Private final int activity_result_cropcamara_with_data = 1; Private File Mpicfile;
Select the picture path private String picpath;
@Override public void onconfigurationchanged (Configuration newconfig) {super.onconfigurationchanged (newconfig); @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresu LT (requEstcode, ResultCode, data);
if (ResultCode!= result_ok) {return;}
Switch (requestcode) {case intentutils.request_image://Select Photo/** Add by ZJL */if (null!= data) { arraylist<string> resultlist = data. Getstringarraylistextra (Multiimageselectoractivity.ext
Ra_result);
Hasselectpicsnocrop (resultlist);
/* if (null!= resultlist) {* *} */} break; Case Activity_result_cropcamara_with_data://Photo/* if (mpicfile.exists ()) {* *}/I F (mpicfile = = NULL &&!
Textutils.isempty (picpath)) Mpicfile = new File (Picpath);
if (null!= mpicfile && mpicfile.exists ()) {hastakephotopic (mpicfile);
} break;
Case IntentUtils.REQUEST_CROPIMAGE:if (NULL = = data) {return;} if (Textutils.isempty (mpicfile.tostring ()) | |!mpicfile.exists ()) {Toast.maketext (this, "No pictures selected", Toast.length_long). Show ();
Return String Mpicnativepath = Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/image" + mpicfile.getname
();
try {filecachetool.copyfile (Mpicfile.getabsolutepath (), Mpicnativepath);
catch (Exception e) {e.printstacktrace ();
} haspicscroped (Mpicnativepath);
Break
}
};
protected void Selectphoto () {imagetool.jumptoselectnocropimg (this);
} protected void Selectphotoandcrop () {mpicfile = Imagetools.inittempfile (); /* photointent = Imagetools.cropphotoofcompressfromgalleryintent (Uri.fromfile (mpicfile)); Startactivityforresult (Photointent, constant.activity_result_cropimage_with_data);
* * IMAGETOOL.JUMPTOSELECANDCROPIMG (this, mpicfile.tostring (), (), +, (), (), true); /** Photo/protected void Takephoto () {if (! Imagetools.issdcardexist ()) {Toast.maketext (this, "No memory Card", Toast.length_long). ShoW ();
Return } mpicfile = new File (Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/" + System.currenttimemi
Llis () + ". jpg");
Picpath = Mpicfile.getabsolutepath ();
Intent Intent = new Intent (mediastore.action_image_capture);
Intent.putextra (Mediastore.extra_output, Uri.fromfile (mpicfile));
Startactivityforresult (Intent, activity_result_cropcamara_with_data);
} protected abstract void Hasselectpicsnocrop (arraylist<string> resultlist);
protected abstract void Hastakephotopic (File mpicfile);
protected abstract void haspicscroped (String mpicnativepath);
@Override protected void Onsaveinstancestate (Bundle outstate) {outstate.putstring ("Picpathcache", Picpath);
Super.onsaveinstancestate (outstate); } @Override protected void Onrestoreinstancestate (Bundle savedinstancestate) {Picpath = Savedinstancestate.getst
Ring ("Picpathcache");
Super.onrestoreinstancestate (savedinstancestate);
}
}
VI, gallery Select simple
public class Albumtestact extends Baseselectpicact implements Onclicklistener {private ImageView iv_showresult; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub super.oncreate
(savedinstancestate);
Setcontentview (r.layout.act_albumtest);
Findviewbyid (R.id.tv_takephoto). Setonclicklistener (this);
Findviewbyid (R.id.tv_selectphoto). Setonclicklistener (this);
Findviewbyid (R.id.tv_selectandcrop). Setonclicklistener (this);
Iv_showresult = (ImageView) Findviewbyid (R.id.iv_showresult); @Override public void OnClick (View v) {//TODO auto-generated Method Stub switch (V.getid ()) {case R.
Id.tv_takephoto:takePhoto ();
Break
Case R.id.tv_selectphoto:selectphoto ();
Break
Case R.id.tv_selectandcrop:selectphotoandcrop ();
Break
Default:break; }} @Override protected void Hasselectpicsnocrop (arraylist<string> resultlist){//TODO auto-generated method stub if (null!= resultlist) {if (resultlist.size () > 0) {
Imageloader.getinstance (). DisplayImage (Scheme.FILE.wrap (resultlist.get (0)), Iv_showresult); }} @Override protected void Hastakephotopic (File mpicfile) {//TODO auto-generated method stub if (n ull!= mpicfile && mpicfile.exists ()) {imageloader.getinstance (). DisplayImage (Scheme.FILE.wrap
Etpath ()), iv_showresult); } @Override protected void haspicscroped (String mpicnativepath) {//TODO auto-generated method stub if (n ull!= mpicnativepath && new File (Mpicnativepath). Exists ()) {imageloader.getinstance (). DisplayImage (Schem
E.file.wrap (Mpicnativepath), iv_showresult);
}
}
}
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.