Skip to content

Commit

Permalink
Release 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Aug 14, 2019
1 parent 1012e02 commit 51b4d8a
Show file tree
Hide file tree
Showing 22 changed files with 599 additions and 55 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.masoudss"
minSdkVersion 14
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -24,12 +24,14 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0-alpha03'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03'
implementation "org.jetbrains.anko:anko-commons:0.10.0"
implementation project(':lib')
}
10 changes: 8 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.masoudss">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:supportsRtl="false"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:name=".activity.SelectAudioActivity">
</activity>
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
99 changes: 72 additions & 27 deletions ...rc/main/java/com/masoudss/MainActivity.kt → ...ava/com/masoudss/activity/MainActivity.kt
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
package com.masoudss
package com.masoudss.activity

import androidx.appcompat.app.AppCompatActivity
import android.app.Activity
import android.app.ProgressDialog
import android.content.Intent
import android.database.Cursor
import android.net.Uri
import android.os.Bundle
import android.widget.RadioButton
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.masoudss.lib.SeekBarOnProgressChanged
import com.masoudss.lib.Utils
import com.masoudss.lib.WaveGravity
import com.masoudss.lib.WaveformSeekBar
import com.masoudss.lib.*
import kotlinx.android.synthetic.main.activity_main.*
import android.content.Intent
import android.net.Uri
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import java.util.*
import android.provider.MediaStore
import com.masoudss.R


class MainActivity : AppCompatActivity() {

private val REQ_CODE_PICK_SOUND_FILE = 1

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

waveformSeekBar.progress = 33
waveformSeekBar.waveWidth = Utils.dp(this,5)
waveformSeekBar.waveGap = Utils.dp(this,2)
waveformSeekBar.waveMinHeight = Utils.dp(this,5)
waveformSeekBar.waveCornerRadius = Utils.dp(this,2)
waveformSeekBar.waveGravity = WaveGravity.CENTER
waveformSeekBar.waveBackgroundColor = ContextCompat.getColor(this,R.color.white)
waveformSeekBar.waveProgressColor = ContextCompat.getColor(this,R.color.blue)
waveformSeekBar.sample = Utils.getDummyWaveSample()
waveformSeekBar.onProgressChanged = object : SeekBarOnProgressChanged {
override fun onProgressChanged(waveformSeekBar: WaveformSeekBar, progress: Int, fromUser: Boolean) {
if (fromUser)
waveProgress.progress = progress
waveformSeekBar.apply {
progress = 33
waveWidth = Utils.dp(this@MainActivity, 5)
waveGap = Utils.dp(this@MainActivity, 2)
waveMinHeight = Utils.dp(this@MainActivity, 5)
waveCornerRadius = Utils.dp(this@MainActivity, 2)
waveGravity = WaveGravity.CENTER
waveBackgroundColor = ContextCompat.getColor(this@MainActivity, R.color.white)
waveProgressColor = ContextCompat.getColor(this@MainActivity, R.color.blue)
sample = getDummyWaveSample()
onProgressChanged = object : SeekBarOnProgressChanged {
override fun onProgressChanged(waveformSeekBar: WaveformSeekBar, progress: Int, fromUser: Boolean) {
if (fromUser)
waveProgress.progress = progress
}
}
}

Expand Down Expand Up @@ -92,9 +101,9 @@ class MainActivity : AppCompatActivity() {
val radioButton = waveColorRadioGroup.findViewById(checkedId) as RadioButton
val index = waveColorRadioGroup.indexOfChild(radioButton)
waveformSeekBar.waveBackgroundColor = when (index){
0 -> ContextCompat.getColor(this,R.color.pink)
1 -> ContextCompat.getColor(this,R.color.yellow)
else -> ContextCompat.getColor(this,R.color.white)
0 -> ContextCompat.getColor(this, R.color.pink)
1 -> ContextCompat.getColor(this, R.color.yellow)
else -> ContextCompat.getColor(this, R.color.white)
}
}

Expand All @@ -103,9 +112,9 @@ class MainActivity : AppCompatActivity() {
val radioButton = progressColorRadioGroup.findViewById(checkedId) as RadioButton
val index = progressColorRadioGroup.indexOfChild(radioButton)
waveformSeekBar.waveProgressColor = when (index){
0 -> ContextCompat.getColor(this,R.color.red)
1 -> ContextCompat.getColor(this,R.color.blue)
else -> ContextCompat.getColor(this,R.color.green)
0 -> ContextCompat.getColor(this, R.color.red)
1 -> ContextCompat.getColor(this, R.color.blue)
else -> ContextCompat.getColor(this, R.color.green)
}
}

Expand All @@ -115,5 +124,41 @@ class MainActivity : AppCompatActivity() {
i.data = Uri.parse(url)
startActivity(i)
}

icImport.setOnClickListener {
val intent = Intent(this@MainActivity,SelectAudioActivity::class.java)
startActivityForResult(intent,REQ_CODE_PICK_SOUND_FILE)
}
}

public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (data!= null && requestCode == REQ_CODE_PICK_SOUND_FILE && resultCode == Activity.RESULT_OK) {
val path = data.getStringExtra("path")

val progressDialog = ProgressDialog(this@MainActivity)
progressDialog.setMessage("Please wait...")
progressDialog.show()

doAsync {

val waves = WaveformOptions.getSampleFrom(path)

uiThread {
waveformSeekBar?.sample = waves
progressDialog.dismiss()
}
}
}
}

private fun getDummyWaveSample(): IntArray {
val data = IntArray(50)
for (i in 0 until data.size)
data[i] = Random().nextInt(data.size)

return data
}


}
79 changes: 79 additions & 0 deletions app/src/main/java/com/masoudss/activity/SelectAudioActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.masoudss.activity

