Java 类android.support.annotation.XmlRes 实例源码

项目:IO_Classic_WatchFace    文件:SettingsFragment.java   
@Override
public void addPreferencesFromResource(@XmlRes int preferencesResId) {
    super.addPreferencesFromResource(preferencesResId);

    Executor executor = (runnable) -> new Thread(runnable).start();

    ProviderInfoRetriever.OnProviderInfoReceivedCallback callback = new ProviderInfoRetriever.OnProviderInfoReceivedCallback() {
        @Override
        public void onProviderInfoReceived(int i, @Nullable ComplicationProviderInfo complicationProviderInfo) {
            setComplicationSummary(i, complicationProviderInfo);
        }
    };

    mProviderInfoRetriever = new ProviderInfoRetriever(mContext, executor);

    mProviderInfoRetriever.init();
    mProviderInfoRetriever.retrieveProviderInfo(callback,
            new ComponentName(mContext, IOClassicWatchFaceService.class),
            IOClassicWatchFaceService.COMPLICATION_IDS);
}
项目:Capsule    文件:ChangelogDialog.java   
/**
 * Setup for ChangelogDialog
 *
 * @param activity        activity for context
 * @param xmlRes          xmlRes of Changelog file
 * @param neutralCallback optional callback & string for neutral button
 */
public static void show(@NonNull final FragmentActivity activity, @XmlRes final int xmlRes,
                        @Nullable final OnChangelogNeutralButtonClick neutralCallback) {
    final Handler mHandler = new Handler();
    new Thread(new Runnable() {
        @Override
        public void run() {
            final ArrayList<ChangelogXmlParser.ChangelogItem> items = ChangelogXmlParser
                    .parse(activity, xmlRes);
            mHandler.post(new TimerTask() {
                @Override
                public void run() {
                    ChangelogDialog f = new ChangelogDialog()
                            .setNeutralCallback(neutralCallback);
                    if (!items.isEmpty()) {
                        Bundle args = new Bundle();
                        args.putParcelableArrayList(ITEM_TAG, items);
                        f.setArguments(args);
                    }
                    f.show(activity.getSupportFragmentManager(), DIALOG_TAG);
                }
            });
        }
    }).start();
}
项目:MaterialPreference    文件:PreferenceFragment.java   
/**
 * 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);
}
项目:android-52Kit    文件:Winds.java   
/**
 * Draft a changelog recycler view ready to be displayed
 *
 * @param ctx           the context to construct the view with
 * @param configId      the xml configuration resource id
 * @return              the built RecyclerView ready for insertion
 */
public static RecyclerView draft(Context ctx, @XmlRes int configId){

    // Parse config
    ChangeLog changeLog = Parser.parse(ctx, configId);

    // Setup the adapter
    ChangeLogAdapter adapter = new ChangeLogAdapter();
    adapter.setChangeLog(changeLog);

    // Parse the configuration from the resource ID and generate a RecyclerView that is ready to go
    RecyclerView recycler = new RecyclerView(ctx);
    recycler.setAdapter(adapter);
    recycler.setLayoutManager(new LinearLayoutManager(ctx));
    recycler.setItemAnimator(new DefaultItemAnimator());
    recycler.addItemDecoration(new StickyRecyclerHeadersElevationDecoration(adapter));

    return recycler;
}
项目:android-52Kit    文件:Winds.java   
/**
 * Check to see if we should show the changelog activity if there are any new changes
 * to the configuration file.
 *
 * @param ctx           the context to launch the activity with
 * @param configId      the changelog configuration xml resource id
 */
public static void checkChangelogActivity(Context ctx, @XmlRes int configId){

    // Parse configuration
    ChangeLog changeLog = Parser.parse(ctx, configId);
    if(changeLog != null){

        // Validate that there is a new version code
        if(validateVersion(ctx, changeLog)) {
            openChangelogActivity(ctx, configId);
        }

    }else{
        throw new NullPointerException("Unable to find a 'Winds' configuration @ " + configId);
    }

}
项目:android-52Kit    文件:Winds.java   
/**
 * Check to see if we should show the changelog activity if there are any new changes
 * to the configuration file.
 *
 * @param ctx           the context to launch the activity with
 * @param configId      the changelog configuration xml resource id
 */
