Skip to content

Commit

Permalink
feat(BackgroundGradient): update demo
Browse files Browse the repository at this point in the history
  • Loading branch information
rbenjami committed Sep 11, 2017
1 parent d6111d3 commit 5a516da
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 60 deletions.
108 changes: 108 additions & 0 deletions .gradletasknamecache
@@ -0,0 +1,108 @@
app:androidDependencies
gradient:androidDependencies
app:signingReport
gradient:signingReport
app:sourceSets
gradient:sourceSets
app:assemble
gradient:assemble
app:assembleAndroidTest
gradient:assembleAndroidTest
app:assembleDebug
gradient:assembleDebug
app:assembleRelease
gradient:assembleRelease
app:build
gradient:build
app:buildDependents
gradient:buildDependents
app:buildNeeded
gradient:buildNeeded
app:clean
gradient:clean
app:cleanBuildCache
gradient:cleanBuildCache
gradient:extractDebugAnnotations
gradient:extractReleaseAnnotations
app:mockableAndroidJar
gradient:mockableAndroidJar
init
wrapper
buildEnvironment
app:buildEnvironment
gradient:buildEnvironment
components
app:components
gradient:components
dependencies
app:dependencies
gradient:dependencies
dependencyInsight
app:dependencyInsight
gradient:dependencyInsight
dependentComponents
app:dependentComponents
gradient:dependentComponents
help
app:help
gradient:help
model
app:model
gradient:model
projects
app:projects
gradient:projects
properties
app:properties
gradient:properties
tasks
app:tasks
gradient:tasks
app:installDebug
app:installDebugAndroidTest
gradient:installDebugAndroidTest
app:uninstallAll
gradient:uninstallAll
app:uninstallDebug
app:uninstallDebugAndroidTest
gradient:uninstallDebugAndroidTest
app:uninstallRelease
gradient:bintrayUpload
app:check
gradient:check
app:connectedAndroidTest
gradient:connectedAndroidTest
app:connectedCheck
gradient:connectedCheck
app:connectedDebugAndroidTest
gradient:connectedDebugAndroidTest
app:deviceAndroidTest
gradient:deviceAndroidTest
app:deviceCheck
gradient:deviceCheck
app:lint
gradient:lint
app:lintDebug
gradient:lintDebug
app:lintRelease
gradient:lintRelease
app:lintVitalRelease
app:test
gradient:test
app:testDebugUnitTest
gradient:testDebugUnitTest
app:testReleaseUnitTest
gradient:testReleaseUnitTest
gradient:bundleDebug
gradient:bundleRelease
app:compileDebugAndroidTestKotlin
gradient:compileDebugAndroidTestKotlin
app:compileDebugKotlin
gradient:compileDebugKotlin
app:compileDebugUnitTestKotlin
gradient:compileDebugUnitTestKotlin
app:compileReleaseKotlin
gradient:compileReleaseKotlin
app:compileReleaseUnitTestKotlin
gradient:compileReleaseUnitTestKotlin
gradient:install
18 changes: 18 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -15,8 +15,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity
android:name=".HomeActivity">
<activity android:name=".HomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -25,6 +24,7 @@

<activity
android:name=".BackgroundGradientActivity"
android:theme="@style/AppThemeBackgroundGradient"
/>

<activity
Expand Down
92 changes: 77 additions & 15 deletions app/src/main/java/co/revely/gradient/BackgroundGradientActivity.kt
Expand Up @@ -2,35 +2,97 @@ package co.revely.gradient

import android.graphics.Color
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v7.app.AppCompatActivity
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_background_gradient.*

class BackgroundGradientActivity : AppCompatActivity()
{
private var mSectionsPagerAdapter: SectionsPagerAdapter? = null

object Data
{
class Gradient(var angle: Float, var colors: List<String>)

val GRADIENT_DATAS: List<Gradient> = mutableListOf(
Gradient(0f, mutableListOf("#17EA19", "#6078EA")),
Gradient(-19f, mutableListOf("#21D4FD", "#B721FF")),
Gradient(90f, mutableListOf("#FEE140", "#FA709A")),
Gradient(-45f, mutableListOf("#FA8BFF", "#2BD2FF", "#2BFF88")),
Gradient(-43f, mutableListOf("#4158D0", "#C850C0", "#FFCC70"))
)
}

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

mSectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager)

