기본 콘텐츠로 건너뛰기

2017의 게시물 표시

Android, OCR Library, Image -> Text

- language data file download https://github.com/tesseract-ocr/tessdata - Gradle dependencies { ... compile 'com.rmtheis:tess-two:5.4.1' } - Permission < uses-permission android :name= "android.permission.WRITE_EXTERNAL_STORAGE" /> < uses-permission android :name= "android.permission.READ_EXTERNAL_STORAGE" /> - language data file 1. set langage data file in assets 2. copy language data file to external storage (in code) (must under subfolder  tessdata ) val tdataPath = File( dataFolder . absoluteFile .toString() + "/eng.traineddata" ) val input = assets .open( "eng.traineddata" ); val output = FileOutputStream(tdataPath) try { input. copyTo (output) } catch (e : Exception){} - module init mTess. init(datafolder, "eng") datafolder : set folder path exist tessdata folder ref : https://qiita.com/Nunocky/items/35770ffc719d55ba0078

Kotlin, Hello

New > New Project (include Kotlin Support : check) Android > Preferences > plugins > Kotlin > install Code > Convert Java File to Kotlin File Tools > Kotlin > Configure Kotlin in Project class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super .onCreate(savedInstanceState) setContentView(R.layout. activity_main ) val v = getVal() println ( "Hello World" ) println ( "v = $ v " ) val textView = findViewById<TextView>(R.id. textview ) textView. text =v } private fun getVal():String{ return "Hello Kotlin!"   } }

android, permission, in code

Activity act = ... if (act.checkSelfPermission(Manifest.permission. WRITE_EXTERNAL_STORAGE ) == PackageManager. PERMISSION_GRANTED ) { Toast. makeText (getContext(), "Permission is granted" , Toast. LENGTH_LONG ).show(); } else { Toast. makeText (getContext(), "Permission is not granted" , Toast. LENGTH_LONG ).show(); ActivityCompat. requestPermissions (act, new String[]{Manifest.permission. WRITE_EXTERNAL_STORAGE }, 1 ); } ref : https://toepic.fail/안드로이드-마쉬멜로우-버전-이상에서-권한처리하기-95527b99aafb

Android, no satus bar

Activity act = ... if (Build.VERSION. SDK_INT < 16 ) { act.getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , WindowManager.LayoutParams. FLAG_FULLSCREEN ); } else { View decorView = act.getWindow().getDecorView(); int uiOptions = View. SYSTEM_UI_FLAG_FULLSCREEN ; decorView.setSystemUiVisibility(uiOptions); // ActionBar actionBar = act.getActionBar(); // actionBar.hide(); } ref : https://stackoverflow.com/questions/5431365/how-to-hide-status-bar-in-android

HttpURLConnection

HttpURLConnection connection = null ; URL url = null; ... connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod( "POST" ); // connection.setRequestProperty( "Accept-Encoding" , "identity" ); connection.setConnectTimeout( 5000 ); connection.connect(); InputStream is = connection.getInputStream(); //connection.getContentLength(); // need setRequestProperty( "Accept-Encoding" , "identity" );

gradle, custom build apk file name

build.gradle applicationVariants.all { variant -> variant.outputs.each { output -> def apkName = "" def formattedDate = new Date().format( 'MMdd' ) def revisionHash = [ "sh" , "-c" , "cd ${project.rootDir} ; git rev-parse --short=10 HEAD" ].execute().in.text.trim() def lastName = variant.versionName + "_" + formattedDate + "_" +revisionHash+ ".apk" if (variant.buildType.name == "release" ) { apkName = "Appname_" + lastName } else { apkName = "Appname_dev" + lastName } output.outputFile = new File(output.outputFile.parent, apkName) } }

Android, WebView, JavaScript, get click event coordinate

<html> <head> <script> function show(event){   var str = event.pageX + ' x '+event.pageY;   alert(str); } </script> </head> <body> <img src="..." onClick="show(event)"> </body> </html> // alert enable webView.getSettings().setJavaScriptEnabled( true ); webView.setWebChromeClient( new WebChromeClient(){ @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { // TODO : result.cancel(); return true ; // return super.onJsAlert(view, url, message, result); } });

Android, SoundPool, play wav

SoundPool sPool = new SoundPool( 1 , AudioManager. STREAM_MUSIC , 0 ); final int intRaw = sPool .load( this , R.raw. sample1 , 1 ); Button btn = (Button)findViewById(R.id. button1 ); btn.setSoundEffectsEnabled( false ); btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { sPool .play( intRaw , 1 , 1 , 0 , 0 , 1 ); } }

iOS, Toast

NSString * message = @ "Some message..." ; UIAlertView * toast = [[ UIAlertView alloc ] initWithTitle : nil message : message delegate : nil cancelButtonTitle : nil otherButtonTitles : nil , nil ]; [ toast show ]; int duration = 1 ; // duration in seconds dispatch_after ( dispatch_time ( DISPATCH_TIME_NOW , duration * NSEC_PER_SEC ), dispatch_get_main_queue (), ^{ [ toast dismissWithClickedButtonIndex : 0 animated : YES ]; }); ref :  http://stackoverflow.com/questions/18680891/displaying-a-message-in-ios-which-has-the-same-functionality-as-toast-in-android