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:com.cc.signalinfo.activities.MainActivity.java

/**
 * Gets the TextViews that map to the signal info data in the code for binding.
 *
 * @param sigInfoIds - the array containing the IDs to the TextView resources
 * @param refreshMap - should we recreate the map or reuse it? (in case we some reason added some, somehow)
 * @return map of the Signal data enumeration types (keys) and corresponding TextViews (values)
 *///  w w w  .ja v  a 2  s. c o m
public Map<Signal, TextView> getSignalTextViewMap(TypedArray sigInfoIds, boolean refreshMap) {
    // no reason to do this over and over if it's already filled (we keep the same text stuff)
    if (signalTextViewMap.isEmpty() || refreshMap) {
        Signal[] values = Signal.values();

        for (int i = 0; i < sigInfoIds.length(); ++i) {
            int id = sigInfoIds.getResourceId(i, -1);

            if (id != -1) {
                TextView currentView = (TextView) findViewById(id);
                signalTextViewMap.put(values[i], currentView);
            }
        }
    }
    return Collections.unmodifiableMap(signalTextViewMap);
}

From source file:com.android.settings.SeekBarPreference.java

public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.ProgressBar,
            defStyleAttr, defStyleRes);//from   w  w w  . j ava2  s. c o  m
    setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax));
    a.recycle();

    a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.SeekBarPreference, defStyleAttr,
            defStyleRes);
    final int layoutResId = a.getResourceId(com.android.internal.R.styleable.SeekBarPreference_layout,
            com.android.internal.R.layout.preference_widget_seekbar);
    a.recycle();

    setLayoutResource(layoutResId);
}

From source file:android.support.v7.app.ActionBarActivityDelegateBase.java

private MenuView getListMenuView(Context context, MenuPresenter.Callback cb) {
    if (mMenu == null) {
        return null;
    }/*from   www  .  j a v a2  s . c om*/

    if (mListMenuPresenter == null) {
        TypedArray a = context.obtainStyledAttributes(R.styleable.Theme);
        final int listPresenterTheme = a.getResourceId(R.styleable.Theme_panelMenuListTheme,
                R.style.Theme_AppCompat_CompactMenu);
        a.recycle();

        mListMenuPresenter = new ListMenuPresenter(R.layout.abc_list_menu_item_layout, listPresenterTheme);
        mListMenuPresenter.setCallback(cb);
        mMenu.addMenuPresenter(mListMenuPresenter);
    } else {
        // Make sure we update the ListView
        mListMenuPresenter.updateMenuView(false);
    }

    return mListMenuPresenter.getMenuView(new FrameLayout(context));
}

From source file:com.github.pedrovgs.DraggableView.java

private void mapGUI(TypedArray attributes) {
    int dragViewId = attributes.getResourceId(R.styleable.draggable_view_top_view_id, R.id.drag_view);
    int secondViewId = attributes.getResourceId(R.styleable.draggable_view_bottom_view_id, R.id.second_view);
    dragView = findViewById(dragViewId);
    secondView = findViewById(secondViewId);
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;//from  w  ww .j a v a2  s  .  c  o m
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:com.andremion.floatingnavigationview.FloatingNavigationView.java

public FloatingNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setImageResource(R.drawable.ic_menu_vector);

    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

    mNavigationView = (NavigationView) LayoutInflater.from(context).inflate(R.layout.navigation_view, null);
    mNavigationView.setOnTouchListener(mNavigationTouchListener);
    mNavigationMenuView = (NavigationMenuView) mNavigationView.findViewById(R.id.design_navigation_view);

    mFabView = (ImageView) mNavigationView.findViewById(R.id.fab_view);
    mFabView.setOnClickListener(mFabClickListener);
    mFabView.setContentDescription(getContentDescription());
    mFabView.bringToFront();/*  w  w w .  j  av a2 s.  c  o m*/

    // Custom attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MenuView, defStyleAttr,
            R.style.Widget_Design_NavigationView);
    if (a.hasValue(R.styleable.MenuView_menu)) {
        mNavigationView.inflateMenu(a.getResourceId(R.styleable.MenuView_menu, 0));
    }
    if (a.hasValue(R.styleable.MenuView_headerLayout)) {
        mNavigationView.inflateHeaderView(a.getResourceId(R.styleable.MenuView_headerLayout, 0));
    }
    mDrawMenuBelowFab = a.getBoolean(R.styleable.MenuView_drawMenuBelowFab, false);
    a.recycle();
}

From source file:com.daiv.android.twitter.settings.SettingsActivityOld.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);

    AppSettings.invalidate();/*from  w w w  . j ava  2s.c om*/

    setUpTheme();

    setContentView(R.layout.settings_main);

    DrawerArrayAdapter.current = 0;

    linkItems = new String[] { getResources().getString(R.string.get_help_settings),
            getResources().getString(R.string.other_apps), getResources().getString(R.string.whats_new),
            getResources().getString(R.string.rate_it) };

    settingsItems = new String[] { getResources().getString(R.string.ui_settings),
            getResources().getString(R.string.timelines_settings),
            getResources().getString(R.string.sync_settings),
            getResources().getString(R.string.notification_settings),
            getResources().getString(R.string.browser_settings),
            getResources().getString(R.string.advanced_settings),
            getResources().getString(R.string.memory_manage) };

    sharedPrefs = getSharedPreferences("com.daiv.android.twitter_world_preferences",
            Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE);

    if (sharedPrefs.getBoolean("version_1.20_1", true)) {
        // necessary because i didnt start out by using sets
        boolean led = sharedPrefs.getBoolean("led", true);
        boolean sound = sharedPrefs.getBoolean("sound", true);
        boolean vibrate = sharedPrefs.getBoolean("vibrate", true);
        boolean wakeScreen = sharedPrefs.getBoolean("wake", true);
        boolean timelineNot = sharedPrefs.getBoolean("timeline_notifications", true);
        boolean mentionsNot = sharedPrefs.getBoolean("mentions_notifications", true);
        boolean dmsNot = sharedPrefs.getBoolean("direct_message_notifications", true);
        boolean favoritesNot = sharedPrefs.getBoolean("favorite_notifications", true);
        boolean retweetNot = sharedPrefs.getBoolean("retweet_notifications", true);
        boolean followersNot = sharedPrefs.getBoolean("follower_notifications", true);

        Set<String> alert = sharedPrefs.getStringSet("alert_types", new HashSet<String>());
        alert.clear();
        if (vibrate) {
            alert.add("1");
        }
        if (led) {
            alert.add("2");
        }
        if (wakeScreen) {
            alert.add("3");
        }
        if (sound) {
            alert.add("4");
        }
        sharedPrefs.edit().putStringSet("alert_types", alert).commit();

        Set<String> timeline = sharedPrefs.getStringSet("timeline_set", new HashSet<String>());
        timeline.clear();
        if (timelineNot) {
            timeline.add("1");
        }
        if (mentionsNot) {
            timeline.add("2");
        }
        if (dmsNot) {
            timeline.add("3");
        }
        sharedPrefs.edit().putStringSet("timeline_set", timeline).commit();

        Set<String> interactions = sharedPrefs.getStringSet("interactions_set", new HashSet<String>());
        interactions.clear();
        if (favoritesNot) {
            interactions.add("1");
        }
        if (retweetNot) {
            interactions.add("2");
        }
        if (followersNot) {
            interactions.add("3");
        }
        sharedPrefs.edit().putStringSet("interactions_set", interactions).commit();

        sharedPrefs.edit().putBoolean("version_1.20_1", false).commit();

        recreate();
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, otherList);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);

    otherList = (ListView) findViewById(R.id.other_list);
    settingsList = (ListView) findViewById(R.id.settings_list);
    mDrawer = (LinearLayout) findViewById(R.id.drawer);

    // Set the adapter for the list view
    otherList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(linkItems))));
    settingsList.setAdapter(new DrawerArrayAdapter(this, new ArrayList<String>(Arrays.asList(settingsItems))));
    // Set the list's click listener
    settingsList.setOnItemClickListener(
            new SettingsDrawerClickListener(this, mDrawerLayout, settingsList, mViewPager, mDrawer));
    otherList.setOnItemClickListener(
            new SettingsLinkDrawerClickListener(this, mDrawerLayout, otherList, mViewPager, mDrawer));

    findViewById(R.id.settingsLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(true);
            settingsLinksActive = true;
            findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
        }
    });

    findViewById(R.id.otherLinks).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            switchToSettingsList(false);
            settingsLinksActive = false;
            findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
            findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
        }
    });

    if (settingsLinksActive) {
        settingsList.setVisibility(View.VISIBLE);
        otherList.setVisibility(View.GONE);
        findViewById(R.id.settingsSelector).setVisibility(View.VISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.INVISIBLE);
    } else {
        settingsList.setVisibility(View.GONE);
        otherList.setVisibility(View.VISIBLE);
        findViewById(R.id.settingsSelector).setVisibility(View.INVISIBLE);
        findViewById(R.id.otherSelector).setVisibility(View.VISIBLE);
    }

    TypedArray a = getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();

    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            resource, /* nav drawer icon to replace 'Up' caret */
            R.string.app_name, /* "open drawer" description */
            R.string.app_name /* "close drawer" description */
    );

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    userKnows = sharedPrefs.getBoolean("user_knows_navigation_drawer", false);

    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        public void onPageScrollStateChanged(int state) {
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        public void onPageSelected(int position) {
            DrawerArrayAdapter.current = position;
            otherList.invalidateViews();
            settingsList.invalidateViews();
        }
    });

    if (!userKnows) {
        mDrawerLayout.openDrawer(mDrawer);
    }

    HoloTextView createdBy = (HoloTextView) findViewById(R.id.created_by);
    HoloTextView versionNumber = (HoloTextView) findViewById(R.id.version_number);

    try {
        String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

        String text = getResources().getString(R.string.created_by) + " daiv";
        String text2 = getResources().getString(R.string.version) + " " + versionName;
        createdBy.setText(text);
        versionNumber.setText(text2);
    } catch (Exception e) {
        String text = getResources().getString(R.string.created_by) + " daiv";
        String text2 = getResources().getString(R.string.version) + " 0.00";
        createdBy.setText(text);
        versionNumber.setText(text2);
    }

    LinearLayout description = (LinearLayout) findViewById(R.id.created_by_layout);
    description.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/developer?id=daiv+Apps")));
        }
    });

    mDrawerLayout.openDrawer(Gravity.START);
}

