forked from mopsicus/umi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix screen slide up on Android when keyboard show
- Loading branch information
Showing
11 changed files
with
188 additions
and
34 deletions.
There are no files selected for viewing
Binary file modified
BIN
+0 Bytes
(100%)
Android/UnityMobileInput/.idea/caches/build_file_checksums.ser
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
.../UnityMobileInput/mobileinput/src/main/java/ru/mopsicus/mobileinput/KeyboardListener.java
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,35 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityMobileInput https://github.com/mopsicus/UnityMobileInput | ||
// Copyright (c) 2018 Mopsicus <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
package ru.mopsicus.mobileinput; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import ru.mopsicus.common.Common; | ||
|
||
public class KeyboardListener implements KeyboardObserver { | ||
|
||
private boolean isPreviousState = false; | ||
private Common common = new Common(); | ||
|
||
@Override | ||
public void onKeyboardHeight(float height, int keyboardHeight, int orientation) { | ||
boolean isShow = (keyboardHeight > 0); | ||
JSONObject json = new JSONObject(); | ||
try { | ||
json.put("msg", Plugin.KEYBOARD_ACTION); | ||
json.put("show", isShow); | ||
json.put("height", height); | ||
} catch (JSONException e) {} | ||
if (isPreviousState != isShow) { | ||
isPreviousState = isShow; | ||
common.sendData(Plugin.name, json.toString()); | ||
} | ||
} | ||
|
||
} | ||
|
15 changes: 15 additions & 0 deletions
15
.../UnityMobileInput/mobileinput/src/main/java/ru/mopsicus/mobileinput/KeyboardObserver.java
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,15 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityMobileInput https://github.com/mopsicus/UnityMobileInput | ||
// Copyright (c) 2018 Mopsicus <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
package ru.mopsicus.mobileinput; | ||
|
||
public interface KeyboardObserver { | ||
void onKeyboardHeight(float height, int keyboardHeight, int orientation); | ||
} | ||
|
||
|
||
|
||
|
96 changes: 96 additions & 0 deletions
96
.../UnityMobileInput/mobileinput/src/main/java/ru/mopsicus/mobileinput/KeyboardProvider.java
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,96 @@ | ||
// ---------------------------------------------------------------------------- | ||
// The MIT License | ||
// UnityMobileInput https://github.com/mopsicus/UnityMobileInput | ||
// Copyright (c) 2018 Mopsicus <[email protected]> | ||
// ---------------------------------------------------------------------------- | ||
|
||
package ru.mopsicus.mobileinput; | ||
|
||
import android.app.Activity; | ||
import android.content.res.Configuration; | ||
import android.content.res.Resources; | ||
import android.graphics.Point; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.view.ViewTreeObserver; | ||
import android.view.WindowManager; | ||
import android.widget.PopupWindow; | ||
|
||
public class KeyboardProvider extends PopupWindow { | ||
|
||
private KeyboardObserver observer; | ||
private int keyboardLandscapeHeight; | ||
private int keyboardPortraitHeight; | ||
private View popupView; | ||
private View parentView; | ||
private Activity activity; | ||
|
||
// Constructor | ||
public KeyboardProvider(Activity activity, ViewGroup parent, KeyboardObserver listener) { | ||
super(activity); | ||
this.observer = listener; | ||
this.activity = activity; | ||
Resources resources = this.activity.getResources(); | ||
String packageName = this.activity.getPackageName(); | ||
int id = resources.getIdentifier("popup", "layout", packageName); | ||
LayoutInflater inflator = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); | ||
this.popupView = inflator.inflate(id, null, false); | ||
setContentView(popupView); | ||
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); | ||
setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); | ||
parentView = parent; | ||
setWidth(0); | ||
setHeight(WindowManager.LayoutParams.MATCH_PARENT); | ||
setBackgroundDrawable(new ColorDrawable(0)); | ||
showAtLocation(parentView, Gravity.NO_GRAVITY, 0, 0); | ||
popupView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | ||
@Override | ||
public void onGlobalLayout() { | ||
if (popupView != null) { | ||
handleOnGlobalLayout(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// Close fake popup | ||
public void disable() { | ||
dismiss(); | ||
} | ||
|
||
// Return screen orientation | ||
private int getScreenOrientation() { | ||
return activity.getResources().getConfiguration().orientation; | ||
} | ||
|
||
// Handler to get keyboard height | ||
private void handleOnGlobalLayout() { | ||
Point screenSize = new Point(); | ||
activity.getWindowManager().getDefaultDisplay().getSize(screenSize); | ||
Rect rect = new Rect(); | ||
popupView.getWindowVisibleDisplayFrame(rect); | ||
int orientation = getScreenOrientation(); | ||
int keyboardHeight = screenSize.y - rect.bottom; | ||
float height = keyboardHeight / (float) screenSize.y; | ||
if (keyboardHeight == 0) { | ||
notifyKeyboardHeight(0, 0, orientation); | ||
} else if (orientation == Configuration.ORIENTATION_PORTRAIT) { | ||
this.keyboardPortraitHeight = keyboardHeight; | ||
notifyKeyboardHeight(height, keyboardPortraitHeight, orientation); | ||
} else { | ||
this.keyboardLandscapeHeight = keyboardHeight; | ||
notifyKeyboardHeight(height, keyboardLandscapeHeight, orientation); | ||
} | ||
} | ||
|
||
// Send data observer | ||
private void notifyKeyboardHeight(float height, int keyboardHeight, int orientation) { | ||
if (observer != null) { | ||
observer.onKeyboardHeight(height, keyboardHeight, orientation); | ||
} | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
Android/UnityMobileInput/mobileinput/src/main/res/layout/popup.xml
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/popup" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent"> | ||
|
||
</LinearLayout> |
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
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