mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Added parser for inset drawables
This commit is contained in:
Binary file not shown.
@@ -15,8 +15,6 @@
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package com.itsaky.androidide.utils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
-18
@@ -552,24 +552,6 @@ public class ViewAttrAdapter extends CommonParseUtils implements IAttributeAdapt
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
protected int getUnitForDimensionType(String dimensionType) {
|
||||
switch (dimensionType) {
|
||||
case "dp" :
|
||||
return TypedValue.COMPLEX_UNIT_DIP;
|
||||
case "sp" :
|
||||
return TypedValue.COMPLEX_UNIT_SP;
|
||||
case "px" :
|
||||
return TypedValue.COMPLEX_UNIT_PX;
|
||||
case "pt" :
|
||||
return TypedValue.COMPLEX_UNIT_PT;
|
||||
case "in" :
|
||||
return TypedValue.COMPLEX_UNIT_IN;
|
||||
case "mm" :
|
||||
return TypedValue.COMPLEX_UNIT_MM;
|
||||
}
|
||||
return TypedValue.COMPLEX_UNIT_DIP;
|
||||
}
|
||||
|
||||
protected boolean isApi26() {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of AndroidIDE.
|
||||
*
|
||||
* AndroidIDE is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* AndroidIDE is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.itsaky.inflater.drawable;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.InsetDrawable;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import com.itsaky.androidide.app.BaseApplication;
|
||||
import com.itsaky.inflater.IResourceTable;
|
||||
import com.itsaky.inflater.InflateException;
|
||||
import com.itsaky.inflater.util.Preconditions;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* Parser for <inset> drawables.
|
||||
*
|
||||
* @author Akash Yadav
|
||||
*/
|
||||
public class InsetDrawableParser extends IDrawableParser {
|
||||
|
||||
protected InsetDrawableParser (XmlPullParser parser, IResourceTable resourceFinder, DisplayMetrics displayMetrics) {
|
||||
super (parser, resourceFinder, displayMetrics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable parse () throws Exception {
|
||||
var index = attrIndex ("drawable");
|
||||
if (index == -1) {
|
||||
throw new InflateException ("No drawable specified for <inset> drawable");
|
||||
}
|
||||
|
||||
var value = value (index);
|
||||
Preconditions.assertNotBlank (value, "Invalid value specified for android:drawable");
|
||||
|
||||
final var drawable = parseDrawable (value, BaseApplication.getBaseInstance ());
|
||||
if (drawable == null) {
|
||||
throw new InflateException ("Unable to parse inset drawable. Failed to parse android:drawable");
|
||||
}
|
||||
|
||||
index = attrIndex ("insetLeft");
|
||||
final var left = index == -1 ? 0 : parseDimension (value (index), 0);
|
||||
|
||||
index = attrIndex ("insetTop");
|
||||
final var top = index == -1 ? 0 : parseDimension (value (index), 0);
|
||||
|
||||
index = attrIndex ("insetRight");
|
||||
final var right = index == -1 ? 0 : parseDimension (value (index), 0);
|
||||
|
||||
index = attrIndex ("insetBottom");
|
||||
final var bottom = index == -1 ? 0 : parseDimension (value (index), 0);
|
||||
|
||||
return new InsetDrawable (drawable, left, top, right, bottom);
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
@@ -72,7 +73,7 @@ public class CommonParseUtils {
|
||||
}
|
||||
|
||||
protected int parseDimension(final String value, int defaultValue) {
|
||||
if (value == null) {
|
||||
if (value == null || value.isEmpty ()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@@ -111,6 +112,7 @@ public class CommonParseUtils {
|
||||
}
|
||||
|
||||
protected int getUnitForDimensionType(@NonNull String dimensionType) {
|
||||
|
||||
switch (dimensionType) {
|
||||
case "dp" :
|
||||
return TypedValue.COMPLEX_UNIT_DIP;
|
||||
@@ -125,6 +127,7 @@ public class CommonParseUtils {
|
||||
case "mm" :
|
||||
return TypedValue.COMPLEX_UNIT_MM;
|
||||
}
|
||||
|
||||
return TypedValue.COMPLEX_UNIT_DIP;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user