기본 콘텐츠로 건너뛰기

2015의 게시물 표시

Android, Nifty Push

**** Google Develop Console  Make Project  API > Cloud Messaging for Android -> 有効 認証情報 > API Key > ServerKey(*1) 作成 ホーム : Project No (*2) **** Nifty  アプリ設定 > Push 通知 > API Key : *1を入力 基本 > API Key : Application Key(*3), Client Key (*4) **** 端末 initializeの時、*3, *4を使う。 registerの時、*2を使う

Android, thread once last one

String lastKey = null ; ... public void method1(){ lastKey = Calendar. getInstance ().getTimeInMillis()+ "" ; final String key = lastKey ; final Handler handler = new Handler(); handler.postDelayed( new Runnable() { @Override public void run() { if ( key .equals( shutdownKey )){ // doSomething } } }, 1000 ); }

Anroid, get Server Data, Connection, HttpClient depracated

HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout( 15000 ); conn.setConnectTimeout( 15000 ); conn.setRequestMethod( "POST" ); conn.setDoInput( true ); conn.setDoOutput( true ); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(os, "UTF-8" )); String paramStr = null ; {// need BasicNameValuePair -> ContentsValue for (BasicNameValuePair record : params ){ if (paramStr == null ){ paramStr = "" ; } else { paramStr = paramStr + "&" ; } paramStr = paramStr + record.getName()+ "=" +record.getValue(); } } writer.write(paramStr); writer.flush(); writer.close(); os.close(); int responseCode=conn.getResponseCode(); if (responseCode == HttpsURLConnection. HTTP_OK ) { String line; BufferedReader br=

Android, doen't work FLAG_ACTIVITY_NO_ANIMATION with FLAG_ACTIVITY_REORDER_TO_FRONT

intent.setFlags(Intent. FLAG_ACTIVITY_REORDER_TO_FRONT ); intent.addFlags(Intent. FLAG_ACTIVITY_NO_ANIMATION ); -> does not work  FLAG_ACTIVITY_NO_ANIMATION @Override protected void onNewIntent(Intent intent) { super .onNewIntent(intent); if (intent.getFlags() == (Intent. FLAG_ACTIVITY_NO_ANIMATION | Intent. FLAG_ACTIVITY_REORDER_TO_FRONT )){ overridePendingTransition( 0 , 0 ); } }

Android, Properties, data to file simple src

public static void saveProperty(String key, String value){ Properties properties = new Properties(); String file = ... try { if ( new File(file).exists()){ properties.load( new FileInputStream(file)); } properties.put(key, value); properties.store( new FileOutputStream(file), null ); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static String loadProperty(String key){ Properties properties = new Properties(); String file = ... try { properties.load( new FileInputStream(file)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return (String)properties.get(key); }

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 )

objc, draw simple line on UIView

- ( void )drawRect:( CGRect )rect {     // Drawing code     CGContextRef context = UIGraphicsGetCurrentContext();  // コンテキストを取得       // 線を黒色にする     CGContextSetStrokeColorWithColor(context,UIColor.blackColor.CGColor);       // 線の太さを指定     CGContextSetLineWidth(context, 10.0);  // 10ptに設定       CGContextMoveToPoint(context, 50, 100);  // 始点     CGContextAddLineToPoint(context, 100, 200);     CGContextAddLineToPoint(context, 200, 200);     CGContextAddLineToPoint(context, 300, 200); // 終点     CGContextStrokePath(context);  // 描画 } //refresh     [ self setNeedsDisplay ]; ref http://d.hatena.ne.jp/kazukingband/20120713/1342176398

c, get distance between a point and a line (two points)

float calcDistance( float x1, float y1, float x2, float y2, float x3, float y3) {      float px = x2-x1;     float py = y2-y1;          float something = px*px + py*py;          float u =  ((x3 - x1) * px + (y3 - y1) * py) / something;          if (u > 1 ){         u = 1 ;     } else if (u < 0 )     {         u = 0 ;     }      float x = x1 + u * px;     float y = y1 + u * py;          float dx = x - x3;     float dy = y - y3;               float dist = sqrt (dx*dx + dy*dy);              return dist; } http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment

Android, MediaPlayer, SurfaceView

public class MainActivity extends ActionBarActivity {     MediaPlayer _videoPlayer;     private SurfaceHolder holder;     private SurfaceView mPreview;     final String url = "http://xxxx/xxx/index.m3u8";     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);         _videoPlayer = new MediaPlayer();         _videoPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {             @Override             public void onPrepared(MediaPlayer mp) {                 _videoPlayer.start();             }         });         mPreview = (SurfaceView)findViewById(R.id.surfaceView);         holder = mPreview.getHolder();         holder.addCallback(new SurfaceHolder.Callback(){             @Override             public void surfaceCreated(SurfaceHolder holder) {                 _videoPlayer.setDisplay(holder);             }             @Overrid

Git, commit, memo

----- cancel add add ./a.txt reset ./a.txt ----- edit lastest commit msg. git commit --amend ----- commit squash git rebase -i HEAD^2 http://git-scm.com/book/ko/v1/Git-%EB%8F%84%EA%B5%AC-%ED%9E%88%EC%8A%A4%ED%86%A0%EB%A6%AC-%EB%8B%A8%EC%9E%A5%ED%95%98%EA%B8%B0

Android, InAppBilling, memo

v3... -Service bind : onCreate - v3 support check - detail info : getSkuDetails -- parameters --- p0 : 3 (version = v3) --- p1 : context.getPackageName() --- p2 : "inapp" --- p3 : Bundle skuList : ArrayList<String> (productId list) - buy : Bundle getBuyIntent -- bundle.getInt("RESPONSE_CODE") -> Billing response codes (ex. 7 = alreay owned) -Service unbind : onDestroy http://developer.android.com/google/play/billing/api.html https://gist.github.com/first087/9088162 https://www.gaffga.de/implementing-in-app-billing-for-android/ http://android-developers.blogspot.jp/2012/12/in-app-billing-version-3.html http://y-anz-m.blogspot.jp/2013/02/android-api-version3.html

Android, app install check

// app install check private boolean appInstalledOrNot(String uri) { PackageManager pm = _context .getPackageManager(); boolean app_installed = false ; try { pm.getPackageInfo(uri, PackageManager. GET_ACTIVITIES ); app_installed = true ; } catch (PackageManager.NameNotFoundException e) { app_installed = false ; } return app_installed ; } http://stackoverflow.com/questions/11392183/how-to-check-programmatically-if-an-application-is-installed-or-not-in-android

Android, set LayoutParams programmatically

////- get LayoutParams and set Layout. Button btn = new Button(this); LayoutParams params = (LayoutParams)ib.getLayoutParams(); params. gravity = Gravity. CENTER_VERTICAL ; ////- make LayoutParams and set Layout.  LayoutParams lp = new LayoutParams(                 LayoutParams. MATCH_PARENT ,                 LayoutParams. MATCH_PARENT ); image .setLayoutParams(lp);