Skip to content

Commit

Permalink
update demo2 and update gif
Browse files Browse the repository at this point in the history
  • Loading branch information
ToDou committed Sep 21, 2017
1 parent c52f781 commit 1acec44
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 114 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Screenshot
|---|---|---|
|Change Radius|Change foreground|Change Corners|
|![](/screenshot/shadow_radius.gif)|![](/screenshot/shadow_foreground.gif)|![](/screenshot/shadow_corners.gif)|
|Change shadow color|change shadow margin||
|![](/screenshot/shadow_color.gif)|![](/screenshot/shadow_margin_hide.gif)||
|Change shadow color|Change shadow margin|Demo|
|![](/screenshot/shadow_color.gif)|![](/screenshot/shadow_margin_hide.gif)|![](/screenshot/shadow_demo.gif)|


Installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ enum class ForegroundColorEnum {
YELLOW("#ffeb3b"),
DEEP_ORANGE("#ff5722"),
BLUE_GREY("#607d8b"),
DEFAULT_LIGHT("#1f000000"),
DEFAULT_DARK("#33ffffff"),;
DEFAULT_DARK("#1f000000"),
DEFAULT_LIGHT("#33ffffff"),;

var color: String

Expand Down
308 changes: 201 additions & 107 deletions app/src/main/res/layout/activity_shadow_view_demo2.xml
Original file line number Diff line number Diff line change
@@ -1,127 +1,221 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<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"
android:background="#F5F5F5"
android:orientation="vertical"
tools:context="com.loopeer.example.shadows.ShadowViewDemo2Activity">
tools:context="com.loopeer.example.shadows.ShadowViewDemo2Activity"
android:background="#F5F5F5">

<com.loopeer.shadow.ShadowView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:clickable="true"
android:elevation="10dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#f44336"
app:cornerRadiusTL="8dp"
app:cornerRadiusTR="8dp"
app:foregroundColor="#03a9f4"
app:shadowColor="#f44336"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowMarginTop="5dp"
app:shadowRadius="5dp">

<TextView
android:orientation="vertical">

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:clickable="true"
android:elevation="10dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
android:text="#F44336"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>
app:cornerRadiusTL="8dp"
app:cornerRadiusTR="8dp"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowMarginTop="5dp"
app:shadowRadius="5dp">

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:elevation="10dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#03a9f4"
app:foregroundColor="#4caf50"
app:shadowColor="#03a9f4"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This library draw android view shadow by ShadowLayer. You may don't like the CardView's black shadow which we can't change it's color."
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<include layout="@layout/view_divider"/>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:elevation="10dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
android:text="#03A9F4"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:elevation="10dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#4caf50"
app:foregroundColor="#607d8b"
app:shadowColor="#4caf50"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Same to CardView wrap content and set shadow radius. You can change shadow color, foreground color and corner radius everywhere. "
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<include layout="@layout/view_divider"/>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
app:cornerRadiusBL="8dp"
app:cornerRadiusBR="8dp"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowMarginBottom="5dp"
app:shadowRadius="5dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Because the shadow is draw in the view. So you must add space to draw the shadow. The ShadowView add one param shadowMargin which must be set before you add shadow radius to the view."
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
android:text="#4CAF50"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>
app:cornerRadius="8dp"
app:shadowDy="2"
app:shadowMargin="5dp"
app:shadowRadius="5dp">

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:elevation="10dp"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#607d8b"
app:cornerRadiusBL="4dp"
app:cornerRadiusBR="4dp"
app:foregroundColor="#f44336"
app:shadowColor="#607d8b"
app:shadowDy="2"
app:shadowMarginBottom="5dp"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<TextView
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Same to CardView wrap content and set shadow radius. You can change shadow color, foreground color and corner radius everywhere. "
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
android:text="#607D8B"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>
</LinearLayout>
app:backgroundColor="#f44336"
app:cornerRadiusTL="8dp"
app:cornerRadiusTR="8dp"
app:foregroundColor="#75ffffff"
app:shadowColor="#f44336"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowMarginTop="5dp"
app:shadowRadius="5dp">

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="10dp"
android:text="#F44336"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#03a9f4"
app:foregroundColor="#75ffffff"
app:shadowColor="#03a9f4"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="10dp"
android:text="#03A9F4"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#4caf50"
app:foregroundColor="#75ffffff"
app:shadowColor="#4caf50"
app:shadowDy="2"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="10dp"
android:text="#4CAF50"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>

<com.loopeer.shadow.ShadowView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:padding="10dp"
app:backgroundColor="#607d8b"
app:cornerRadiusBL="4dp"
app:cornerRadiusBR="4dp"
app:foregroundColor="@color/shadow_view_foreground_color_light"
app:shadowColor="#607d8b"
app:shadowDy="2"
app:shadowMarginBottom="5dp"
app:shadowMarginLeft="5dp"
app:shadowMarginRight="5dp"
app:shadowRadius="5dp">

<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="10dp"
android:text="#607D8B"
android:textColor="@android:color/white"
android:textSize="40sp"
android:textStyle="bold"/>
</com.loopeer.shadow.ShadowView>
</LinearLayout>

</ScrollView>
9 changes: 9 additions & 0 deletions app/src/main/res/layout/view_divider.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<View
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#EEEEEE"/>
Binary file added screenshot/shadow_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions shadow/src/main/java/com/loopeer/shadow/ShadowView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.graphics.drawable.RippleDrawable
import android.util.AttributeSet
import android.widget.FrameLayout
import android.os.Build
import android.support.v4.content.ContextCompat
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -98,9 +99,10 @@ class ShadowView @JvmOverloads constructor(context: Context?, attributeSet: Attr
init {
val a = getContext().obtainStyledAttributes(attributeSet, R.styleable.ShadowView,
defStyleInt, 0)
shadowColor = a.getColor(R.styleable.ShadowView_shadowColor, Color.parseColor("#DCDDE0"))
/** dark #33ffffff light 1f000000 */
foregroundColor = a.getColor(R.styleable.ShadowView_foregroundColor, Color.parseColor("#1f000000"))
shadowColor = a.getColor(R.styleable.ShadowView_shadowColor
, ContextCompat.getColor(context, R.color.shadow_view_default_shadow_color))
foregroundColor = a.getColor(R.styleable.ShadowView_foregroundColor
, ContextCompat.getColor(context, R.color.shadow_view_foreground_color_dark))
backgroundClr = a.getColor(R.styleable.ShadowView_backgroundColor, Color.WHITE)
shadowDx = a.getFloat(R.styleable.ShadowView_shadowDx, 0f)
shadowDy = a.getFloat(R.styleable.ShadowView_shadowDy, 0f)
Expand Down
6 changes: 6 additions & 0 deletions shadow/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="shadow_view_foreground_color_light">#33ffffff</color>
<color name="shadow_view_default_shadow_color">#DCDDE0</color>
<color name="shadow_view_foreground_color_dark">#1f000000</color>
</resources>

0 comments on commit 1acec44

Please sign in to comment.