Skip to content

Commit

Permalink
#11 Improve resume
Browse files Browse the repository at this point in the history
  • Loading branch information
SrMouraSilva committed Feb 25, 2018
1 parent e902edf commit 016118a
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 72 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
android:theme="@style/AppTheme"
android:name="io.github.pedalpi.displayview.communication.server.App">
<!--<activity android:name="io.github.pedalpi.displayview.MainActivity">-->
<activity android:name="io.github.pedalpi.displayview.resume.ResumeActivity">
<activity android:name="io.github.pedalpi.displayview.resume.ResumeActivity"
android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
43 changes: 24 additions & 19 deletions app/src/main/java/io/github/pedalpi/displayview/Data.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ object Data {
"audio": [],
"midi": [],
"control": {"input": [
{"name": "param1"},
{"name": "param2"},
{"name": "param3"},
{"name": "param4"},
{"name": "param5"},
{"name": "param6"},
{"name": "param7"},
{"name": "param8"},
{"name": "param9"},
{"name": "param10"},
{"name": "param11"},
{"name": "param12"},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]},
{"name": "Parameter", "properties":[], "scalePoints":[]}
]}
}
}
Expand All @@ -34,13 +30,22 @@ object Data {
"connections": [],
"data": {},
"effects": [
{"plugin": "???", "params": [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}]},
{"plugin": "!!!"}, {"plugin": "*****"},
{"plugin": "???"}, {"plugin": "!!!"}, {"plugin": "*****"},
{"plugin": "???"}, {"plugin": "!!!"}, {"plugin": "*****"},
{"plugin": "???"}, {"plugin": "!!!"}, {"plugin": "*****"},
{"plugin": "???"}, {"plugin": "!!!"}, {"plugin": "*****"},
{"plugin": "???"}, {"plugin": "!!!"}, {"plugin": "*****"}
{"active": true, "plugin": "???", "params": [
{"minimum": 0, "maximum": 10, "value":0},
{"minimum": 0, "maximum": 10, "value":0},
{"minimum": 0, "maximum": 10, "value":5},
{"minimum": 0, "maximum": 10, "value":0},
{"minimum": 0, "maximum": 10, "value":0},
{"minimum": 0, "maximum": 10, "value":0},
{"minimum": 0, "maximum": 10, "value":0},
{"minimum": 0, "maximum": 10, "value":0}
]},
{"active": true, "plugin": ""}, {"active": true, "plugin": ""},
{"active": true, "plugin": ""}, {"active": true, "plugin": ""},
{"active": true, "plugin": ""}, {"active": true, "plugin": ""},
{"active": true, "plugin": ""}, {"active": true, "plugin": ""},
{"active": true, "plugin": ""}, {"active": true, "plugin": ""},
{"active": true, "plugin": ""}, {"active": true, "plugin": ""}
]
}
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import io.github.pedalpi.displayview.effects.EffectsActivity
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper




class MainActivity : AppCompatActivity() {

private lateinit var progress: ProgressDialog
Expand Down Expand Up @@ -60,7 +58,6 @@ class MainActivity : AppCompatActivity() {
progress.show()
}


override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
package io.github.pedalpi.displayview.resume

import android.app.ProgressDialog
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.WindowManager
import android.widget.GridView
import android.widget.TextView
import com.github.salomonbrys.kotson.array
import com.github.salomonbrys.kotson.get
import io.github.pedalpi.displayview.Data
import io.github.pedalpi.displayview.R
import io.github.pedalpi.displayview.communication.message.request.Messages
import io.github.pedalpi.displayview.communication.message.response.EventMessage
import io.github.pedalpi.displayview.communication.message.response.EventType
import io.github.pedalpi.displayview.communication.message.response.ResponseMessage
import io.github.pedalpi.displayview.communication.message.response.ResponseVerb
import io.github.pedalpi.displayview.communication.server.Server
import io.github.pedalpi.displayview.resume.effectview.EffectsView
import io.github.pedalpi.displayview.resume.paramview.ParamsView
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper


class ResumeActivity : AppCompatActivity() {
private lateinit var number: TextView
private lateinit var name: TextView

private lateinit var title: TitleView
private lateinit var effectsView: EffectsView
private lateinit var paramsView: ParamsView

private lateinit var progress: ProgressDialog

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_resume)
Expand All @@ -30,19 +35,45 @@ class ResumeActivity : AppCompatActivity() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
supportActionBar?.hide()

this.number = findViewById(R.id.resumePedalboardNumber) as TextView
this.name = findViewById(R.id.resumePedalboardName) as TextView
this.title = TitleView(this)
this.title.update(Data.pedalboardIndex, Data.currentPedalboard)

this.effectsView = EffectsView(this.applicationContext, findViewById(R.id.resumePedalboardEffects) as GridView)
effectsView.update(Data.currentPedalboard)
this.effectsView.update(Data.currentPedalboard)

this.paramsView = ParamsView(this.applicationContext, findViewById(R.id.resumeEffectParams) as GridView)
this.paramsView.updateWithPedalboard(Data.currentPedalboard)

Server.setListener({ onMessage(it) })

if (!Data.isDataLoaded())
showLoading()
}

