mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-21 19:55:33 -04:00
universal7885: Format Kotlin code using ktlint
* Also, refactor CameraLightSensor Signed-off-by: roynatech2544 <whiteshell2544@naver.com>
This commit is contained in:
parent
95d062a8b1
commit
3c7ca85990
35 changed files with 338 additions and 402 deletions
|
|
@ -11,4 +11,4 @@ class BootReceiver : BroadcastReceiver() {
|
|||
context.startForegroundService(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,38 +13,27 @@ import android.graphics.BitmapFactory
|
|||
import android.graphics.Color
|
||||
import android.graphics.ImageFormat
|
||||
import android.hardware.camera2.*
|
||||
import android.hardware.camera2.CameraManager.AvailabilityCallback
|
||||
import android.media.Image
|
||||
import android.media.ImageReader
|
||||
import android.net.Uri
|
||||
import android.os.*
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.SettingNotFoundException
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
open class CameraLightSensorService : Service() {
|
||||
var screenStateFilter: IntentFilter? = null
|
||||
class CameraLightSensorService : Service() {
|
||||
private lateinit var screenStateFilter: IntentFilter
|
||||
lateinit var mContext: Context
|
||||
private var mRegistered = false
|
||||
var destroy = false
|
||||
private var cameraDevice: CameraDevice? = null
|
||||
private var session: CameraCaptureSession? = null
|
||||
|
||||
@Volatile
|
||||
var avail = true
|
||||
private var imageReader: ImageReader? = null
|
||||
private var manager: CameraManager? = null
|
||||
private var mServiceStarted = false
|
||||
|
||||
@Volatile
|
||||
private var mLock = false
|
||||
private var mThreadRunning = false
|
||||
private lateinit var manager: CameraManager
|
||||
private lateinit var mCameraHandler: Handler
|
||||
private fun pushNotification(): Notification {
|
||||
val nm = mContext.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||
val channel = NotificationChannel(
|
||||
mContext.basePackageName, "Useless Notification",
|
||||
mContext.basePackageName, "CameraLightSensor",
|
||||
NotificationManager.IMPORTANCE_NONE
|
||||
)
|
||||
channel.isBlockable = true
|
||||
|
|
@ -67,20 +56,7 @@ open class CameraLightSensorService : Service() {
|
|||
if (DEBUG) Log.d(TAG, "Destroying service")
|
||||
if (mRegistered) contentResolver!!.unregisterContentObserver(mSettingsObserver)
|
||||
mRegistered = false
|
||||
cameraDevice!!.close()
|
||||
if (session != null && avail) {
|
||||
try {
|
||||
session!!.abortCaptures()
|
||||
session!!.close()
|
||||
} catch (e: CameraAccessException) {
|
||||
Log.e(TAG, e.message)
|
||||
} catch (e2: IllegalStateException) {
|
||||
Log.e(TAG, "Session Already Closed")
|
||||
}
|
||||
}
|
||||
manager!!.unregisterAvailabilityCallback(availabilityCallback)
|
||||
avail = false
|
||||
destroy = true
|
||||
imageReader.close()
|
||||
stopForeground(true)
|
||||
super.onDestroy()
|
||||
}
|
||||
|
|
@ -92,14 +68,21 @@ open class CameraLightSensorService : Service() {
|
|||
private val mScreenStateReceiver: BroadcastReceiver = object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == Intent.ACTION_USER_PRESENT) {
|
||||
onDisplayOn()
|
||||
mServiceStarted = true
|
||||
if (mPoolExecutor == null) {
|
||||
mPoolExecutor = ScheduledThreadPoolExecutor(4)
|
||||
mPoolExecutor!!.scheduleWithFixedDelay(
|
||||
mScheduler, 0, 2, TimeUnit.SECONDS
|
||||
)
|
||||
}
|
||||
} else if (intent.action == Intent.ACTION_SCREEN_OFF) {
|
||||
if (mServiceStarted) onDisplayOff()
|
||||
mServiceStarted = false
|
||||
if (mPoolExecutor != null) {
|
||||
mPoolExecutor!!.shutdown()
|
||||
mPoolExecutor = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private val mScheduler = Runnable { readyCamera() }
|
||||
|
||||
// Make a listener for settings
|
||||
private var mSettingsObserver: ContentObserver =
|
||||
|
|
@ -116,11 +99,19 @@ open class CameraLightSensorService : Service() {
|
|||
) {
|
||||
registerReceiver(mScreenStateReceiver, screenStateFilter)
|
||||
mRegistered = true
|
||||
onDisplayOn()
|
||||
if (mPoolExecutor == null) {
|
||||
mPoolExecutor = ScheduledThreadPoolExecutor(4)
|
||||
mPoolExecutor!!.scheduleWithFixedDelay(
|
||||
mScheduler, 0, 2, TimeUnit.SECONDS
|
||||
)
|
||||
}
|
||||
} else {
|
||||
if (mRegistered) unregisterReceiver(mScreenStateReceiver)
|
||||
mRegistered = false
|
||||
onDisplayOff()
|
||||
if (mPoolExecutor != null) {
|
||||
mPoolExecutor!!.shutdown()
|
||||
mPoolExecutor = null
|
||||
}
|
||||
}
|
||||
} catch (e: SettingNotFoundException) {
|
||||
e.printStackTrace()
|
||||
|
|
@ -131,20 +122,6 @@ open class CameraLightSensorService : Service() {
|
|||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDisplayOn() {
|
||||
if (DEBUG) Log.d(TAG, "Screen is on. Starting Service...")
|
||||
avail = true
|
||||
readyCamera()
|
||||
}
|
||||
|
||||
private fun onDisplayOff() {
|
||||
if (DEBUG) Log.d(TAG, "Screen is off. Stopping Service...")
|
||||
thread.interrupt()
|
||||
avail = false
|
||||
mThreadRunning = false
|
||||
}
|
||||
|
||||
private var cameraStateCallback: CameraDevice.StateCallback =
|
||||
object : CameraDevice.StateCallback() {
|
||||
override fun onOpened(camera: CameraDevice) {
|
||||
|
|
@ -164,24 +141,22 @@ open class CameraLightSensorService : Service() {
|
|||
private var sessionStateCallback: CameraCaptureSession.StateCallback =
|
||||
object : CameraCaptureSession.StateCallback() {
|
||||
override fun onReady(session: CameraCaptureSession) {
|
||||
if (!destroy) {
|
||||
this@CameraLightSensorService.session = session
|
||||
this@CameraLightSensorService.session = session
|
||||
try {
|
||||
if (createCaptureRequest() == null) return
|
||||
try {
|
||||
if (createCaptureRequest() == null) return
|
||||
try {
|
||||
session.capture(createCaptureRequest(), captureCallback, null)
|
||||
} catch (e: CameraAccessException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(TAG, "onReady: Session is NULL")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Camera is in use")
|
||||
session.capture(createCaptureRequest(), null, mCameraHandler)
|
||||
} catch (e: CameraAccessException) {
|
||||
e.printStackTrace()
|
||||
} catch (e: IllegalStateException) {
|
||||
Log.w(TAG, "onReady: Session is NULL")
|
||||
}
|
||||
cameraDevice!!.close() session.close()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Camera is in use")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onConfigured(session: CameraCaptureSession) {}
|
||||
override fun onConfigureFailed(session: CameraCaptureSession) {}
|
||||
}
|
||||
|
|
@ -198,12 +173,6 @@ open class CameraLightSensorService : Service() {
|
|||
e.printStackTrace()
|
||||
}
|
||||
img.close()
|
||||
if (DEBUG) Log.d(
|
||||
TAG,
|
||||
"ImageReader.OnImageAvailableListener: Closing Camera and Sessions.."
|
||||
)
|
||||
cameraDevice!!.close()
|
||||
session!!.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,16 +181,8 @@ open class CameraLightSensorService : Service() {
|
|||
manager = getSystemService(CAMERA_SERVICE) as CameraManager
|
||||
try {
|
||||
val pickedCamera = getCamera(manager)
|
||||
manager!!.registerAvailabilityCallback(availabilityCallback, null)
|
||||
manager!!.openCamera(pickedCamera, cameraStateCallback, null)
|
||||
imageReader =
|
||||
ImageReader.newInstance(50, 50, ImageFormat.JPEG, 2 /* images buffered */)
|
||||
imageReader?.setOnImageAvailableListener(onImageAvailableListener, null)
|
||||
if (!mThreadRunning) {
|
||||
val mMyThread = Thread(thread)
|
||||
mMyThread.start()
|
||||
mThreadRunning = true
|
||||
}
|
||||
manager.openCamera(pickedCamera, cameraStateCallback, mCameraHandler)
|
||||
imageReader.setOnImageAvailableListener(onImageAvailableListener, mCameraHandler)
|
||||
if (DEBUG) Log.d(TAG, "imageReader created")
|
||||
} catch (e: CameraAccessException) {
|
||||
Log.e(TAG, e.message)
|
||||
|
|
@ -244,13 +205,15 @@ open class CameraLightSensorService : Service() {
|
|||
}
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
mContext = applicationContext
|
||||
val mCameraHandlerThread = HandlerThread("CameraLightSensor")
|
||||
mCameraHandlerThread.start()
|
||||
mCameraHandler = Handler(mCameraHandlerThread.looper)
|
||||
mContext = this
|
||||
@Suppress("SameParameterValue")
|
||||
startForeground(50, pushNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA)
|
||||
batteryOptimization(mContext)
|
||||
mRegistered = false
|
||||
screenStateFilter = IntentFilter(Intent.ACTION_USER_PRESENT)
|
||||
screenStateFilter!!.addAction(Intent.ACTION_SCREEN_OFF)
|
||||
screenStateFilter.addAction(Intent.ACTION_SCREEN_OFF)
|
||||
try {
|
||||
if (Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS_MODE)
|
||||
== Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
|
||||
|
|
@ -264,15 +227,13 @@ open class CameraLightSensorService : Service() {
|
|||
val setting = Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE)
|
||||
contentResolver?.registerContentObserver(setting, false, mSettingsObserver)
|
||||
if (DEBUG) Log.d(TAG, "onStartCommand flags $flags startId $startId")
|
||||
destroy = false
|
||||
avail = true
|
||||
startForeground(50, pushNotification())
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
if (DEBUG) Log.d(TAG, "onCreate service")
|
||||
mContext = applicationContext
|
||||
mContext = this
|
||||
startForeground(50, pushNotification())
|
||||
super.onCreate()
|
||||
}
|
||||
|
|
@ -280,13 +241,12 @@ open class CameraLightSensorService : Service() {
|
|||
fun actOnReadyCameraDevice() {
|
||||
try {
|
||||
cameraDevice!!.createCaptureSession(
|
||||
listOf(imageReader!!.surface),
|
||||
listOf(imageReader.surface),
|
||||
sessionStateCallback,
|
||||
null
|
||||
mCameraHandler
|
||||
)
|
||||
} catch (e: CameraAccessException) {
|
||||
Log.e(TAG, e.message)
|
||||
mLock = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -307,54 +267,9 @@ open class CameraLightSensorService : Service() {
|
|||
builder.build()
|
||||
} catch (e: CameraAccessException) {
|
||||
Log.e(TAG, e.message)
|
||||
mLock = false
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private var availabilityCallback: AvailabilityCallback = object : AvailabilityCallback() {
|
||||
override fun onCameraOpened(cameraId: String, packageId: String) {
|
||||
super.onCameraOpened(cameraId, packageId)
|
||||
Log.i(
|
||||
TAG, "CameraManager.AvailabilityCallback: Camera " + cameraId
|
||||
+ " Opened by Package " + packageId
|
||||
)
|
||||
mLock = true
|
||||
if (packageId == mContext.basePackageName) return
|
||||
avail = false
|
||||
}
|
||||
|
||||
override fun onCameraUnavailable(cameraId: String) {
|
||||
if (DEBUG) Log.i(TAG, "CameraManager.AvailabilityCallback : Camera NOT Available. ")
|
||||
avail = false
|
||||
super.onCameraUnavailable(cameraId)
|
||||
}
|
||||
|
||||
override fun onCameraAvailable(cameraId: String) {
|
||||
if (DEBUG) Log.i(TAG, "CameraManager.AvailabilityCallback : Camera IS Available. ")
|
||||
avail = true
|
||||
mLock = false
|
||||
super.onCameraAvailable(cameraId)
|
||||
}
|
||||
|
||||
override fun onCameraClosed(cameraId: String) {
|
||||
super.onCameraClosed(cameraId)
|
||||
}
|
||||
}
|
||||
var captureCallback: CameraCaptureSession.CaptureCallback =
|
||||
object : CameraCaptureSession.CaptureCallback() {
|
||||
override fun onCaptureSequenceCompleted(
|
||||
session: CameraCaptureSession,
|
||||
sequenceId: Int,
|
||||
frameNumber: Long
|
||||
) {
|
||||
if (DEBUG) Log.d(TAG, "captureCallback: Closing Session")
|
||||
super.onCaptureSequenceCompleted(session, sequenceId, frameNumber)
|
||||
cameraDevice!!.close()
|
||||
session.close()
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateBrightnessEstimate(bitmap: Bitmap, pixelSpacing: Int): Int {
|
||||
var r = 0
|
||||
var g = 0
|
||||
|
|
@ -382,8 +297,9 @@ open class CameraLightSensorService : Service() {
|
|||
val oldbrightness =
|
||||
Settings.System.getInt(contentResolver, Settings.System.SCREEN_BRIGHTNESS)
|
||||
if (DEBUG) Log.i(
|
||||
TAG, "AdjustBrightness: OldVal = " + oldbrightness + " NewVal = " +
|
||||
brightness + " Adjusting.."
|
||||
TAG,
|
||||
"AdjustBrightness: OldVal = " + oldbrightness + " NewVal = " +
|
||||
brightness + " Adjusting.."
|
||||
)
|
||||
var newbrightness = brightness
|
||||
if (newbrightness > 255) {
|
||||
|
|
@ -398,32 +314,13 @@ open class CameraLightSensorService : Service() {
|
|||
)
|
||||
}
|
||||
|
||||
private var thread = Thread {
|
||||
while (!Thread.currentThread().isInterrupted) {
|
||||
if (avail && !mLock) {
|
||||
SystemClock.sleep(DELAY.toLong())
|
||||
ContextCompat.getMainExecutor(mContext).execute { if (avail) readyCamera() }
|
||||
}else{
|
||||
SystemClock.sleep(DELAY.toLong() / 10) // For Fast Detection
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val imageReader =
|
||||
ImageReader.newInstance(50, 50, ImageFormat.JPEG, 2 /* images buffered */)
|
||||
protected val TAG: String = CameraLightSensorService::class.java.simpleName
|
||||
const val DEBUG = false
|
||||
protected const val CAMERA_CHOICE = CameraCharacteristics.LENS_FACING_FRONT
|
||||
private const val DELAY = 5 * 1000 // 5 Seconds
|
||||
fun batteryOptimization(context: Context?) {
|
||||
val intent = Intent()
|
||||
val packageName = context!!.packageName
|
||||
val pm = context.getSystemService(POWER_SERVICE) as PowerManager
|
||||
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
|
||||
intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
|
||||
intent.data = Uri.parse("package:$packageName")
|
||||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
const val CAMERA_CHOICE = CameraCharacteristics.LENS_FACING_FRONT
|
||||
private var mPoolExecutor: ScheduledThreadPoolExecutor? = null
|
||||
private var mRegistered = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,11 @@ import com.eurekateam.fmradio.enums.PlayState
|
|||
import com.eurekateam.fmradio.enums.PowerState
|
||||
import com.eurekateam.fmradio.fragments.MainFragment
|
||||
import com.eurekateam.fmradio.utils.Log
|
||||
import java.io.File
|
||||
|
||||
|
||||
class FMRadioService : Service() {
|
||||
private lateinit var mContext: Context
|
||||
private lateinit var mAudioManager: AudioManager
|
||||
private lateinit var mTracks : LongArray
|
||||
private lateinit var mTracks: LongArray
|
||||
private lateinit var mNativeFMInterface: NativeFMInterface
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return null
|
||||
|
|
@ -32,8 +30,7 @@ class FMRadioService : Service() {
|
|||
mAudioManager = getSystemService(AUDIO_SERVICE) as AudioManager
|
||||
mTracks = MainFragment.mTracks
|
||||
mIndex = MainFragment.getIndex()
|
||||
if (mTracks.isEmpty() || mIndex == -1)
|
||||
{
|
||||
if (mTracks.isEmpty() || mIndex == -1) {
|
||||
return super.onStartCommand(intent, flags, startId)
|
||||
}
|
||||
if (intent != null) {
|
||||
|
|
@ -43,7 +40,7 @@ class FMRadioService : Service() {
|
|||
if (mPlayState == PlayState.STATE_PLAYING) {
|
||||
mPlayState = PlayState.STATE_STOPPED
|
||||
mAudioManager.setParameters(PowerState.FM_POWER_OFF.mAudioParam)
|
||||
}else if (mPlayState == PlayState.STATE_STOPPED){
|
||||
} else if (mPlayState == PlayState.STATE_STOPPED) {
|
||||
mPlayState = PlayState.STATE_PLAYING
|
||||
mAudioManager.setParameters(PowerState.FM_POWER_ON.mAudioParam)
|
||||
}
|
||||
|
|
@ -73,9 +70,9 @@ class FMRadioService : Service() {
|
|||
}
|
||||
ACTION_OUTPUT -> {
|
||||
changeOutputDevice(mOutput)
|
||||
if (mOutput == OutputState.OUTPUT_HEADSET){
|
||||
if (mOutput == OutputState.OUTPUT_HEADSET) {
|
||||
mOutput = OutputState.OUTPUT_SPEAKER
|
||||
}else if (mOutput == OutputState.OUTPUT_SPEAKER){
|
||||
} else if (mOutput == OutputState.OUTPUT_SPEAKER) {
|
||||
mOutput = OutputState.OUTPUT_HEADSET
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +87,7 @@ class FMRadioService : Service() {
|
|||
}
|
||||
sendMetaData("FM ${mTracks[mIndex].toFloat() / 1000} Mhz")
|
||||
startForeground(51, pushNotification())
|
||||
if (mOutput == OutputState.OUTPUT_SPEAKER){
|
||||
if (mOutput == OutputState.OUTPUT_SPEAKER) {
|
||||
changeOutputDevice(OutputState.OUTPUT_HEADSET)
|
||||
}
|
||||
Log.i("--- FMRadio Background (OUT) ---")
|
||||
|
|
@ -100,8 +97,8 @@ class FMRadioService : Service() {
|
|||
val state = PlaybackState.Builder()
|
||||
.setActions(
|
||||
PlaybackState.ACTION_PLAY or PlaybackState.ACTION_SKIP_TO_NEXT
|
||||
or PlaybackState.ACTION_PAUSE or PlaybackState.ACTION_SKIP_TO_PREVIOUS
|
||||
or PlaybackState.ACTION_STOP or PlaybackState.ACTION_PLAY_PAUSE
|
||||
or PlaybackState.ACTION_PAUSE or PlaybackState.ACTION_SKIP_TO_PREVIOUS
|
||||
or PlaybackState.ACTION_STOP or PlaybackState.ACTION_PLAY_PAUSE
|
||||
)
|
||||
.build()
|
||||
mMediaSession.setPlaybackState(state)
|
||||
|
|
@ -110,8 +107,10 @@ class FMRadioService : Service() {
|
|||
val metadata = MediaMetadata.Builder()
|
||||
.putString(MediaMetadata.METADATA_KEY_TITLE, mTitle)
|
||||
.putString(MediaMetadata.METADATA_KEY_ARTIST, resources.getString(R.string.app_name))
|
||||
.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART,
|
||||
BitmapFactory.decodeResource(mContext.resources, R.drawable.ic_radio))
|
||||
.putBitmap(
|
||||
MediaMetadata.METADATA_KEY_ALBUM_ART,
|
||||
BitmapFactory.decodeResource(mContext.resources, R.drawable.ic_radio)
|
||||
)
|
||||
.build()
|
||||
mMediaSession.setMetadata(metadata)
|
||||
}
|
||||
|
|
@ -138,7 +137,7 @@ class FMRadioService : Service() {
|
|||
val rewind = PendingIntent.getService(mContext, 0, Intent(ACTION_BEFORE), PendingIntent.FLAG_IMMUTABLE)
|
||||
val close = PendingIntent.getService(mContext, 0, Intent(ACTION_QUIT), PendingIntent.FLAG_IMMUTABLE)
|
||||
val output = PendingIntent.getService(mContext, 0, Intent(ACTION_OUTPUT), PendingIntent.FLAG_IMMUTABLE)
|
||||
val mOutputAction : Notification.Action = Notification.Action.Builder(
|
||||
val mOutputAction: Notification.Action = Notification.Action.Builder(
|
||||
when (mOutput) {
|
||||
OutputState.OUTPUT_HEADSET -> {
|
||||
Icon.createWithResource(this, R.drawable.ic_volume_up)
|
||||
|
|
@ -146,7 +145,8 @@ class FMRadioService : Service() {
|
|||
OutputState.OUTPUT_SPEAKER -> {
|
||||
Icon.createWithResource(this, R.drawable.ic_headphones)
|
||||
}
|
||||
}, "Output Configuration", output
|
||||
},
|
||||
"Output Configuration", output
|
||||
).build()
|
||||
val mPausePlayAction: Notification.Action = Notification.Action.Builder(
|
||||
when (mPlayState) {
|
||||
|
|
@ -156,7 +156,8 @@ class FMRadioService : Service() {
|
|||
PlayState.STATE_STOPPED -> {
|
||||
Icon.createWithResource(this, R.drawable.ic_play)
|
||||
}
|
||||
}, "Start/Stop", togglePlay
|
||||
},
|
||||
"Start/Stop", togglePlay
|
||||
|
||||
).build()
|
||||
val mRewindAction: Notification.Action = Notification.Action.Builder(
|
||||
|
|
@ -186,17 +187,17 @@ class FMRadioService : Service() {
|
|||
private const val ACTION_BEFORE = "$PACKAGENAME.BEFORE"
|
||||
private const val ACTION_QUIT = "$PACKAGENAME.QUIT"
|
||||
private const val ACTION_OUTPUT = "$PACKAGENAME.OUTPUT"
|
||||
private var mPlayState : PlayState = PlayState.STATE_PLAYING
|
||||
private var mOutput : OutputState = MainFragment.mHeadset
|
||||
private var fd : Int = -1
|
||||
private var mPlayState: PlayState = PlayState.STATE_PLAYING
|
||||
private var mOutput: OutputState = MainFragment.mHeadset
|
||||
private var fd: Int = -1
|
||||
private var mIndex = -1
|
||||
lateinit var mMediaSession : MediaSession
|
||||
lateinit var mMediaSession: MediaSession
|
||||
}
|
||||
private fun changeOutputDevice(output: OutputState){
|
||||
if (output == OutputState.OUTPUT_SPEAKER){
|
||||
mNativeFMInterface.setAudioRoute(false);
|
||||
}else if (output == OutputState.OUTPUT_HEADSET){
|
||||
mNativeFMInterface.setAudioRoute(true);
|
||||
private fun changeOutputDevice(output: OutputState) {
|
||||
if (output == OutputState.OUTPUT_SPEAKER) {
|
||||
mNativeFMInterface.setAudioRoute(false)
|
||||
} else if (output == OutputState.OUTPUT_HEADSET) {
|
||||
mNativeFMInterface.setAudioRoute(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,8 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
|
|||
import com.google.android.material.color.DynamicColors
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private lateinit var mIntent : Intent
|
||||
private lateinit var mIntent: Intent
|
||||
|
||||
/**
|
||||
* Function to change current [Fragment] to other [Fragment]
|
||||
|
|
@ -43,10 +42,10 @@ class MainActivity : AppCompatActivity() {
|
|||
}
|
||||
private val mFMInterface = NativeFMInterface()
|
||||
private lateinit var mAlertView: View
|
||||
private lateinit var mAlertTitle : MaterialTextView
|
||||
private lateinit var mAlertDesc : MaterialTextView
|
||||
private lateinit var mAlertImage : AppCompatImageView
|
||||
private lateinit var mAudioManager : AudioManager
|
||||
private lateinit var mAlertTitle: MaterialTextView
|
||||
private lateinit var mAlertDesc: MaterialTextView
|
||||
private lateinit var mAlertImage: AppCompatImageView
|
||||
private lateinit var mAudioManager: AudioManager
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
System.loadLibrary("fmnative_jni")
|
||||
MainFragment.fd = mFMInterface.openFMDevice()
|
||||
|
|
@ -57,7 +56,7 @@ class MainActivity : AppCompatActivity() {
|
|||
mAlertDesc = mAlertView.findViewById(R.id.alert_desc)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_navigation)
|
||||
if (MainFragment.fd == -1){
|
||||
if (MainFragment.fd == -1) {
|
||||
Log.e("CANNOT OPEN /dev/radio0!!!")
|
||||
mAlertTitle.text = getString(R.string.radio_io_error)
|
||||
mAlertDesc.text = getString(R.string.radio_io_error_desc)
|
||||
|
|
@ -78,19 +77,23 @@ class MainActivity : AppCompatActivity() {
|
|||
* @see AudioManager.getDevices
|
||||
*/
|
||||
val mAudioDeviceInfo = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)
|
||||
for (i in mAudioDeviceInfo.indices){
|
||||
for (i in mAudioDeviceInfo.indices) {
|
||||
if (mAudioDeviceInfo[i].type == AudioDeviceInfo.TYPE_WIRED_HEADSET ||
|
||||
mAudioDeviceInfo[i].type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES) {
|
||||
mAudioDeviceInfo[i].type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
|
||||
) {
|
||||
MainFragment.mHeadSetPlugged = HeadsetState.HEADSET_STATE_CONNECTED
|
||||
Log.i("Wired Headphones detected")
|
||||
}
|
||||
}
|
||||
if (MainFragment.mHeadSetPlugged != HeadsetState.HEADSET_STATE_CONNECTED){
|
||||
if (MainFragment.mHeadSetPlugged != HeadsetState.HEADSET_STATE_CONNECTED) {
|
||||
mAlertTitle.text = getString(R.string.no_headphones_error)
|
||||
mAlertDesc.text = getString(R.string.no_headphones_error_desc)
|
||||
mAlertImage.setImageIcon(Icon.createWithResource(mAlertView.context,
|
||||
R.drawable.ic_headphones
|
||||
))
|
||||
mAlertImage.setImageIcon(
|
||||
Icon.createWithResource(
|
||||
mAlertView.context,
|
||||
R.drawable.ic_headphones
|
||||
)
|
||||
)
|
||||
AlertDialog.Builder(mAlertView.context)
|
||||
.setCancelable(false)
|
||||
.setView(mAlertView)
|
||||
|
|
@ -99,7 +102,7 @@ class MainActivity : AppCompatActivity() {
|
|||
v.dismiss()
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
finish()
|
||||
},500)
|
||||
}, 500)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
|
@ -111,7 +114,7 @@ class MainActivity : AppCompatActivity() {
|
|||
changeFragment(mRadioMainFragment, MainFragment::class.java.name)
|
||||
mIntent = Intent(this, FMRadioService::class.java)
|
||||
findViewById<BottomNavigationView>(R.id.bottom_nav_bar).setOnItemSelectedListener {
|
||||
when (it.itemId){
|
||||
when (it.itemId) {
|
||||
R.id.radio_main -> changeFragment(mRadioMainFragment, MainFragment::class.java.name)
|
||||
R.id.channel_list -> changeFragment(mRadioChannelListFragment, ChannelListFragment::class.java.name)
|
||||
R.id.fav_list -> changeFragment(mFavouriteFragment, FavouriteFragment::class.java.name)
|
||||
|
|
@ -128,19 +131,23 @@ class MainActivity : AppCompatActivity() {
|
|||
if (intent.action == AudioManager.ACTION_HEADSET_PLUG) {
|
||||
MainFragment.mHeadSetPlugged = HeadsetState.HEADSET_STATE_DISCONNECTED
|
||||
val mAudioDeviceInfo = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS)
|
||||
for (i in mAudioDeviceInfo.indices){
|
||||
for (i in mAudioDeviceInfo.indices) {
|
||||
if (mAudioDeviceInfo[i].type == AudioDeviceInfo.TYPE_WIRED_HEADSET ||
|
||||
mAudioDeviceInfo[i].type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES){
|
||||
mAudioDeviceInfo[i].type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
|
||||
) {
|
||||
MainFragment.mHeadSetPlugged = HeadsetState.HEADSET_STATE_CONNECTED
|
||||
}
|
||||
}
|
||||
if (MainFragment.mHeadSetPlugged != HeadsetState.HEADSET_STATE_CONNECTED){
|
||||
if (MainFragment.mHeadSetPlugged != HeadsetState.HEADSET_STATE_CONNECTED) {
|
||||
Log.w("onReceive: Headset Unplugged")
|
||||
mAlertTitle.text = getString(R.string.no_headphones_error)
|
||||
mAlertDesc.text = getString(R.string.no_headphones_error_desc)
|
||||
mAlertImage.setImageIcon(Icon.createWithResource(mAlertView.context,
|
||||
R.drawable.ic_headphones
|
||||
))
|
||||
mAlertImage.setImageIcon(
|
||||
Icon.createWithResource(
|
||||
mAlertView.context,
|
||||
R.drawable.ic_headphones
|
||||
)
|
||||
)
|
||||
val mAlertDialog = AlertDialog.Builder(mAlertView.context)
|
||||
mAlertDialog
|
||||
.setCancelable(false)
|
||||
|
|
@ -150,7 +157,7 @@ class MainActivity : AppCompatActivity() {
|
|||
mAudioManager.setParameters(PowerState.FM_POWER_OFF.mAudioParam)
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
finish()
|
||||
},500)
|
||||
}, 500)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package com.eurekateam.fmradio
|
||||
|
||||
class NativeFMInterface {
|
||||
external fun openFMDevice() : Int
|
||||
external fun getFMFreq(fd : Int): Long
|
||||
external fun setFMFreq(fd : Int, freq : Int): Int
|
||||
external fun openFMDevice(): Int
|
||||
external fun getFMFreq(fd: Int): Long
|
||||
external fun setFMFreq(fd: Int, freq: Int): Int
|
||||
external fun setFMVolume(fd: Int, volume: Int /* 1 - 15 */): Int
|
||||
external fun setFMMute(fd: Int, mute: Boolean): Int
|
||||
external fun getFmUpper(fd: Int): Int
|
||||
external fun getFMLower(fd: Int): Int
|
||||
external fun getRMSSI(fd: Int): Int
|
||||
external fun getFMTracks(fd: Int) : LongArray
|
||||
external fun getFMTracks(fd: Int): LongArray
|
||||
external fun setFMStereo(fd: Int): Int
|
||||
external fun setFMMono(fd: Int): Int
|
||||
external fun setFMThread(fd: Int, run: Boolean): Int
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ import android.graphics.*
|
|||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
|
||||
|
||||
class PebbleTextView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : View(context, attrs, defStyleAttr) {
|
||||
constructor (context: Context) : this(context, null)
|
||||
constructor (context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
|
||||
|
||||
var mText : String = "102.7"
|
||||
var mColor : Int = Color.GREEN
|
||||
var mText: String = "102.7"
|
||||
var mColor: Int = Color.GREEN
|
||||
|
||||
private val mPaint = Paint()
|
||||
private val mRectf = RectF(25F, 25F, 350F, 270F)
|
||||
|
|
@ -42,7 +41,8 @@ class PebbleTextView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
|
|||
* the text that should be that width
|
||||
*/
|
||||
private fun setTextSizeForWidth(
|
||||
paint: Paint, desiredWidth: Float,
|
||||
paint: Paint,
|
||||
desiredWidth: Float,
|
||||
text: String
|
||||
) {
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import android.widget.BaseAdapter
|
|||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import com.eurekateam.fmradio.*
|
||||
import com.eurekateam.fmradio.NativeFMInterface
|
||||
import com.eurekateam.fmradio.fragments.MainFragment
|
||||
import com.eurekateam.fmradio.utils.FileUtilities
|
||||
import com.eurekateam.fmradio.utils.Log
|
||||
import com.eurekateam.fmradio.NativeFMInterface
|
||||
import com.google.android.material.textview.MaterialTextView
|
||||
|
||||
class ListViewAdapter (private val mContext: Context) : BaseAdapter() {
|
||||
class ListViewAdapter(private val mContext: Context) : BaseAdapter() {
|
||||
private val mFMInterface = NativeFMInterface()
|
||||
private var mListofViews = HashMap<Int, View>(30)
|
||||
override fun getCount(): Int {
|
||||
|
|
@ -32,10 +32,13 @@ class ListViewAdapter (private val mContext: Context) : BaseAdapter() {
|
|||
override fun getView(id: Int, mConvertView: View?, parent: ViewGroup?): View {
|
||||
val mAnotherConvertView = mConvertView
|
||||
?: (mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater).inflate(
|
||||
R.layout.channel_list_items, parent, false)
|
||||
R.layout.channel_list_items, parent, false
|
||||
)
|
||||
mAnotherConvertView.findViewById<MaterialTextView>(R.id.channel_list_title).text =
|
||||
String.format(mContext.getString(R.string.fm_radio_freq),
|
||||
MainFragment.mTracks[id].toFloat() / 1000)
|
||||
String.format(
|
||||
mContext.getString(R.string.fm_radio_freq),
|
||||
MainFragment.mTracks[id].toFloat() / 1000
|
||||
)
|
||||
mAnotherConvertView.findViewById<MaterialTextView>(R.id.channel_list_title).setOnClickListener {
|
||||
mFMInterface.setFMFreq(MainFragment.fd, MainFragment.mTracks[id].toInt())
|
||||
MainFragment.mFreqCurrent = MainFragment.mTracks[id].toInt()
|
||||
|
|
@ -47,19 +50,21 @@ class ListViewAdapter (private val mContext: Context) : BaseAdapter() {
|
|||
}
|
||||
mAnotherConvertView.findViewById<AppCompatImageView>(R.id.star_button_list).let {
|
||||
val mStar = ResourcesCompat.getDrawable(mContext.resources, R.drawable.ic_star, mContext.theme)
|
||||
val mStarFilled = ResourcesCompat.getDrawable(mContext.resources,
|
||||
R.drawable.ic_star_filled, mContext.theme)
|
||||
val mStarFilled = ResourcesCompat.getDrawable(
|
||||
mContext.resources,
|
||||
R.drawable.ic_star_filled, mContext.theme
|
||||
)
|
||||
val mIndex = MainFragment.mTracks[id].toInt()
|
||||
if (MainFragment.mFavStats[mIndex] == null){
|
||||
if (MainFragment.mFavStats[mIndex] == null) {
|
||||
MainFragment.mFavStats.putIfAbsent(mIndex, false)
|
||||
}
|
||||
if (MainFragment.mFavStats[mIndex]!!){
|
||||
if (MainFragment.mFavStats[mIndex]!!) {
|
||||
it.setImageDrawable(mStarFilled)
|
||||
}else {
|
||||
} else {
|
||||
it.setImageDrawable(mStar)
|
||||
}
|
||||
}
|
||||
if (MainFragment.mFreqCurrent == MainFragment.mTracks[id].toInt()){
|
||||
if (MainFragment.mFreqCurrent == MainFragment.mTracks[id].toInt()) {
|
||||
setCurrentFMChannel(id)
|
||||
}
|
||||
mListofViews[id] = mAnotherConvertView!!
|
||||
|
|
@ -68,11 +73,19 @@ class ListViewAdapter (private val mContext: Context) : BaseAdapter() {
|
|||
|
||||
private fun setCurrentFMChannel(mPosition: Int) {
|
||||
Log.i("Position: $mPosition")
|
||||
for (mItem in mListofViews){
|
||||
mItem.value.setBackgroundColor(ResourcesCompat.getColor(mContext.resources,
|
||||
android.R.color.system_accent2_100, mContext.theme))
|
||||
for (mItem in mListofViews) {
|
||||
mItem.value.setBackgroundColor(
|
||||
ResourcesCompat.getColor(
|
||||
mContext.resources,
|
||||
android.R.color.system_accent2_100, mContext.theme
|
||||
)
|
||||
)
|
||||
}
|
||||
mListofViews[mPosition]?.setBackgroundColor(ResourcesCompat.getColor(mContext.resources,
|
||||
android.R.color.system_accent3_400, mContext.theme))
|
||||
mListofViews[mPosition]?.setBackgroundColor(
|
||||
ResourcesCompat.getColor(
|
||||
mContext.resources,
|
||||
android.R.color.system_accent3_400, mContext.theme
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,18 +12,17 @@ import com.eurekateam.fmradio.R
|
|||
import com.eurekateam.fmradio.fragments.MainFragment
|
||||
import com.eurekateam.fmradio.utils.FileUtilities
|
||||
|
||||
|
||||
class PebbleLayoutAdapter (private val mContext: Context) : BaseAdapter() {
|
||||
private val mFavoriteList : MutableList<Int> = emptyList<Int>().toMutableList()
|
||||
class PebbleLayoutAdapter(private val mContext: Context) : BaseAdapter() {
|
||||
private val mFavoriteList: MutableList<Int> = emptyList<Int>().toMutableList()
|
||||
init {
|
||||
for (mItem in MainFragment.mFavStats){
|
||||
if (mItem.value){
|
||||
for (mItem in MainFragment.mFavStats) {
|
||||
if (mItem.value) {
|
||||
mFavoriteList.add(mItem.key)
|
||||
}
|
||||
}
|
||||
mFavoriteList.sort()
|
||||
var mData = ""
|
||||
for (i in mFavoriteList){
|
||||
for (i in mFavoriteList) {
|
||||
mData += "$i\n"
|
||||
}
|
||||
FileUtilities.writeToFile(FileUtilities.mFavouriteChannelFileName, mData, mContext)
|
||||
|
|
@ -48,8 +47,10 @@ class PebbleLayoutAdapter (private val mContext: Context) : BaseAdapter() {
|
|||
)
|
||||
mAnotherConvertView.findViewById<PebbleTextView>(R.id.pebble_textview).apply {
|
||||
mText = (mFavoriteList[id].toFloat() / 1000).toString()
|
||||
mColor = ResourcesCompat.getColor(mContext.resources, android.R.color.system_accent1_400,
|
||||
mContext.theme)
|
||||
mColor = ResourcesCompat.getColor(
|
||||
mContext.resources, android.R.color.system_accent1_400,
|
||||
mContext.theme
|
||||
)
|
||||
setOnClickListener {
|
||||
mFMInterface.setFMFreq(MainFragment.fd, mFavoriteList[id])
|
||||
MainFragment.mFreqCurrent = mFavoriteList[id]
|
||||
|
|
@ -61,4 +62,4 @@ class PebbleLayoutAdapter (private val mContext: Context) : BaseAdapter() {
|
|||
}
|
||||
return mAnotherConvertView
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ package com.eurekateam.fmradio.enums
|
|||
enum class HeadsetState {
|
||||
HEADSET_STATE_CONNECTED,
|
||||
HEADSET_STATE_DISCONNECTED,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ package com.eurekateam.fmradio.enums
|
|||
enum class OutputState {
|
||||
OUTPUT_SPEAKER,
|
||||
OUTPUT_HEADSET
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ package com.eurekateam.fmradio.enums
|
|||
enum class PlayState {
|
||||
STATE_PLAYING,
|
||||
STATE_STOPPED
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ package com.eurekateam.fmradio.enums
|
|||
enum class PowerState(val mAudioParam: String) {
|
||||
FM_POWER_ON("l_fmradio_mode=on"),
|
||||
FM_POWER_OFF("l_fmradio_mode=off")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,10 @@ import kotlinx.coroutines.GlobalScope
|
|||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class ChannelListFragment : Fragment(R.layout.activity_channel_list),
|
||||
class ChannelListFragment :
|
||||
Fragment(R.layout.activity_channel_list),
|
||||
View.OnClickListener {
|
||||
private lateinit var mListView : ListView
|
||||
private lateinit var mListView: ListView
|
||||
private lateinit var mFloatingActionButton: FloatingActionButton
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
|
|
@ -33,7 +34,7 @@ class ChannelListFragment : Fragment(R.layout.activity_channel_list),
|
|||
mListView.adapter = ListViewAdapter(requireContext())
|
||||
var mIsLight = true
|
||||
val nightModeFlags = requireContext().resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
when (nightModeFlags) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mIsLight = false
|
||||
Configuration.UI_MODE_NIGHT_NO -> mIsLight = true
|
||||
|
|
@ -50,10 +51,10 @@ class ChannelListFragment : Fragment(R.layout.activity_channel_list),
|
|||
|
||||
override fun onClick(v: View?) {
|
||||
GlobalScope.launch {
|
||||
withContext(Dispatchers.IO){
|
||||
withContext(Dispatchers.IO) {
|
||||
MainFragment.mRefreshTracks()
|
||||
}
|
||||
withContext(Dispatchers.Main){
|
||||
withContext(Dispatchers.Main) {
|
||||
(requireActivity() as MainActivity).getMySupportFragmentManager().apply {
|
||||
beginTransaction().remove(this@ChannelListFragment).commit()
|
||||
executePendingTransactions()
|
||||
|
|
@ -62,4 +63,4 @@ class ChannelListFragment : Fragment(R.layout.activity_channel_list),
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.GridView
|
||||
import android.widget.ListView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.eurekateam.fmradio.R
|
||||
import com.eurekateam.fmradio.adapters.PebbleLayoutAdapter
|
||||
|
|
@ -22,7 +21,7 @@ class FavouriteFragment : Fragment(R.layout.fragment_fav_list) {
|
|||
mGridView.adapter = PebbleLayoutAdapter(requireContext())
|
||||
var mIsLight = true
|
||||
val nightModeFlags = requireContext().resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
when (nightModeFlags) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mIsLight = false
|
||||
Configuration.UI_MODE_NIGHT_NO -> mIsLight = true
|
||||
|
|
@ -36,4 +35,4 @@ class FavouriteFragment : Fragment(R.layout.fragment_fav_list) {
|
|||
}
|
||||
return mRootView
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,23 +30,24 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import java.text.DecimalFormat
|
||||
|
||||
|
||||
class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
||||
class MainFragment :
|
||||
Fragment(R.layout.fragment_main),
|
||||
View.OnClickListener,
|
||||
SeekBar.OnSeekBarChangeListener {
|
||||
private val mFMInterface = NativeFMInterface()
|
||||
private lateinit var mVolumeUp : FloatingActionButton
|
||||
private lateinit var mVolumeDown : FloatingActionButton
|
||||
private lateinit var mVolumeUp: FloatingActionButton
|
||||
private lateinit var mVolumeDown: FloatingActionButton
|
||||
private lateinit var mSeekBar: AppCompatSeekBar
|
||||
private lateinit var mFavButton : FloatingActionButton
|
||||
private lateinit var mFMFreq : MaterialTextView
|
||||
private lateinit var mFavButton: FloatingActionButton
|
||||
private lateinit var mFMFreq: MaterialTextView
|
||||
private val mCleanFormat: DecimalFormat = DecimalFormat("0.#")
|
||||
private lateinit var mOutputSwitch : FloatingActionButton
|
||||
private lateinit var mBeforeChannelBtn : FloatingActionButton
|
||||
private lateinit var mNextChannelBtn : FloatingActionButton
|
||||
private lateinit var mPowerBtn : FloatingActionButton
|
||||
private lateinit var mOutputSwitch: FloatingActionButton
|
||||
private lateinit var mBeforeChannelBtn: FloatingActionButton
|
||||
private lateinit var mNextChannelBtn: FloatingActionButton
|
||||
private lateinit var mPowerBtn: FloatingActionButton
|
||||
private lateinit var mAudioManager: AudioManager
|
||||
private lateinit var mStar : Drawable
|
||||
private lateinit var mStarFilled : Drawable
|
||||
private lateinit var mStar: Drawable
|
||||
private lateinit var mStarFilled: Drawable
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
@ -54,10 +55,14 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
): View? {
|
||||
val mRootView = inflater.inflate(R.layout.fragment_main, container, false)
|
||||
super.onCreate(savedInstanceState)
|
||||
mStar = ResourcesCompat.getDrawable(requireContext().resources,
|
||||
R.drawable.ic_star, requireContext().theme)!!
|
||||
mStarFilled = ResourcesCompat.getDrawable(requireContext().resources,
|
||||
R.drawable.ic_star_filled, requireContext().theme)!!
|
||||
mStar = ResourcesCompat.getDrawable(
|
||||
requireContext().resources,
|
||||
R.drawable.ic_star, requireContext().theme
|
||||
)!!
|
||||
mStarFilled = ResourcesCompat.getDrawable(
|
||||
requireContext().resources,
|
||||
R.drawable.ic_star_filled, requireContext().theme
|
||||
)!!
|
||||
mAudioManager = requireContext().getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
mVolumeUp = mRootView.findViewById(R.id.volume_up)
|
||||
mVolumeDown = mRootView.findViewById(R.id.volume_down)
|
||||
|
|
@ -78,14 +83,14 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mFavButton.setOnClickListener(this)
|
||||
var mIsLight = true
|
||||
val nightModeFlags = requireContext().resources.configuration.uiMode and
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
Configuration.UI_MODE_NIGHT_MASK
|
||||
when (nightModeFlags) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> mIsLight = false
|
||||
Configuration.UI_MODE_NIGHT_NO -> mIsLight = true
|
||||
Configuration.UI_MODE_NIGHT_UNDEFINED -> mIsLight = true
|
||||
}
|
||||
val mTextViewList = listOf(R.id.app_banner, R.id.fm_freq, R.id.freq_misc)
|
||||
for (mResID in mTextViewList){
|
||||
for (mResID in mTextViewList) {
|
||||
mRootView.findViewById<MaterialTextView>(mResID).apply {
|
||||
if (mIsLight)
|
||||
setTextColor(resources.getColor(android.R.color.system_accent2_500, requireContext().theme))
|
||||
|
|
@ -100,7 +105,7 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
setBackgroundColor(resources.getColor(android.R.color.system_accent1_700, requireContext().theme))
|
||||
}
|
||||
GlobalScope.launch {
|
||||
withContext(Dispatchers.IO){
|
||||
withContext(Dispatchers.IO) {
|
||||
if (FileUtilities.checkIfExistFile(FileUtilities.mFavouriteChannelFileName, requireContext())) {
|
||||
val mFavData = FileUtilities.readFromFile(
|
||||
FileUtilities.mFavouriteChannelFileName, requireContext()
|
||||
|
|
@ -113,13 +118,13 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
var mMute = false
|
||||
if (mFreqCurrent == -1) {
|
||||
mAudioManager.setParameters(PowerState.FM_POWER_OFF.mAudioParam)
|
||||
withContext(Dispatchers.Main){
|
||||
withContext(Dispatchers.Main) {
|
||||
mUpdateEnableDisable(false, mRootView)
|
||||
}
|
||||
mMute = true
|
||||
}
|
||||
|
||||
if (FileUtilities.checkIfExistFile(FileUtilities.mFMFreqFileName, requireContext())){
|
||||
if (FileUtilities.checkIfExistFile(FileUtilities.mFMFreqFileName, requireContext())) {
|
||||
mFreqCurrent = FileUtilities.readFromFile(
|
||||
FileUtilities.mFMFreqFileName,
|
||||
requireContext()
|
||||
|
|
@ -129,7 +134,7 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mFMFreq.text = mCleanFormat.format(mFreqCurrent.toFloat() / 1000)
|
||||
}
|
||||
}
|
||||
if (FileUtilities.checkIfExistFile(FileUtilities.mFMVolumeFileName, requireContext())){
|
||||
if (FileUtilities.checkIfExistFile(FileUtilities.mFMVolumeFileName, requireContext())) {
|
||||
mVolume = FileUtilities.readFromFile(
|
||||
FileUtilities.mFMVolumeFileName,
|
||||
requireContext()
|
||||
|
|
@ -139,11 +144,11 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mSeekBar.progress = mVolume
|
||||
}
|
||||
}
|
||||
withContext(Dispatchers.Main){
|
||||
withContext(Dispatchers.Main) {
|
||||
mSeekBar.min = 1
|
||||
mSeekBar.max = 15
|
||||
}
|
||||
withContext(Dispatchers.IO){
|
||||
withContext(Dispatchers.IO) {
|
||||
if (mVolume == -1) {
|
||||
mVolume = 8
|
||||
mFMInterface.setFMVolume(fd, mVolume)
|
||||
|
|
@ -156,7 +161,7 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mFMInterface.setFMMute(fd, true)
|
||||
mFMInterface.setFMFreq(fd, mFMInterface.getFMLower(fd))
|
||||
mRefreshTracks()
|
||||
if (mFreqCurrent != -1){
|
||||
if (mFreqCurrent != -1) {
|
||||
mFMInterface.setFMFreq(fd, mFreqCurrent)
|
||||
} else {
|
||||
mFreqCurrent = mFMInterface.getFMLower(fd)
|
||||
|
|
@ -165,20 +170,20 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mFreqCurrent = mFMInterface.getFMFreq(fd).toInt()
|
||||
mFMInterface.setFMFreq(fd, mFreqCurrent)
|
||||
withContext(Dispatchers.Main) {
|
||||
mFMFreq.text = mCleanFormat.format( mFreqCurrent.toFloat() / 1000)
|
||||
mFMFreq.text = mCleanFormat.format(mFreqCurrent.toFloat() / 1000)
|
||||
}
|
||||
if (!mMute)
|
||||
mFMInterface.setFMMute(fd, false)
|
||||
if (mFreqCurrent == -1)
|
||||
mFMInterface.setFMThread(fd, true)
|
||||
withContext(Dispatchers.Main){
|
||||
withContext(Dispatchers.Main) {
|
||||
mFavButton.let {
|
||||
if (mFavStats[mFreqCurrent] == null){
|
||||
if (mFavStats[mFreqCurrent] == null) {
|
||||
mFavStats.putIfAbsent(mFreqCurrent, false)
|
||||
}
|
||||
if (mFavStats[mFreqCurrent]!!){
|
||||
if (mFavStats[mFreqCurrent]!!) {
|
||||
it.setImageDrawable(mStarFilled)
|
||||
}else {
|
||||
} else {
|
||||
it.setImageDrawable(mStar)
|
||||
}
|
||||
}
|
||||
|
|
@ -193,18 +198,18 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
* @param mTextView Whether the target view is touchable [FloatingActionButton] or
|
||||
* [MaterialTextView] with useless touch attr
|
||||
*/
|
||||
private fun View.disable(mTextView : Boolean = false) {
|
||||
private fun View.disable(mTextView: Boolean = false) {
|
||||
alpha = .7f
|
||||
if(!mTextView) isEnabled = false
|
||||
if (!mTextView) isEnabled = false
|
||||
}
|
||||
/**
|
||||
* Extension function for [View], for reverting Grayed out, disabled View
|
||||
* @param mTextView Whether the target view is touchable [FloatingActionButton] or
|
||||
* [MaterialTextView] with useless touch attr
|
||||
*/
|
||||
private fun View.enable(mTextView : Boolean = false) {
|
||||
private fun View.enable(mTextView: Boolean = false) {
|
||||
alpha = 1.0f
|
||||
if(!mTextView) isEnabled = true
|
||||
if (!mTextView) isEnabled = true
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -215,19 +220,19 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
* @see [enable]
|
||||
* @see [disable]
|
||||
*/
|
||||
private fun mUpdateEnableDisable(mEnabled: Boolean, mView: View = requireView()){
|
||||
private fun mUpdateEnableDisable(mEnabled: Boolean, mView: View = requireView()) {
|
||||
val mTextViewList = listOf(R.id.fm_freq, R.id.freq_misc)
|
||||
val mFloatButtonList = listOf(
|
||||
R.id.volume_down, R.id.volume_up,
|
||||
R.id.before_channel, R.id.next_channel, R.id.fm_output_btn
|
||||
)
|
||||
for (i in mTextViewList){
|
||||
for (i in mTextViewList) {
|
||||
if (mEnabled)
|
||||
mView.findViewById<View>(i).enable(true)
|
||||
else
|
||||
mView.findViewById<View>(i).disable(true)
|
||||
}
|
||||
for (i in mFloatButtonList){
|
||||
for (i in mFloatButtonList) {
|
||||
if (mEnabled)
|
||||
mView.findViewById<View>(i).enable()
|
||||
else
|
||||
|
|
@ -245,21 +250,21 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
R.drawable.ic_volume_up
|
||||
)
|
||||
)
|
||||
val ret = mFMInterface.setAudioRoute(true);
|
||||
Log.i("mFMInterface.setAudioRoute return $ret");
|
||||
}else if (mHeadset == OutputState.OUTPUT_SPEAKER){
|
||||
val ret = mFMInterface.setAudioRoute(true)
|
||||
Log.i("mFMInterface.setAudioRoute return $ret")
|
||||
} else if (mHeadset == OutputState.OUTPUT_SPEAKER) {
|
||||
mOutputSwitch.setImageIcon(
|
||||
Icon.createWithResource(
|
||||
requireContext(),
|
||||
R.drawable.ic_headphones
|
||||
)
|
||||
)
|
||||
val ret = mFMInterface.setAudioRoute(false);
|
||||
Log.i("mFMInterface.setAudioRoute return $ret");
|
||||
val ret = mFMInterface.setAudioRoute(false)
|
||||
Log.i("mFMInterface.setAudioRoute return $ret")
|
||||
}
|
||||
if (mHeadset == OutputState.OUTPUT_HEADSET){
|
||||
if (mHeadset == OutputState.OUTPUT_HEADSET) {
|
||||
mHeadset = OutputState.OUTPUT_SPEAKER
|
||||
}else if (mHeadset == OutputState.OUTPUT_SPEAKER){
|
||||
} else if (mHeadset == OutputState.OUTPUT_SPEAKER) {
|
||||
mHeadset = OutputState.OUTPUT_HEADSET
|
||||
}
|
||||
}
|
||||
|
|
@ -290,10 +295,11 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
val mTempFreq = mFMInterface.getBeforeChannel(fd)
|
||||
if (mTempFreq > mFMInterface.getFMLower(fd) && mTempFreq < mFMInterface.getFmUpper(
|
||||
fd
|
||||
)){
|
||||
)
|
||||
) {
|
||||
mFreqCurrent = mTempFreq
|
||||
}
|
||||
if (!mFMInterface.getSysfsSupport()){
|
||||
if (!mFMInterface.getSysfsSupport()) {
|
||||
mFMInterface.setFMFreq(fd, mFreqCurrent)
|
||||
}
|
||||
mFMInterface.setFMMute(fd, false)
|
||||
|
|
@ -302,21 +308,21 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mFreqCurrent.toString(), requireContext()
|
||||
)
|
||||
mFavButton.let {
|
||||
if (mFavStats[mFreqCurrent] == null){
|
||||
if (mFavStats[mFreqCurrent] == null) {
|
||||
mFavStats.putIfAbsent(mFreqCurrent, false)
|
||||
}
|
||||
if (mFavStats[mFreqCurrent]!!){
|
||||
if (mFavStats[mFreqCurrent]!!) {
|
||||
it.setImageDrawable(mStarFilled)
|
||||
}else {
|
||||
} else {
|
||||
it.setImageDrawable(mStar)
|
||||
}
|
||||
}
|
||||
}
|
||||
mPowerBtn.id -> {
|
||||
if (mFMPower){
|
||||
if (mFMPower) {
|
||||
mAudioManager.setParameters(PowerState.FM_POWER_OFF.mAudioParam)
|
||||
mFMFreq.text = getText(R.string.inital_freq)
|
||||
}else{
|
||||
} else {
|
||||
mAudioManager.setParameters(PowerState.FM_POWER_ON.mAudioParam)
|
||||
mFMFreq.text = mCleanFormat.format(mFreqCurrent.toFloat() / 1000)
|
||||
}
|
||||
|
|
@ -328,10 +334,11 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
val mTempFreq = mFMInterface.getNextChannel(fd)
|
||||
if (mTempFreq > mFMInterface.getFMLower(fd) && mTempFreq < mFMInterface.getFmUpper(
|
||||
fd
|
||||
)){
|
||||
)
|
||||
) {
|
||||
mFreqCurrent = mTempFreq
|
||||
}
|
||||
if (!mFMInterface.getSysfsSupport()){
|
||||
if (!mFMInterface.getSysfsSupport()) {
|
||||
mFMInterface.setFMFreq(fd, mFreqCurrent)
|
||||
}
|
||||
mFMInterface.setFMMute(fd, false)
|
||||
|
|
@ -340,32 +347,32 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
mFreqCurrent.toString(), requireContext()
|
||||
)
|
||||
mFavButton.let {
|
||||
if (mFavStats[mFreqCurrent] == null){
|
||||
if (mFavStats[mFreqCurrent] == null) {
|
||||
mFavStats.putIfAbsent(mFreqCurrent, false)
|
||||
}
|
||||
if (mFavStats[mFreqCurrent]!!){
|
||||
if (mFavStats[mFreqCurrent]!!) {
|
||||
it.setImageDrawable(mStarFilled)
|
||||
}else {
|
||||
} else {
|
||||
it.setImageDrawable(mStar)
|
||||
}
|
||||
}
|
||||
}
|
||||
mFavButton.id -> {
|
||||
val mIndex = mFreqCurrent
|
||||
if (mFavStats[mIndex] == null){
|
||||
val mIndex = mFreqCurrent
|
||||
if (mFavStats[mIndex] == null) {
|
||||
mFavStats.putIfAbsent(mIndex, false)
|
||||
}
|
||||
mFavStats[mIndex] = !mFavStats[mIndex]!!
|
||||
mFavButton.let {
|
||||
if (mFavStats[mIndex]!!){
|
||||
if (mFavStats[mIndex]!!) {
|
||||
it.setImageDrawable(mStarFilled)
|
||||
}else {
|
||||
} else {
|
||||
it.setImageDrawable(mStar)
|
||||
}
|
||||
}
|
||||
Log.d(
|
||||
"Fav stats for $mIndex changed. " +
|
||||
"Current value ${mFavStats[mIndex]}"
|
||||
"Current value ${mFavStats[mIndex]}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -387,9 +394,9 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
var mHeadset = OutputState.OUTPUT_SPEAKER
|
||||
var mFreqCurrent = -1
|
||||
private var mFMPower = false
|
||||
var mHeadSetPlugged : HeadsetState = HeadsetState.HEADSET_STATE_DISCONNECTED
|
||||
var mTracks : LongArray = emptyArray<Long>().toLongArray()
|
||||
fun mRefreshTracks(){
|
||||
var mHeadSetPlugged: HeadsetState = HeadsetState.HEADSET_STATE_DISCONNECTED
|
||||
var mTracks: LongArray = emptyArray<Long>().toLongArray()
|
||||
fun mRefreshTracks() {
|
||||
NativeFMInterface().setFMFreq(fd, NativeFMInterface().getFMLower(fd))
|
||||
mTracks = NativeFMInterface().getFMTracks(fd)
|
||||
mTracks = MainFragment().removeZeros(mTracks)
|
||||
|
|
@ -410,15 +417,14 @@ class MainFragment : Fragment(R.layout.fragment_main), View.OnClickListener,
|
|||
* @param array The target Long array
|
||||
* @return Long array with zeros removed
|
||||
*/
|
||||
private fun removeZeros(array : LongArray): LongArray{
|
||||
val mArray : MutableList<Long> = emptyList<Long>().toMutableList()
|
||||
private fun removeZeros(array: LongArray): LongArray {
|
||||
val mArray: MutableList<Long> = emptyList<Long>().toMutableList()
|
||||
Log.d("removeZeros: Got array size ${array.size}")
|
||||
for (i in array.indices){
|
||||
if(array[i] > 0L){
|
||||
for (i in array.indices) {
|
||||
if (array[i] > 0L) {
|
||||
mArray.add(array[i])
|
||||
}
|
||||
}
|
||||
return mArray.toLongArray()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ object FileUtilities {
|
|||
const val mFMVolumeFileName = "fm_volume_current"
|
||||
const val mFavouriteChannelFileName = "fm_fav_freqs"
|
||||
|
||||
fun writeToFile(fileName : String, data: String, mContext: Context){
|
||||
fun writeToFile(fileName: String, data: String, mContext: Context) {
|
||||
var os: OutputStream? = null
|
||||
try {
|
||||
os = FileOutputStream(File(mContext.filesDir.absolutePath + "/" + fileName))
|
||||
|
|
@ -23,7 +23,7 @@ object FileUtilities {
|
|||
}
|
||||
}
|
||||
}
|
||||
fun readFromFile(fileName: String, mContext: Context): String{
|
||||
fun readFromFile(fileName: String, mContext: Context): String {
|
||||
val mFile = File(mContext.filesDir.absolutePath + "/" + fileName)
|
||||
var os: InputStream? = null
|
||||
val mByteArray = ByteArray(mFile.length().toInt())
|
||||
|
|
@ -45,4 +45,4 @@ object FileUtilities {
|
|||
fun checkIfExistFile(fileName: String, mContext: Context): Boolean {
|
||||
return File(mContext.filesDir.absolutePath + "/" + fileName).exists()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package com.eurekateam.fmradio.utils
|
||||
|
||||
|
||||
import android.util.Log
|
||||
|
||||
/**
|
||||
|
|
@ -16,7 +15,7 @@ object Log {
|
|||
Log.e(TAG, getMessage(message))
|
||||
}
|
||||
|
||||
fun d(message: String){
|
||||
fun d(message: String) {
|
||||
Log.d(TAG, getMessage(message))
|
||||
}
|
||||
private fun getMessage(message: String): String {
|
||||
|
|
@ -33,4 +32,4 @@ object Log {
|
|||
fun w(message: String) {
|
||||
Log.w(TAG, getMessage(message))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,27 +17,35 @@ class BootReceiver : BroadcastReceiver() {
|
|||
override fun onReceive(p0: Context?, p1: Intent?) {
|
||||
val mSharedPreferences = p0?.let { PreferenceManager.getDefaultSharedPreferences(it) }
|
||||
if (p1 != null && mSharedPreferences != null) {
|
||||
if (p1.action == Intent.ACTION_BOOT_COMPLETED){
|
||||
System.loadLibrary("samsungparts_jni")
|
||||
if (p1.action == Intent.ACTION_BOOT_COMPLETED) {
|
||||
System.loadLibrary("samsungparts_jni")
|
||||
// Battery
|
||||
Battery.chargeSysfs = if (mSharedPreferences
|
||||
.getBoolean(BatteryFragment.PREF_CHARGE, true)) 0 else 1
|
||||
Battery.setFastCharge(if (mSharedPreferences
|
||||
.getBoolean(BatteryFragment.PREF_FASTCHARGE, true)) 0 else 1)
|
||||
.getBoolean(BatteryFragment.PREF_CHARGE, true)
|
||||
) 0 else 1
|
||||
Battery.setFastCharge(
|
||||
if (mSharedPreferences
|
||||
.getBoolean(BatteryFragment.PREF_FASTCHARGE, true)
|
||||
) 0 else 1
|
||||
)
|
||||
// Dolby
|
||||
DolbyCore.setEnabled(mSharedPreferences
|
||||
.getBoolean(DolbyFragment.PREF_DOLBY_ENABLE, false))
|
||||
DolbyCore.setProfile(mSharedPreferences
|
||||
.getInt(DolbyFragment.PREF_DOLBY_PROFILE, 0))
|
||||
DolbyCore.setEnabled(
|
||||
mSharedPreferences
|
||||
.getBoolean(DolbyFragment.PREF_DOLBY_ENABLE, false)
|
||||
)
|
||||
DolbyCore.setProfile(
|
||||
mSharedPreferences
|
||||
.getInt(DolbyFragment.PREF_DOLBY_PROFILE, 0)
|
||||
)
|
||||
|
||||
// FlashLight
|
||||
Flashlight.setFlash(mSharedPreferences.getInt(FlashLightFragment.PREF_FLASHLIGHT, 5))
|
||||
|
||||
// Display
|
||||
Display.DT2W = mSharedPreferences.getBoolean(DeviceSettings.PREF_DOUBLE_TAP, true)
|
||||
Display.GloveMode = mSharedPreferences.getBoolean(DeviceSettings.PREF_GLOVE_MODE, false)
|
||||
Display.GloveMode = mSharedPreferences.getBoolean(DeviceSettings.PREF_GLOVE_MODE, false)
|
||||
Log.i("SamsungParts", "Applied settings")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ package com.eurekateam.samsungextras
|
|||
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
|
|
@ -26,13 +26,13 @@ import androidx.preference.SwitchPreference
|
|||
import com.eurekateam.samsungextras.battery.BatteryActivity
|
||||
import com.eurekateam.samsungextras.flashlight.FlashLightActivity
|
||||
import com.eurekateam.samsungextras.fps.FPSInfoService
|
||||
import com.eurekateam.samsungextras.interfaces.Display.GloveMode
|
||||
import com.eurekateam.samsungextras.interfaces.Display.DT2W
|
||||
import com.eurekateam.samsungextras.interfaces.Display.GloveMode
|
||||
import com.eurekateam.samsungextras.speaker.ClearSpeakerActivity
|
||||
|
||||
class DeviceSettings : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
||||
|
||||
private lateinit var mPrefs : SharedPreferences
|
||||
private lateinit var mPrefs: SharedPreferences
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
System.loadLibrary("samsungparts_jni")
|
||||
setPreferencesFromResource(R.xml.preferences_samsung_parts, rootKey)
|
||||
|
|
@ -84,7 +84,7 @@ class DeviceSettings : PreferenceFragmentCompat(), Preference.OnPreferenceChange
|
|||
mPrefs.edit().putBoolean(PREF_KEY_FPS_INFO, mEnabled).apply()
|
||||
}
|
||||
PREF_DOUBLE_TAP -> {
|
||||
DT2W = value as Boolean
|
||||
DT2W = value as Boolean
|
||||
mPrefs.edit().putBoolean(PREF_DOUBLE_TAP, value).apply()
|
||||
}
|
||||
PREF_GLOVE_MODE -> {
|
||||
|
|
|
|||
|
|
@ -173,4 +173,4 @@ class SurfaceFlingerFPS private constructor() {
|
|||
mPrevPrevFlipCount = 0
|
||||
mPrevPrevCheckStartTime = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
package com.eurekateam.samsungextras.battery
|
||||
|
||||
import android.R.id.content
|
||||
import android.R.id.home
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import android.R.id.content
|
||||
import android.R.id.home
|
||||
|
||||
class BatteryActivity : FragmentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.eurekateam.samsungextras.battery
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.preference.ListPreference
|
||||
|
|
@ -22,14 +23,13 @@ import androidx.preference.Preference
|
|||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.preference.SwitchPreference
|
||||
import android.content.SharedPreferences
|
||||
import com.eurekateam.samsungextras.R
|
||||
import com.eurekateam.samsungextras.interfaces.Battery
|
||||
|
||||
class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
||||
private lateinit var mFastChargePref: SwitchPreference
|
||||
private lateinit var mChargePref: SwitchPreference
|
||||
private lateinit var mSharedPreferences : SharedPreferences
|
||||
private lateinit var mSharedPreferences: SharedPreferences
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.battery_settings)
|
||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
|
|
@ -39,7 +39,7 @@ class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
|||
mChargePref = findPreference(PREF_CHARGE)!!
|
||||
mChargePref.onPreferenceChangeListener = this
|
||||
mChargePref.isChecked = mSharedPreferences.getBoolean(PREF_CHARGE, true)
|
||||
val mBatteryInfo : ListPreference = findPreference(BATTERY_INFO)!!
|
||||
val mBatteryInfo: ListPreference = findPreference(BATTERY_INFO)!!
|
||||
val items = arrayOf<CharSequence>(
|
||||
Battery.getGeneralBatteryStats(1).toString() + " mAh",
|
||||
Battery.getGeneralBatteryStats(2).toString() + " %",
|
||||
|
|
@ -80,4 +80,4 @@ class BatteryFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
|||
const val PREF_CHARGE = "charge_pref"
|
||||
private const val BATTERY_INFO = "battery_info"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,9 @@
|
|||
|
||||
package com.eurekateam.samsungextras.dolby
|
||||
|
||||
import android.os.Bundle
|
||||
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import android.R.id.content
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
|
||||
class DolbyActivity : FragmentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ package com.eurekateam.samsungextras.dolby
|
|||
|
||||
import android.content.Context
|
||||
import android.media.audiofx.AudioEffect
|
||||
|
||||
import com.eurekateam.samsungextras.dolby.DolbyFragment.Companion.PREF_DOLBY_MODES
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
object DolbyCore {
|
||||
|
|
@ -53,9 +51,11 @@ object DolbyCore {
|
|||
val profile = getProfile()
|
||||
val resourceName = PREF_DOLBY_MODES.filter { it.value == profile }.keys.first()
|
||||
|
||||
return context.resources.getString(context.resources.getIdentifier(
|
||||
return context.resources.getString(
|
||||
context.resources.getIdentifier(
|
||||
resourceName, "string", context.packageName
|
||||
))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun setProfile(profile: Int) {
|
||||
|
|
|
|||
|
|
@ -16,24 +16,20 @@
|
|||
|
||||
package com.eurekateam.samsungextras.dolby
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.os.PerformanceHintManager
|
||||
import android.widget.Switch
|
||||
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
|
||||
import com.android.settingslib.widget.MainSwitchPreference
|
||||
import com.android.settingslib.widget.OnMainSwitchChangeListener
|
||||
import com.android.settingslib.widget.RadioButtonPreference
|
||||
|
||||
import com.eurekateam.samsungextras.R
|
||||
import android.content.SharedPreferences
|
||||
|
||||
class DolbyFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListener {
|
||||
|
||||
private lateinit var switchBar: MainSwitchPreference
|
||||
private lateinit var mSharedPreferences : SharedPreferences
|
||||
private lateinit var mSharedPreferences: SharedPreferences
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.dolby_settings)
|
||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
|
|
@ -69,15 +65,15 @@ class DolbyFragment : PreferenceFragmentCompat(), OnMainSwitchChangeListener {
|
|||
const val PREF_DOLBY_ENABLE = "dolby_enable"
|
||||
const val PREF_DOLBY_PROFILE = "dolby_profile"
|
||||
val PREF_DOLBY_MODES = mapOf(
|
||||
"dolby_profile_auto" to DolbyCore.PROFILE_AUTO,
|
||||
"dolby_profile_movie" to DolbyCore.PROFILE_MOVIE,
|
||||
"dolby_profile_music" to DolbyCore.PROFILE_MUSIC,
|
||||
"dolby_profile_voice" to DolbyCore.PROFILE_VOICE,
|
||||
"dolby_profile_game" to DolbyCore.PROFILE_GAME,
|
||||
"dolby_profile_off" to DolbyCore.PROFILE_OFF,
|
||||
"dolby_profile_game_1" to DolbyCore.PROFILE_GAME_1,
|
||||
"dolby_profile_game_2" to DolbyCore.PROFILE_GAME_2,
|
||||
"dolby_profile_spacial_audio" to DolbyCore.PROFILE_SPACIAL_AUDIO,
|
||||
"dolby_profile_auto" to DolbyCore.PROFILE_AUTO,
|
||||
"dolby_profile_movie" to DolbyCore.PROFILE_MOVIE,
|
||||
"dolby_profile_music" to DolbyCore.PROFILE_MUSIC,
|
||||
"dolby_profile_voice" to DolbyCore.PROFILE_VOICE,
|
||||
"dolby_profile_game" to DolbyCore.PROFILE_GAME,
|
||||
"dolby_profile_off" to DolbyCore.PROFILE_OFF,
|
||||
"dolby_profile_game_1" to DolbyCore.PROFILE_GAME_1,
|
||||
"dolby_profile_game_2" to DolbyCore.PROFILE_GAME_2,
|
||||
"dolby_profile_spacial_audio" to DolbyCore.PROFILE_SPACIAL_AUDIO,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package com.eurekateam.samsungextras.dolby
|
|||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.provider.SearchIndexableResource
|
||||
import android.provider.SearchIndexablesProvider
|
||||
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_CLASS_NAME
|
||||
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_ICON_RESID
|
||||
import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_INTENT_ACTION
|
||||
|
|
@ -30,6 +29,7 @@ import android.provider.SearchIndexablesContract.COLUMN_INDEX_XML_RES_RESID
|
|||
import android.provider.SearchIndexablesContract.INDEXABLES_RAW_COLUMNS
|
||||
import android.provider.SearchIndexablesContract.INDEXABLES_XML_RES_COLUMNS
|
||||
import android.provider.SearchIndexablesContract.NON_INDEXABLES_KEYS_COLUMNS
|
||||
import android.provider.SearchIndexablesProvider
|
||||
import com.eurekateam.samsungextras.R
|
||||
|
||||
class DolbySearchIndexablesProvider : SearchIndexablesProvider() {
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@ package com.eurekateam.samsungextras.dolby
|
|||
|
||||
import android.service.quicksettings.Tile
|
||||
import android.service.quicksettings.TileService
|
||||
|
||||
import androidx.preference.PreferenceManager
|
||||
|
||||
import com.eurekateam.samsungextras.dolby.DolbyFragment.Companion.PREF_DOLBY_ENABLE
|
||||
|
||||
class DolbyTile : TileService() {
|
||||
|
|
@ -41,8 +39,8 @@ class DolbyTile : TileService() {
|
|||
isEnabled = !isEnabled
|
||||
DolbyCore.setEnabled(isEnabled)
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.edit()
|
||||
.putBoolean(PREF_DOLBY_ENABLE, isEnabled)
|
||||
.apply()
|
||||
.edit()
|
||||
.putBoolean(PREF_DOLBY_ENABLE, isEnabled)
|
||||
.apply()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@
|
|||
package com.eurekateam.samsungextras.flashlight
|
||||
|
||||
import android.R.id.content
|
||||
import android.R.id.home
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import android.R.id.home
|
||||
|
||||
class FlashLightActivity : FragmentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
|
|||
|
|
@ -15,20 +15,19 @@
|
|||
*/
|
||||
package com.eurekateam.samsungextras.flashlight
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.PerformanceHintManager
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import android.content.SharedPreferences
|
||||
import com.eurekateam.samsungextras.R
|
||||
import com.eurekateam.samsungextras.interfaces.Flashlight
|
||||
import com.eurekateam.samsungextras.preferences.CustomSeekBarPreference
|
||||
|
||||
class FlashLightFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
|
||||
private lateinit var mFlashLightPref: CustomSeekBarPreference
|
||||
private lateinit var mSharedPreferences : SharedPreferences
|
||||
private lateinit var mSharedPreferences: SharedPreferences
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
addPreferencesFromResource(R.xml.flashlight_settings)
|
||||
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
|
|
|
|||
|
|
@ -78,8 +78,11 @@ open class FPSInfoService : Service() {
|
|||
val y = mPaddingTop - mAscent.toInt()
|
||||
val s = fPSInfoString
|
||||
canvas.drawText(
|
||||
s, (LEFT - mPaddingLeft - mMaxWidth).toFloat(), (
|
||||
y - 1).toFloat(), mOnlinePaint
|
||||
s, (LEFT - mPaddingLeft - mMaxWidth).toFloat(),
|
||||
(
|
||||
y - 1
|
||||
).toFloat(),
|
||||
mOnlinePaint
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +157,7 @@ open class FPSInfoService : Service() {
|
|||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY,
|
||||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
|
||||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
|
||||
PixelFormat.TRANSLUCENT
|
||||
)
|
||||
params.y = 50
|
||||
|
|
@ -239,11 +242,11 @@ open class FPSInfoService : Service() {
|
|||
mCurFPSThread = null
|
||||
}
|
||||
|
||||
fun getRunning() : Boolean{
|
||||
fun getRunning(): Boolean {
|
||||
return mRunning
|
||||
}
|
||||
companion object {
|
||||
private var surfaceFlingerFPS: SurfaceFlingerFPS? = null
|
||||
private var mRunning : Boolean = false
|
||||
private var mRunning: Boolean = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import android.service.quicksettings.TileService
|
|||
|
||||
// TODO: Add FPS drawables
|
||||
class FPSTileService : TileService() {
|
||||
private lateinit var fpsinfo : Intent
|
||||
private lateinit var fpsinfo: Intent
|
||||
private var isShowing = false
|
||||
override fun onStartListening() {
|
||||
super.onStartListening()
|
||||
|
|
|
|||
|
|
@ -25,4 +25,4 @@ object Battery {
|
|||
external get
|
||||
|
||||
external fun getGeneralBatteryStats(id: Int): Int
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@ package com.eurekateam.samsungextras.interfaces
|
|||
object Flashlight {
|
||||
external fun setFlash(value: Int)
|
||||
external fun getFlash(isA10: Int): Int
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,13 +34,18 @@ import androidx.preference.PreferenceViewHolder
|
|||
import androidx.preference.R
|
||||
|
||||
open class CustomSeekBarPreference @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = TypedArrayUtils.getAttr(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = TypedArrayUtils.getAttr(
|
||||
context,
|
||||
R.attr.preferenceStyle,
|
||||
android.R.attr.preferenceStyle
|
||||
), defStyleRes: Int = 0
|
||||
) : Preference(context, attrs, defStyleAttr, defStyleRes), OnSeekBarChangeListener,
|
||||
View.OnClickListener, OnLongClickListener {
|
||||
),
|
||||
defStyleRes: Int = 0
|
||||
) : Preference(context, attrs, defStyleAttr, defStyleRes),
|
||||
OnSeekBarChangeListener,
|
||||
View.OnClickListener,
|
||||
OnLongClickListener {
|
||||
private val TAG: String = javaClass.name
|
||||
private var mInterval = 1
|
||||
private var mShowSign = false
|
||||
|
|
@ -114,8 +119,10 @@ open class CustomSeekBarPreference @JvmOverloads constructor(
|
|||
mValueTextView!!.text = context.getString(
|
||||
com.eurekateam.samsungextras.R.string.custom_seekbar_value,
|
||||
if (!mTrackingTouch || mContinuousUpdates) getTextValue(mValue) +
|
||||
(if (mDefaultValueExists && mValue == mDefaultValue) " (" +
|
||||
context.getString(com.eurekateam.samsungextras.R.string.custom_seekbar_default_value) + ")" else "") else getTextValue(
|
||||
(
|
||||
if (mDefaultValueExists && mValue == mDefaultValue) " (" +
|
||||
context.getString(com.eurekateam.samsungextras.R.string.custom_seekbar_default_value) + ")" else ""
|
||||
) else getTextValue(
|
||||
mTrackingValue
|
||||
)
|
||||
)
|
||||
|
|
@ -215,7 +222,8 @@ open class CustomSeekBarPreference @JvmOverloads constructor(
|
|||
if (mMaxValue - mMinValue > mInterval * 2 && mMaxValue + mMinValue < mValue * 2) Math.floorDiv(
|
||||
mMaxValue + mMinValue,
|
||||
2
|
||||
) else mMinValue, true
|
||||
) else mMinValue,
|
||||
true
|
||||
)
|
||||
}
|
||||
com.eurekateam.samsungextras.R.id.plus -> {
|
||||
|
|
@ -223,7 +231,8 @@ open class CustomSeekBarPreference @JvmOverloads constructor(
|
|||
if (mMaxValue - mMinValue > mInterval * 2 && mMaxValue + mMinValue > mValue * 2) -1 * Math.floorDiv(
|
||||
-1 * (mMaxValue + mMinValue),
|
||||
2
|
||||
) else mMaxValue, true
|
||||
) else mMaxValue,
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,4 +102,4 @@ class ClearSpeakerFragment : PreferenceFragmentCompat(), Preference.OnPreference
|
|||
private val TAG = ClearSpeakerFragment::class.java.simpleName
|
||||
private const val PREF_CLEAR_SPEAKER = "clear_speaker_pref"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue