change MainActivity to waterfall layout

dev
xufuji456 3 years ago
parent e0260de888
commit 92f1800c43
  1. 2
      app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt
  2. 71
      app/src/main/java/com/frank/ffmpeg/activity/MainActivity.kt
  3. 72
      app/src/main/java/com/frank/ffmpeg/adapter/WaterfallAdapter.kt
  4. 89
      app/src/main/res/layout/activity_main.xml
  5. 18
      app/src/main/res/layout/item_waterfall.xml

@ -38,7 +38,7 @@ class EqualizerActivity : BaseActivity(), OnSeeBarListener {
private var mAudioPlayer: AudioPlayer? = null
private var visualizerView: VisualizerView? = null
private var equalizerAdapter: EqualizerAdapter? = null
private var audioPath = Environment.getExternalStorageDirectory().path + "/boy.mp3"
private var audioPath = Environment.getExternalStorageDirectory().path + "/know_play.mp3"
override val layoutId: Int
get() = R.layout.activity_equalizer

@ -3,8 +3,12 @@ package com.frank.ffmpeg.activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.frank.ffmpeg.R
import com.frank.ffmpeg.adapter.WaterfallAdapter
import com.frank.ffmpeg.listener.OnItemClickListener
/**
* The main entrance of all Activity
@ -18,49 +22,66 @@ class MainActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initViewsWithClick(
R.id.btn_audio,
R.id.btn_video,
R.id.btn_media,
R.id.btn_play,
R.id.btn_push,
R.id.btn_live,
R.id.btn_filter,
R.id.btn_preview,
R.id.btn_probe,
R.id.btn_audio_effect
)
initView()
}
override fun onViewClick(view: View) {
private fun initView() {
val list = listOf(
getString(R.string.audio_handle),
getString(R.string.video_handle),
getString(R.string.media_handle),
getString(R.string.video_push),
getString(R.string.video_live),
getString(R.string.video_filter),
getString(R.string.video_preview),
getString(R.string.media_probe),
getString(R.string.audio_effect))
val viewWaterfall: RecyclerView = findViewById(R.id.list_main_item)
val layoutManager = StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
viewWaterfall.layoutManager = layoutManager
val adapter = WaterfallAdapter(list)
adapter.setOnItemClickListener(object : OnItemClickListener {
override fun onItemClick(position: Int) {
doClick(position)
}
})
viewWaterfall.adapter = adapter
}
private fun doClick(pos: Int) {
val intent = Intent()
when (view.id) {
R.id.btn_audio//handle audio
when (pos) {
0 //handle audio
-> intent.setClass(this@MainActivity, AudioHandleActivity::class.java)
R.id.btn_video//handle video
1 //handle video
-> intent.setClass(this@MainActivity, VideoHandleActivity::class.java)
R.id.btn_media//handle media
2 //handle media
-> intent.setClass(this@MainActivity, MediaHandleActivity::class.java)
R.id.btn_play//media play
-> intent.setClass(this@MainActivity, MediaPlayerActivity::class.java)
R.id.btn_push//pushing
3 //pushing
-> intent.setClass(this@MainActivity, PushActivity::class.java)
R.id.btn_live//realtime living with rtmp stream
4 //realtime living with rtmp stream
-> intent.setClass(this@MainActivity, LiveActivity::class.java)
R.id.btn_filter//filter effect
5 //filter effect
-> intent.setClass(this@MainActivity, FilterActivity::class.java)
R.id.btn_preview//preview thumbnail
6 //preview thumbnail
-> intent.setClass(this@MainActivity, VideoPreviewActivity::class.java)
R.id.btn_probe//probe media format
7 //probe media format
-> intent.setClass(this@MainActivity, ProbeFormatActivity::class.java)
R.id.btn_audio_effect//audio effect
8 //audio effect
-> intent.setClass(this@MainActivity, AudioEffectActivity::class.java)
// -> intent.setClass(this@MainActivity, MediaPlayerActivity::class.java)
else -> {
}
}
startActivity(intent)
}
override fun onViewClick(view: View) {
}
override fun onSelectedFile(filePath: String) {
}

@ -0,0 +1,72 @@
package com.frank.ffmpeg.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.frank.ffmpeg.R
import com.frank.ffmpeg.listener.OnItemClickListener
import java.util.*
/**
* waterfall layout adapter
* Created by frank on 2021/9/27.
*/
class WaterfallAdapter() : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
companion object {
const val DEFAULT_MARGIN = 5
}
private var itemList: List<String>? = null
private var heightList: ArrayList<Int>? = null
private var onItemClickListener: OnItemClickListener? = null
constructor(itemList: List<String>?) : this() {
this.itemList = itemList
heightList = arrayListOf(itemList!!.size)
for (i in itemList.indices) {
val height = Random().nextInt(20) + DEFAULT_MARGIN
heightList?.add(height)
}
}
fun setOnItemClickListener(onItemClickListener: OnItemClickListener) {
this.onItemClickListener = onItemClickListener
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return RandomHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_waterfall ,parent, false))
}
override fun getItemCount(): Int {
return itemList?.size ?: 0
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val randomHolder = holder as RandomHolder
val layoutParams:ViewGroup.MarginLayoutParams =
randomHolder.txtComponent.layoutParams as ViewGroup.MarginLayoutParams
var margin = DEFAULT_MARGIN
if (heightList!![position] > DEFAULT_MARGIN) margin = heightList!![position]
layoutParams.topMargin = margin
layoutParams.bottomMargin = margin
randomHolder.txtComponent.layoutParams = layoutParams
randomHolder.txtComponent.text = itemList!![position]
if (onItemClickListener != null) {
randomHolder.txtComponent.setOnClickListener {
onItemClickListener!!.onItemClick(randomHolder.absoluteAdapterPosition)
}
}
}
private inner class RandomHolder internal constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {
internal val txtComponent :TextView = itemView.findViewById(R.id.txt_component)
}
}

@ -1,89 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
<ScrollView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_main_item"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<Button
android:id="@+id/btn_audio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/audio_handle"/>
<Button
android:id="@+id/btn_video"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video_handle"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_handle"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_play"
android:layout_marginTop="10dp"
android:visibility="gone"/>
<Button
android:id="@+id/btn_push"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video_push"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_live"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video_live"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video_filter"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_preview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/video_preview"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_probe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/media_probe"
android:layout_marginTop="10dp" />
<Button
android:id="@+id/btn_audio_effect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/audio_effect"
android:layout_marginTop="10dp" />
</LinearLayout>
</ScrollView>
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="@+id/txt_component"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:gravity="center"
android:clickable="true"
android:focusable="true"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:background="@drawable/btn_rect"/>
</LinearLayout>
Loading…
Cancel
Save