container.adapter = mSectionsPagerAdapter
}


inner class SectionsPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm)
{
override fun getItem(position: Int): Fragment
{
return BackgroundGradientFragment.newInstance(position)
}

override fun getCount(): Int
{
return BackgroundGradientActivity.Data.GRADIENT_DATAS.size
}
}


class BackgroundGradientFragment : Fragment()
{
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?
{
val rootView = inflater.inflate(R.layout.fragment_background_gradient, container, false)
val gradientData: Data.Gradient = BackgroundGradientActivity.Data.GRADIENT_DATAS[arguments.getInt(ARG_POSITION)]

RevelyGradient
.linear()
.colors(resources.getIntArray(R.array.colorRevely))
.onBackgroundOf(test_view1)
RevelyGradient.linear()
.angle(gradientData.angle)
.colors(gradientData.colors.map { s -> Color.parseColor(s) }.toIntArray())
.onBackgroundOf(rootView.findViewById<View>(R.id.constraintLayout))

val colorsString = SpannableStringBuilder()
for ( color in gradientData.colors )
{
colorsString.append(color)
colorsString.setSpan(ForegroundColorSpan(Color.parseColor(color)), colorsString.length - color.length, colorsString.length, Spanned.SPAN_INCLUSIVE_INCLUSIVE)
colorsString.append(" ")
}

RevelyGradient
.linear()
.angle(90.0f)
.colors(intArrayOf(Color.CYAN, Color.YELLOW))
.onBackgroundOf(test_view2)
rootView.findViewById<TextView>(R.id.colors).text = colorsString
return rootView
}

companion object
{
private val ARG_POSITION = "position"

RevelyGradient
.linear()
.colors(resources.getIntArray(R.array.colorRevely))
.angle(-50.0f)
.alpha(0.5f)
.onBackgroundOf(test_view3)
fun newInstance(position: Int): BackgroundGradientFragment
{
val fragment = BackgroundGradientFragment()
val args = Bundle()
args.putInt(ARG_POSITION, position)
fragment.arguments = args
return fragment
}
}
}
}
52 changes: 9 additions & 43 deletions app/src/main/res/layout/activity_background_gradient.xml
@@ -1,51 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<LinearLayout
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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.revely.gradient.TestActivity"
android:fitsSystemWindows="true"
tools:context="co.revely.gradient.BackgroundGradientActivity"
>

<View
android:id="@+id/test_view1"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<View
android:id="@+id/test_view2"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/test_view1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>

<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="8dp"
android:src="@android:drawable/ic_dialog_map"
app:layout_constraintTop_toBottomOf="@+id/test_view2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>

<View
android:id="@+id/test_view3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="8dp"
android:src="@android:drawable/ic_dialog_map"
app:layout_constraintTop_toBottomOf="@+id/test_view2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
23 changes: 23 additions & 0 deletions app/src/main/res/layout/fragment_background_gradient.xml
@@ -0,0 +1,23 @@
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<TextView
android:id="@+id/colors"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#AAFFFFFF"
android:padding="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
android:letterSpacing="0.1"
android:textSize="18sp"
/>

</android.support.constraint.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Expand Up @@ -5,4 +5,5 @@
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="appbar_padding_top">8dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -107,4 +107,5 @@
completions."
</string>
<string name="title_activity_test3">Test3Activity</string>
<string name="section_format">Hello World from section: %1$d</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/styles.xml
Expand Up @@ -17,6 +17,10 @@

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppThemeBackgroundGradient" parent="AppTheme.NoActionBar">
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
</style>

<style name="AppThemeTest2" parent="AppTheme.NoActionBar">
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="colorPrimary">#fc4672</item>
Expand Down

0 comments on commit 5a516da

Please sign in to comment.