본문 바로가기

728x90
반응형
SMALL

Android

(80)
ScrollView 안에 있는 자식 뷰에서 독단적으로 scroll 해야 할 때 gps, chart, 3d 모션등이 ScrollView 안에 있는 경우 독자적인 수평, 수직 스크롤을 수행하지 못하고 스크롤이 넘어가는 경우가 있습니다. 그럴 경우 스크롤 사용하고자 하는 Child View에서 TouchListener를 달아 아래같이 해결하는 법이 있습니다. surface_view: child view, scrollView: ScrollView surface_view.setOnTouchListener { view, motionEvent -> scrollView.requestDisallowInterceptTouchEvent(true) false }
[안드로이드 Kotlin] BLE(Bluetooth Low Energy) 통신 예제 전체적으로 BLE 기능 구현을 심플하게 작성하였습니다. UI 업데이트 부분은, 데이터 바인딩을 사용하였습니다. BLE 기능구현 위주로 봐주세요. Permission BLE사용을 위해 위 세개의 퍼미션을 AndroidManifest에 추가해줍니다. Ble 지원 확인 override fun onResume() { super.onResume() // finish app if the BLE is not supported if (!packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) { finish() } } ble를 지원하지 않으면 어플이 종료되도록 합니다. Constants.kt class Constants{ companion object..
[안드로이드] 권한 확인/허가 요청 코드 + 블루투스 확인/요청 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..
ViewModel과 View(Activity, Fragment)간의 이벤트 처리― Event Wrapper 사용하기 ViewModel에서는 view를 참조할 수 없습니다. (하면 안됩니다.) 그래서 view를 참조하는 메서드는 Activity, Fragment 내에서 구현되게 되는데요. ViewModel안에서 그 메서드들이 필요할 때, 또는 ViewModel에서 View에 이벤트를 보내주어야할 때! LiveData를 이용해서 ViewModel의 변수 값을 변화시키고, 그 변수를 view에서 observer하는 방식으로 이벤트를 처리할 수 있습니다. 이것이 아주 간편한 방식이죠. 예를 들어, 텍스트를 입력하다 버튼 클릭 시 키보드를 숨겨야 하는 Fragment의 메서드 hideKeyboard() 메서드를 실행해야 합니다. ViewModel에서 hideKeyboard 변수를 라이브데이터로 만들어주고, Fragment에서 ..

728x90
반응형
LIST