Example usage for android.content.res TypedArray getResourceId

List of usage examples for android.content.res TypedArray getResourceId

Introduction

In this page you can find the example usage for android.content.res TypedArray getResourceId.

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:androidx.navigation.NavDestination.java

/**
 * Called when inflating a destination from a resource.
 *
 * @param context local context performing inflation
 * @param attrs attrs to parse during inflation
 *///from  w  ww.  ja v  a  2s  . co  m
@CallSuper
public void onInflate(@NonNull Context context, @NonNull AttributeSet attrs) {
    final TypedArray a = context.getResources().obtainAttributes(attrs, R.styleable.Navigator);
    setId(a.getResourceId(R.styleable.Navigator_android_id, 0));
    setLabel(a.getText(R.styleable.Navigator_android_label));
    a.recycle();
}

From source file:com.artemchep.horario.ui.widgets.ContainersLayout.java

private void init(@Nullable AttributeSet attrs) {
    // Obtain layout resource
    int layout = 0;
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ContainersLayout);
    try {/*from  ww w  .  ja  va 2  s .  c  o  m*/
        layout = a.getResourceId(R.styleable.ContainersLayout_layout, 0);
    } finally {
        a.recycle();
    }
    if (layout == 0) {
        layout = R.layout.view_main_containers;
    }

    Context context = getContext();
    LayoutInflater.from(context).inflate(layout, this, true);

    mTransition = new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER)
            .addTransition(new ChangeBounds().setStartDelay(32)).addTransition(new Fade(Fade.IN | Fade.OUT));

    mBoundedCardView = (CardView) findViewById(R.id.bounded_card_view);

    if (mBoundedCardView != null) {
        mCardViewBackgroundColor = mBoundedCardView.getCardBackgroundColor();
        mCardViewElevation = mBoundedCardView.getCardElevation();
    }

    spaceMaster = findViewById(R.id.activity_main__space_master);
    spaceMaster2 = findViewById(R.id.activity_main__space_master2);
    spaceDetails = findViewById(R.id.activity_main__space_details);
    frameMaster = (ViewGroup) findViewById(R.id.activity_main__frame_master);
    frameDetails = (ViewGroup) findViewById(R.id.activity_main__frame_details);
}

From source file:com.example.testapp.MyFragmentTabHost.java

private void initFragmentTabHost(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.inflatedId }, 0, 0);
    mContainerId = a.getResourceId(0, 0);
    a.recycle();//from  w  w  w .j  a v a2 s  . c  o  m

    super.setOnTabChangedListener(this);

    /***** HERE COMMENT CODE BECAUSE findViewById(android.R.id.tabs) EVERY TIME IS NULL WE HAVE OWN LAYOUT ******/
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void initializeLevelSpinner() {
    ArrayList<String> levelNames = new ArrayList<String>();

    TypedArray array = getResources().obtainTypedArray(R.array.pref_level_values);

    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        int resourceId = array.getResourceId(i, defaultId);

        String name = getResources().getString(resourceId);
        levelNames.add(name);/*from w  w  w . j  a v  a  2s . com*/
    }

    array.recycle();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            levelNames);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mLevelSpinner = (Spinner) mRootView.findViewById(R.id.spinner_level);
    mLevelSpinner.setAdapter(adapter);

    mLevelSpinner.setOnItemSelectedListener(this);
}

From source file:com.github.jvanhie.discogsscrobbler.DrawerActivity.java

public void setDrawer(int layout, int list, String title, String drawerTitle, boolean showDrawerIcon) {
    mTitle = title;//from  w  w w .j  ava  2s .  c om
    mDrawerTitle = drawerTitle;
    mDrawerLayout = (DrawerLayout) findViewById(layout);
    //populate the navigation drawer
    mDrawerList = (ListView) findViewById(list);
    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // load slide menu items
    String[] navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
    // nav drawer icons from resources
    TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons);
    NavDrawerListAdapter adapter = new NavDrawerListAdapter(this);
    for (int i = 0; i < navMenuTitles.length; i++) {
        adapter.addItem(navMenuTitles[i], navMenuIcons.getResourceId(i, -1));
    }
    // Set the adapter for the list view
    mDrawerList.setAdapter(adapter);
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            switch (i) {
            case 0: //collection
                startActivity(new Intent(DrawerActivity.this, ReleaseListActivity.class));
                break;
            case 1: //search
                startActivity(new Intent(DrawerActivity.this, SearchActivity.class));
                break;
            case 2: //now playing
                startActivity(new Intent(DrawerActivity.this, NowPlayingActivity.class));
                break;
            case 3: //settings
                startActivity(new Intent(DrawerActivity.this, SettingsActivity.class));
                break;
            case 4: //help
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("https://github.com/jvanhie/discogsscrobbler/wiki")));
                break;
            }
        }
    });

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
        }
    };
    mDrawerToggle.setDrawerIndicatorEnabled(showDrawerIcon);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
}

