mirror of
https://github.com/chararomandroid/android_device_samsung_a20
synced 2026-08-24 04:45:32 -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
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue