Search in sources :

Example 11 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class ManagedServices method loadComponentNamesFromSetting.

@NonNull
protected ArraySet<ComponentName> loadComponentNamesFromSetting(String settingName, int userId) {
    final ContentResolver cr = mContext.getContentResolver();
    String settingValue = Settings.Secure.getStringForUser(cr, settingName, userId);
    if (TextUtils.isEmpty(settingValue))
        return new ArraySet<>();
    String[] restored = settingValue.split(ENABLED_SERVICES_SEPARATOR);
    ArraySet<ComponentName> result = new ArraySet<>(restored.length);
    for (int i = 0; i < restored.length; i++) {
        ComponentName value = ComponentName.unflattenFromString(restored[i]);
        if (null != value) {
            result.add(value);
        }
    }
    return result;
}
Also used : ArraySet(android.util.ArraySet) ComponentName(android.content.ComponentName) ContentResolver(android.content.ContentResolver) NonNull(android.annotation.NonNull)

Example 12 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class Resources_Delegate method resolveReference.

@NonNull
private static String resolveReference(Resources resources, @NonNull String ref, boolean forceFrameworkOnly) {
    if (ref.startsWith(SdkConstants.PREFIX_RESOURCE_REF) || ref.startsWith(SdkConstants.PREFIX_THEME_REF)) {
        ResourceValue rv = resources.mContext.getRenderResources().findResValue(ref, forceFrameworkOnly);
        rv = resources.mContext.getRenderResources().resolveResValue(rv);
        if (rv != null) {
            return rv.getValue();
        } else {
            Bridge.getLog().error(LayoutLog.TAG_RESOURCES_RESOLVE, "Unable to resolve resource " + ref, null);
        }
    }
    // Not a reference.
    return ref;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) NonNull(android.annotation.NonNull)

Example 13 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class FontFamily_Delegate method deriveFont.

/**
     * Try to derive a font from {@code srcFont} for the style in {@code outFont}.
     * <p/>
     * {@code outFont} is updated to reflect the style of the derived font.
     * @param srcFont the source font
     * @param outFont contains the desired font style. Updated to contain the derived font and
     *                its style
     * @return outFont
     */
@NonNull
private FontInfo deriveFont(@NonNull FontInfo srcFont, @NonNull FontInfo outFont) {
    int desiredWeight = outFont.mWeight;
    int srcWeight = srcFont.mWeight;
    assert srcFont.mFont != null;
    Font derivedFont = srcFont.mFont;
    // Embolden the font if required.
    if (desiredWeight >= BOLD_FONT_WEIGHT && desiredWeight - srcWeight > BOLD_FONT_WEIGHT_DELTA / 2) {
        derivedFont = derivedFont.deriveFont(Font.BOLD);
        srcWeight += BOLD_FONT_WEIGHT_DELTA;
    }
    // Italicize the font if required.
    if (outFont.mIsItalic && !srcFont.mIsItalic) {
        derivedFont = derivedFont.deriveFont(Font.ITALIC);
    } else if (outFont.mIsItalic != srcFont.mIsItalic) {
        // The desired font is plain, but the src font is italics. We can't convert it back. So
        // we update the value to reflect the true style of the font we're deriving.
        outFont.mIsItalic = srcFont.mIsItalic;
    }
    outFont.mFont = derivedFont;
    outFont.mWeight = srcWeight;
    // No need to update mIsItalics, as it's already been handled above.
    return outFont;
}
Also used : Font(java.awt.Font) NonNull(android.annotation.NonNull)

Example 14 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class Typeface_Delegate method getFonts.

/**
     * Return a list of fonts that match the style and variant. The list is ordered according to
     * preference of fonts.
     *
     * The list may contain null when the font failed to load. If null is reached when trying to
     * render with this list of fonts, then a warning should be logged letting the user know that
     * some font failed to load.
     *
     * @param variant The variant preferred. Can only be {@link FontVariant#COMPACT} or
     *                {@link FontVariant#ELEGANT}
     */
@NonNull
public List<Font> getFonts(FontVariant variant) {
    assert variant != FontVariant.NONE;
    // Calculate the required weight based on style and weight of this typeface.
    int weight = mWeight + ((mStyle & Font.BOLD) == 0 ? 0 : FontFamily_Delegate.BOLD_FONT_WEIGHT_DELTA);
    if (weight > 900) {
        weight = 900;
    }
    final boolean isItalic = (mStyle & Font.ITALIC) != 0;
    List<Font> fonts = new ArrayList<Font>(mFontFamilies.length);
    for (int i = 0; i < mFontFamilies.length; i++) {
        FontFamily_Delegate ffd = mFontFamilies[i];
        if (ffd != null && ffd.isValid()) {
            Font font = ffd.getFont(weight, isItalic);
            if (font != null) {
                FontVariant ffdVariant = ffd.getVariant();
                if (ffdVariant == FontVariant.NONE) {
                    fonts.add(font);
                    continue;
                }
                // always appear in pairs.
                assert i < mFontFamilies.length - 1;
                FontFamily_Delegate ffd2 = mFontFamilies[++i];
                assert ffd2 != null;
                FontVariant ffd2Variant = ffd2.getVariant();
                Font font2 = ffd2.getFont(weight, isItalic);
                assert ffd2Variant != FontVariant.NONE && ffd2Variant != ffdVariant && font2 != null;
                // Add the font with the matching variant to the list.
                if (variant == ffd.getVariant()) {
                    fonts.add(font);
                } else {
                    fonts.add(font2);
                }
            } else {
                // The FontFamily is valid but doesn't contain any matching font. This means
                // that the font failed to load. We add null to the list of fonts. Don't throw
                // the warning just yet. If this is a non-english font, we don't want to warn
                // users who are trying to render only english text.
                fonts.add(null);
            }
        }
    }
    return fonts;
}
Also used : FontVariant(android.graphics.FontFamily_Delegate.FontVariant) ArrayList(java.util.ArrayList) Font(java.awt.Font) NonNull(android.annotation.NonNull)

Example 15 with NonNull

use of android.annotation.NonNull in project platform_frameworks_base by android.

the class ImageUtils method saveImageAndAppendMessage.

/**
     * Saves the generated thumbnail image and appends the info message to an initial message
     */
@NonNull
private static String saveImageAndAppendMessage(@NonNull BufferedImage image, @NonNull String initialMessage, @NonNull String relativePath) throws IOException {
    File output = new File(getTempDir(), getName(relativePath));
    if (output.exists()) {
        boolean deleted = output.delete();
        assertTrue(deleted);
    }
    ImageIO.write(image, "PNG", output);
    initialMessage += "Thumbnail for current rendering stored at " + output.getPath();
    // and it makes the tests pass without the code being actually checked in.
    return initialMessage;
}
Also used : File(java.io.File) NonNull(android.annotation.NonNull)

Aggregations

NonNull (android.annotation.NonNull)322 ArrayList (java.util.ArrayList)46 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 IOException (java.io.IOException)35 ComponentName (android.content.ComponentName)25 File (java.io.File)22 XmlPullParser (org.xmlpull.v1.XmlPullParser)20 Intent (android.content.Intent)18 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)16 ResolveInfo (android.content.pm.ResolveInfo)16 Bundle (android.os.Bundle)15 RemoteException (android.os.RemoteException)15 FileNotFoundException (java.io.FileNotFoundException)15 Paint (android.graphics.Paint)14 PackageParser (android.content.pm.PackageParser)12 ContentResolver (android.content.ContentResolver)10 UserInfo (android.content.pm.UserInfo)10 StorageManager (android.os.storage.StorageManager)10 VolumeInfo (android.os.storage.VolumeInfo)10 KeyCharacteristics (android.security.keymaster.KeyCharacteristics)10