if (Data.currentPedalboard["effects"].array.size() > 0)
paramsView.update(Data.currentPedalboard["effects"][0])
private fun showLoading() {
this.progress = ProgressDialog(this)
progress.setTitle("Connecting")
progress.setMessage("Reading plugins data")
progress.setCancelable(false)
progress.show()
}

override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase))
}

private fun onMessage(message : ResponseMessage) {
if (message.request isEquivalentTo Messages.PLUGINS) {
progress.dismiss()

} else if (message.request isEquivalentTo Messages.CURRENT_PEDALBOARD_DATA
|| message.verb == ResponseVerb.EVENT && EventMessage(message.content).type == EventType.CURRENT) {

runOnUiThread({
this.title.update(Data.pedalboardIndex, Data.currentPedalboard)
this.effectsView.update(Data.currentPedalboard)
this.paramsView.updateWithPedalboard(Data.currentPedalboard)
})
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package io.github.pedalpi.displayview.resume

import android.app.Activity
import android.widget.TextView
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonElement
import io.github.pedalpi.displayview.R

class TitleView

class TitleView(activity: Activity) {
private var number: TextView = activity.findViewById(R.id.resumePedalboardNumber) as TextView
private var name: TextView = activity.findViewById(R.id.resumePedalboardName) as TextView

fun update(index: Int, pedalboard: JsonElement) {
number.text = if (index < 10) "0$index" else "$index"
name.text = pedalboard["name"].string
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.pedalpi.displayview.resume.effectview

import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.support.v4.content.res.ResourcesCompat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -15,9 +18,8 @@ class EffectsGridItemAdapter(private val context: Context, private val items: Li

var selectEffectListener: SelectEffectListener = { }

class ViewHolder(row: View, private val adapter : EffectsGridItemAdapter) {
class ViewHolder(row: View, private val adapter: EffectsGridItemAdapter, val resources: Resources) {
val name = row.findViewById(R.id.effectsGridItemName) as Button
var selected : Boolean = false

private lateinit var dto: EffectsGridItemDTO

Expand All @@ -28,6 +30,16 @@ class EffectsGridItemAdapter(private val context: Context, private val items: Li
fun update(effect: EffectsGridItemDTO) {
dto = effect
name.text = dto.name

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN)
name.setBackgroundDrawable(drawable(effect.active))
else
name.background = drawable(effect.active)
}

private fun drawable(active: Boolean): Drawable? {
val drawable = if (active) R.drawable.button_effect_active else R.drawable.button_effect_not_active
return ResourcesCompat.getDrawable(resources, drawable, null)
}
}

Expand All @@ -38,7 +50,7 @@ class EffectsGridItemAdapter(private val context: Context, private val items: Li
if (convertView == null) {
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
view = inflater.inflate(R.layout.resume_effects_grid_item, null)
viewHolder = ViewHolder(view, this)
viewHolder = ViewHolder(view, this, context.resources)
view.tag = viewHolder

} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package io.github.pedalpi.displayview.resume.effectview

import com.github.salomonbrys.kotson.bool
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.string
import com.google.gson.JsonElement

class EffectsGridItemDTO(val index : Int, private val effect: JsonElement, private val plugin: JsonElement) {
val name = "$index - ${plugin["name"].string}"

val active: Boolean
get() = effect["active"].bool

val name = plugin["name"].string

lateinit var viewHolder: EffectsGridItemAdapter.ViewHolder
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import java.util.*

class EffectsView(private val activity: Context, private val gridView: GridView) {
private lateinit var pedalboard: JsonElement
private lateinit var selected: EffectsGridItemAdapter.ViewHolder

private lateinit var adapter: EffectsGridItemAdapter

public fun update(pedalboard: JsonElement) {
fun update(pedalboard: JsonElement) {
this.pedalboard = pedalboard

populateViews()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
package io.github.pedalpi.displayview.resume.paramview

import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.string
import com.github.salomonbrys.kotson.*
import com.google.gson.JsonElement

class ParamsGridItemDTO(val index : Int, private val param: JsonElement, private val plugin: JsonElement) {
val name = "$index - ${plugin["name"].string}"

class ParamsGridItemDTO(val index : Int, val param: JsonElement, val plugin: JsonElement) {

enum class ParamType {
COMBOBOX,
KNOB,
TOGGLE
}

lateinit var viewHolder: ParamsGridItemAdapter.ParamsGridItemViewHolder

val name: String = plugin["name"].string
var value: Number
get() = param["value"].number
set(value) {
param["value"] = value
}

val minimum: Double = param["minimum"].double
val maximum: Double = param["maximum"].double

private val properties = plugin["properties"].array.map { value -> value.string }

val type : ParamType = when {
properties.contains("enumeration") -> ParamType.COMBOBOX
properties.contains("toggled") -> ParamType.TOGGLE
else -> ParamType.KNOB
}

val percent: Int
get() = calculatePercent(value.toDouble())

private fun calculatePercent(current: Double): Int {
return ((current - minimum) * 100 / (maximum - minimum)).toInt()
}

fun calculateValue(progress: Int): Double {
return (progress * maximum + (100 - progress) * minimum) / 100.0
}

val options: List<String> = plugin["scalePoints"].array.map { data -> data["label"].string }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,39 @@ class ParamsListItemViewHolderProgress: ParamsGridItemAdapter.ParamsGridItemView

override var row: View? = null
set(row) {
/*
field = row
name = row?.findViewById(R.id.paramsGridItemName) as TextView
value = row?.findViewById(R.id.paramsGridItemValue) as TextView

slider = row?.findViewById(R.id.paramsGridItemProgress) as SeekBar
slider.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
progress = row?.findViewById(R.id.paramsGridItemProgress) as ProgressBar
/*
slider.setOnSeekBarChangeListener(object: SeekBar.OnSeekBarChangeListener {
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
if (!fromUser)
return
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
if (!fromUser)
return
value.text = "$progress%"
dto.value = dto.calculateValue(progress)
adapter.valueChangeListener(dto)
}
})
*/
value.text = "$progress%"
dto.value = dto.calculateValue(progress)
adapter.valueChangeListener(dto)
}
})
*/
}

override fun update(context : Context) {
this.update(context, dto)
}

override fun update(context: Context, param: ParamsGridItemDTO) {
/*
dto = param

name.text = param.name
value.text = "${param.percent}%"
slider.progress = param.percent
*/
progress.progress = param.percent
}

override val layout: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class ParamsView(private val context: Context, private val gridView: GridView) {
private lateinit var plugin: JsonElement
private lateinit var adapter: ParamsGridItemAdapter

fun updateWithPedalboard(currentPedalboard: JsonElement) {
if (Data.currentPedalboard["effects"].array.size() > 0)
this.update(Data.currentPedalboard["effects"][0])
else {
//TODO - Clear parameters
}
}

fun update(effect: JsonElement) {
this.effect = effect
this.plugin = Data.plugin(effect["plugin"].string)
Expand Down
Loading

0 comments on commit 016118a

Please sign in to comment.