From source file:ameircom.keymedia.Activity.transition.FabTransform.java

public FabTransform(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = null;
    try {/*from ww w. j a v a2  s . com*/
        a = context.obtainStyledAttributes(attrs, R.styleable.FabTransform);
        if (!a.hasValue(R.styleable.FabTransform_fabColor) || !a.hasValue(R.styleable.FabTransform_fabIcon)) {
            throw new IllegalArgumentException("Must provide both color & icon.");
        }
        color = a.getColor(R.styleable.FabTransform_fabColor, Color.TRANSPARENT);
        icon = a.getResourceId(R.styleable.FabTransform_fabIcon, 0);
        setPathMotion(new GravityArcMotion());
        if (getDuration() < 0) {
            setDuration(DEFAULT_DURATION);
        }
    } finally {
        a.recycle();
    }
}

From source file:com.givewaygames.transition.TransitionInflater.java

private Transition loadTransition(Transition transition, AttributeSet attrs)
        throws Resources.NotFoundException {

    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Transition);
    long duration = a.getInt(R.styleable.Transition_duration, -1);
    if (duration >= 0) {
        transition.setDuration(duration);
    }//from  w w w  .j a v a 2  s . c  o m
    long startDelay = a.getInt(R.styleable.Transition_startDelay, -1);
    if (startDelay > 0) {
        transition.setStartDelay(startDelay);
    }
    final int resID = a.getResourceId(R.styleable.Transition_interpolator, 0);
    if (resID > 0) {
        transition.setInterpolator(AnimationUtils.loadInterpolator(mContext, resID));
    }
    a.recycle();
    return transition;
}

From source file:com.ichi2.anki.widgets.DeckAdapter.java

public DeckAdapter(LayoutInflater layoutInflater, Context context) {
    mLayoutInflater = layoutInflater;/*from   w  w w . jav  a  2 s . com*/
    mDeckList = new ArrayList<>();
    // Get the colors from the theme attributes
    int[] attrs = new int[] { R.attr.zeroCountColor, R.attr.newCountColor, R.attr.learnCountColor,
            R.attr.reviewCountColor, R.attr.currentDeckBackground, android.R.attr.textColor,
            R.attr.dynDeckColor, R.attr.expandRef, R.attr.collapseRef };
    TypedArray ta = context.obtainStyledAttributes(attrs);
    Resources res = context.getResources();
    mZeroCountColor = ta.getColor(0, res.getColor(R.color.zero_count));
    mNewCountColor = ta.getColor(1, res.getColor(R.color.new_count));
    mLearnCountColor = ta.getColor(2, res.getColor(R.color.learn_count));
    mReviewCountColor = ta.getColor(3, res.getColor(R.color.review_count));
    mRowCurrentDrawable = ta.getResourceId(4, 0);
    mDeckNameDefaultColor = ta.getColor(5, res.getColor(R.color.black));
    mDeckNameDynColor = ta.getColor(6, res.getColor(R.color.deckadapter_deck_name_dyn));
    mExpandImage = ta.getDrawable(7);
    mCollapseImage = ta.getDrawable(8);
    ta.recycle();
}