-
Notifications
You must be signed in to change notification settings - Fork 21
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 #26 from SimformSolutionsPvtLtd/develop
Develop to Main LGTM.
- Loading branch information
Showing
2 changed files
with
34 additions
and
10 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
31 changes: 31 additions & 0 deletions
31
sspulltorefresh/src/main/java/com/simform/refresh/ViewExtensions.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,31 @@ | ||
package com.simform.refresh | ||
|
||
import android.view.View | ||
|
||
/** | ||
* Defines the coordinates of the view in its window | ||
* | ||
* @return Pair of [Int] representing x and y | ||
*/ | ||
val View.windowCoordinates: Pair<Int, Int> | ||
get() { | ||
val location = IntArray(2) | ||
getLocationInWindow(location) | ||
val x = location[0] | ||
val y = location[1] | ||
return x to y | ||
} | ||
|
||
/** | ||
* Check if view bounds include the given point in window | ||
* | ||
* @param x The x coordinate of the point | ||
* @param y The y coordinate of the point | ||
* | ||
* @return True if the view contains given point, false otherwise | ||
*/ | ||
fun View.hasPoint(x: Int, y: Int): Boolean { | ||
val viewCoordinates = windowCoordinates | ||
return x in viewCoordinates.first..(viewCoordinates.first + width) && | ||
y in viewCoordinates.second..(viewCoordinates.second + height) | ||
} |