-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Yalantis/hotfix/Issue_4
Add lost functionality and fix issue #4
- Loading branch information
Showing
8 changed files
with
402 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp"> | ||
<path android:fillColor="#FFFFFF" android:pathData="M12,5V1L7,6l5,5V7c3.31,0 6,2.69 6,6s-2.69,6 -6,6 -6,-2.69 -6,-6H4c0,4.42 3.58,8 8,8s8,-3.58 8,-8 -3.58,-8 -8,-8z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
|
||
<item | ||
android:id="@+id/actionReload" | ||
android:title="" | ||
android:icon="@drawable/ic_reload" | ||
app:showAsAction="always"/> | ||
|
||
</menu> |
106 changes: 106 additions & 0 deletions
106
library/src/main/java/com/yalantis/library/CardLayout.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.yalantis.library | ||
|
||
import android.content.Context | ||
import android.os.Build | ||
import android.support.annotation.DrawableRes | ||
import android.support.v4.content.ContextCompat | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.FrameLayout | ||
import android.widget.ImageView | ||
|
||
/** | ||
* Created by anna on 1/2/18. | ||
*/ | ||
class CardLayout | ||
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0, var cardParams: CardParams) : FrameLayout(context, attrs, defStyleAttr) { | ||
|
||
private var rightImageView: ImageView? = null | ||
private var leftImageView: ImageView? = null | ||
private var cardView: View? = null | ||
var layoutAlpha = 1f | ||
set(value) { | ||
field = value | ||
cardView?.alpha = value | ||
} | ||
|
||
|
||
fun addOverlays(cardView: View?, @DrawableRes rightOverlayImage: Int?, | ||
@DrawableRes leftOverlayImage: Int?) { | ||
this.cardView = cardView | ||
addView(cardView) | ||
|
||
leftOverlayImage?.let { | ||
leftImageView = ImageView(context) | ||
leftImageView?.setImageDrawable(ContextCompat.getDrawable(context, it)) | ||
leftImageView?.alpha = 0f | ||
addView(leftImageView) | ||
} | ||
|
||
rightOverlayImage?.let { | ||
rightImageView = ImageView(context) | ||
rightImageView?.setImageDrawable(ContextCompat.getDrawable(context, it)) | ||
rightImageView?.alpha = 0f | ||
addView(rightImageView) | ||
} | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
rightImageView?.translationZ = SMALL_ELEVATION | ||
leftImageView?.translationZ = SMALL_ELEVATION | ||
cardView?.translationZ = NO_ELEVATION | ||
} | ||
} | ||
|
||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
val layoutParamsCardView = cardView?.layoutParams as FrameLayout.LayoutParams | ||
|
||
cardView?.alpha = layoutAlpha | ||
cardParams.onParamsMeasure(layoutParamsCardView) | ||
|
||
rightImageView?.layoutParams?.let { | ||
(rightImageView?.layoutParams as FrameLayout.LayoutParams).apply { | ||
width = layoutParamsCardView.width | ||
height = layoutParamsCardView.height | ||
gravity = layoutParamsCardView.gravity | ||
|
||
setMargins(layoutParamsCardView.leftMargin, layoutParamsCardView.topMargin, | ||
layoutParamsCardView.rightMargin, layoutParamsCardView.bottomMargin) | ||
} | ||
rightImageView?.setPadding(cardView?.paddingLeft ?: 0, cardView?.paddingTop ?: 0, | ||
cardView?.paddingRight ?: 0, cardView?.paddingBottom ?: 0) | ||
} | ||
|
||
leftImageView?.layoutParams?.let { | ||
(leftImageView?.layoutParams as FrameLayout.LayoutParams).apply { | ||
width = layoutParamsCardView.width | ||
height = layoutParamsCardView.height | ||
gravity = layoutParamsCardView.gravity | ||
setMargins(layoutParamsCardView.leftMargin, layoutParamsCardView.topMargin, | ||
layoutParamsCardView.rightMargin, layoutParamsCardView.bottomMargin) | ||
} | ||
|
||
leftImageView?.setPadding(cardView?.paddingLeft ?: 0, cardView?.paddingTop ?: 0, | ||
cardView?.paddingRight ?: 0, cardView?.paddingBottom ?: 0) | ||
} | ||
} | ||
|
||
internal fun changeRightOverlayAlpha(progress: Float) { | ||
rightImageView?.alpha = progress | ||
} | ||
|
||
internal fun changeLeftOverlayAlpha(progress: Float) { | ||
leftImageView?.alpha = Math.abs(progress) | ||
} | ||
|
||
interface CardParams { | ||
fun onParamsMeasure(layoutParamsCardView: LayoutParams) | ||
} | ||
|
||
companion object { | ||
private const val NO_ELEVATION = 0F | ||
private const val SMALL_ELEVATION = 10F | ||
} | ||
|
||
} |
Oops, something went wrong.