android.annotation.XmlRes Java Examples

The following examples show how to use android.annotation.XmlRes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Keyboard.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a keyboard from the given xml key layout file. Weeds out rows
 * that have a keyboard mode defined but don't match the specified mode. 
 * @param context the application or service context
 * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
 * @param modeId keyboard mode identifier
 */
public Keyboard(Context context, @XmlRes int xmlLayoutResId, int modeId) {
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    mDisplayWidth = dm.widthPixels;
    mDisplayHeight = dm.heightPixels;
    //Log.v(TAG, "keyboard's display metrics:" + dm);

    mDefaultHorizontalGap = 0;
    mDefaultWidth = mDisplayWidth / 10;
    mDefaultVerticalGap = 0;
    mDefaultHeight = mDefaultWidth;
    mKeys = new ArrayList<Key>();
    mModifierKeys = new ArrayList<Key>();
    mKeyboardMode = modeId;
    loadKeyboard(context, context.getResources().getXml(xmlLayoutResId));
}
 
Example #2
Source File: Keyboard.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a keyboard from the given xml key layout file. Weeds out rows
 * that have a keyboard mode defined but don't match the specified mode.
 * @param context the application or service context
 * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
 * @param modeId keyboard mode identifier
 * @param width sets width of keyboard
 * @param height sets height of keyboard
 */
public Keyboard(Context context, @XmlRes int xmlLayoutResId, int modeId, int width,
        int height) {
    mDisplayWidth = width;
    mDisplayHeight = height;

    mDefaultHorizontalGap = 0;
    mDefaultWidth = mDisplayWidth / 10;
    mDefaultVerticalGap = 0;
    mDefaultHeight = mDefaultWidth;
    mKeys = new ArrayList<Key>();
    mModifierKeys = new ArrayList<Key>();
    mKeyboardMode = modeId;
    loadKeyboard(context, context.getResources().getXml(xmlLayoutResId));
}
 
Example #3
Source File: PreferenceFragment.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Inflates the given XML resource and adds the preference hierarchy to the current
 * preference hierarchy.
 *
 * @param preferencesResId The XML resource ID to inflate.
 */
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
    requirePreferenceManager();

    setPreferenceScreen(mPreferenceManager.inflateFromResource(getActivity(),
            preferencesResId, getPreferenceScreen()));
}
 
Example #4
Source File: PreferenceManager.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Inflates a preference hierarchy from XML. If a preference hierarchy is
 * given, the new preference hierarchies will be merged in.
 *
 * @param context The context of the resource.
 * @param resId The resource ID of the XML to inflate.
 * @param rootPreferences Optional existing hierarchy to merge the new
 *            hierarchies into.
 * @return The root hierarchy (if one was not provided, the new hierarchy's
 *         root).
 * @hide
 */
public PreferenceScreen inflateFromResource(Context context, @XmlRes int resId,
        PreferenceScreen rootPreferences) {
    // Block commits
    setNoCommit(true);

    final PreferenceInflater inflater = new PreferenceInflater(context, this);
    rootPreferences = (PreferenceScreen) inflater.inflate(resId, rootPreferences, true);
    rootPreferences.onAttachedToHierarchy(this);

    // Unblock commits
    setNoCommit(false);

    return rootPreferences;
}
 
Example #5
Source File: PointerIcon.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void loadResource(Context context, Resources resources, @XmlRes int resourceId) {
    final XmlResourceParser parser = resources.getXml(resourceId);
    final int bitmapRes;
    final float hotSpotX;
    final float hotSpotY;
    try {
        XmlUtils.beginDocument(parser, "pointer-icon");

        final TypedArray a = resources.obtainAttributes(
                parser, com.android.internal.R.styleable.PointerIcon);
        bitmapRes = a.getResourceId(com.android.internal.R.styleable.PointerIcon_bitmap, 0);
        hotSpotX = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotX, 0);
        hotSpotY = a.getDimension(com.android.internal.R.styleable.PointerIcon_hotSpotY, 0);
        a.recycle();
    } catch (Exception ex) {
        throw new IllegalArgumentException("Exception parsing pointer icon resource.", ex);
    } finally {
        parser.close();
    }

    if (bitmapRes == 0) {
        throw new IllegalArgumentException("<pointer-icon> is missing bitmap attribute.");
    }

    Drawable drawable;
    if (context == null) {
        drawable = resources.getDrawable(bitmapRes);
    } else {
        drawable = context.getDrawable(bitmapRes);
    }
    if (drawable instanceof AnimationDrawable) {
        // Extract animation frame bitmaps.
        final AnimationDrawable animationDrawable = (AnimationDrawable) drawable;
        final int frames = animationDrawable.getNumberOfFrames();
        drawable = animationDrawable.getFrame(0);
        if (frames == 1) {
            Log.w(TAG, "Animation icon with single frame -- simply treating the first "
                    + "frame as a normal bitmap icon.");
        } else {
            // Assumes they have the exact duration.
            mDurationPerFrame = animationDrawable.getDuration(0);
            mBitmapFrames = new Bitmap[frames - 1];
            final int width = drawable.getIntrinsicWidth();
            final int height = drawable.getIntrinsicHeight();
            for (int i = 1; i < frames; ++i) {
                Drawable drawableFrame = animationDrawable.getFrame(i);
                if (!(drawableFrame instanceof BitmapDrawable)) {
                    throw new IllegalArgumentException("Frame of an animated pointer icon "
                            + "must refer to a bitmap drawable.");
                }
                if (drawableFrame.getIntrinsicWidth() != width ||
                    drawableFrame.getIntrinsicHeight() != height) {
                    throw new IllegalArgumentException("The bitmap size of " + i + "-th frame "
                            + "is different. All frames should have the exact same size and "
                            + "share the same hotspot.");
                }
                BitmapDrawable bitmapDrawableFrame = (BitmapDrawable) drawableFrame;
                mBitmapFrames[i - 1] = getBitmapFromDrawable(bitmapDrawableFrame);
            }
        }
    }
    if (!(drawable instanceof BitmapDrawable)) {
        throw new IllegalArgumentException("<pointer-icon> bitmap attribute must "
                + "refer to a bitmap drawable.");
    }

    BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
    final Bitmap bitmap = getBitmapFromDrawable(bitmapDrawable);
    validateHotSpot(bitmap, hotSpotX, hotSpotY);
    // Set the properties now that we have successfully loaded the icon.
    mBitmap = bitmap;
    mHotSpotX = hotSpotX;
    mHotSpotY = hotSpotY;
}
 
Example #6
Source File: DevelopmentSettingsDashboardFragment.java    From haystack with GNU General Public License v3.0 4 votes vote down vote up
@DexAdd
@Override
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
    super.addPreferencesFromResource(preferencesResId);
    FakeSignatureGlobalUI.addPreference(this);
}
 
Example #7
Source File: DevelopmentSettingsDashboardFragment.java    From haystack with GNU General Public License v3.0 4 votes vote down vote up
@DexAdd
@Override
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
    super.addPreferencesFromResource(preferencesResId);
    FakeSignatureGlobalUI.addPreference(this);
}
 
Example #8
Source File: PointerIcon.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Loads a custom pointer icon from an XML resource.
 * <p>
 * The XML resource should have the following form:
 * <code>
 * &lt;?xml version="1.0" encoding="utf-8"?&gt;
 * &lt;pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
 *   android:bitmap="@drawable/my_pointer_bitmap"
 *   android:hotSpotX="24"
 *   android:hotSpotY="24" /&gt;
 * </code>
 * </p>
 *
 * @param resources The resources object.
 * @param resourceId The resource id.
 * @return The pointer icon.
 *
 * @throws IllegalArgumentException if resources is null.
 * @throws Resources.NotFoundException if the resource was not found or the drawable
 * linked in the resource was not found.
 */
public static PointerIcon load(@NonNull Resources resources, @XmlRes int resourceId) {
    if (resources == null) {
        throw new IllegalArgumentException("resources must not be null");
    }

    PointerIcon icon = new PointerIcon(TYPE_CUSTOM);
    icon.loadResource(null, resources, resourceId);
    return icon;
}
 