public static void checkChangelogDialog(Activity ctx, @XmlRes int configId){

    // Parse configuration
    ChangeLog changeLog = Parser.parse(ctx, configId);
    if(changeLog != null){

        // Validate that there is a new version code
        if(validateVersion(ctx, changeLog)) {
            openChangelogDialog(ctx, configId);
        }

    }else{
        throw new NullPointerException("Unable to find a 'Winds' configuration @ " + configId);
    }

}
项目:ReminderDatePicker    文件:PickerSpinner.java   
/**
 *
 */
protected ArrayList<TwinTextItem> getItemsFromXml(@XmlRes int xmlResource)
        throws XmlPullParserException, IOException {
    final Resources res = getResources();
    XmlResourceParser parser = res.getXml(xmlResource);
    ArrayList<TwinTextItem> items = new ArrayList<>();

    int eventType;
    while((eventType = parser.next()) != XmlPullParser.END_DOCUMENT) {
        if(eventType == XmlPullParser.START_TAG) {
            // call our subclass to parse the correct item
            TwinTextItem item = parseItemFromXmlTag(parser);
            if(item != null)
                items.add(item);
        }
    }

    return items;
}
项目:YourAppIdea    文件:EulaChangeLogChainHelper.java   
public static void show(FragmentActivity fragmentActivity,
                        @StringRes int resEulaTitle,
                        @StringRes int resEulaAcceptLabel,
                        @StringRes int resEulaRefuseLabel,
                        @StringRes int resChangeLogTitle,
                        @StringRes int resChangeLogClose,
                        @XmlRes int resChangeLog) {
    //not shown = already accepted
    boolean shown = EulaHelper.showAcceptRefuse(fragmentActivity, resEulaTitle, resEulaAcceptLabel, resEulaRefuseLabel);

    ChangeLogHelper changeLogHelper = new ChangeLogHelper();
    if (!shown) {
        changeLogHelper.showWhatsNew(resChangeLogTitle, resChangeLogClose, resChangeLog, fragmentActivity);
    } else {
        //We don't show the changelog at first run of the first install, but we have to save the current version
        //for the future upgrades
        changeLogHelper.saveCurrentVersion(fragmentActivity);
    }
}
项目:SkinFramework    文件:ComposedResources.java   
@Override
public XmlResourceParser getXml(@XmlRes int id) throws NotFoundException {
    int realId = getCorrespondResIdStrictly(id);
    if (realId > 0) {
        return mSkinResources.getXml(realId);
    }
    return super.getXml(id);
}
项目:QiangHongBao    文件:BottomBar.java   
/**
 * Set the item for the BottomBar from XML Resource with a default configuration
 * for each tab.
 */
public void setItems(@XmlRes int xmlRes, BottomBarTab.Config defaultTabConfig) {
    if (xmlRes == 0) {
        throw new RuntimeException("No items specified for the BottomBar!");
    }

    if (defaultTabConfig == null) {
        defaultTabConfig = getTabConfig();
    }

    TabParser parser = new TabParser(getContext(), defaultTabConfig, xmlRes);
    updateItems(parser.getTabs());
}
项目:QiangHongBao    文件:TabParser.java   
TabParser(Context context, BottomBarTab.Config defaultTabConfig, @XmlRes int tabsXmlResId) {
    this.context = context;
    this.defaultTabConfig = defaultTabConfig;

    parser = context.getResources().getXml(tabsXmlResId);
    tabs = new ArrayList<>();

    parse();
}
项目:Programmers    文件:SettingsFragment.java   
/**
 * Method do get an instance of the Fragment
 * Needed to reuse.
 *
 * @param category_xml the XML file to load in UI
 * @return SettingsFragment
 */
public static SettingsFragment newInstance(@XmlRes int category_xml) {
    SettingsFragment instance = new SettingsFragment();
    Bundle b = new Bundle();
    b.putInt(Presenter.CATEGORY, category_xml);
    instance.setArguments(b);
    return instance;
}
项目:Programmers    文件:SettingsFragment.java   
/**
 * To replace the current fragment, with new xml to show.
 *
 * @param resid the xml UI to show in the fragment
 */
