java类android.support.annotation.XmlRes的实例源码

SettingsFragment.java 文件源码 项目:IO_Classic_WatchFace 阅读 45 收藏 0 点赞 0 评论 0
@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);
}
ChangelogDialog.java 文件源码 项目:Capsule 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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();
}
PreferenceFragment.java 文件源码 项目:MaterialPreference 阅读 68 收藏 0 点赞 0 评论 0
/**
 * 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);
}
Winds.java 文件源码 项目:android-52Kit 阅读 40 收藏 0 点赞 0 评论 0
/**
 * 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;
}
Winds.java 文件源码 项目:android-52Kit 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 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);
    }

}
Winds.java 文件源码 项目:android-52Kit 阅读 31 收藏 0 点赞 0 评论 0
/**
 * 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);
    }

}
PickerSpinner.java 文件源码 项目:ReminderDatePicker 阅读 38 收藏 0 点赞 0 评论 0
/**
 *
 */
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;
}
EulaChangeLogChainHelper.java 文件源码 项目:YourAppIdea 阅读 35 收藏 0 点赞 0 评论 0
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);
    }
}
ComposedResources.java 文件源码 项目:SkinFramework 阅读 36 收藏 0 点赞 0 评论 0
@Override
public XmlResourceParser getXml(@XmlRes int id) throws NotFoundException {
    int realId = getCorrespondResIdStrictly(id);
    if (realId > 0) {
        return mSkinResources.getXml(realId);
    }
    return super.getXml(id);
}
BottomBar.java 文件源码 项目:QiangHongBao 阅读 33 收藏 0 点赞 0 评论 0
/**
 * 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());
}
TabParser.java 文件源码 项目:QiangHongBao 阅读 38 收藏 0 点赞 0 评论 0
TabParser(Context context, BottomBarTab.Config defaultTabConfig, @XmlRes int tabsXmlResId) {
    this.context = context;
    this.defaultTabConfig = defaultTabConfig;

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

    parse();
}
SettingsFragment.java 文件源码 项目:Programmers 阅读 40 收藏 0 点赞 0 评论 0
/**
 * 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;
}
SettingsFragment.java 文件源码 项目:Programmers 阅读 50 收藏 0 点赞 0 评论 0
/**
 * 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();
}
PreferencesActivity.java 文件源码 项目:Tusky 阅读 38 收藏 0 点赞 0 评论 0
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.java 文件源码 项目:BottomBar 阅读 33 收藏 0 点赞 0 评论 0
/**
 * 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());
}
XmlPreferenceParser.java 文件源码 项目:wearDrip 阅读 90 收藏 0 点赞 0 评论 0
@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);
    }
}
PluginPackageManager.java 文件源码 项目:PluginM 阅读 41 收藏 0 点赞 0 评论 0
@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);
}
ChipDrawable.java 文件源码 项目:material-components-android 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 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;
  }
}
DrawableXmlParser.java 文件源码 项目:polar-dashboard 阅读 44 收藏 0 点赞 0 评论 0
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;
}
PreferenceFragment.java 文件源码 项目:ticdesign 阅读 40 收藏 0 点赞 0 评论 0
/**
 * 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()));
}
PreferenceFragment.java 文件源码 项目:MaterialPreference 阅读 41 收藏 0 点赞 0 评论 0
/**
 * 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()));
}
ChangeLogDialog.java 文件源码 项目:android-52Kit 阅读 42 收藏 0 点赞 0 评论 0
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;
}
XmlPreferenceParser.java 文件源码 项目:WearPreferenceActivity 阅读 36 收藏 0 点赞 0 评论 0
@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);
    }
}
PreferenceUtils.java 文件源码 项目:365browser 阅读 39 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
SprocketsPreferenceFragment.java 文件源码 项目:sprockets-android 阅读 109 收藏 0 点赞 0 评论 0
/**
 * 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;
}
PreferenceListFragment.java 文件源码 项目:android_dbinspector 阅读 34 收藏 0 点赞 0 评论 0
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;
}
ColorPreset.java 文件源码 项目:SimpleWatchface 阅读 41 收藏 0 点赞 0 评论 0
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;
}
TaskerSettingsActivity.java 文件源码 项目:PebbleDialer-Android 阅读 31 收藏 0 点赞 0 评论 0
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();
}
GenericPreferenceScreen.java 文件源码 项目:PebbleDialer-Android 阅读 38 收藏 0 点赞 0 评论 0
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;
}
MainActivity.java 文件源码 项目:PebbleDialer-Android 阅读 33 收藏 0 点赞 0 评论 0
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();
}


问题


面经


文章

微信
公众号

扫码关注公众号