-
Notifications
You must be signed in to change notification settings - Fork 4
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
22 changed files
with
243 additions
and
84 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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
71 changes: 71 additions & 0 deletions
71
app/src/main/kotlin/com/ediposouza/teslesgendstracker/ui/util/KeyboardUtil.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,71 @@ | ||
package com.ediposouza.teslesgendstracker.ui.util | ||
|
||
import android.app.Activity | ||
import android.graphics.Rect | ||
import android.os.Build | ||
import android.view.View | ||
import android.view.ViewTreeObserver | ||
|
||
|
||
/** | ||
* Created by EdipoSouza on 12/31/16. | ||
*/ | ||
/** | ||
* Created by mikepenz on 14.03.15. | ||
* This class implements a hack to change the layout padding on bottom if the keyboard is shown | ||
* to allow long lists with editTextViews | ||
* Basic idea for this solution found here: http://stackoverflow.com/a/9108219/325479 | ||
*/ | ||
class KeyboardUtil(act: Activity, private val contentView: View?) { | ||
|
||
//a small helper to allow showing the editText focus | ||
private var onGlobalLayoutListener: ViewTreeObserver.OnGlobalLayoutListener = ViewTreeObserver.OnGlobalLayoutListener { | ||
val r = Rect() | ||
//r will be populated with the coordinates of your view that area still visible. | ||
decorView.getWindowVisibleDisplayFrame(r) | ||
|
||
//get screen height and calculate the difference with the useable area from the r | ||
val height = decorView.context.resources.displayMetrics.heightPixels | ||
val diff = height - r.bottom | ||
|
||
//if it could be a keyboard add the padding to the view | ||
if (diff != 0) { | ||
// if the use-able screen height differs from the total screen height we assume that it shows a keyboard now | ||
//check if the padding is 0 (if yes set the padding for the keyboard) | ||
if (contentView?.paddingBottom !== diff) { | ||
//set the padding of the contentView for the keyboard | ||
contentView?.setPadding(0, 0, 0, diff) | ||
} | ||
} else { | ||
//check if the padding is != 0 (if yes reset the padding) | ||
if (contentView?.paddingBottom !== 0) { | ||
//reset the padding of the contentView | ||
contentView?.setPadding(0, 0, 0, 0) | ||
} | ||
} | ||
} | ||
|
||
private val decorView: View | ||
|
||
init { | ||
this.decorView = act.window.decorView | ||
|
||
//only required on newer android versions. it was working on API level 19 (Build.VERSION_CODES.KITKAT) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
decorView.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener) | ||
} | ||
} | ||
|
||
fun enable() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
decorView.viewTreeObserver.addOnGlobalLayoutListener(onGlobalLayoutListener) | ||
} | ||
} | ||
|
||
fun disable() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { | ||
decorView.viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener) | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.