Notice
Recent Posts
Recent Comments
Link
투케이2K
271. (kotlin/코틀린) [유틸 파일] observableImageView : 이미지 뷰 (imageView) 표시 alert 팝업창 호출 실시 본문
Kotlin
271. (kotlin/코틀린) [유틸 파일] observableImageView : 이미지 뷰 (imageView) 표시 alert 팝업창 호출 실시
투케이2K 2023. 4. 15. 21:00[개발 환경 설정]
개발 툴 : AndroidStudio
개발 언어 : Kotlin
[소스 코드]
// ----------------------------------------------------------------------------------
// TODO [SEARCH FAST] : [Observable] : [ImageView 팝업창 호출 처리 메소드]
// ----------------------------------------------------------------------------------
// TODO [호출 방법 소스 코드]
// ----------------------------------------------------------------------------------
/*
try {
// [팝업창 활성 수행]
C_Ui_View.observableImageView(A_Intro@this, "알림", C_App.drawableToBitmap(A_Intro@this, R.drawable.sample)!!, "확인", "취소")
.subscribeOn(AndroidSchedulers.mainThread()) // [Observable (생성자) 로직을 IO 스레드에서 실행 : 백그라운드]
.observeOn(Schedulers.io()) // [Observer (관찰자) 로직을 메인 스레드에서 실행]
.subscribe(
{ value ->
S_Log.ltw("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> ImageView 팝업창 활성 :: onNext]")
S_Log.cnt("-----------------------------------------")
S_Log.cnt("[VALUE :: $value]")
S_Log.lbw("================================================")
},
{ error ->
S_Log.lte("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> ImageView 팝업창 활성 :: onError]")
S_Log.cnt("-----------------------------------------")
S_Log.cnt("[ERROR :: " + error.message.toString() + "]")
S_Log.lbe("================================================")
}
)
{
}
}
catch (e : Exception) {
e.printStackTrace()
}
*/
// ----------------------------------------------------------------------------------
fun observableImageView(mContext: Context, title: String, bitmap: Bitmap, ok: String, no: String): Observable<String> {
// [로직 처리 실시]
return Observable.create { subscriber: ObservableEmitter<String> ->
try {
S_Log.ltd("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> observableImageView :: ImageView 팝업창 호출 수행 실시]")
S_Log.lbd("================================================")
// [UI 생성 실시]
val imageView = ImageView(mContext)
imageView.setPadding(70, 70, 70, 70)
// [이미지 뷰에 비트맵 지정]
imageView.setImageBitmap(bitmap)
imageView.scaleType = ImageView.ScaleType.FIT_XY
// [팝업창 생성 실시]
Handler(Looper.getMainLooper()).postDelayed({
if (mContext != null) {
// [AlertDialog 팝업창 생성]
val dialog = AlertDialog.Builder(mContext)
.setTitle(title) //[팝업창 타이틀 지정]
//.setIcon(R.drawable.app_icon) //[팝업창 아이콘 지정]
//.setMessage("\n") //[팝업창 내용 지정]
.setView(imageView)
.setCancelable(false) //[외부 레이아웃 클릭시도 팝업창이 사라지지않게 설정]
.setPositiveButton(ok) { dialog, which ->
// TODO Auto-generated method stub
// -----------------------------------------
// TODO [확인 버튼 클릭 이벤트 처리]
// -----------------------------------------
S_Log.ltd("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> observableImageView :: ImageView 팝업창 호출 [확인] 클릭]")
S_Log.lbd("================================================")
// -----------------------------------------
// TODO [리턴 데이터 반환]
// -----------------------------------------
try {
subscriber.onNext(ok)
subscriber.onComplete()
} catch (ex: Exception) {
ex.printStackTrace()
}
// -----------------------------------------
}
.setNegativeButton(no) { dialog, which ->
// TODO Auto-generated method stub
// -----------------------------------------
// TODO [취소 버튼 클릭 이벤트 처리]
// -----------------------------------------
S_Log.lte("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> observableImageView :: ImageView 팝업창 호출 [취소] 클릭]")
S_Log.lbe("================================================")
// -----------------------------------------
// TODO [리턴 데이터 반환]
// -----------------------------------------
try {
subscriber.onNext(no)
subscriber.onComplete()
} catch (ex: Exception) {
ex.printStackTrace()
}
// -----------------------------------------
}
.show()
// [팝업창 레이아웃 사이즈 변경]
//*
val lp = WindowManager.LayoutParams()
val window = dialog.window
lp.copyFrom(window!!.attributes)
//lp.width = WindowManager.LayoutParams.MATCH_PARENT;
//lp.height = WindowManager.LayoutParams.MATCH_PARENT;
//lp.width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, mContext.getResources().getDisplayMetrics());
//lp.height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 350, mContext.getResources().getDisplayMetrics());
val display = (mContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
val outMetrics = DisplayMetrics()
display.getMetrics(outMetrics)
val density = mContext.resources.displayMetrics.density
val dpHeight = outMetrics.heightPixels / density
val dpWidth = outMetrics.widthPixels / density
val dpWidthValue = dpWidth.toInt()
val dpHeightValue = dpHeight.toInt()
S_Log.ltw("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> observableImageView :: ImageView 팝업창 사이즈 확인]")
S_Log.cnt("[dpWidthValue :: $dpWidthValue]")
S_Log.lbw("================================================")
val width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpWidthValue.toFloat(), mContext.resources.displayMetrics).toInt()
val height = width + width / 4
lp.width = width
lp.height = height
window!!.attributes = lp
// */
}
}, 0)
} catch (e: Exception) {
e.printStackTrace()
S_Log.lte("================================================")
S_Log.cnt("[" + ACTIVITY_NAME + " >> observableImageView :: ImageView 팝업창 호출 [Exception] 확인]")
S_Log.cnt("-----------------------------------------")
S_Log.cnt("[EXCEPTION :: " + e.message.toString() + "]")
S_Log.lbe("================================================")
// ------------------------------------------------------
// TODO [리턴 데이터 반환]
// ------------------------------------------------------
try {
subscriber.onNext("")
subscriber.onComplete()
} catch (ex: Exception) {
ex.printStackTrace()
}
}
}
}
[결과 출력]
반응형
'Kotlin' 카테고리의 다른 글
Comments