투케이2K

117. (TWOK/UTIL) [Android/kotlin] - C_KeyVolumeEvt : 모바일 디바이스 볼륨 (volume) 업 , 다운 키 이벤트 컨트롤 클래스 본문

투케이2K 유틸파일

117. (TWOK/UTIL) [Android/kotlin] - C_KeyVolumeEvt : 모바일 디바이스 볼륨 (volume) 업 , 다운 키 이벤트 컨트롤 클래스

투케이2K 2023. 8. 12. 22:12

[설 명]

프로그램 : Android / Kotlin

설 명 : C_KeyVolumeEvt : 모바일 디바이스 볼륨 (volume) 업 , 다운 키 이벤트 컨트롤 클래스

 

[소스 코드]

 

package com.example.kotlinproject

import android.content.Context
import android.media.AudioManager

class C_KeyVolumeEvt {


    /**
     * // --------------------------------------------------------------------------------------
     * TODO [클래스 설명]
     * // --------------------------------------------------------------------------------------
     * 1. onKeyDown 키 이벤트 발생 시 볼륨 조절 수행 클래스
     * // --------------------------------------------------------------------------------------
     * 2. 호출 방법 : onKeyDown 이벤트 정의 >> 볼륨 업 , 볼륨 다운 이벤트 감지 실시
     *
     *     // TODO [모바일 키 이벤트 발생 체크 부분]
     *     @Override
     *     public boolean onKeyDown(int keyCode, KeyEvent event) {
     *
     *
     *         // [모바일 디바이스의 볼륨 업 키 이벤트가 발생한 경우]
     *         if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
     *         }
     *
     *
     *         // [모바일 디바이스의 볼륨 다운 키 이벤트가 발생한 경우]
     *         if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
     *         }
     *
     *
     *         // [이벤트 종료 리턴]
     *         return true;
     *     }
     *
     * // --------------------------------------------------------------------------------------
     * */





    /**
     * // --------------------------------------------------------------------------------------
     * // TODO [빠른 로직 찾기 : 주석 로직 찾기]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [미디어 볼륨 UP]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [미디어 볼륨 DOWN]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [벨소리 볼륨 UP]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [벨소리 볼륨 DOWN]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [알림 볼륨 UP]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [알림 볼륨 DOWN]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [시스템 볼륨 UP]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [시스템 볼륨 DOWN]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [알람 볼륨 UP]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [알람 볼륨 DOWN]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [통화 볼륨 UP]
     * // --------------------------------------------------------------------------------------
     * // [SEARCH FAST] : [통화 볼륨 DOWN]
     * // --------------------------------------------------------------------------------------
     *
     * // --------------------------------------------------------------------------------------
     *
     * // --------------------------------------------------------------------------------------
     *
     * // --------------------------------------------------------------------------------------
     *
     * // --------------------------------------------------------------------------------------
     * */






    // --------------------------------------------------------------------------------------
    // TODO [companion object >> static 선언 실시]
    // --------------------------------------------------------------------------------------
    companion object {


        // ----------------------------------------------------------------------------------
        // TODO [전역 변수]
        // ----------------------------------------------------------------------------------
        private val ACTIVITY_NAME = "C_KeyVolumeEvt"





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [미디어 볼륨 UP]
        // ----------------------------------------------------------------------------------
        fun setMediaVolumeUP(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "미디어 볼륨 UP 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }

        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [미디어 볼륨 DOWN]
        // ----------------------------------------------------------------------------------
        fun setMediaVolumeDOWN(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "미디어 볼륨 DOWN 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [벨소리 볼륨 UP]
        // ----------------------------------------------------------------------------------
        fun setRingVolumeUP(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "벨소리 볼륨 UP 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [벨소리 볼륨 DOWN]
        // ----------------------------------------------------------------------------------
        fun setRingVolumeDOWN(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "벨소리 볼륨 DOWN 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [알림 볼륨 UP]
        // ----------------------------------------------------------------------------------
        fun setNotiVolumeUP(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "알림 볼륨 UP 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [알림 볼륨 DOWN]
        // ----------------------------------------------------------------------------------
        fun setNotiVolumeDOWN(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "알림 볼륨 DOWN 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [시스템 볼륨 UP]
        // ----------------------------------------------------------------------------------
        fun setSystemVolumeUP(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "시스템 볼륨 UP 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [시스템 볼륨 DOWN]
        // ----------------------------------------------------------------------------------
        fun setSystemVolumeDOWN(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "시스템 볼륨 DOWN 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [알람 볼륨 UP]
        // ----------------------------------------------------------------------------------
        fun setAlramVolumeUP(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "알람 볼륨 UP 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [알람 볼륨 DOWN]
        // ----------------------------------------------------------------------------------
        fun setAlramVolumeDOWN(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "알람 볼륨 DOWN 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [통화 볼륨 UP]
        // ----------------------------------------------------------------------------------
        fun setVoiceVolumeUP(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "통화 볼륨 UP 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }





        // ----------------------------------------------------------------------------------
        // TODO [SEARCH FAST] : [통화 볼륨 DOWN]
        // ----------------------------------------------------------------------------------
        fun setVoiceVolumeDOWN(mContext: Context) {
            try {
                // ===============================================================
                S_Log._F_(mContext, "통화 볼륨 DOWN 이벤트 지정", null)
                // ===============================================================

                val mAudioManager = mContext.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                mAudioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI)
            } catch (e: Exception) {
                S_Log._printStackTrace_(mContext, S_FinalMsg.LOG_BUG_STATE, null, e)
            }
        }


    } // [companion 종료]


} // TODO [클래스 종료]

 

반응형
Comments