import android.app.Activity
import android.content.Intent
import android.database.Cursor
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

import kotlinx.android.synthetic.main.activity_select_audio.*
import android.provider.MediaStore
import androidx.recyclerview.widget.LinearLayoutManager
import com.masoudss.model.AudioModel
import com.masoudss.R
import com.masoudss.adapter.AudioAdapter
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread


class SelectAudioActivity : AppCompatActivity() {

private val audioList = ArrayList<AudioModel>()
private val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_select_audio)
initViews()
loadAudioFiles()
}

private fun initViews(){
audioRecyclerView.layoutManager = LinearLayoutManager(this)
audioRecyclerView.adapter = AudioAdapter(this@SelectAudioActivity, audioList)
}

private fun loadAudioFiles() {

doAsync {

var cursor: Cursor? = null
try {
cursor = contentResolver.query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
projection,
null,
null,
MediaStore.Audio.Media.DATE_ADDED + " DESC")

while (cursor!!.moveToNext()) {
val audioModel = AudioModel()
audioModel.artist = cursor.getString(1)
audioModel.title = cursor.getString(2)
audioModel.path = cursor.getString(3)
audioList.add(audioModel)
}
} catch (e: Exception) {
e.printStackTrace()
} finally {
cursor?.close()
}

uiThread {
audioRecyclerView.adapter?.notifyDataSetChanged()
}
}
}

fun onSelectAudio(audioModel: AudioModel){
val intent = Intent()
intent.putExtra("path",audioModel.path)
setResult(Activity.RESULT_OK,intent)
finish()
}

}
37 changes: 37 additions & 0 deletions app/src/main/java/com/masoudss/adapter/AudioAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.masoudss.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.masoudss.R
import com.masoudss.activity.SelectAudioActivity
import com.masoudss.model.AudioModel
import kotlinx.android.synthetic.main.item_audio.view.*

class AudioAdapter(private val activity: SelectAudioActivity,private val audioList : ArrayList<AudioModel>) :
RecyclerView.Adapter<AudioAdapter.AudioViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AudioViewHolder {
return AudioViewHolder(LayoutInflater.from(activity).inflate(R.layout.item_audio,parent,false))
}

override fun getItemCount(): Int {
return audioList.size
}

override fun onBindViewHolder(holder: AudioViewHolder, position: Int) {
holder.itemView.title.text = "${audioList[position].title}\n${audioList[position].artist}".trim()
}

inner class AudioViewHolder(view: View) : RecyclerView.ViewHolder(view) {

init {
view.setOnClickListener {
activity.onSelectAudio(audioList[adapterPosition])
}
}
}


}
10 changes: 10 additions & 0 deletions app/src/main/java/com/masoudss/model/AudioModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.masoudss.model

class AudioModel {

var title = ""

var artist = ""

var path = ""
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_audio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M12,1c-4.97,0 -9,4.03 -9,9v7c0,1.66 1.34,3 3,3h3v-8H5v-2c0,-3.87 3.13,-7 7,-7s7,3.13 7,7v2h-4v8h3c1.66,0 3,-1.34 3,-3v-7c0,-4.97 -4.03,-9 -9,-9z"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_import.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,3L4.99,3c-1.11,0 -1.98,0.9 -1.98,2L3,19c0,1.1 0.88,2 1.99,2L19,21c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,15h-4c0,1.66 -1.35,3 -3,3s-3,-1.34 -3,-3L4.99,15L4.99,5L19,5v10zM16,10h-2L14,7h-4v3L8,10l4,4 4,-4z"/>
</vector>
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@
android:layout_gravity="right"
android:background="?attr/actionBarItemBackground"/>

<ImageView
android:id="@+id/icImport"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:src="@drawable/ic_import"
android:padding="12dp"
android:clickable="true"
android:focusable="true"
android:layout_gravity="right"
android:background="?attr/actionBarItemBackground"/>

</androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout>
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/layout/activity_select_audio.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.SelectAudioActivity">


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/audioRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit 51b4d8a

Please sign in to comment.