mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merge remote-tracking branch 'origin/main' into feat/v9-prerelease
This commit is contained in:
@@ -4,20 +4,13 @@ def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
|
||||
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
def computeCompileSdkVersion() {
|
||||
if (project.hasProperty("compileSdk")) {
|
||||
return compileSdk
|
||||
} else {
|
||||
return 35
|
||||
}
|
||||
}
|
||||
|
||||
def computeBuildToolsVersion() {
|
||||
if (project.hasProperty("buildToolsVersion")) {
|
||||
return buildToolsVersion
|
||||
} else {
|
||||
return "35.0.0"
|
||||
}
|
||||
def computeCompileSdkValue () {
|
||||
if(project.hasProperty("compileSdk")) {
|
||||
return compileSdk
|
||||
}
|
||||
else {
|
||||
return 35
|
||||
}
|
||||
}
|
||||
|
||||
def computeTargetSdkVersion() {
|
||||
@@ -29,20 +22,22 @@ def computeTargetSdkVersion() {
|
||||
}
|
||||
|
||||
android {
|
||||
namespace "org.nativescript.widgets"
|
||||
compileSdkVersion computeCompileSdkVersion()
|
||||
buildToolsVersion computeBuildToolsVersion()
|
||||
// AGP 8 DSL: use 'compileSdk' and specify namespace
|
||||
compileSdk computeCompileSdkValue()
|
||||
namespace "org.nativescript.widgets"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion computeTargetSdkVersion()
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
defaultConfig {
|
||||
minSdk 21
|
||||
targetSdk computeTargetSdkVersion()
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -364,6 +364,17 @@ public class ImageView extends androidx.appcompat.widget.AppCompatImageView impl
|
||||
float uniformScale;
|
||||
float pivotX, pivotY;
|
||||
switch (this.getScaleType()) {
|
||||
case CENTER:
|
||||
uniformScale = 1;
|
||||
matrix.postTranslate((innerWidth - bitmapWidth) / 2, (innerHeight - bitmapHeight) / 2);
|
||||
matrix.postScale(uniformScale, uniformScale, innerWidth / 2, innerHeight / 2);
|
||||
canvas.clipRect(
|
||||
borderLeftWidth + (innerWidth - bitmapWidth * uniformScale) / 2,
|
||||
borderTopWidth + (innerHeight - bitmapHeight * uniformScale) / 2,
|
||||
borderLeftWidth + (innerWidth + bitmapWidth * uniformScale) / 2,
|
||||
borderTopWidth + (innerHeight + bitmapHeight * uniformScale) / 2
|
||||
);
|
||||
break;
|
||||
case FIT_CENTER: // aspectFit
|
||||
uniformScale = Math.min(fittingScaleX, fittingScaleY);
|
||||
matrix.postTranslate((innerWidth - bitmapWidth) / 2, (innerHeight - bitmapHeight) / 2);
|
||||
|
||||
@@ -219,6 +219,36 @@ public class Utils {
|
||||
boolean autoScaleFactor;
|
||||
}
|
||||
|
||||
private static int parsePositiveInt(JSONObject object, String key) {
|
||||
if (object == null || key == null) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
if (!object.has(key) || object.isNull(key)) {
|
||||
return 0;
|
||||
}
|
||||
Object value = object.get(key);
|
||||
if (value instanceof Number) {
|
||||
int parsed = (int) Math.floor(((Number) value).doubleValue());
|
||||
return parsed > 0 ? parsed : 0;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
String s = ((String) value).trim();
|
||||
if (s.length() == 0) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
int parsed = Integer.parseInt(s);
|
||||
return parsed > 0 ? parsed : 0;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final Executor executors = Executors.newCachedThreadPool();
|
||||
|
||||
|
||||
@@ -346,8 +376,9 @@ public class Utils {
|
||||
|
||||
try {
|
||||
JSONObject object = new JSONObject(options);
|
||||
opts.width = object.optInt("width", 0);
|
||||
opts.height = object.optInt("height", 0);
|
||||
// Coerce numeric strings or numbers; fallback to 0 for invalid values
|
||||
opts.width = parsePositiveInt(object, "width");
|
||||
opts.height = parsePositiveInt(object, "height");
|
||||
opts.keepAspectRatio = object.optBoolean("keepAspectRatio", true);
|
||||
opts.autoScaleFactor = object.optBoolean("autoScaleFactor", true);
|
||||
} catch (JSONException ignored) {
|
||||
|
||||
Reference in New Issue
Block a user