Move requestLayout to AndroidUtils
This commit is contained in:
parent
594ed86b60
commit
2e09dd8731
2 changed files with 26 additions and 24 deletions
|
@ -48,6 +48,7 @@ import android.util.TypedValue;
|
|||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewParent;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -551,19 +552,40 @@ public class AndroidUtils {
|
|||
return coordinates;
|
||||
}
|
||||
|
||||
public static void enterToFullScreen(Activity activity) {
|
||||
public static void enterToFullScreen(Activity activity, View view) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
requestLayout(view);
|
||||
activity.getWindow().getDecorView()
|
||||
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
|
||||
public static void exitFromFullScreen(Activity activity) {
|
||||
public static void exitFromFullScreen(Activity activity, View view) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
requestLayout(view);
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requestLayout(final View view) {
|
||||
if (view != null) {
|
||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
obs.removeOnGlobalLayoutListener(this);
|
||||
} else {
|
||||
obs.removeGlobalOnLayoutListener(this);
|
||||
}
|
||||
view.requestLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
|
||||
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.activities;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Dialog;
|
||||
|
@ -38,7 +37,6 @@ import android.view.KeyEvent;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewStub;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -376,29 +374,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
|
||||
public void exitFromFullScreen(View view) {
|
||||
runLayoutListener(view);
|
||||
AndroidUtils.exitFromFullScreen(this);
|
||||
AndroidUtils.exitFromFullScreen(this, view);
|
||||
}
|
||||
|
||||
public void enterToFullScreen() {
|
||||
runLayoutListener(getLayout());
|
||||
AndroidUtils.enterToFullScreen(this);
|
||||
}
|
||||
|
||||
private void runLayoutListener(final View view) {
|
||||
if (view != null) {
|
||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
public void onGlobalLayout() {
|
||||
ViewTreeObserver obs = view.getViewTreeObserver();
|
||||
obs.removeOnGlobalLayoutListener(this);
|
||||
view.requestLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
AndroidUtils.enterToFullScreen(this, getLayout());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue