Skip to content

Commit

Permalink
updated styles and theme, implemented Ripple using RippleDrawable, ad…
Browse files Browse the repository at this point in the history
…ded RootLayout and view refreshing
  • Loading branch information
ZieIony committed Mar 15, 2020
1 parent 53a2254 commit e5faf7c
Show file tree
Hide file tree
Showing 26 changed files with 561 additions and 251 deletions.
89 changes: 53 additions & 36 deletions app/src/main/java/comprise/test/MainLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import android.content.res.ColorStateList
import android.graphics.drawable.ColorDrawable
import android.util.AttributeSet
import comprise.app.CompriseLayout
import comprise.material.MaterialTextButton
import comprise.material.MaterialTheme
import comprise.material.*
import comprise.theme.dp
import comprise.view.LayoutSize
import comprise.view.Padding
import comprise.view.Ripple
import comprise.view.View
import comprise.widget.*

Expand All @@ -23,7 +23,7 @@ class MainLayout : CompriseLayout {
val theme = MaterialTheme(context)

val button = MaterialTextButton(
style = theme.buttonStyle,
style = theme.textButtonStyle,
background = ColorDrawable(resources.getColor(R.color.colorAccent)),
text = "TEST BUTTON"
)
Expand All @@ -35,32 +35,46 @@ class MainLayout : CompriseLayout {
invalidate()
}

val toolbar = Toolbar(
style = theme.toolbarStyle,
icon = IconButton(
drawable = resources.getDrawable(R.drawable.ic_arrow_back_black_24dp)
),
title = Text(
textSize = theme.toolbarStyle.textSize,
textColor = theme.toolbarStyle.textColor,
text = "Main activity"
)
)

views.add(
Column(
views = listOf(
Toolbar(
background = ColorDrawable(resources.getColor(R.color.colorPrimary)),
icon = resources.getDrawable(R.drawable.ic_arrow_back_black_24dp),
text = "Main activity"
),
toolbar,
Padding(
width = LayoutSize.MATCH_PARENT,
padding = 16.dp,
content = makeContent()
),
button,
MaterialTextButton(
width = LayoutSize.MATCH_PARENT,
MaterialButton(
style = theme.buttonStyle,
background = ColorDrawable(resources.getColor(R.color.colorAccent)),
text = "TEST BUTTON 2"
width = LayoutSize.MATCH_PARENT,
content = Text(
text = "TEST BUTTON 2",
textColor = theme.textButtonStyle.textColor,
textSize = theme.textButtonStyle.textSize
)
),
MaterialTextButton(
Button(
style = theme.buttonStyle,
width = LayoutSize(56.dp),
height = LayoutSize(56.dp),
style = theme.buttonStyle,
background = ColorDrawable(resources.getColor(R.color.colorAccent)),
text = "TEST BUTTON 3"
content = Text(
text = "TEST BUTTON 3",
textColor = theme.textButtonStyle.textColor,
textSize = theme.textButtonStyle.textSize
)
)
)
)
Expand All @@ -70,27 +84,30 @@ class MainLayout : CompriseLayout {
private fun makeContent(): View {
return Card(
width = LayoutSize.MATCH_PARENT,
content = Stack(
views = listOf(
Image(
width = LayoutSize.MATCH_PARENT,
height = LayoutSize(500),
drawable = ColorDrawable(0xff7fffff.toInt())
),
Column(
views = listOf(
Image(
drawable = resources.getDrawable(R.drawable.ic_arrow_back_black_24dp)
),
Text(
text = "test",
textSize = resources.getDimension(R.dimen.comprise_textSize),
textColor = ColorStateList.valueOf(
0xff000000.toInt()
content = Ripple(
width = LayoutSize.MATCH_PARENT,
content = Stack(
views = listOf(
Image(
width = LayoutSize.MATCH_PARENT,
height = LayoutSize(500),
drawable = ColorDrawable(0xff7fffff.toInt())
),
Column(
views = listOf(
Image(
drawable = resources.getDrawable(R.drawable.ic_arrow_back_black_24dp)
),
Text(
text = "test",
textSize = resources.getDimension(R.dimen.comprise_textSize),
textColor = ColorStateList.valueOf(
0xff000000.toInt()
)
),
Image(
drawable = resources.getDrawable(R.drawable.ic_arrow_back_black_24dp)
)
),
Image(
drawable = resources.getDrawable(R.drawable.ic_arrow_back_black_24dp)
)
)
)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 09 01:12:11 CET 2019
#Sat Mar 14 13:46:57 CET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
9 changes: 9 additions & 0 deletions lib/src/main/java/comprise/app/CompriseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ open class CompriseActivity : AppCompatActivity() {
compoundLayout.views.add(compoundView)
}

val Int.dp: Int
get() = (this * resources.displayMetrics.density).toInt()
val Int.sp: Int
get() = (this * resources.displayMetrics.scaledDensity).toInt()

val Float.dp: Float
get() = (this * resources.displayMetrics.density)
val Float.sp: Float
get() = (this * resources.displayMetrics.scaledDensity)
}
41 changes: 16 additions & 25 deletions lib/src/main/java/comprise/app/CompriseLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,36 @@ import android.graphics.Canvas
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.FrameLayout
import comprise.view.View
import comprise.view.LayoutSize

open class CompriseLayout : FrameLayout {
open class CompriseLayout @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(
context,
attrs,
defStyleAttr
) {

val views = mutableListOf<View>()
private val root = RootLayout(LayoutSize.MATCH_PARENT, LayoutSize.MATCH_PARENT, androidView = this)

@JvmOverloads
constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : super(
context,
attrs,
defStyleAttr
) {
setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null)
}
val views = root.views

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)

views.forEach {
it.measure()
it.layout(0, 0, width, height)
}
root.measure()
root.layout(0, 0, width, height)
}

override fun dispatchDraw(canvas: Canvas) {
super.dispatchDraw(canvas)

views.forEach {
it.draw(canvas)
}
root.draw(canvas)
}

override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
views.forEach {
if (it.x <= ev.x && it.y <= ev.y && (it.x + it.width) >= ev.x && (it.y + it.height) >= ev.y)
if (it.touchEvent(ev))
return true
}

return true
return root.touchEvent(ev)
}
}
20 changes: 20 additions & 0 deletions lib/src/main/java/comprise/app/RootLayout.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package comprise.app

import comprise.view.LayoutSize
import comprise.widget.Stack


class RootLayout(
width: LayoutSize = LayoutSize.WRAP_CONTENT,
height: LayoutSize = LayoutSize.WRAP_CONTENT,
var androidView: android.view.View
) : Stack(width, height) {

override fun requestLayout() {
androidView.requestLayout()
}

override fun requestDraw() {
androidView.postInvalidate()
}
}
20 changes: 8 additions & 12 deletions lib/src/main/java/comprise/material/IconButton.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package comprise.material

import android.graphics.drawable.Drawable
import comprise.theme.dp
import comprise.view.ContentView
import comprise.view.LayoutSize
import comprise.view.Padding
import comprise.view.Ripple
import comprise.widget.HorizontalGravity
import comprise.widget.Image
import comprise.widget.Stack
import comprise.widget.VerticalGravity

class IconButton(
width: LayoutSize = LayoutSize.WRAP_CONTENT,
Expand All @@ -16,15 +15,12 @@ class IconButton(
) : ContentView(
width, height,
content = Ripple(
content = Stack(
horizontalGravity = HorizontalGravity.CENTER,
verticalGravity = VerticalGravity.CENTER,
views = listOf(
Image(
width = LayoutSize(24 * 3),
height = LayoutSize(24 * 3),
drawable = drawable
)
content = Padding(
padding = 16.dp,
content = Image(
width = LayoutSize(24.dp),
height = LayoutSize(24.dp),
drawable = drawable
)
)
)
Expand Down
Loading

0 comments on commit e5faf7c

Please sign in to comment.