Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up runtime OS version check #1480

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions Source/Fuse.Android.TextRenderer/StaticLayoutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ public static synchronized void ensureInitialized() {
}

try {
final Class<?> textDirClass;
if (Build.VERSION.SDK_INT >= 18) {
textDirClass = TextDirectionHeuristic.class;
sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
} else {
final ClassLoader loader = StaticLayoutBuilder.class.getClassLoader();
textDirClass = loader.loadClass(TEXT_DIR_CLASS);

final Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
}
final Class<?> textDirClass = TextDirectionHeuristic.class;
sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;

final Class<?>[] signature = new Class[] {
CharSequence.class,
Expand All @@ -64,22 +55,12 @@ public static synchronized void ensureInitialized() {
sConstructorArgs = new Object[signature.length];
} catch (NoSuchMethodException e) {
Log.e(LOGTAG, "StaticLayout constructor with max lines not found.", e);
} catch (ClassNotFoundException e) {
Log.e(LOGTAG, "TextDirectionHeuristic class not found.", e);
} catch (NoSuchFieldException e) {
Log.e(LOGTAG, "TextDirectionHeuristics.FIRSTSTRONG_LTR not found.", e);
} catch (IllegalAccessException e) {
Log.e(LOGTAG, "TextDirectionHeuristics.FIRSTSTRONG_LTR not accessible.", e);
} finally {
sInitialized = true;
}
}

public static boolean isSupported() {
if (Build.VERSION.SDK_INT < 14) {
return false;
}

ensureInitialized();
return (sConstructor != null);
}
Expand Down
3 changes: 1 addition & 2 deletions Source/Fuse.Controls.Native/Android/TextEdit.uno
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ namespace Fuse.Controls.Native.Android
t.setIncludeFontPadding(false);
t.setBackgroundResource(0);
t.setPadding(0, 0, 0, 0);
if (android.os.Build.VERSION.SDK_INT >= 17)
t.setPaddingRelative(0, 0, 0, 0);
t.setPaddingRelative(0, 0, 0, 0);
@}
}

Expand Down
4 changes: 1 addition & 3 deletions Source/Fuse.Controls.Native/Android/TextView.uno
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ namespace Fuse.Controls.Native.Android
[Foreign(Language.Java)]
static void SetTextAlignment(Java.Object handle, int alignment)
@{
if (android.os.Build.VERSION.SDK_INT >= 17)
((android.widget.TextView)handle).setTextAlignment(android.view.View.TEXT_ALIGNMENT_GRAVITY);

((android.widget.TextView)handle).setTextAlignment(android.view.View.TEXT_ALIGNMENT_GRAVITY);
((android.widget.TextView)handle).setGravity(alignment);
@}

Expand Down
31 changes: 2 additions & 29 deletions Source/Fuse.Controls.Primitives/TextControls/MobileTextEdit.uno
Original file line number Diff line number Diff line change
Expand Up @@ -337,35 +337,8 @@ namespace Fuse.Controls

target.setGravity(source.getGravity());

if (android.os.Build.VERSION.SDK_INT >= 17)
{
target.setTextAlignment(android.view.View.TEXT_ALIGNMENT_GRAVITY);
target.setHorizontallyScrolling(false);
}
else
{
target.setHorizontallyScrolling(!isMultiline);
if (updateTextAlignment)
{
// This piece of code fixes the textalignment issues we have
// been having for a long time. What happens is that TextView/EditText
// has some internal state for text alignment that is not updated when
// setting properties like textAlignment/gravity/scroll etc.
// Reading the TextView code, I found that the following method
// calls will hit the codepaths that update the text alignment state
target.setSelection(source.getSelectionStart(), source.getSelectionEnd());
target.layout(0, 0, width, height);
target.onPreDraw();
}
else
{
// One cause of the issue above is that the source TextEdit's scrollposition
// does not have a valid value. One frame after changing textalignment this state
// will be valid
target.setScrollX(source.getScrollX());
target.setScrollY(source.getScrollY());
}
}
target.setTextAlignment(android.view.View.TEXT_ALIGNMENT_GRAVITY);
target.setHorizontallyScrolling(false);
@}

[Foreign(Language.Java)]
Expand Down
3 changes: 0 additions & 3 deletions Source/Fuse.Controls.Video/Android/VideoPlayer.uno
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,6 @@ namespace Fuse.Controls.VideoImpl.Android
catch (Exception e) { /* We do not care if this fails */ }
}

if (android.os.Build.VERSION.SDK_INT < 19) // we need API level 19 to call MediaPlayer.TrackInfo.getFormat()
return 0;