@Override
public void replaceFragment(@XmlRes int resid) {

    Fragment fragment = SettingsFragment.newInstance(resid);
    getFragmentManager()
            .beginTransaction()
            .addToBackStack(null)
            .replace(R.id.frame_layout, fragment, Contract.Presenter.CATEGORY_TAG)
            .commit();
}
项目:Tusky    文件:PreferencesActivity.java   
public void showFragment(@XmlRes int preferenceId, @StringRes int title) {

        //TODO: cache the Fragments so they can be reused
        getFragmentManager().beginTransaction()
                .replace(R.id.fragment_container, PreferencesFragment.newInstance(preferenceId))
                .commit();

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(title);
        }

        currentPreferences = preferenceId;
        currentTitle = title;
    }
项目:BottomBar    文件:BottomBar.java   
/**
 * Set the item for the BottomBar from XML Resource with a default configuration
 * for each tab.
 */
public void setItems(@XmlRes int xmlRes, BottomBarTab.Config defaultTabConfig) {
    if (xmlRes == 0) {
        throw new RuntimeException("No items specified for the BottomBar!");
    }

    if (defaultTabConfig == null) {
        defaultTabConfig = getTabConfig();
    }

    TabParser parser = new TabParser(getContext(), defaultTabConfig, xmlRes);
    updateItems(parser.parseTabs());
}
项目:wearDrip    文件:XmlPreferenceParser.java   
@NonNull
WearPreferenceScreen parse(@NonNull final Context context, @XmlRes final int prefsResId) {
    try {
        final XmlResourceParser parser = context.getResources().getXml(prefsResId);
        return parseScreen(context, parser);
    } catch (XmlPullParserException | IOException e) {
        throw new RuntimeException("Error parsing preferences file", e);
    }
}
项目:PluginM    文件:PluginPackageManager.java   
@Override
public XmlResourceParser getXml(String packageName, @XmlRes int resid, ApplicationInfo appInfo) {
    Resources pluginResource = getPluginResouces(packageName);
    if (pluginResource != null) {
        return pluginResource.getXml(resid);
    }
    return mBase.getXml(packageName, resid, appInfo);
}
项目:material-components-android    文件:ChipDrawable.java   
/**
 * Returns a ChipDrawable from the given XML resource. All attributes from {@link
 * R.styleable#ChipDrawable} 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>
 */
public static ChipDrawable createFromResource(Context context, @XmlRes int id) {
  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(), "chip")) {
      throw new XmlPullParserException("Must have a <chip> start tag");
    }

    AttributeSet attrs = Xml.asAttributeSet(parser);
    @StyleRes int style = attrs.getStyleAttribute();
    if (style == 0) {
      style = R.style.Widget_MaterialComponents_Chip_Entry;
    }

    return createFromAttributes(context, attrs, R.attr.chipStandaloneStyle, style);
  } catch (XmlPullParserException | IOException e) {
    Resources.NotFoundException exception =
        new NotFoundException("Can't load chip resource ID #0x" + Integer.toHexString(id));
    exception.initCause(e);
    throw exception;
  }
}
项目:polar-dashboard    文件:DrawableXmlParser.java   
public static List<Category> parse(@NonNull Context context, @XmlRes int xmlRes) {
  mCategories = new ArrayList<>();
  XmlResourceParser parser = null;
  try {
    parser = context.getResources().getXml(xmlRes);
    int eventType = parser.getEventType();
    while (eventType != XmlPullParser.END_DOCUMENT) {
      switch (eventType) {
        case XmlPullParser.START_TAG:
          final String tagName = parser.getName();
          if (tagName.equalsIgnoreCase("category")) {
            mCurrentCategory = new Category(parser.getAttributeValue(null, "title"));
            mCategories.add(mCurrentCategory);
          } else if (tagName.equalsIgnoreCase("item")) {
            if (mCurrentCategory == null) {
              mCurrentCategory = new Category(context.getString(R.string.default_category));
              mCategories.add(mCurrentCategory);
            }
            mCurrentCategory.addItem(
                new Icon(parser.getAttributeValue(null, "drawable"), mCurrentCategory));
          }
          break;
      }
      eventType = parser.next();
    }

  } catch (XmlPullParserException | IOException e) {
    e.printStackTrace();
  } finally {
    if (parser != null) {
      parser.close();
    }
  }

  mCurrentCategory = null;
  return mCategories;
}
项目:ticdesign    文件:PreferenceFragment.java   
/**
 * 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()));
}
项目:MaterialPreference    文件:PreferenceFragment.java   
/**
 * 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()));
}
项目:android-52Kit    文件:ChangeLogDialog.java   
public static ChangeLogDialog createInstance(@XmlRes int configResId){
    ChangeLogDialog dialog = new ChangeLogDialog();
    Bundle args = new Bundle();
    args.putInt(EXTRA_CONFIG, configResId);
    dialog.setArguments(args);
    return dialog;
}
项目:WearPreferenceActivity    文件:XmlPreferenceParser.java   
@NonNull
WearPreferenceScreen parse(@NonNull final Context context, @XmlRes final int prefsResId) {
    try {
        final XmlResourceParser parser = context.getResources().getXml(prefsResId);
        return parseScreen(context, parser);
    } catch (XmlPullParserException | IOException e) {
        throw new RuntimeException("Error parsing preferences file", e);
    }
}
项目:365browser    文件:PreferenceUtils.java   
/**
 * A helper that is used to load preferences from XML resources without causing a
 * StrictModeViolation. See http://crbug.com/692125.
 *
 * @param preferenceFragment A PreferenceFragment.
 * @param preferencesResId   The id of the XML resource to add to the PreferenceFragment.
 */