From source file:com.ameron32.apps.tapnotes._trial.ui.MultiViewPager.java

private void init(Context context, AttributeSet attrs) {
    setClipChildren(false);// ww  w  .  j a  va 2s  .co  m
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MultiViewPager);
    setMaxWidth(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxWidth, -1));
    setMaxHeight(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxHeight, -1));
    setMatchChildWidth(ta.getResourceId(R.styleable.MultiViewPager_matchChildWidth, 0));
    ta.recycle();
}

From source file:com.github.ppamorim.library.DraggerView.java

private void mapGUI(TypedArray attributes) {
    if (getChildCount() == 2) {
        int dragViewId = attributes.getResourceId(R.styleable.dragger_layout_drag_view_id, R.id.drag_view);
        int shadowViewId = attributes.getResourceId(R.styleable.dragger_layout_shadow_view_id,
                R.id.shadow_view);/*from   w  ww . j  a v  a  2 s .c  o m*/
        dragView = findViewById(dragViewId);
        shadowView = findViewById(shadowViewId);
    } else {
        throw new IllegalStateException("DraggerView must contains only two direct child");
    }
}

From source file:com.achep.base.dashboard.DashboardCategory.java

public DashboardCategory(Context context, AttributeSet attrs) {
    TypedArray sa = context.obtainStyledAttributes(attrs, R.styleable.DashboardTile);

    id = sa.getResourceId(R.styleable.DashboardTile_dashboard_id, CAT_ID_UNDEFINED);

    TypedValue tv = sa.peekValue(R.styleable.DashboardTile_dashboard_title);
    if (tv != null && tv.type == TypedValue.TYPE_STRING) {
        if (tv.resourceId != 0) {
            titleRes = tv.resourceId;/*from  w  w w .  ja  va  2s  .c om*/
        } else {
            title = tv.string;
        }
    }

    sa.recycle();
}

From source file:com.androidformenhancer.helper.FormHelper.java

private Drawable getIconFromStyle(TypedArray a, int index, int defaultResId) {
    int id = a.getResourceId(index, 0);
    Drawable d;/*w  w w  . jav  a 2  s . com*/
    if (id > 0) {
        d = mContext.getResources().getDrawable(id);
    } else {
        d = mContext.getResources().getDrawable(defaultResId);
    }
    setDrawableIntrinsicBounds(d);
    return d;
}

From source file:com.artemchep.horario.ui.dialogs.FeedbackDialog.java

@NonNull
@Override//  w w  w .  jav a  2s .com
public Dialog onCreateDialog(Bundle savedState) {
    Activity activity = getActivity();
    assert activity != null;

    // Load icon
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(new int[] { R.attr.icon_email });
    int iconDrawableRes = a.getResourceId(0, 0);
    a.recycle();

    MaterialDialog md = new MaterialDialog.Builder(activity).iconRes(iconDrawableRes)
            .title(R.string.dialog_feedback_title).customView(R.layout.dialog_feedback, true)
            .negativeText(android.R.string.cancel).positiveText(R.string.dialog_send)
            .onAny(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    switch (which) {
                    case POSITIVE: {
                        if (!validateMessage()) {
                            mEditTextName.requestFocus();
                            return; // do not dismiss
                        }

                        Context context = getActivity();
                        CharSequence message = getMessage();
                        int type = mSpinner.getSelectedItemPosition();

                        CharSequence title = createTitle(context, type);
                        CharSequence body = createBody(context, message);
                        boolean sent = send(title, body);
                        if (!sent) {
                            return; // do not dismiss
                        }
                    }
                    }
                    dismiss();
                }
            }).autoDismiss(false).build();

    View view = md.getCustomView();
    assert view != null;
    mSpinner = view.findViewById(R.id.type);
    mEditTextName = view.findViewById(R.id.input_message);
    mTextInputName = view.findViewById(R.id.input_layout_message);

    if (savedState != null) {
        mSpinner.setSelection(savedState.getInt(EXTRA_TYPE));
        mEditTextName.setText(savedState.getString(EXTRA_MESSAGE));
    }

    mEditTextName.addTextChangedListener(new Watcher(mEditTextName));

    return md;
}