- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
package com.shivamkapila.echo.fragments
import android.app.Activity
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.media.AudioManager
import android.media.MediaPlayer
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.support.v4.app.Fragment
import android.support.v4.content.ContextCompat
import android.util.Log
import android.view.*
import android.widget.ImageButton
import android.widget.SeekBar
import android.widget.TextView
import android.widget.Toast
import com.cleveroad.audiovisualization.AudioVisualization
import com.cleveroad.audiovisualization.DbmHandler
import com.cleveroad.audiovisualization.GLAudioVisualizationView
import com.shivamkapila.echo.CurrentSongHelper
import com.shivamkapila.echo.R
import com.shivamkapila.echo.Songs
import com.shivamkapila.echo.activities.MainActivity
import com.shivamkapila.echo.databases.EchoDatabase
import com.shivamkapila.echo.utils.SeekBarController
import java.util.*
import java.util.concurrent.TimeUnit
class SongPlayingFragment : Fragment() {
object Statified {
var myActivity: Activity? = null
var mediaPlayer: MediaPlayer? = null
var startTimeNext: TextView? = null
var endTimeNext: TextView? = null
var playPauseImageButton: ImageButton? = null
var previousImageButton: ImageButton? = null
var nextImageButton: ImageButton? = null
var loopImageButton: ImageButton? = null
var seekbar: SeekBar? = null
var songArtistView: TextView? = null
var songTitleView: TextView? = null
var shuffleImageButton: ImageButton? = null
var check: Boolean = true
var _currentPosition: Int = 0
var fetchSongs: ArrayList<Songs>? = null
var currentSongHelper: CurrentSongHelper? = null
var audioVisualization: AudioVisualization? = null
var glView: GLAudioVisualizationView? = null
var fab: ImageButton? = null
var favoriteContent: EchoDatabase? = null
var counter: Int = 0
var mSensorManager: SensorManager? = null
var mSensorListener: SensorEventListener? = null
var MY_PREFS_NAME = "ShakeFeature"
var back: String? = null
var updateSongTime = object : Runnable {
override fun run() {
try {
val getCurrent = Statified.mediaPlayer?.getCurrentPosition()
startTimeNext?.setText(String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(getCurrent?.toLong() as Long),
TimeUnit.MILLISECONDS.toSeconds(getCurrent?.toLong() as Long) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(getCurrent?.toLong() as Long))))
seekbar?.setProgress(getCurrent?.toInt() as Int)
Statified.check = true
Handler().postDelayed(this, 1000)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}
object Staticated {
var MY_PREFS_SHUFFLE = "Shuffle feature"
var MY_PREFS_LOOP = "Loop feature"
fun onSongComplete() {
if (Statified.currentSongHelper?.isShuffle as Boolean) {
playNext("PlayNextLikeNormalShuffle")
Statified.currentSongHelper?.isPlaying = true
} else {
if (Statified.currentSongHelper?.isLoop as Boolean) {
Statified.currentSongHelper?.isPlaying = true
var nextSong = Statified.fetchSongs?.get(Statified._currentPosition)
Statified.currentSongHelper?.songPath = nextSong?.songData
Statified.currentSongHelper?.songTitle = nextSong?.songTitle
Statified.currentSongHelper?.songArtist = nextSong?.artist
Statified.currentSongHelper?.songId = nextSong?.songID as Long
Statified.currentSongHelper?.currentPosition = Statified._currentPosition
updateTextViews(Statified.currentSongHelper?.songTitle as String, Statified.currentSongHelper?.songArtist as String)
Statified.mediaPlayer?.reset()
try {
Statified.mediaPlayer?.setDataSource(Statified.myActivity, Uri.parse(Statified.currentSongHelper?.songPath) as Uri)
Statified.mediaPlayer?.prepare()
Statified.mediaPlayer?.start()
processInformation(Statified.mediaPlayer as MediaPlayer)
} catch (e: Exception) {
e.printStackTrace()
}
} else {
playNext("PlayNextNormal")
Statified.currentSongHelper?.isPlaying = true
}
}
if (Statified.favoriteContent?.checkifIdExists(Statified.currentSongHelper?.songId?.toInt() as Int) as Boolean) {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_on))
} else {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_off))
}
}
fun updateTextViews(songTitle: String, songArtist: String) {
var songTitleUpdated = songTitle
var songArtistUpdated = songArtist
if (songTitle.equals("<unknown>", true)) {
songTitleUpdated = "unknown"
}
if (songArtist.equals("<unknown>", true)) {
songArtistUpdated = "unknown"
}
Statified.songTitleView?.setText(songTitleUpdated)
Statified.songArtistView?.setText(songArtistUpdated)
}
fun processInformation(mediaPlayer: MediaPlayer) {
val finalTime = mediaPlayer.duration
val startTime = mediaPlayer.currentPosition
Statified.seekbar?.max = finalTime
Statified.startTimeNext?.setText(String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(startTime.toLong()),
TimeUnit.MILLISECONDS.toSeconds(startTime.toLong()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(startTime.toLong()))))
Statified.endTimeNext?.setText(String.format("%02d:%02d",
TimeUnit.MILLISECONDS.toMinutes(finalTime.toLong()),
TimeUnit.MILLISECONDS.toSeconds(finalTime.toLong()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(finalTime.toLong()))))
Statified.seekbar?.setProgress(startTime)
Handler().postDelayed(Statified.updateSongTime, 1000)
}
fun playNext(check: String) {
if (check.equals("PlayNextNormal", true)) {
Statified._currentPosition = Statified._currentPosition + 1
} else if (check.equals("PlayNextLikeNormalShuffle", true)) {
var randomObject = Random()
var randomPosition = randomObject.nextInt(Statified.fetchSongs?.size?.plus(1) as Int)
Statified._currentPosition = randomPosition
}
if (Statified._currentPosition == Statified.fetchSongs?.size) {
Statified._currentPosition = 0
}
Statified.currentSongHelper?.isLoop = false
var nextSong = Statified.fetchSongs?.get(Statified._currentPosition)
Statified.currentSongHelper?.songPath = nextSong?.songData
Statified.currentSongHelper?.songTitle = nextSong?.songTitle
Statified.currentSongHelper?.songArtist = nextSong?.artist
Statified.currentSongHelper?.songId = nextSong?.songID as Long
Statified.currentSongHelper?.currentPosition = Statified._currentPosition
var editorLoop = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_LOOP, Context.MODE_PRIVATE)?.edit()
Statified.currentSongHelper?.isLoop = false
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
editorLoop?.putBoolean("feature", false)
editorLoop?.apply()
if (Statified.currentSongHelper?.isPlaying as Boolean) {
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.pause_icon)
} else {
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.play_icon)
}
updateTextViews(Statified.currentSongHelper?.songTitle as String, Statified.currentSongHelper?.songArtist as String)
Statified.mediaPlayer?.reset()
try {
Statified.mediaPlayer?.setDataSource(Statified.myActivity, Uri.parse(Statified.currentSongHelper?.songPath) as Uri)
Statified.mediaPlayer?.prepare()
Statified.mediaPlayer?.start()
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
processInformation(Statified.mediaPlayer as MediaPlayer)
} catch (e: Exception) {
e.printStackTrace()
}
if (Statified.favoriteContent?.checkifIdExists(Statified.currentSongHelper?.songId?.toInt() as Int) as Boolean) {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_on))
} else {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_off))
}
}
fun playPrevious() {
Statified._currentPosition = Statified._currentPosition - 1
if (Statified._currentPosition == -1) {
Statified._currentPosition = 0
}
if (Statified.currentSongHelper?.isPlaying as Boolean) {
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.pause_icon)
} else {
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.play_icon)
}
Statified.currentSongHelper?.isLoop = false
var nextSong = Statified.fetchSongs?.get(Statified._currentPosition)
Statified.currentSongHelper?.songPath = nextSong?.songData
Statified.currentSongHelper?.songTitle = nextSong?.songTitle
Statified.currentSongHelper?.songArtist = nextSong?.artist
Statified.currentSongHelper?.songId = nextSong?.songID as Long
Statified.currentSongHelper?.currentPosition = Statified._currentPosition
Staticated.updateTextViews(Statified.currentSongHelper?.songTitle as String, Statified.currentSongHelper?.songArtist as String)
Statified.mediaPlayer?.reset()
try {
Statified.mediaPlayer?.setDataSource(Statified.myActivity, Uri.parse(Statified.currentSongHelper?.songPath) as Uri)
Statified.mediaPlayer?.prepare()
Statified.mediaPlayer?.start()
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
processInformation(Statified.mediaPlayer as MediaPlayer)
} catch (e: Exception) {
e.printStackTrace()
}
if (Statified.favoriteContent?.checkifIdExists(Statified.currentSongHelper?.songId?.toInt() as Int) as Boolean) {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_on))
} else {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_off))
}
}
}
var mAcceleration: Float = 0f
var mAccelerationCurrent: Float = 0f
var mAccelerationLast: Float = 0f
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
val view = inflater!!.inflate(R.layout.fragment_song_playing, container, false)
setHasOptionsMenu(true)
activity.title = "Now Playing"
Statified.seekbar = view?.findViewById(R.id.seekBar)
Statified.startTimeNext = view?.findViewById(R.id.startTime)
Statified.endTimeNext = view?.findViewById(R.id.endTime)
Statified.playPauseImageButton = view?.findViewById(R.id.playPauseButton)
Statified.nextImageButton = view?.findViewById(R.id.nextButton)
Statified.previousImageButton = view?.findViewById(R.id.previousButton)
Statified.loopImageButton = view?.findViewById(R.id.loopButton)
Statified.shuffleImageButton = view?.findViewById(R.id.shuffleButton)
Statified.songArtistView = view?.findViewById(R.id.songArtist)
Statified.songTitleView = view?.findViewById(R.id.songTitle)
Statified.glView = view?.findViewById(R.id.visualizer_view)
Statified.fab = view?.findViewById(R.id.favoriteIcon)
Statified.fab?.alpha = 0.8f
return view
}
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Statified.audioVisualization = Statified.glView as AudioVisualization
}
override fun onAttach(context: Context?) {
super.onAttach(context)
Statified.myActivity = context as Activity
}
override fun onAttach(activity: Activity?) {
super.onAttach(activity)
Statified.myActivity = activity
}
override fun onResume() {
super.onResume()
Statified.audioVisualization?.onResume()
Statified.mSensorManager?.registerListener(Statified.mSensorListener, Statified.mSensorManager?.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL)
}
override fun onPause() {
Statified.audioVisualization?.onPause()
Statified.mSensorManager?.unregisterListener(Statified.mSensorListener)
super.onPause()
}
override fun onDestroyView() {
super.onDestroyView()
Statified.audioVisualization?.release()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
Statified.currentSongHelper = CurrentSongHelper()
Statified.currentSongHelper?.isPlaying = true
Statified.currentSongHelper?.isLoop = false
Statified.currentSongHelper?.isShuffle = false
Statified.favoriteContent = EchoDatabase(Statified.myActivity)
var path: String? = null
var _songTitle: String? = null
var _songArtist: String? = null
var songId: Long = 0
var fromFavBottomBar: String? = null
var fromMainScreenBottomBar: String? = null
try {
path = arguments.getString("path")
_songTitle = arguments.getString("songTitle")
_songArtist = arguments.getString("songArtist")
songId = arguments.getInt("songId").toLong()
Statified._currentPosition = arguments.getInt("songPosition")
Statified.fetchSongs = arguments.getParcelableArrayList("songData")
Statified.currentSongHelper?.songPath = path
Statified.currentSongHelper?.songTitle = _songTitle
Statified.currentSongHelper?.songArtist = _songArtist
Statified.currentSongHelper?.songId = songId
Statified.currentSongHelper?.currentPosition = Statified._currentPosition
fromFavBottomBar = arguments.get("FavBottomBar") as? String
fromMainScreenBottomBar = arguments.get("MainScreenBottomBar") as? String
Staticated.updateTextViews(Statified.currentSongHelper?.songTitle as String, Statified.currentSongHelper?.songArtist as String)
} catch (e: Exception) {
e.printStackTrace()
}
if (fromFavBottomBar != null) {
Statified.mediaPlayer = FavoriteFragment.Statified.mediaPlayer
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
} else if (fromMainScreenBottomBar != null) {
Statified.mediaPlayer = MainScreenFragment.Statified.mediaPlayer
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
} else {
Statified.mediaPlayer = MediaPlayer()
Statified.mediaPlayer?.setAudioStreamType(AudioManager.STREAM_MUSIC)
try {
Statified.mediaPlayer?.setDataSource(Statified.myActivity, Uri.parse(path) as Uri)
Statified.mediaPlayer?.prepare()
} catch (e: Exception) {
e.printStackTrace()
}
Statified.mediaPlayer?.start()
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
}
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
if (Statified.mediaPlayer?.isPlaying as Boolean) {
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.pause_icon)
} else {
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.play_icon)
}
Statified.mediaPlayer?.setOnCompletionListener {
Staticated.onSongComplete()
}
clickHandler()
var visualizationHandler = DbmHandler.Factory.newVisualizerHandler(Statified.myActivity as Context, 0)
Statified.audioVisualization?.linkTo(visualizationHandler)
var prefsForShuffle = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_SHUFFLE, Context.MODE_PRIVATE)
var isShuffleAllowed = prefsForShuffle?.getBoolean("feature", false)
if (isShuffleAllowed as Boolean) {
Statified.currentSongHelper?.isShuffle = true
Statified.currentSongHelper?.isLoop = false
Statified.shuffleImageButton?.setBackgroundResource(R.drawable.shuffle_icon)
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
} else {
Statified.currentSongHelper?.isShuffle = false
Statified.shuffleImageButton?.setBackgroundResource(R.drawable.shuffle_white_icon)
}
var prefsForLoop = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_LOOP, Context.MODE_PRIVATE)
var isLoopAllowed = prefsForLoop?.getBoolean("feature", false)
if (isLoopAllowed as Boolean) {
Statified.currentSongHelper?.isShuffle = false
Statified.currentSongHelper?.isLoop = true
Statified.shuffleImageButton?.setBackgroundResource(R.drawable.shuffle_white_icon)
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_icon)
} else {
Statified.currentSongHelper?.isLoop = false
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
}
if (Statified.favoriteContent?.checkifIdExists(Statified.currentSongHelper?.songId?.toInt() as Int) as Boolean) {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_on))
} else {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_off))
}
seekbarHandler()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Statified.mSensorManager = Statified.myActivity?.getSystemService(Context.SENSOR_SERVICE) as SensorManager
mAcceleration = 0.0f
mAccelerationCurrent = SensorManager.GRAVITY_EARTH
mAccelerationLast = SensorManager.GRAVITY_EARTH
bindShakeListener()
}
override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) {
menu?.clear()
inflater?.inflate(R.menu.song_playing_menu, menu)
super.onCreateOptionsMenu(menu, inflater)
}
override fun onPrepareOptionsMenu(menu: Menu?) {
super.onPrepareOptionsMenu(menu)
val item: MenuItem? = menu?.findItem(R.id.action_redirect)
item?.isVisible = true
val item2: MenuItem? = menu?.findItem(R.id.action_sort)
item2?.isVisible = false
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.action_redirect -> {
var pos = 0
if (Statified.back.equals("Favorite", true)) {
pos = 0
}
if (Statified.back.equals("MainScreen", true)) {
pos = 1
}
if (pos == 1) {
val mainScreenFragment = MainScreenFragment()
(context as MainActivity).supportFragmentManager
.beginTransaction()
.replace(R.id.details_fragment, mainScreenFragment)
.commit()
}
if (pos == 0) {
val favoriteFragment = FavoriteFragment()
(context as MainActivity).supportFragmentManager
.beginTransaction()
.replace(R.id.details_fragment, favoriteFragment)
.commit()
}
return false
}
}
return false
}
fun clickHandler() {
Statified.fab?.setOnClickListener({
if (Statified.favoriteContent?.checkifIdExists(Statified.currentSongHelper?.songId?.toInt() as Int) as Boolean) {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_off))
Statified.favoriteContent?.deleteFavourite(Statified.currentSongHelper?.songId?.toInt() as Int)
Toast.makeText(Statified.myActivity, "Removed from favorites", Toast.LENGTH_SHORT).show()
} else {
Statified.fab?.setImageDrawable(ContextCompat.getDrawable(Statified.myActivity, R.drawable.favorite_on))
Statified.favoriteContent?.storeAsFavorite(Statified.currentSongHelper?.songId?.toInt(), Statified.currentSongHelper?.songArtist,
Statified.currentSongHelper?.songTitle, Statified.currentSongHelper?.songPath)
Toast.makeText(Statified.myActivity, "Added to Favorites", Toast.LENGTH_SHORT).show()
}
})
Statified.shuffleImageButton?.setOnClickListener({
var editorShuffle = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_SHUFFLE, Context.MODE_PRIVATE)?.edit()
var editorLoop = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_LOOP, Context.MODE_PRIVATE)?.edit()
if (Statified.currentSongHelper?.isShuffle as Boolean) {
Statified.currentSongHelper?.isShuffle = false
Statified.shuffleImageButton?.setBackgroundResource(R.drawable.shuffle_white_icon)
editorShuffle?.putBoolean("feature", false)
editorShuffle?.apply()
} else {
Statified.currentSongHelper?.isLoop = false
Statified.currentSongHelper?.isShuffle = true
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
Statified.shuffleImageButton?.setBackgroundResource(R.drawable.shuffle_icon)
editorShuffle?.putBoolean("feature", true)
editorShuffle?.apply()
editorLoop?.putBoolean("feature", false)
editorLoop?.apply()
}
})
Statified.nextImageButton?.setOnClickListener({
Statified.currentSongHelper?.isPlaying = true
if (Statified.currentSongHelper?.isLoop as Boolean) {
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
}
if (Statified.currentSongHelper?.isShuffle as Boolean) {
Staticated.playNext("PlayNextLikeNormalShuffle")
} else {
Staticated.playNext("PlayNextNormal")
}
})
Statified.previousImageButton?.setOnClickListener({
Statified.currentSongHelper?.isPlaying = true
if (Statified.currentSongHelper?.isLoop as Boolean) {
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
}
Staticated.playPrevious()
})
Statified.loopImageButton?.setOnClickListener({
var editorShuffle = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_SHUFFLE, Context.MODE_PRIVATE)?.edit()
var editorLoop = Statified.myActivity?.getSharedPreferences(Staticated.MY_PREFS_LOOP, Context.MODE_PRIVATE)?.edit()
if (Statified.currentSongHelper?.isLoop as Boolean) {
Statified.currentSongHelper?.isLoop = false
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
editorLoop?.putBoolean("feature", false)
editorLoop?.apply()
} else {
Statified.currentSongHelper?.isLoop = true
Statified.currentSongHelper?.isShuffle = false
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_icon)
Statified.shuffleImageButton?.setBackgroundResource(R.drawable.shuffle_white_icon)
editorLoop?.putBoolean("feature", true)
editorLoop?.apply()
editorShuffle?.putBoolean("feature", false)
editorShuffle?.apply()
}
})
Statified.playPauseImageButton?.setOnClickListener({
if (Statified.mediaPlayer?.isPlaying as Boolean) {
Statified.mediaPlayer?.pause()
Statified.currentSongHelper?.isPlaying = false
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.play_icon)
} else {
Statified.mediaPlayer?.start()
Statified.currentSongHelper?.isPlaying = true
Statified.playPauseImageButton?.setBackgroundResource(R.drawable.pause_icon)
Staticated.processInformation(Statified.mediaPlayer as MediaPlayer)
}
})
}
fun bindShakeListener() {
Statified.mSensorListener = object : SensorEventListener {
override fun onAccuracyChanged(p0: Sensor?, p1: Int) {
}
override fun onSensorChanged(p0: SensorEvent) {
val x = p0.values[0]
val y = p0.values[1]
val z = p0.values[2]
mAccelerationLast = mAccelerationCurrent
mAccelerationCurrent = Math.sqrt(((x * x + y * y + z * z).toDouble())).toFloat()
val delta = mAccelerationCurrent - mAccelerationLast
mAcceleration = mAcceleration * 0.9f + delta
if (mAcceleration > 12) {
println("11111")
val prefs = Statified.myActivity?.getSharedPreferences(Statified.MY_PREFS_NAME, Context.MODE_PRIVATE)
val isAllowed = prefs?.getBoolean("feature", false)
if (isAllowed as Boolean && Statified.check == true) {
Statified.currentSongHelper?.isPlaying = true
if (Statified.currentSongHelper?.isLoop as Boolean) {
Statified.loopImageButton?.setBackgroundResource(R.drawable.loop_white_icon)
}
if (Statified.currentSongHelper?.isShuffle as Boolean) {
Staticated.playNext("PlayNextLikeNormalShuffle")
} else {
Staticated.playNext("PlayNextNormal")
}
Statified.check = false
}
}
}
}
}
fun seekbarHandler() {
val seekbarListener = SeekBarController()
Statified.seekbar?.setOnSeekBarChangeListener(seekbarListener)
}
最佳答案
让我们试试这个,
这是 java 代码只要你可以转换成 kotlin 就可以正常工作。
在你的 Activity 中
声明一个静态变量
public static boolean IS_MUSIC_SCREEN = false;
实现这个方法
@Override
public void onBackPressed() {
if (IS_MUSIC_SCREEN) {
IS_MUSIC_SCREEN=false;
startActivity(new Activity(this,MainActivity.class));
}else{
super.onBackPressed();
}
}
在你的 fragment 中,
IS_MUSIC_SCREEN在onCreateView中设置为true
像这样,
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_song_playing, container, false);
MainActivity.IS_MUSIC_SCREEN =true;
return view;
}
关于android - 我希望当我在 SongPlayingFragment 中按下硬件后退按钮时,我应该返回到主屏幕。我该怎么做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51154103/
我刚刚意识到二进制编译器会将源代码转换为目标平台的二进制文件。有点明显...但如果编译器以这种方式工作,那么同一个编译器如何用于不同的系统,如 x86、ARM、MIPS 等? 难道他们不应该“知道”硬
在我的 SDL 游戏中,出于游戏玩法和性能原因,我希望保留固定的游戏区域分辨率。 我想做的是有一个小分辨率(例如 320 * 240),并且在调整窗口大小时/切换到全屏模式时让 SDL/显卡缩放每个像
我正在使用这些方法来激活 SurFaceView 上的触摸焦点 private SurfaceView surfaceiew; private CameraSource camSource; priv
您好,当我从硬件菜单更改设备时,我遇到了这个奇怪的问题,但我想我可能遗漏了一些简单的东西。 我的 View Controller 中有这段代码: - (void)touchesBegan:(NSSet
编写一个名为 weird() 的函数,它将三个字符串作为参数并向后打印最长的一个。 (在平局的情况下,应该选择较早的参数字符串。 函数调用: weird("I", "Love", "Python")
您好,我正在尝试设置 hadoop 环境。简而言之,我要解决的问题涉及数十亿个大小为几 MB 的 XML 文件,使用 HIVE 从中提取相关信息,并对这些信息进行一些分析工作。我知道这在 hadoop
我知道 Phidgets,但是,我正在寻找可以与 C# 接口(interface)的一些其他类型的硬件。 谁有好东西? 最佳答案 查看 Netduino .它基于 Arduino,但使用 .Net
说一个函数(例如模乘法、正弦函数)是在硬件而不是软件中实现是什么意思? 最佳答案 在硬件中实现意味着电路(通过逻辑门等)可以执行操作。 例如,在 ALU 中,处理器在物理上能够将一个字节加到另一个字节
我需要编写一个程序,在可能状态的大空间中执行并行搜索,在此过程中发现了新区域(并开始了他们的探索),并且由于在其他地方获得的中间结果消除了可能性,因此提前终止了对某些区域的探索在其中发现新的有用结果。
我们需要通过带有硬件 token 的 EV 代码对 InstallShield 2013 Express 的安装进行签名,但是无法导出私钥证书文件,因此唯一的方法是使用 DigiCertUtil 工具
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 2 年前。 Improve this ques
我考虑从库中丢弃处理大端情况的代码,如果平台不是小端,则在初始化期间简单地抛出一个异常。如果我们限制为,我无法想象会有任何大端硬件 托管任何网站的典型服务器硬件 服务器根据开放计算项目规范 所有常见的
我知道这可以做到,但找不到交换目标调试设备的地方。我现在正在使用模拟器,但想切换到设备,反之亦然。谁能指出我正确的方向? 谢谢。 最佳答案 像这样.. 右键单击 PROJECT--->Run As--
我正在尝试创建一个监听音量键事件的服务。 每当按下音量键时,服务应向号码发送短信,但我无法检测到音量键事件。 最佳答案 您可以使用 OnKeyListener可以检测按键事件(包括音量键)。您可以找到
谁能解释一下中断如何从最低层(硬件)传递到应用程序。 所以在下图中我知道处理器之后发生了什么。 但是我想要从键盘按下到处理器的中断过程在硬件中发生了什么,例如它如何传递扫描代码,中断 Controll
我的任务是构建一个应用程序,其中业务用户将定义一些数据操作和处理规则(例如,取一个数值并将其平均分配给根据中指定的条件选择的多个记录)规则)。 每月必须运行一个批处理应用程序,以便根据定义的规则处理大
所以这是我的愚蠢问题: PGP/GPGP可以用来对文本进行签名,其他的使用公钥来验证。 比方说,非对称密码算法处理空间。 有没有什么算法可以处理时间? 例如在 2011-10-10 10:10:10
使用 nvcc 编译 CUDA 程序是否需要安装支持 CUDA 的显卡(在 Linux 中)?或者可以在任何地方编译程序并且只能在这样的系统上运行? 最佳答案 不,编译不需要显卡。 您甚至不需要一个来
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我有一个奇怪的问题,但我对这个话题很感兴趣。 是否有可能直接访问当前基于 x64 的计算机的硬件,而无需使用某种 HAL(硬件抽象层)或其他操作系统(udev、upower 等)的附属物?我不是在谈论
我是一名优秀的程序员,十分优秀!