diff options
Diffstat (limited to 'graphics/java')
10 files changed, 170 insertions, 109 deletions
diff --git a/graphics/java/android/graphics/FontFamily.java b/graphics/java/android/graphics/FontFamily.java index 11d3165..b8b7e76 100644 --- a/graphics/java/android/graphics/FontFamily.java +++ b/graphics/java/android/graphics/FontFamily.java @@ -18,8 +18,6 @@ package android.graphics; import android.content.res.AssetManager; -import java.io.File; - /** * A family of typefaces with different styles. * @@ -64,6 +62,10 @@ public class FontFamily { return nAddFont(mNativePtr, path); } + public boolean addFontWeightStyle(String path, int weight, boolean style) { + return nAddFontWeightStyle(mNativePtr, path, weight, style); + } + public boolean addFontFromAsset(AssetManager mgr, String path) { return nAddFontFromAsset(mNativePtr, mgr, path); } @@ -71,6 +73,8 @@ public class FontFamily { private static native long nCreateFamily(String lang, int variant); private static native void nUnrefFamily(long nativePtr); private static native boolean nAddFont(long nativeFamily, String path); + private static native boolean nAddFontWeightStyle(long nativeFamily, String path, + int weight, boolean isItalic); private static native boolean nAddFontFromAsset(long nativeFamily, AssetManager mgr, String path); } diff --git a/graphics/java/android/graphics/FontListParser.java b/graphics/java/android/graphics/FontListParser.java index a863a06..97081f9 100644 --- a/graphics/java/android/graphics/FontListParser.java +++ b/graphics/java/android/graphics/FontListParser.java @@ -33,23 +33,48 @@ import java.util.List; */ public class FontListParser { + public static class Config { + Config() { + families = new ArrayList<Family>(); + aliases = new ArrayList<Alias>(); + } + public List<Family> families; + public List<Alias> aliases; + } + + public static class Font { + Font(String fontName, int weight, boolean isItalic) { + this.fontName = fontName; + this.weight = weight; + this.isItalic = isItalic; + } + public String fontName; + public int weight; + public boolean isItalic; + } + + public static class Alias { + public String name; + public String toName; + public int weight; + } + public static class Family { - public Family(List<String> names, List<String> fontFiles, String lang, String variant) { - this.names = names; - this.fontFiles = fontFiles; + public Family(String name, List<Font> fonts, String lang, String variant) { + this.name = name; + this.fonts = fonts; this.lang = lang; this.variant = variant; } - public List<String> names; - // todo: need attributes for font files - public List<String> fontFiles; + public String name; + public List<Font> fonts; public String lang; public String variant; } /* Parse fallback list (no names) */ - public static List<Family> parse(InputStream in) throws XmlPullParserException, IOException { + public static Config parse(InputStream in) throws XmlPullParserException, IOException { try { XmlPullParser parser = Xml.newPullParser(); parser.setInput(in, null); @@ -60,57 +85,59 @@ public class FontListParser { } } - private static List<Family> readFamilies(XmlPullParser parser) + private static Config readFamilies(XmlPullParser parser) throws XmlPullParserException, IOException { - List<Family> families = new ArrayList<Family>(); + Config config = new Config(); parser.require(XmlPullParser.START_TAG, null, "familyset"); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; if (parser.getName().equals("family")) { - families.add(readFamily(parser)); + config.families.add(readFamily(parser)); + } else if (parser.getName().equals("alias")) { + config.aliases.add(readAlias(parser)); } else { skip(parser); } } - return families; + return config; } private static Family readFamily(XmlPullParser parser) throws XmlPullParserException, IOException { - List<String> names = null; - List<String> fontFiles = new ArrayList<String>(); - String lang = null; - String variant = null; + String name = parser.getAttributeValue(null, "name"); + String lang = parser.getAttributeValue(null, "lang"); + String variant = parser.getAttributeValue(null, "variant"); + List<Font> fonts = new ArrayList<Font>(); while (parser.next() != XmlPullParser.END_TAG) { if (parser.getEventType() != XmlPullParser.START_TAG) continue; String tag = parser.getName(); - if (tag.equals("fileset")) { - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) continue; - if (parser.getName().equals("file")) { - if (lang == null) { - lang = parser.getAttributeValue(null, "lang"); - } - if (variant == null) { - variant = parser.getAttributeValue(null, "variant"); - } - String filename = parser.nextText(); - String fullFilename = "/system/fonts/" + filename; - fontFiles.add(fullFilename); - } - } - } else if (tag.equals("nameset")) { - names = new ArrayList<String>(); - while (parser.next() != XmlPullParser.END_TAG) { - if (parser.getEventType() != XmlPullParser.START_TAG) continue; - if (parser.getName().equals("name")) { - String name = parser.nextText(); - names.add(name); - } - } + if (tag.equals("font")) { + String weightStr = parser.getAttributeValue(null, "weight"); + int weight = weightStr == null ? 400 : Integer.parseInt(weightStr); + boolean isItalic = "italic".equals(parser.getAttributeValue(null, "style")); + String filename = parser.nextText(); + String fullFilename = "/system/fonts/" + filename; + fonts.add(new Font(fullFilename, weight, isItalic)); + } else { + skip(parser); } } - return new Family(names, fontFiles, lang, variant); + return new Family(name, fonts, lang, variant); + } + + private static Alias readAlias(XmlPullParser parser) + throws XmlPullParserException, IOException { + Alias alias = new Alias(); + alias.name = parser.getAttributeValue(null, "name"); + alias.toName = parser.getAttributeValue(null, "to"); + String weightStr = parser.getAttributeValue(null, "weight"); + if (weightStr == null) { + alias.weight = 400; + } else { + alias.weight = Integer.parseInt(weightStr); + } + skip(parser); // alias tag is empty, ignore any contents and consume end tag + return alias; } private static void skip(XmlPullParser parser) throws XmlPullParserException, IOException { diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java index 568d3f2..db42314 100644 --- a/graphics/java/android/graphics/Typeface.java +++ b/graphics/java/android/graphics/Typeface.java @@ -66,8 +66,7 @@ public class Typeface { static Map<String, Typeface> sSystemFontMap; static FontFamily[] sFallbackFonts; - static final String SYSTEM_FONTS_CONFIG = "system_fonts.xml"; - static final String FALLBACK_FONTS_CONFIG = "fallback_fonts.xml"; + static final String FONTS_CONFIG = "fonts.xml"; /** * @hide @@ -261,10 +260,9 @@ public class Typeface { } private static FontFamily makeFamilyFromParsed(FontListParser.Family family) { - // TODO: expand to handle attributes like lang and variant FontFamily fontFamily = new FontFamily(family.lang, family.variant); - for (String fontFile : family.fontFiles) { - fontFamily.addFont(fontFile); + for (FontListParser.Font font : family.fonts) { + fontFamily.addFontWeightStyle(font.fontName, font.weight, font.isItalic); } return fontFamily; } @@ -277,48 +275,53 @@ public class Typeface { private static void init() { // Load font config and initialize Minikin state File systemFontConfigLocation = getSystemFontConfigLocation(); - File systemConfigFilename = new File(systemFontConfigLocation, SYSTEM_FONTS_CONFIG); - File configFilename = new File(systemFontConfigLocation, FALLBACK_FONTS_CONFIG); + File configFilename = new File(systemFontConfigLocation, FONTS_CONFIG); try { - // TODO: throws an exception non-Minikin builds, to fail early; - // remove when Minikin-only - new FontFamily(); + FileInputStream fontsIn = new FileInputStream(configFilename); + FontListParser.Config fontConfig = FontListParser.parse(fontsIn); - FileInputStream systemIn = new FileInputStream(systemConfigFilename); - List<FontListParser.Family> systemFontConfig = FontListParser.parse(systemIn); - - FileInputStream fallbackIn = new FileInputStream(configFilename); List<FontFamily> familyList = new ArrayList<FontFamily>(); // Note that the default typeface is always present in the fallback list; // this is an enhancement from pre-Minikin behavior. - familyList.add(makeFamilyFromParsed(systemFontConfig.get(0))); - for (Family f : FontListParser.parse(fallbackIn)) { - familyList.add(makeFamilyFromParsed(f)); + for (int i = 0; i < fontConfig.families.size(); i++) { + Family f = fontConfig.families.get(i); + if (i == 0 || f.name == null) { + familyList.add(makeFamilyFromParsed(f)); + } } sFallbackFonts = familyList.toArray(new FontFamily[familyList.size()]); setDefault(Typeface.createFromFamilies(sFallbackFonts)); Map<String, Typeface> systemFonts = new HashMap<String, Typeface>(); - for (int i = 0; i < systemFontConfig.size(); i++) { + for (int i = 0; i < fontConfig.families.size(); i++) { Typeface typeface; - Family f = systemFontConfig.get(i); - if (i == 0) { - // The first entry is the default typeface; no sense in duplicating - // the corresponding FontFamily. - typeface = sDefaultTypeface; - } else { - FontFamily fontFamily = makeFamilyFromParsed(f); - FontFamily[] families = { fontFamily }; - typeface = Typeface.createFromFamiliesWithDefault(families); + Family f = fontConfig.families.get(i); + if (f.name != null) { + if (i == 0) { + // The first entry is the default typeface; no sense in + // duplicating the corresponding FontFamily. + typeface = sDefaultTypeface; + } else { + FontFamily fontFamily = makeFamilyFromParsed(f); + FontFamily[] families = { fontFamily }; + typeface = Typeface.createFromFamiliesWithDefault(families); + } + systemFonts.put(f.name, typeface); } - for (String name : f.names) { - systemFonts.put(name, typeface); + } + for (FontListParser.Alias alias : fontConfig.aliases) { + Typeface base = systemFonts.get(alias.toName); + Typeface newFace = base; + int weight = alias.weight; + if (weight != 400) { + newFace = new Typeface(nativeCreateWeightAlias(base.native_instance, weight)); } + systemFonts.put(alias.name, newFace); } sSystemFontMap = systemFonts; } catch (RuntimeException e) { - Log.w(TAG, "Didn't create default family (most likely, non-Minikin build)"); + Log.w(TAG, "Didn't create default family (most likely, non-Minikin build)", e); // TODO: normal in non-Minikin case, remove or make error when Minikin-only } catch (FileNotFoundException e) { Log.e(TAG, "Error opening " + configFilename); @@ -383,6 +386,7 @@ public class Typeface { } private static native long nativeCreateFromTypeface(long native_instance, int style); + private static native long nativeCreateWeightAlias(long native_instance, int weight); private static native void nativeUnref(long native_instance); private static native int nativeGetStyle(long native_instance); private static native long nativeCreateFromArray(long[] familyArray); diff --git a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java index 0bc4fdf..4c8b4f1 100644 --- a/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedRotateDrawable.java @@ -346,22 +346,24 @@ public class AnimatedRotateDrawable extends Drawable implements Drawable.Callbac private boolean mCanConstantState; private boolean mCheckedConstantState; - public AnimatedRotateState(AnimatedRotateState source, AnimatedRotateDrawable owner, + public AnimatedRotateState(AnimatedRotateState orig, AnimatedRotateDrawable owner, Resources res) { - if (source != null) { + if (orig != null) { if (res != null) { - mDrawable = source.mDrawable.getConstantState().newDrawable(res); + mDrawable = orig.mDrawable.getConstantState().newDrawable(res); } else { - mDrawable = source.mDrawable.getConstantState().newDrawable(); + mDrawable = orig.mDrawable.getConstantState().newDrawable(); } mDrawable.setCallback(owner); - mDrawable.setLayoutDirection(source.mDrawable.getLayoutDirection()); - mPivotXRel = source.mPivotXRel; - mPivotX = source.mPivotX; - mPivotYRel = source.mPivotYRel; - mPivotY = source.mPivotY; - mFramesCount = source.mFramesCount; - mFrameDuration = source.mFrameDuration; + mDrawable.setLayoutDirection(orig.mDrawable.getLayoutDirection()); + mDrawable.setBounds(orig.mDrawable.getBounds()); + mDrawable.setLevel(orig.mDrawable.getLevel()); + mPivotXRel = orig.mPivotXRel; + mPivotX = orig.mPivotX; + mPivotYRel = orig.mPivotYRel; + mPivotY = orig.mPivotY; + mFramesCount = orig.mFramesCount; + mFrameDuration = orig.mFrameDuration; mCanConstantState = mCheckedConstantState = true; } } diff --git a/graphics/java/android/graphics/drawable/ClipDrawable.java b/graphics/java/android/graphics/drawable/ClipDrawable.java index f116376..61ef81b 100644 --- a/graphics/java/android/graphics/drawable/ClipDrawable.java +++ b/graphics/java/android/graphics/drawable/ClipDrawable.java @@ -285,6 +285,8 @@ public class ClipDrawable extends Drawable implements Drawable.Callback { } mDrawable.setCallback(owner); mDrawable.setLayoutDirection(orig.mDrawable.getLayoutDirection()); + mDrawable.setBounds(orig.mDrawable.getBounds()); + mDrawable.setLevel(orig.mDrawable.getLevel()); mOrientation = orig.mOrientation; mGravity = orig.mGravity; mCheckedConstantState = mCanConstantState = true; diff --git a/graphics/java/android/graphics/drawable/InsetDrawable.java b/graphics/java/android/graphics/drawable/InsetDrawable.java index dd0f06f..a20b6d8 100644 --- a/graphics/java/android/graphics/drawable/InsetDrawable.java +++ b/graphics/java/android/graphics/drawable/InsetDrawable.java @@ -400,6 +400,8 @@ public class InsetDrawable extends Drawable implements Drawable.Callback { } mDrawable.setCallback(owner); mDrawable.setLayoutDirection(orig.mDrawable.getLayoutDirection()); + mDrawable.setBounds(orig.mDrawable.getBounds()); + mDrawable.setLevel(orig.mDrawable.getLevel()); mInsetLeft = orig.mInsetLeft; mInsetTop = orig.mInsetTop; mInsetRight = orig.mInsetRight; diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java index 43bc89a..001ed88 100644 --- a/graphics/java/android/graphics/drawable/LayerDrawable.java +++ b/graphics/java/android/graphics/drawable/LayerDrawable.java @@ -961,20 +961,22 @@ public class LayerDrawable extends Drawable implements Drawable.Callback { // Default empty constructor. } - ChildDrawable(ChildDrawable or, LayerDrawable owner, Resources res) { + ChildDrawable(ChildDrawable orig, LayerDrawable owner, Resources res) { if (res != null) { - mDrawable = or.mDrawable.getConstantState().newDrawable(res); + mDrawable = orig.mDrawable.getConstantState().newDrawable(res); } else { - mDrawable = or.mDrawable.getConstantState().newDrawable(); + mDrawable = orig.mDrawable.getConstantState().newDrawable(); } mDrawable.setCallback(owner); - mDrawable.setLayoutDirection(or.mDrawable.getLayoutDirection()); - mThemeAttrs = or.mThemeAttrs; - mInsetL = or.mInsetL; - mInsetT = or.mInsetT; - mInsetR = or.mInsetR; - mInsetB = or.mInsetB; - mId = or.mId; + mDrawable.setLayoutDirection(orig.mDrawable.getLayoutDirection()); + mDrawable.setBounds(orig.mDrawable.getBounds()); + mDrawable.setLevel(orig.mDrawable.getLevel()); + mThemeAttrs = orig.mThemeAttrs; + mInsetL = orig.mInsetL; + mInsetT = orig.mInsetT; + mInsetR = orig.mInsetR; + mInsetB = orig.mInsetB; + mId = orig.mId; } } diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index ca32751..7402bdb 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -33,7 +33,6 @@ import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.util.AttributeSet; import android.util.DisplayMetrics; -import android.util.Log; import com.android.internal.R; @@ -41,6 +40,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; +import java.util.Arrays; /** * Drawable that shows a ripple effect in response to state changes. The @@ -88,7 +88,6 @@ import java.io.IOException; * @attr ref android.R.styleable#RippleDrawable_color */ public class RippleDrawable extends LayerDrawable { - private static final String LOG_TAG = RippleDrawable.class.getSimpleName(); private static final PorterDuffXfermode DST_IN = new PorterDuffXfermode(Mode.DST_IN); private static final PorterDuffXfermode SRC_ATOP = new PorterDuffXfermode(Mode.SRC_ATOP); private static final PorterDuffXfermode SRC_OVER = new PorterDuffXfermode(Mode.SRC_OVER); @@ -215,10 +214,14 @@ public class RippleDrawable extends LayerDrawable { final Ripple[] ripples = mAnimatingRipples; for (int i = 0; i < count; i++) { ripples[i].jump(); - ripples[i] = null; + } + if (ripples != null) { + Arrays.fill(ripples, 0, count, null); } mAnimatingRipplesCount = 0; mClearingHotspots = false; + + invalidateSelf(); } @Override @@ -549,6 +552,15 @@ public class RippleDrawable extends LayerDrawable { mAnimatingRipples[mAnimatingRipplesCount++] = mRipple; } + @Override + public void invalidateSelf() { + // Don't invalidate when we're clearing hotspots. We'll handle that + // manually when we're done. + if (!mClearingHotspots) { + super.invalidateSelf(); + } + } + private void removeRipple() { if (mRipple != null) { mRipple.exit(); @@ -572,7 +584,9 @@ public class RippleDrawable extends LayerDrawable { final Ripple[] ripples = mAnimatingRipples; for (int i = 0; i < count; i++) { ripples[i].cancel(); - ripples[i] = null; + } + if (ripples != null) { + Arrays.fill(ripples, 0, count, null); } mAnimatingRipplesCount = 0; mClearingHotspots = false; @@ -680,7 +694,7 @@ public class RippleDrawable extends LayerDrawable { final int count = mAnimatingRipplesCount; final int index = getRippleIndex(ripple); if (index >= 0) { - System.arraycopy(ripples, index + 1, ripples, index + 1 - 1, count - (index + 1)); + System.arraycopy(ripples, index + 1, ripples, index, count - (index + 1)); ripples[count - 1] = null; mAnimatingRipplesCount--; invalidateSelf(); diff --git a/graphics/java/android/graphics/drawable/RotateDrawable.java b/graphics/java/android/graphics/drawable/RotateDrawable.java index 63b9e02..70482a6 100644 --- a/graphics/java/android/graphics/drawable/RotateDrawable.java +++ b/graphics/java/android/graphics/drawable/RotateDrawable.java @@ -507,21 +507,23 @@ public class RotateDrawable extends Drawable implements Drawable.Callback { private boolean mCanConstantState; private boolean mCheckedConstantState; - public RotateState(RotateState source, RotateDrawable owner, Resources res) { - if (source != null) { + public RotateState(RotateState orig, RotateDrawable owner, Resources res) { + if (orig != null) { if (res != null) { - mDrawable = source.mDrawable.getConstantState().newDrawable(res); + mDrawable = orig.mDrawable.getConstantState().newDrawable(res); } else { - mDrawable = source.mDrawable.getConstantState().newDrawable(); + mDrawable = orig.mDrawable.getConstantState().newDrawable(); } mDrawable.setCallback(owner); - mDrawable.setLayoutDirection(source.mDrawable.getLayoutDirection()); - mPivotXRel = source.mPivotXRel; - mPivotX = source.mPivotX; - mPivotYRel = source.mPivotYRel; - mPivotY = source.mPivotY; - mFromDegrees = mCurrentDegrees = source.mFromDegrees; - mToDegrees = source.mToDegrees; + mDrawable.setLayoutDirection(orig.mDrawable.getLayoutDirection()); + mDrawable.setBounds(orig.mDrawable.getBounds()); + mDrawable.setLevel(orig.mDrawable.getLevel()); + mPivotXRel = orig.mPivotXRel; + mPivotX = orig.mPivotX; + mPivotYRel = orig.mPivotYRel; + mPivotY = orig.mPivotY; + mFromDegrees = mCurrentDegrees = orig.mFromDegrees; + mToDegrees = orig.mToDegrees; mCanConstantState = mCheckedConstantState = true; } } diff --git a/graphics/java/android/graphics/drawable/ScaleDrawable.java b/graphics/java/android/graphics/drawable/ScaleDrawable.java index a954474..b40038a 100644 --- a/graphics/java/android/graphics/drawable/ScaleDrawable.java +++ b/graphics/java/android/graphics/drawable/ScaleDrawable.java @@ -295,6 +295,8 @@ public class ScaleDrawable extends Drawable implements Drawable.Callback { } mDrawable.setCallback(owner); mDrawable.setLayoutDirection(orig.mDrawable.getLayoutDirection()); + mDrawable.setBounds(orig.mDrawable.getBounds()); + mDrawable.setLevel(orig.mDrawable.getLevel()); mScaleWidth = orig.mScaleWidth; mScaleHeight = orig.mScaleHeight; mGravity = orig.mGravity; |