기본 콘텐츠로 건너뛰기

4월, 2015의 게시물 표시

Android, scale drawable Image with ImageView

//> set height after ImageView draw. ViewTreeObserver vto = campaignImageView.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { public boolean onPreDraw() { campaignImageView.getViewTreeObserver().removeOnPreDrawListener(this); float height = drw.getIntrinsicHeight(); float width = drw.getIntrinsicWidth(); float ratio = height / width; int imageViewHeight = (int) ( campaignImageView.getMeasuredWidth() * ratio); LayoutParams lp = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); lp.height = imageViewHeight; campaignImageView.setLayoutParams(lp); return true; } }); http://stackoverflow.com/questions/4680499/how-to-get-the-width-and-height-of-an-android-widget-imageview

Android, JSON

**Json : (jsonStr) { "a":"textA", "array":[{"array1":"1","array2":"2"}] } **Code: JSONObject jsonObj = new JSONObject(jsonStr); JSONArray array = jsonObj.getJSONArray("array"); JSONObject obj = array.getJSONObject(0); String array1 = obj.getString("array1"); **************************************************************************** **Json : {   aa: "1111"} **Code: JSONObject jsonObj = new JSONObject(json); String aa = jsonObj.getString("aa"); //aa = "1111" **************************************************************************** Json String -> JsonObject JsonParser jsonParser = new JsonParser(); JsonObject jo = (JsonObject)jsonParser.parse(json);

Android, BasicNameValuePair

ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add( new BasicNameValuePair( "aname" , "avalue" )); params.add( new  BasicNameValuePair( "bname" ,  "bvalue" )); API ref :  http://developer.android.com/reference/org/apache/http/message/BasicNameValuePair.html

Android, Date

//******************************** // String date to Date //******************************** Date date = null ; SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); try {     date = formatter.parse(strDate); } catch (ParseException e) {     e.printStackTrace(); } http://javaworkspace.tistory.com/entry/JavaTip-%EB%82%A0%EC%A7%9C-%EB%8B%A4%EB%A3%A8%EA%B8%B0

sqlite, blob

//****************** // uri image -> byte[] //****************** InputStream is = (InputStream) new URL(url).getContent(); Bitmap bmp = BitmapFactory.decodeStream(is); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat. PNG , 100, stream); byte[] byteArray = stream.toByteArray(); //****************** // Bitmap -> byte array //****************** Bitmap bmp = intent .getExtras().get( "data" ); ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat. PNG , 100, stream); byte [] byteArray = stream.toByteArray(); //****************** // Select //****************** Cursor cs = ... ... byte [] image = cs.getBlob(cs.getColumnIndex("blob_attr")); Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image. length ); -bitmap -> byte array http://stackoverflow.com/questions/4989182/converting-java-bitmap-to-byte...

Android, EditText

***** setInputType not working editPass.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); -> editPass . setInputType ( InputType . TYPE_CLASS_TEXT | InputType . TYPE_TEXT_VARIATION_PASSWORD ) http://stackoverflow.com/questions/2586301/set-inputtype-for-an-edittext ***** select all when select EditText editText ?.setSelectAllOnFocus( true )