Skip to content

Commit

Permalink
Sample: Add activity to test color APIs simply
Browse files Browse the repository at this point in the history
  • Loading branch information
fornewid committed Jun 2, 2020
1 parent 90a79d8 commit 52c4ff7
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ android {
versionCode 1
versionName "1.0"
}
buildFeatures {
viewBinding = true
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ColorSampleActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package soup.neumorphism.sample

import android.content.res.ColorStateList
import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import soup.neumorphism.sample.databinding.ActivitySampleColorBinding

class ColorSampleActivity : AppCompatActivity() {

private lateinit var binding: ActivitySampleColorBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySampleColorBinding.inflate(LayoutInflater.from(this))
setContentView(binding.root)

onBackgroundColorChanged(Color.RED)
}

private fun onBackgroundColorChanged(backgroundColor: Int) {
binding.run {
card.setBackgroundColor(backgroundColor)
imageView.setBackgroundColor(backgroundColor)
imageButton.setBackgroundColor(backgroundColor)
button.setBackgroundColor(backgroundColor)
fab.setBackgroundColor(backgroundColor)
}
}

private fun onBackgroundColorChanged(backgroundColor: ColorStateList?) {
binding.run {
card.setBackgroundColor(backgroundColor)
imageView.setBackgroundColor(backgroundColor)
imageButton.setBackgroundColor(backgroundColor)
button.setBackgroundColor(backgroundColor)
fab.setBackgroundColor(backgroundColor)
}
}

private fun onStrokeColorChanged(strokeColor: ColorStateList?) {
binding.run {
card.setStrokeColor(strokeColor)
imageView.setStrokeColor(strokeColor)
imageButton.setStrokeColor(strokeColor)
button.setStrokeColor(strokeColor)
fab.setStrokeColor(strokeColor)
}
}

private fun onStrokeWidthChanged(strokeWidth: Float) {
binding.run {
card.setStrokeWidth(strokeWidth)
imageView.setStrokeWidth(strokeWidth)
imageButton.setStrokeWidth(strokeWidth)
button.setStrokeWidth(strokeWidth)
fab.setStrokeWidth(strokeWidth)
}
}
}
6 changes: 6 additions & 0 deletions sample/src/main/java/soup/neumorphism/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package soup.neumorphism.sample

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

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

findViewById<View>(R.id.button).setOnClickListener {
startActivity(Intent(this, ColorSampleActivity::class.java))
}
}
}
8 changes: 8 additions & 0 deletions sample/src/main/res/drawable-night/gradation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:endColor="#444444"
android:startColor="#111111" />
</shape>
8 changes: 8 additions & 0 deletions sample/src/main/res/drawable/gradation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="135"
android:endColor="#eeeeee"
android:startColor="#cccccc" />
</shape>
85 changes: 85 additions & 0 deletions sample/src/main/res/layout/activity_sample_color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ColorSampleActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<soup.neumorphism.NeumorphCardView
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
app:layout_constraintEnd_toStartOf="@id/pressed_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview">

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradation" />

</soup.neumorphism.NeumorphCardView>

<soup.neumorphism.NeumorphCardView
android:id="@+id/card"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
app:layout_constraintEnd_toStartOf="@id/pressed_card"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview" />

<soup.neumorphism.NeumorphImageView
android:id="@+id/image_view"
style="@style/Widget.Neumorph.ImageButton"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside"
android:src="@drawable/ic_daynight_sky"
app:layout_constraintEnd_toStartOf="@id/pressed_image_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/card_barrier" />

<soup.neumorphism.NeumorphImageButton
android:id="@+id/image_button"
style="@style/Widget.Neumorph.ImageButton"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside"
android:src="@drawable/ic_daynight_sky"
app:layout_constraintEnd_toStartOf="@id/pressed_image_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/card_barrier" />

<soup.neumorphism.NeumorphButton
android:id="@+id/button"
style="@style/Widget.Neumorph.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<soup.neumorphism.NeumorphFloatingActionButton
android:id="@+id/fab"
style="@style/Widget.Neumorph.FloatingActionButton"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside"
android:src="@drawable/ic_filter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</LinearLayout>
</ScrollView>

0 comments on commit 52c4ff7

Please sign in to comment.