public static void addPreferencesFromResource(
        PreferenceFragment preferenceFragment, @XmlRes int preferencesResId) {
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        preferenceFragment.addPreferencesFromResource(preferencesResId);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
项目:sprockets-android    文件:SprocketsPreferenceFragment.java   
/**
 * Display the preferences and log changes in analytics.
 *
 * @since 2.6.0
 */
public static SprocketsPreferenceFragment newInstance(@XmlRes int prefs, boolean logChanges) {
    SprocketsPreferenceFragment frag = new SprocketsPreferenceFragment();
    Bundle args = Fragments.arguments(frag);
    args.putInt(PREFS, prefs);
    args.putBoolean(LOG_CHANGES, logChanges);
    return frag;
}
项目:android_dbinspector    文件:PreferenceListFragment.java   
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;
}
项目:SimpleWatchface    文件:ColorPreset.java   
public static ColorPreset fromXml(Context context, @XmlRes int xmlResId) throws IOException, XmlPullParserException {
    ColorPreset res = new ColorPreset();
    XmlResourceParser xmlResourceParser = context.getResources().getXml(xmlResId);
    String name = null;
    int eventType;
    while ((eventType = xmlResourceParser.next()) != XmlPullParser.END_DOCUMENT) {
        switch (eventType) {
            case XmlPullParser.START_TAG:
                String tagName = xmlResourceParser.getName();
                if ("color".equals(tagName)) {
                    name = xmlResourceParser.getAttributeValue(null, "name");
                }
                break;

            case XmlPullParser.TEXT:
                String colorStr = xmlResourceParser.getText().trim();
                int color = Color.parseColor(colorStr);
                switch (name) {
                    case "background":
                        res.background = color;
                        break;
                    case "hourMinutes":
                        res.hourMinutes = color;
                        break;
                    case "seconds":
                        res.seconds = color;
                        break;
                    case "amPm":
                        res.amPm = color;
                        break;
                    case "date":
                        res.date = color;
                        break;
                }
        }
    }
    xmlResourceParser.close();

    return res;
}
项目:PebbleDialer-Android    文件:TaskerSettingsActivity.java   
public void switchToGenericPreferenceScreen(@XmlRes int xmlRes, String root)
{
    Fragment fragment = GenericPreferenceScreen.newInstance(xmlRes, root);
    getSupportFragmentManager()
            .beginTransaction()
            .addToBackStack(null)
            .replace(R.id.content_frame, fragment)
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
            .commit();
}
项目:PebbleDialer-Android    文件:GenericPreferenceScreen.java   
public static GenericPreferenceScreen newInstance(@XmlRes int preferenceXml, String root)
{
    Bundle arguments = new Bundle();
    arguments.putInt("PreferencesXML", preferenceXml);
    arguments.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, root);

    GenericPreferenceScreen genericPreferenceScreen = new GenericPreferenceScreen();
    genericPreferenceScreen.setArguments(arguments);
    return genericPreferenceScreen;
}
项目:PebbleDialer-Android    文件:MainActivity.java   
public void switchToGenericPreferenceScreen(@XmlRes int xmlRes, String root)
{
    Fragment fragment = GenericPreferenceScreen.newInstance(xmlRes, root);
    getSupportFragmentManager()
            .beginTransaction()
            .addToBackStack(null)
            .replace(R.id.content_frame, fragment)
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
            .commit();
}
项目:markor    文件:GsPreferenceFragmentCompat.java   
@XmlRes
public abstract int getPreferenceResourceForInflation();
项目:QiangHongBao    文件:BottomBar.java   
/**
 * Set the items for the BottomBar from XML Resource.
 */
