-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
1,909 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Built application files | ||
*.apk | ||
*.ap_ | ||
|
||
# Files for the ART/Dalvik VM | ||
*.dex | ||
|
||
# Java class files | ||
*.class | ||
|
||
# Generated files | ||
bin/ | ||
gen/ | ||
out/ | ||
|
||
# Gradle files | ||
/.idea | ||
.gradle/ | ||
build/ | ||
|
||
# Local configuration file (sdk path, etc) | ||
local.properties | ||
|
||
# Proguard folder generated by Eclipse | ||
proguard/ | ||
|
||
# Log Files | ||
*.log | ||
|
||
# Android Studio Navigation editor temp files | ||
.navigation/ | ||
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# Intellij | ||
*.iml | ||
.idea/workspace.xml | ||
.idea/tasks.xml | ||
.idea/gradle.xml | ||
.idea/dictionaries | ||
.idea/libraries | ||
|
||
# Keystore files | ||
*.jks | ||
|
||
# External native build folder generated in Android Studio 2.2 and later | ||
.externalNativeBuild | ||
|
||
# Google Services (e.g. APIs or Firebase) | ||
google-services.json | ||
|
||
# Freeline | ||
freeline.py | ||
freeline/ | ||
freeline_project_description.json |
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 @@ | ||
/build |
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,38 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'com.novoda.bintray-release' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
} | ||
|
||
publish { | ||
userOrg = 'devmagician' | ||
groupId = 'com.github.skydoves' | ||
artifactId = 'androidveil' | ||
publishVersion = '1.0.1' | ||
desc = 'This is AndroidVeil by skydoves' | ||
website = 'https://github.com/skydoves/AndroidVeil' | ||
issueTracker = "${website}/issues" | ||
repository = "${website}.git" | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation "com.android.support:appcompat-v7:$support_version" | ||
implementation "com.android.support:recyclerview-v7:$support_version" | ||
implementation "com.github.skydoves:baserecyclerviewadapter:$adapter_version" | ||
api "com.facebook.shimmer:shimmer:$shimmer_version" | ||
} | ||
|
||
tasks.withType(Javadoc) { | ||
excludes = ['**/*.kt'] | ||
options.addBooleanOption('Xdoclint:none', true) | ||
} |
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.skydoves.androidveil" /> |
234 changes: 234 additions & 0 deletions
234
androidveil/src/main/java/com/skydoves/androidveil/VeilLayout.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,234 @@ | ||
|
||
/* | ||
* Copyright (C) 2018 skydoves | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.skydoves.androidveil | ||
|
||
import android.annotation.TargetApi | ||
import android.content.Context | ||
import android.graphics.Color | ||
import android.os.Build | ||
import android.support.annotation.ColorInt | ||
import android.support.annotation.LayoutRes | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.ViewTreeObserver | ||
import android.widget.FrameLayout | ||
import com.facebook.shimmer.Shimmer | ||
import com.facebook.shimmer.ShimmerFrameLayout | ||
import java.util.* | ||
class VeilLayout : FrameLayout { | ||
|
||
@ColorInt var baseColor = Color.LTGRAY | ||
@ColorInt var highlightColor = Color.DKGRAY | ||
var baseAlpha = 1.0f | ||
var highlightAlpha = 1.0f | ||
var dropOff = 0.5f | ||
|
||
@LayoutRes var layout = -1 | ||
set(value) { | ||
field = value | ||
reDrawLayout(value) | ||
} | ||
|
||
var isVeiled = false | ||
private set | ||
|
||
private val maskElements = ArrayList<View>() | ||
val shimmerContainer = ShimmerFrameLayout(context) | ||
val nonShimmer = Shimmer.AlphaHighlightBuilder().setBaseAlpha(1.0f).setDropoff(1.0f).build() | ||
var shimmer = Shimmer.AlphaHighlightBuilder().build() | ||
set(value) { | ||
field = value | ||
shimmerContainer.setShimmer(value) | ||
} | ||
var shimmerEnable: Boolean = true | ||
set(value) { | ||
field = value | ||
when(value) { | ||
true -> shimmerContainer.setShimmer(shimmer) | ||
false -> shimmerContainer.setShimmer(nonShimmer) | ||
} | ||
} | ||
|
||
constructor(context: Context) : super(context) { | ||
onCreate() | ||
} | ||
|
||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { | ||
getAttrs(attrs) | ||
onCreate() | ||
} | ||
|
||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { | ||
getAttrs(attrs) | ||
onCreate() | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { | ||
getAttrs(attrs) | ||
onCreate() | ||
} | ||
|
||
private fun getAttrs(attrs: AttributeSet?) { | ||
val a = context.obtainStyledAttributes(attrs, R.styleable.VeilLayout) | ||
try { | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_veiled)) | ||
isVeiled = a.getBoolean(R.styleable.VeilLayout_veilLayout_veiled, isVeiled) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_layout)) | ||
layout = a.getResourceId(R.styleable.VeilLayout_veilLayout_layout, -1) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_shimmerEnable)) | ||
shimmerEnable = a.getBoolean(R.styleable.VeilLayout_veilLayout_shimmerEnable, shimmerEnable) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_baseColor)) | ||
baseColor = a.getColor(R.styleable.VeilLayout_veilLayout_baseColor, baseColor) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_highlightColor)) | ||
highlightColor = a.getColor(R.styleable.VeilLayout_veilLayout_highlightColor, highlightColor) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_baseAlpha)) | ||
baseAlpha = a.getFloat(R.styleable.VeilLayout_veilLayout_baseAlpha, baseAlpha) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_highlightAlpha)) | ||
highlightAlpha = a.getFloat(R.styleable.VeilLayout_veilLayout_highlightAlpha, highlightAlpha) | ||
if (a.hasValue(R.styleable.VeilLayout_veilLayout_dropOff)) | ||
dropOff = a.getFloat(R.styleable.VeilLayout_veilLayout_dropOff, dropOff) | ||
} finally { | ||
a.recycle() | ||
} | ||
} | ||
|
||
private fun onCreate() { | ||
shimmerContainer.invisible() | ||
val shimmerBuilder = Shimmer.ColorHighlightBuilder() | ||
shimmerBuilder.setBaseColor(baseColor).setHighlightColor(highlightColor) | ||
shimmerBuilder.setBaseAlpha(baseAlpha).setDropoff(highlightAlpha).setDropoff(dropOff) | ||
shimmerBuilder.setAutoStart(false) | ||
shimmer = shimmerBuilder.build() | ||
shimmerEnable = shimmerEnable | ||
} | ||
|
||
/** Remove previous views and inflate a new layout. */ | ||
private fun reDrawLayout(layout: Int) { | ||
removeAllViews() | ||
LayoutInflater.from(context).inflate(layout, this, true) | ||
onFinishInflate() | ||
} | ||
|
||
/** Call addMaskElements method after inflating. */ | ||
override fun onFinishInflate() { | ||
super.onFinishInflate() | ||
removeView(shimmerContainer) | ||
addView(shimmerContainer) | ||
addMaskElements(this) | ||
} | ||
|
||
/** | ||
* Called when addMaskElements is called. | ||
* Adds masked views by viewTree structure except for ViewGroup. | ||
*/ | ||
private fun addMaskElements(parent: ViewGroup) { | ||
for (i in 0 until parent.childCount) { | ||
val child = parent.getChildAt(i) | ||
child.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { | ||
@Suppress("DEPRECATION") | ||
override fun onGlobalLayout() { | ||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { | ||
viewTreeObserver.removeGlobalOnLayoutListener(this) | ||
} else { | ||
viewTreeObserver.removeOnGlobalLayoutListener(this) | ||
} | ||
|
||
if (child is ViewGroup) { | ||
addMaskElements(child) | ||
} else { | ||
var marginX = 0f | ||
var marginY = 0f | ||
var parentUpper = parent.parent | ||
while((parentUpper !is VeilLayout)) { | ||
if(parentUpper is ViewGroup) { | ||
val params = parentUpper.layoutParams | ||
if(params is MarginLayoutParams) { | ||
marginX += parentUpper.x | ||
marginY += parentUpper.y | ||
} | ||
parentUpper = parentUpper.parent | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
// create a masked view | ||
val view = View(context) | ||
view.layoutParams = FrameLayout.LayoutParams(child.measuredWidth, child.measuredHeight) | ||
view.x = marginX + parent.x + child.x | ||
view.y = marginY + parent.y + child.y | ||
view.setBackgroundColor(baseColor) | ||
maskElements.add(view) | ||
shimmerContainer.addView(view) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// Invalidate the whole masked view. | ||
invalidate() | ||
|
||
// Auto veiled | ||
isVeiled = !isVeiled | ||
when(isVeiled) { | ||
true -> unVeil() | ||
false -> veil() | ||
} | ||
} | ||
|
||
/** Make appear the mask. */ | ||
fun veil() { | ||
if (!isVeiled) { | ||
isVeiled = true | ||
startShimmer() | ||
invalidate() | ||
} | ||
} | ||
|
||
/** Make disappear the mask. */ | ||
fun unVeil() { | ||
if (isVeiled) { | ||
isVeiled = false | ||
stopShimmer() | ||
invalidate() | ||
} | ||
} | ||
|
||
/** Starts the shimmer animation. */ | ||
fun startShimmer() { | ||
shimmerContainer.visible() | ||
if(shimmerEnable) { | ||
shimmerContainer.startShimmer() | ||
} | ||
} | ||
|
||
/** Stops the shimmer animation. */ | ||
fun stopShimmer() { | ||
shimmerContainer.invisible() | ||
shimmerContainer.stopShimmer() | ||
} | ||
|
||
/** Invalidate VeilLayout & Shimmer */ | ||
override fun invalidate() { | ||
super.invalidate() | ||
shimmerContainer.invalidate() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
androidveil/src/main/java/com/skydoves/androidveil/VeilParams.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,29 @@ | ||
|
||
/* | ||
* Copyright (C) 2018 skydoves | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.skydoves.androidveil | ||
|
||
import android.support.annotation.ColorInt | ||
import com.facebook.shimmer.Shimmer | ||
|
||
data class VeilParams(@ColorInt var baseColor: Int, | ||
@ColorInt var highlightColor: Int, | ||
var baseAlpha: Float, | ||
var highlightAlpha: Float, | ||
var dropOff: Float, | ||
var shimmerEnable: Boolean, | ||
var shimmer: Shimmer?) |
Oops, something went wrong.