본문 바로가기

728x90
반응형

Android/Function

(29)
[안드로이드 Kotlin] 카운트 다운 타이머(CountdownTimer) 간단 사용하기 5초 카운트 다운 후 버튼 실행을 해보겠습니다. private val mCountDown: CountDownTimer = object : CountDownTimer(5250, 500) { override fun onTick(millisUntilFinished: Long) { //update the UI with the new count counterText.set("${(millisUntilFinished.toFloat() / 1000.0f).roundToInt()}초 뒤에 자동으로 시작 됩니다..") } override fun onFinish() { //countdown finish onClickStart() } } 500ms interval 마다 ui를 업데이트하고, 5250ms(5.25s) 부터 카..
ScrollView 안에 있는 자식 뷰에서 독단적으로 scroll 해야 할 때 gps, chart, 3d 모션등이 ScrollView 안에 있는 경우 독자적인 수평, 수직 스크롤을 수행하지 못하고 스크롤이 넘어가는 경우가 있습니다. 그럴 경우 스크롤 사용하고자 하는 Child View에서 TouchListener를 달아 아래같이 해결하는 법이 있습니다. surface_view: child view, scrollView: ScrollView surface_view.setOnTouchListener { view, motionEvent -> scrollView.requestDisallowInterceptTouchEvent(true) false }
[안드로이드] 권한 확인/허가 요청 코드 + 블루투스 확인/요청 Permission 확인 companion object{ // used to identify adding bluetooth names const val REQUEST_ENABLE_BT = 1 // used to request fine location permission const val REQUEST_ALL_PERMISSION = 2 val PERMISSIONS = arrayOf( Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION ) } PERMISSIONS array안에 요청할 권한을 넣어줍니다. // check if location permission if (!hasPermissions(this, P..
[안드로이드] 외부저장소(SAF) ↔ 내부저장소 파일 옮기기/복사하기 SAF(Scoped Access Framework)를 이용한 파일 쓰기를 대비해야하는데요 ^^ 내부저장소에 저장된 파일을 SAF를 이용하여 외부저장소에 복사, 혹은 그 반대의 예제 입니다. SAF 파일 쓰기는 밑의 포스트를 참조해 주세요. [Android/Function] - [안드로이드] 외부 저장소에 데이터 파일 저장하기(쓰기) ― SAF(Storage Access Framework)로 파일 쓰기 내부저장소 → 외부저장소(SAF) SAF 열기 /** * Export */ private val REQUEST_WRITE = 43 fun onClickCopy(view: View){ saf() } fun saf() { try { /** * SAF 파일 편집 */ val fileName = //... 파일명 ..
[안드로이드] 특정 확장자의 파일 목록 불러와서 최신순, 이름순 정렬 하기 //내부저장소 경로 private val mOutputDir = MyApplication.applicationContext().getExternalFilesDir(null) companion object{ const val COMPARETYPE_NAME = 0 const val COMPARETYPE_DATE = 1 } fun getFiles(): ArrayList? { //.zip 확장자 파일목록 불러오기 var fileArray = mOutputDir?.listFiles { pathname -> pathname.name.endsWith(".zip") } //최신순으로 정렬 fileArray = fileArray?.let { sortFileList(it,COMPARETYPE_DATE) } //ArrayL..
[Kotlin] 검색 필터링과 아이템 클릭 가능한 RecyclerView 만들기 예제 소개 특정 파일의 이름을 RecylcerView에 띄우기 EditText를 통해 문자를 입력시 필터 특정 RecyclerView Item 클릭 (Item Click Listener) 문자열 입력시 필터 가능한 RecyclerView 만들기 FileListAdapter.kt class FileListAdapter internal constructor(val context: Context, val fileList: ArrayList?) : RecyclerView.Adapter(), Filterable { //필터링을 위해 필요한 변수 private var files: ArrayList? = fileList inner class FileViewHolder(itemView: View) : RecyclerV..
[안드로이드] 앱 내에서 파일 압축하기, zip 파일 만들기 Manifest permisiion 추가 ZipManager Class public class ZipManager { private static final int BUFFER = 80000; private static final int BUFFER_SIZE = 1024 * 2; private static final int COMPRESSION_LEVEL = 8; /** * 파일 압축 * @param _files : 압축할 파일 이름 경로 리스트 * @param zipFileName : 저장될 경로의 파일 이름 */ public void zip(String[] _files, String zipFileName) { try { BufferedInputStream origin = null; FileOutputS..
[Android Test] Espresso 로 View의 Visibility 설정 하기 종속성 추가 dependencies { ... // test dependency testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test:core:1.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementatio..

728x90
반응형