public void setItems(@XmlRes int xmlRes) {
    setItems(xmlRes, null);
}
项目:Programmers    文件:Presenter.java   
/**
 * Hadle here Preference Item click
 *
 * @param preference the preference that was clicked
 * @return true if the click was handled
 */
@Override
public boolean onPreferenceClick(Preference preference) {
    String key = preference.getKey() != null ? preference.getKey() : "";

    // Categories click
    @XmlRes int resid = 0;

    switch (key) {

        case CATEGORY_NOTIFICATIONS:
            resid = R.xml.settings_notifications;
            break;

        case CATEGORY_SHARE_APP:
            view.startShareAppIntent();
            break;

        case CATEGORY_CHANGE_PASSWORD:
            view.showResetPasswordFragment();
            break;

        case CATEGORY_UPDATES:
            resid = R.xml.settings_updates;
            break;

        case CATEGORY_PRIVACY_POLICE:
            view.startPrivacyPoliceActivity();
            break;

        case CATEGORY_ABOUT:
            resid = R.xml.settings_about;
            break;

        case CATEGORY_QUIT:
            // Logout user
            view.logout();
            break;
    }

    if (resid != 0) {
        view.replaceFragment(resid);
    }

    // Sub- categories click
    switch (key) {
        case FEEDBACK:

            String appEmail = getContext().getString(R.string.app_email);
            view.startActivityToSendMail(appEmail);
            break;

        case ON_FACEBOOK:
            IntentUtils.startAppOnFacebookIntent(getContext());
            break;

        case DONATE:
            view.startDonateActivity();
            break;

        case MORE_ABOUT_APP:
            view.startAboutAppActivity();
            break;
    }

    return false;
}
项目:memetastic    文件:GsPreferenceFragmentCompat.java   
@XmlRes
public abstract int getPreferenceResourceForInflation();
项目:RxFireDroid    文件:RxFireDroidRemoteConfig.java   
public static Completable setDefaults(@XmlRes int xmlRes) {
    return Completable.fromAction(() -> FirebaseRemoteConfig.getInstance().setDefaults(xmlRes))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
}
项目:RxFireDroid    文件:RxFireDroidRemoteConfig.java   
public static Completable setDefaults(@XmlRes int xmlRes, @NonNull String namespace) {
    return Completable.fromAction(() ->
            FirebaseRemoteConfig.getInstance().setDefaults(xmlRes, namespace))
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread());
}
项目:BottomBar    文件:BottomBar.java   
/**
 * Set the items for the BottomBar from XML Resource.
 */
public void setItems(@XmlRes int xmlRes) {
    setItems(xmlRes, null);
}
项目:BottomBar    文件:TabParser.java   
TabParser(@NonNull Context context, @NonNull BottomBarTab.Config defaultTabConfig, @XmlRes int tabsXmlResId) {
    this.context = context;
    this.defaultTabConfig = defaultTabConfig;
    this.parser = context.getResources().getXml(tabsXmlResId);
}
项目:Capsule    文件:ChangelogDialog.java   
public static void show(@NonNull final FragmentActivity activity, @XmlRes final int xmlRes) {
    show(activity, xmlRes, null);
}
项目:xowa_android    文件:BasePreferenceLoader.java   
protected void loadPreferences(@XmlRes int id) {
    preferenceHost.addPreferencesFromResource(id);
}