android.media.MediaPlayer player = (android.media.MediaPlayer)handle;
android.media.MediaPlayer.TrackInfo[] tracks = player.getTrackInfo();
for (int i = 0; i < tracks.length; i++)
Expand Down
44 changes: 19 additions & 25 deletions Source/Fuse.Controls.WebView/Android/FuseWebChromeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ public boolean onTouch(View view, MotionEvent event) {
intent.setType("*/*");

if (allowMultiple) {
if (Build.VERSION.SDK_INT >= 18) {
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}

com.fuse.Activity.ResultListener listener = new com.fuse.Activity.ResultListener() {
Expand All @@ -129,15 +127,13 @@ public boolean onResult(int requestCode, int resultCode, Intent intent) {
dataUris = new Uri[] { Uri.parse(intent.getDataString()) };
}
else {
if (Build.VERSION.SDK_INT >= 16) {
if (intent.getClipData() != null) {
final int numSelectedFiles = intent.getClipData().getItemCount();
if (intent.getClipData() != null) {
final int numSelectedFiles = intent.getClipData().getItemCount();

dataUris = new Uri[numSelectedFiles];
dataUris = new Uri[numSelectedFiles];

for (int i = 0; i < numSelectedFiles; i++) {
dataUris[i] = intent.getClipData().getItemAt(i).getUri();
}
for (int i = 0; i < numSelectedFiles; i++) {
dataUris[i] = intent.getClipData().getItemAt(i).getUri();
}
}
}
Expand Down Expand Up @@ -183,24 +179,22 @@ public boolean onJsAlert(WebView view, String url, String message, JsResult resu

@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
if (_customView != null) {
callback.onCustomViewHidden();
return;
}
if (_customView != null) {
callback.onCustomViewHidden();
return;
}

_originalOrientation = _activity.getRequestedOrientation();
_originalOrientation = _activity.getRequestedOrientation();

FrameLayout decor = (FrameLayout) _activity.getWindow().getDecorView();
FrameLayout decor = (FrameLayout) _activity.getWindow().getDecorView();

_fullscreenContainer = new FullscreenHolder(_activity);
_fullscreenContainer.addView(view, ViewGroup.LayoutParams.MATCH_PARENT);
decor.addView(_fullscreenContainer, ViewGroup.LayoutParams.MATCH_PARENT);
_customView = view;
setFullscreen(true);
_customViewCallback = callback;
_activity.setRequestedOrientation(_originalOrientation);
}
_fullscreenContainer = new FullscreenHolder(_activity);
_fullscreenContainer.addView(view, ViewGroup.LayoutParams.MATCH_PARENT);
decor.addView(_fullscreenContainer, ViewGroup.LayoutParams.MATCH_PARENT);
_customView = view;
setFullscreen(true);
_customViewCallback = callback;
_activity.setRequestedOrientation(_originalOrientation);
super.onShowCustomView(view, callback);
}

Expand Down
4 changes: 1 addition & 3 deletions Source/Fuse.MediaPicker/Android/MediaPickerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ public void launchPickImageFromGalleryIntent() {

public void launchMultiPickImageFromGalleryIntent() {
Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
pickImageIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
}
pickImageIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
pickImageIntent.setType("image/*");

com.fuse.Activity.getRootActivity().startActivityForResult(pickImageIntent, REQUEST_CODE_CHOOSE_MULTI_IMAGE_FROM_GALLERY);
Expand Down
101 changes: 25 additions & 76 deletions Source/Fuse.Platform/Android/SystemUI.uno
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,10 @@ namespace Fuse.Platform
com.fuse.Activity.getRootActivity().runOnUiThread(new Runnable() { public void run()
{
@{_systemUIState:Set(@{SysUIState.Normal})};
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (android.os.Build.VERSION.SDK_INT < 16)
{
com.fuse.Activity.getRootActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = com.fuse.Activity.getRootActivity().getWindow().getDecorView();
// Hide the status bar.
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
@{HideActionBar():Call()};
}
View decorView = com.fuse.Activity.getRootActivity().getWindow().getDecorView();
// Hide the status bar.
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
@{HideActionBar():Call()};
@{CompensateRootLayoutForSystemUI():Call()};
@{cppOnTopFrameChanged(int):Call((int)@{GetStatusBarHeight():Call()})};
}});
Expand All @@ -300,16 +293,10 @@ namespace Fuse.Platform
com.fuse.Activity.getRootActivity().runOnUiThread(new Runnable() { public void run()
{
@{_systemUIState:Set(@{SysUIState.StatusBarHidden})};
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (android.os.Build.VERSION.SDK_INT < 16) {
com.fuse.Activity.getRootActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else {
View decorView = com.fuse.Activity.getRootActivity().getWindow().getDecorView();
// Hide the status bar.
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
@{HideActionBar():Call()};
}
View decorView = com.fuse.Activity.getRootActivity().getWindow().getDecorView();
// Hide the status bar.
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
@{HideActionBar():Call()};
@{CompensateRootLayoutForSystemUI():Call()};
@{cppOnTopFrameChanged(int):Call(0)};
}});
Expand Down Expand Up @@ -404,22 +391,16 @@ namespace Fuse.Platform
@{
com.fuse.Activity.getRootActivity().runOnUiThread(new Runnable() { public void run() {
@{_systemUIState:Set(@{SysUIState.Fullscreen})};
// If the Android version is lower than Jellybean, use this call to hide
// the status bar.
if (android.os.Build.VERSION.SDK_INT < 19) {
@{HideStatusBar():Call()};
} else {
View decorView = com.fuse.Activity.getRootActivity().getWindow().getDecorView();
// Hide the status bar.
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
@{HideActionBar():Call()};
}
View decorView = com.fuse.Activity.getRootActivity().getWindow().getDecorView();
// Hide the status bar.
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
@{HideActionBar():Call()};
@{CompensateRootLayoutForSystemUI():Call()};
@{cppOnTopFrameChanged(int):Call(0)};
}});
Expand Down Expand Up @@ -454,30 +435,10 @@ namespace Fuse.Platform
@{
//cache initialSize so we have something sane
android.view.Display display = com.fuse.Activity.getRootActivity().getWindowManager().getDefaultDisplay();
if (android.os.Build.VERSION.SDK_INT >= 17) {
//new pleasant way to get real metrics
DisplayMetrics realMetrics = new DisplayMetrics();
display.getRealMetrics(realMetrics);
@{realWidth:Set(realMetrics.widthPixels)};
@{realHeight:Set(realMetrics.heightPixels)};
} else if (android.os.Build.VERSION.SDK_INT >= 14) {
//reflection for this weird in-between time
try {
Method mGetRawH = android.view.Display.class.getMethod("getRawHeight");
Method mGetRawW = android.view.Display.class.getMethod("getRawWidth");
@{realWidth:Set((Integer)mGetRawW.invoke(display))};
@{realHeight:Set((Integer)mGetRawH.invoke(display))};
} catch (Exception e) {
//this may not be 100% accurate, but it's all we've got
@{realWidth:Set(display.getWidth())};
@{realHeight:Set(display.getHeight())};
}
} else {
//This should be close, as lower API devices should not have window navigation bars
@{realWidth:Set(display.getWidth())};
@{realHeight:Set(display.getHeight())};
}

DisplayMetrics realMetrics = new DisplayMetrics();
display.getRealMetrics(realMetrics);
@{realWidth:Set(realMetrics.widthPixels)};
@{realHeight:Set(realMetrics.heightPixels)};
if (@{SuperLayout}!=null) {
int tmp = ((FrameLayout)@{SuperLayout}).getWidth();
if (tmp!=0 && tmp!= @{realHeight} && @{realWidth}!=tmp) {
Expand All @@ -490,13 +451,8 @@ namespace Fuse.Platform
static public Java.Object GetDisplayMetrics()
@{
DisplayMetrics metrics = new DisplayMetrics();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
com.fuse.Activity.getRootActivity().getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
return metrics;
} else {
com.fuse.Activity.getRootActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics;
}
com.fuse.Activity.getRootActivity().getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
return metrics;
@}

static public int GetRealDisplayWidth()
Expand Down Expand Up @@ -609,9 +565,6 @@ namespace Fuse.Platform
int width = FrameLayout.LayoutParams.MATCH_PARENT;
View uview = (View)view;
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width,height);
if (android.os.Build.VERSION.SDK_INT < 14) {
lp.gravity = Gravity.TOP;
}
lp.leftMargin = originX;
lp.topMargin = originY;
uview.setLayoutParams(lp);
Expand All @@ -634,11 +587,7 @@ namespace Fuse.Platform
static public void Detach() // Also use this for DetachFromActivity()
@{
if (@{layoutAttachedTo}!=null) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
((FrameLayout)@{RootLayout}).getViewTreeObserver().removeOnGlobalLayoutListener(((ViewTreeObserver.OnGlobalLayoutListener)@{_keyboardListener}));
} else {
((FrameLayout)@{RootLayout}).getViewTreeObserver().removeGlobalOnLayoutListener(((ViewTreeObserver.OnGlobalLayoutListener)@{_keyboardListener}));
}
((FrameLayout)@{RootLayout}).getViewTreeObserver().removeOnGlobalLayoutListener(((ViewTreeObserver.OnGlobalLayoutListener)@{_keyboardListener}));
}
@{layoutAttachedTo:Set(null)};
@}
Expand Down
Loading