Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
6fd3a157
Commit
6fd3a157
authored
Dec 20, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delete LayoutHelper.kt
parent
090acd8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
70 deletions
+0
-70
LayoutHelper.kt
app/src/main/java/chat/rocket/android/app/LayoutHelper.kt
+0
-70
No files found.
app/src/main/java/chat/rocket/android/app/LayoutHelper.kt
deleted
100644 → 0
View file @
090acd8a
package
chat.rocket.android.app
import
android.app.Activity
import
android.graphics.Rect
import
android.util.Log
import
android.view.View
import
android.view.ViewTreeObserver
import
android.widget.FrameLayout
//TODO: check if this code has memory leak.
class
LayoutHelper
{
private
var
childOfContent
:
View
?
=
null
private
var
usableHeightPrevious
:
Int
=
0
private
var
frameLayoutParams
:
FrameLayout
.
LayoutParams
?
=
null
/**
* Workaround to adjust the layout when in the full screen mode.
*
* The original author of this code is Joseph Johnson and you can see his answer here: https://stackoverflow.com/a/19494006/4744263
*
* Note that this function has some differences from the original, like using *frameLayoutParams.height = usableHeightNow* instead of
* *frameLayoutParams.height = usableHeightSansKeyboard* (RobertoAllende's comment - from the same link above).
*
* @param activity The Activity to adjust the layout.
*/
fun
install
(
activity
:
Activity
)
{
try
{
val
content
=
activity
.
findViewById
<
View
>(
android
.
R
.
id
.
content
)
as
FrameLayout
childOfContent
=
content
.
getChildAt
(
0
)
childOfContent
?.
viewTreeObserver
?.
addOnGlobalLayoutListener
(
listener
)
frameLayoutParams
=
childOfContent
?.
layoutParams
as
FrameLayout
.
LayoutParams
}
catch
(
exception
:
ClassCastException
)
{
// TODO: are we using the android.util.Log for logging that type of errors? or should we use the SDK logger?
Log
.
e
(
"ERROR"
,
exception
.
message
)
}
}
private
val
listener
=
ViewTreeObserver
.
OnGlobalLayoutListener
{
resizeChildOfContent
()
}
private
fun
resizeChildOfContent
()
{
val
usableHeightNow
=
computeUsableHeight
()
if
(
usableHeightNow
!=
usableHeightPrevious
)
{
val
usableHeightSansKeyboard
=
childOfContent
?.
rootView
?.
height
?:
0
val
heightDifference
=
usableHeightSansKeyboard
-
usableHeightNow
if
(
heightDifference
>
usableHeightSansKeyboard
/
4
)
{
// keyboard probably just became visible
frameLayoutParams
?.
height
=
usableHeightSansKeyboard
-
heightDifference
}
else
{
// keyboard probably just became hidden
frameLayoutParams
?.
height
=
usableHeightNow
}
childOfContent
?.
requestLayout
()
usableHeightPrevious
=
usableHeightNow
}
}
private
fun
computeUsableHeight
():
Int
{
val
rect
=
Rect
()
childOfContent
?.
getWindowVisibleDisplayFrame
(
rect
)
return
rect
.
bottom
-
rect
.
top
}
fun
remove
()
{
childOfContent
?.
viewTreeObserver
?.
removeOnGlobalLayoutListener
(
listener
)
childOfContent
=
null
frameLayoutParams
=
null
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment