androidx.annotation.XmlRes Java Examples

The following examples show how to use androidx.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: CircularProgressIcon.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setResultState(@DrawableRes @XmlRes int imageId) {
    if (state == STATE_PROGRESS) {
        state = STATE_RESULT;

        cancelAllAnimation();
        progress.stopAnimation();
        image.setImageResource(imageId);

        showAnimation = new ShowAnimation(image);
        image.startAnimation(showAnimation);

        hideAnimation = new HideAnimation(progress);
        progress.startAnimation(hideAnimation);
    } else {
        forceSetResultState(imageId);
    }
}
 
Example #2
Source File: CircularProgressIcon.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void forceSetResultState(@DrawableRes @XmlRes int imageId) {
    state = STATE_RESULT;

    cancelAllAnimation();
    setAnimating(false);

    image.setImageResource(imageId);

    image.setAlpha(1f);
    image.setScaleX(1f);
    image.setScaleY(1f);
    image.setRotation(0);

    progress.setAlpha(0f);
    progress.setScaleX(1f);
    progress.setScaleY(1f);
    progress.setRotation(0);
}
 
Example #3
Source File: Keyboard.java    From libcommon 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
 * @param width          sets width of keyboard
 * @param height         sets height of keyboard
 */
public Keyboard(@NonNull final  Context context,
	@XmlRes int xmlLayoutResId, int modeId,
	final int width, final 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 #4
Source File: Keyboard.java    From libcommon 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
 */
@SuppressWarnings("SuspiciousNameCombination")
public Keyboard(@NonNull final Context context,
	@XmlRes final int xmlLayoutResId, final int modeId) {

	final 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 #5
Source File: PreferenceFragment.java    From MaterialPreference with Apache License 2.0 6 votes vote down vote up
/**
 * Inflates the given XML resource and replaces the current preference hierarchy (if any) with
 * the preference hierarchy rooted at {@code key}.
 *
 * @param preferencesResId The XML resource ID to inflate.
 * @param key              The preference key of the {@link PreferenceScreen} to use as the root of the
 *                         preference hierarchy, or null to use the root {@link PreferenceScreen}.
 */
public void setPreferencesFromResource(@XmlRes int preferencesResId, @Nullable String key) {
    requirePreferenceManager();

    final PreferenceScreen xmlRoot = mPreferenceManager.inflateFromResource(mStyledContext,
            preferencesResId, null);

    final Preference root;
    if (key != null) {
        root = xmlRoot.findPreference(key);
        if (!(root instanceof PreferenceScreen)) {
            throw new IllegalArgumentException("Preference object with key " + key
                    + " is not a PreferenceScreen");
        }
    } else {
        root = xmlRoot;
    }

    setPreferenceScreen((PreferenceScreen) root);
}
 
Example #6
Source File: SettingsFragment.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("JavaReflectionMemberAccess")
@Override
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
    if(!(this instanceof AboutFragment)) {
        U.allowReflection();
        try {
            Context context = U.wrapContext(U.getDisplayContext(getActivity()));
            Class.forName("android.preference.PreferenceManager")
                    .getMethod("inflateFromResource", Context.class, int.class, PreferenceScreen.class)
                    .invoke(getPreferenceManager(), context, preferencesResId, getPreferenceScreen());
        } catch (Exception e) { /* Gracefully fail */ }
    }

    super.addPreferencesFromResource(preferencesResId);
}
 
Example #7
Source File: PhotoButtonBar.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@DrawableRes @XmlRes
private int getCollectIcon(boolean collected) {
    if (collected) {
        return R.drawable.ic_item_collected;
    } else {
        return R.drawable.ic_item_collect;
    }
}
 
Example #8
Source File: PhotoButtonBar.java    From Mysplash with GNU Lesser General Public License v3.0 5 votes vote down vote up
@DrawableRes @XmlRes
private int getLikeIcon(boolean liked) {
    if (liked) {
        return R.drawable.ic_heart_red;
    } else {
        return R.drawable.ic_heart_outline_white;
    }
}
 
Example #9
Source File: BadgeDrawableTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private TypedArray getTypedArray(@XmlRes int xmlId) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, xmlId, "badge");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = R.style.Widget_MaterialComponents_Badge;
  }
  return context
      .getTheme()
      .obtainStyledAttributes(attrs, R.styleable.Badge, R.attr.badgeStyle, style);
}
 
Example #10
Source File: BadgeDrawableTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void testBadgeGravityValueHelper(@XmlRes int xmlId, int expectedValue) {
  TypedArray a = getTypedArray(xmlId);

  int value = 0;
  if (a.hasValue(R.styleable.Badge_badgeGravity)) {
    value = a.getInt(R.styleable.Badge_badgeGravity, 0);
  }
  assertThat(value).isEqualTo(expectedValue);
  a.recycle();
}
 
Example #11
Source File: PreferenceFragment.java    From MaterialPreference 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(mStyledContext,
            preferencesResId, getPreferenceScreen()));
}
 
Example #12
Source File: DrawableUtils.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
public static AttributeSet parseDrawableXml(
    @NonNull Context context, @XmlRes int id, @NonNull CharSequence startTag) {
  try {
    XmlPullParser parser = context.getResources().getXml(id);

    int type;
    do {
      type = parser.next();
    } while (type != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT);
    if (type != XmlPullParser.START_TAG) {
      throw new XmlPullParserException("No start tag found");
    }

    if (!TextUtils.equals(parser.getName(), startTag)) {
      throw new XmlPullParserException("Must have a <" + startTag + "> start tag");
    }

    AttributeSet attrs = Xml.asAttributeSet(parser);

    return attrs;
  } catch (XmlPullParserException | IOException e) {
    NotFoundException exception =
        new NotFoundException("Can't load badge resource ID #0x" + Integer.toHexString(id));
    exception.initCause(e);
    throw exception;
  }
}
 
Example #13
Source File: KeyboardDelegater.java    From libcommon with Apache License 2.0 5 votes vote down vote up
public KeyboardDelegater(
	@NonNull final EditText editText,
	@NonNull final KeyboardView keyboardView,
	@XmlRes final int keyboardLayoutRes) {

	if (DEBUG) Log.v(TAG, "コンストラクタ:");
	mEditText = editText;
	mKeyboardView = keyboardView;
	mKeyboardLayoutRes = keyboardLayoutRes;
}
 
Example #14
Source File: PreferenceSettingsUtils.java    From talkback with Apache License 2.0 5 votes vote down vote up
/**
 * Inflates the given XML resource and replaces the current preference hierarchy (if any) with the
 * preference hierarchy rooted at {@code key}.{@link
 * PreferenceFragmentCompat#setPreferencesFromResource(int, String)}
 */
public static void setPreferencesFromResource(
    PreferenceFragmentCompat preferenceFragment, @XmlRes int preferencesResId, String key) {
  // Set preferences to use device-protected storage.
  if (BuildVersionUtils.isAtLeastN()) {
    preferenceFragment.getPreferenceManager().setStorageDeviceProtected();
  }
  preferenceFragment.setPreferencesFromResource(preferencesResId, key);
}
 
Example #15
Source File: PreferenceSettingsUtils.java    From talkback 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. {@link PreferenceFragmentCompat#addPreferencesFromResource}
 */
public static void addPreferencesFromResource(
    PreferenceFragmentCompat preferenceFragment, @XmlRes int preferencesResId) {
  // Set preferences to use device-protected storage.
  if (BuildVersionUtils.isAtLeastN()) {
    preferenceFragment.getPreferenceManager().setStorageDeviceProtected();
  }
  preferenceFragment.addPreferencesFromResource(preferencesResId);
}
 
Example #16
Source File: PreferenceSettingsUtils.java    From talkback 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. {@link PreferenceFragment#addPreferencesFromResource}
 */
public static void addPreferencesFromResource(
    PreferenceFragment preferenceFragment, @XmlRes int preferencesResId) {
  // Set preferences to use device-protected storage.
  if (BuildVersionUtils.isAtLeastN()) {
    preferenceFragment.getPreferenceManager().setStorageDeviceProtected();
  }
  preferenceFragment.addPreferencesFromResource(preferencesResId);
}
 
Example #17
Source File: PreferenceListFragment.java    From android_dbinspector with Apache License 2.0 5 votes vote down vote up
public static PreferenceListFragment newInstance(@XmlRes int xmlId) {
    Bundle args = new Bundle();
    args.putInt(XML_ID, xmlId);
    PreferenceListFragment prefListFragment = new PreferenceListFragment();
    prefListFragment.setArguments(args);
    return prefListFragment;
}
 
Example #18
Source File: PreferenceActivity.java    From MaterialPreferenceLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * this should return the R.xml.menu file of the preferenceActivity
 */
protected abstract
@XmlRes
int getPreferencesXmlId();
 
Example #19
Source File: XmlIndexableFragment.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
public XmlIndexableFragment(
        Class<? extends BaseSearchablePolicyPreferenceFragment> fragmentClass,
        @XmlRes int xmlRes) {
    super(fragmentClass);
    this.xmlRes = xmlRes;
}
 
Example #20
Source File: MaxLockPreferenceFragment.java    From MaxLock with GNU General Public License v3.0 4 votes vote down vote up
Screen(@StringRes int t, @XmlRes int p) {
    title = t;
    preferenceXML = p;
}
 
Example #21
Source File: PhotoButtonBar.java    From Mysplash with GNU Lesser General Public License v3.0 4 votes vote down vote up
@DrawableRes @XmlRes
private int getDownloadIcon() {
    return R.drawable.ic_download_white;
}
 
Example #22
Source File: MongolEditText.java    From mongol-library with MIT License 4 votes vote down vote up
public void setInputExtras(@XmlRes int xmlResId) throws XmlPullParserException, IOException {
    XmlResourceParser parser = getResources().getXml(xmlResId);
    createInputContentTypeIfNeeded();
    mInputContentType.extras = new Bundle();
    getResources().parseBundleExtras(parser, mInputContentType.extras);
}
 
Example #23
Source File: SearchConfiguration.java    From SearchPreference with MIT License 4 votes vote down vote up
@XmlRes int getResId() {
    return resId;
}
 
Example #24
Source File: SearchConfiguration.java    From SearchPreference with MIT License 4 votes vote down vote up
/**
 * Includes the given R.xml resource in the index
 * @param resId The resource to index
 */
private SearchIndexItem(@XmlRes int resId, SearchConfiguration searchConfiguration) {
    this.resId = resId;
    this.searchConfiguration = searchConfiguration;
}
 
Example #25
Source File: SearchConfiguration.java    From SearchPreference with MIT License 4 votes vote down vote up
/**
 * Adds a new file to the index
 * @param resId The preference file to index
 */
public SearchIndexItem index(@XmlRes int resId) {
    SearchIndexItem item = new SearchIndexItem(resId, this);
    itemsToIndex.add(item);
    return item;
}
 
Example #26
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a ChipDrawable from the given XML resource. All attributes from {@link
 * R.styleable#Chip} and a custom <code>style</code> attribute are supported. A chip resource may
 * look like:
 *
 * <pre>{@code
 * <chip
 *     xmlns:app="http://schemas.android.com/apk/res-auto"
 *     style="@style/Widget.MaterialComponents.Chip.Entry"
 *     app:chipIcon="@drawable/custom_icon"/>
 * }</pre>
 */
@NonNull
public static ChipDrawable createFromResource(@NonNull Context context, @XmlRes int id) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, id, "chip");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = R.style.Widget_MaterialComponents_Chip_Entry;
  }
  return createFromAttributes(context, attrs, R.attr.chipStandaloneStyle, style);
}
 
Example #27
Source File: BadgeDrawable.java    From material-components-android with Apache License 2.0 3 votes vote down vote up
/**
 * Returns a BadgeDrawable from the given XML resource. All attributes from {@link
 * R.styleable#Badge} and a custom <code>style</code> attribute are supported. A badge resource
 * may look like:
 *
 * <pre>{@code
 * <badge
 *     xmlns:app="http://schemas.android.com/apk/res-auto"
 *     style="@style/Widget.MaterialComponents.Badge"
 *     app:maxCharacterCount="2"/>
 * }</pre>
 */
@NonNull
public static BadgeDrawable createFromResource(@NonNull Context context, @XmlRes int id) {
  AttributeSet attrs = DrawableUtils.parseDrawableXml(context, id, "badge");
  @StyleRes int style = attrs.getStyleAttribute();
  if (style == 0) {
    style = DEFAULT_STYLE;
  }
  return createFromAttributes(context, attrs, DEFAULT_THEME_ATTR, style);
}
 
Example #28
Source File: Keyboard.java    From libcommon with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a keyboard from the given xml key layout file.
 *
 * @param context        the application or service context
 * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
 */
public Keyboard(@NonNull final  Context context, @XmlRes final int xmlLayoutResId) {
	this(context, xmlLayoutResId, 0);
}
 
Example #29
Source File: FirebaseRemoteConfig.java    From firebase-android-sdk with Apache License 2.0 2 votes vote down vote up
/**
 * Sets default configs using an XML resource.
 *
 * @param resourceId Id for the XML resource, which should be in your application's {@code
 *     res/xml} folder.
 */
@NonNull
public Task<Void> setDefaultsAsync(@XmlRes int resourceId) {
  Map<String, String> xmlDefaults = DefaultsXmlParser.getDefaultsFromXml(context, resourceId);
  return setDefaultsWithStringsMapAsync(xmlDefaults);
}
 
Example #30
Source File: FirebaseRemoteConfig.java    From firebase-android-sdk with Apache License 2.0 2 votes vote down vote up
/**
 * Sets default configs using an XML resource.
 *
 * @param resourceId Id for the XML resource, which should be in your application's {@code
 *     res/xml} folder.
 * @deprecated Use {@link #setDefaultsAsync} instead.
 */
@Deprecated
public void setDefaults(@XmlRes int resourceId) {
  Map<String, String> xmlDefaults = DefaultsXmlParser.getDefaultsFromXml(context, resourceId);
  setDefaultsWithStringsMap(xmlDefaults);
}