Example #9
Source File: GenericInflater.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Inflate a new hierarchy from the specified xml resource. Throws
 * InflaterException if there is an error.
 * 
 * @param resource ID for an XML resource to load (e.g.,
 *        <code>R.layout.main_page</code>)
 * @param root Optional root to be the parent of the generated hierarchy (if
 *        <em>attachToRoot</em> is true), or else simply an object that
 *        provides a set of values for root of the returned
 *        hierarchy (if <em>attachToRoot</em> is false.)
 * @param attachToRoot Whether the inflated hierarchy should be attached to
 *        the root parameter?
 * @return The root of the inflated hierarchy. If root was supplied and
 *         attachToRoot is true, this is root; otherwise it is the root of
 *         the inflated XML file.
 */
public T inflate(@XmlRes int resource, P root, boolean attachToRoot) {
    if (DEBUG) System.out.println("INFLATING from resource: " + resource);
    XmlResourceParser parser = getContext().getResources().getXml(resource);
    try {
        return inflate(parser, root, attachToRoot);
    } finally {
        parser.close();
    }
}
 
Example #10
Source File: PreferenceManager.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * Sets the default values from an XML preference file by reading the values defined
 * by each {@link Preference} item's {@code android:defaultValue} attribute. This should
 * be called by the application's main activity.
 * <p>
 *
 * @param context The context of the shared preferences.
 * @param resId The resource ID of the preference XML file.
 * @param readAgain Whether to re-read the default values.
 * If false, this method sets the default values only if this
 * method has never been called in the past (or if the
 * {@link #KEY_HAS_SET_DEFAULT_VALUES} in the default value shared
 * preferences file is false). To attempt to set the default values again
 * bypassing this check, set {@code readAgain} to true.
 *            <p class="note">
 *            Note: this will NOT reset preferences back to their default
 *            values. For that functionality, use
 *            {@link PreferenceManager#getDefaultSharedPreferences(Context)}
 *            and clear it followed by a call to this method with this
 *            parameter set to true.
 */
public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain) {

    // Use the default shared preferences name and mode
    setDefaultValues(context, getDefaultSharedPreferencesName(context),
            getDefaultSharedPreferencesMode(), resId, readAgain);
}
 
Example #11
Source File: PackageManager.java    From AndroidComponentPlugin with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve an XML file from a package.  This is a low-level API used to
 * retrieve XML meta data.
 *
 * @param packageName The name of the package that this xml is coming from.
 * Cannot be null.
 * @param resid The resource identifier of the desired xml.  Cannot be 0.
 * @param appInfo Overall information about <var>packageName</var>.  This
 * may be null, in which case the application information will be retrieved
 * for you if needed; if you already have this information around, it can
 * be much more efficient to supply it here.
 *
 * @return Returns an XmlPullParser allowing you to parse out the XML
 * data.  Returns null if the xml resource could not be found for any
 * reason.
 */
public abstract XmlResourceParser getXml(String packageName, @XmlRes int resid,
        ApplicationInfo appInfo);
 
Example #12
Source File: Resources.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Return an XmlResourceParser through which you can read a generic XML
 * resource for the given resource ID.
 * 
 * <p>The XmlPullParser implementation returned here has some limited
 * functionality.  In particular, you can't change its input, and only
 * high-level parsing events are available (since the document was
 * pre-parsed for you at build time, which involved merging text and
 * stripping comments).
 * 
 * @param id The desired resource identifier, as generated by the aapt
 *           tool. This integer encodes the package, type, and resource
 *           entry. The value 0 is an invalid identifier.
 *
 * @throws NotFoundException Throws NotFoundException if the given ID does not exist.
 * 
 * @return A new parser object through which you can read
 *         the XML data.
 *         
 * @see android.util.AttributeSet
 */
@NonNull
public XmlResourceParser getXml(@XmlRes int id) throws NotFoundException {
    return loadXmlResourceParser(id, "xml");
}
 
Example #13
Source File: GenericInflater.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * Inflate a new item hierarchy from the specified xml resource. Throws
 * InflaterException if there is an error.
 * 
 * @param resource ID for an XML resource to load (e.g.,
 *        <code>R.layout.main_page</code>)
 * @param root Optional parent of the generated hierarchy.
 * @return The root of the inflated hierarchy. If root was supplied,
 *         this is the root item; otherwise it is the root of the inflated
 *         XML file.
 */
public T inflate(@XmlRes int resource, P root) {
    return inflate(resource, root, root != null);
}