Example usage for android.content.res TypedArray length

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

Introduction

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

Prototype

public int length() 

Source Link

Document

Returns the number of values in this array.

Usage

From source file:com.tevinjeffrey.njitct.ui.utils.TintImageView.java

public TintImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = getContext().obtainStyledAttributes(attrs, TINT_ATTRS, defStyleAttr, 0);

    color = fetchAccentColor();//w w  w .  j a  v a 2  s. c o m

    Drawable drawable;
    if (a.length() > 0) {
        if (a.hasValue(2)) {
            color = a.getColor(2, 0);
        }
        if (a.hasValue(0)) {
            drawable = a.getDrawable(0);
            tintDrawable(drawable, color);
            setBackgroundDrawable(drawable);
        }
        if (a.hasValue(1)) {
            drawable = a.getDrawable(1);
            tintDrawable(drawable, color);
            setImageDrawable(drawable);
        }
    }
    a.recycle();
}

From source file:com.android.dokdo.NavigationDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    setBehindContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();/*from ww  w  . ja  v  a 2  s  .co  m*/
    mCityNames = getResources().getStringArray(R.array.drawer_items);
    TypedArray typedArray = getResources().obtainTypedArray(R.array.city_images);
    mCityImages = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); ++i) {
        mCityImages[i] = typedArray.getResourceId(i, 0);
    }
    typedArray.recycle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mCityNames));
    mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == 0) {
                Intent intent = new Intent(NavigationDrawerActivity.this, NavigationDrawerActivity.class);
                startActivity(intent);
                finish();
            } else if (position == 1) {
                Intent intent = new Intent(NavigationDrawerActivity.this, Developer.class);
                startActivity(intent);
            }
        }
    });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    mDrawerToggle = new ActionBarDrawerToggleCompat(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:cafe.com.navigationdrawer.NavigationDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();//from   www  .  j  a va 2 s  .c o  m

    mMenuNames = getResources().getStringArray(R.array.drawer_items);
    TypedArray typedArray = getResources().obtainTypedArray(R.array.menu_images);
    mMenuImages = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); ++i) {
        mMenuImages[i] = typedArray.getResourceId(i, 0);
    }
    typedArray.recycle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    //mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuNames));
    mDrawerList.setOnItemClickListener(this);

    // enable ActionBar app icon to behave as action to toggle
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:com.gudong.appkit.ui.fragment.ColorChooseDialog.java

private int[] initColors() {
    final TypedArray ta = getActivity().getResources().obtainTypedArray(R.array.material_designer_colors);
    int[] mColors = new int[ta.length()];
    for (int i = 0; i < ta.length(); i++)
        mColors[i] = ta.getColor(i, 0);/*from www.  jav  a  2  s.c o m*/
    ta.recycle();
    return mColors;
}

From source file:com.github.pockethub.android.ui.WelcomeActivity.java

/**
 * Loads the color array/*from ww w.  ja  va  2s  .co m*/
 */
private void loadColors() {
    TypedArray ta = getResources().obtainTypedArray(R.array.welcome_screen_colors);
    colors = new int[ta.length()];
    for (int i = 0; i < ta.length(); i++) {
        colors[i] = ta.getColor(i, 0);
    }
    ta.recycle();
    accentsColorDark = ContextCompat.getColor(this, R.color.primary);
}

From source file:net.alexjf.tmm.fragments.IconPickerFragment.java

private void updateIcons() {
    Resources res = getActivity().getResources();

    TypedArray iconCats = res.obtainTypedArray(R.array.iconcats);
    int numCategories = iconCats.length();

    iconCategories = new ArrayList<IconCategory>(numCategories);

    for (int i = 0; i < numCategories; i++) {
        int resId = iconCats.peekValue(i).resourceId;

        if (resId > 0) {
            IconCategory iconCat = new IconCategory();
            TypedArray catInfo = res.obtainTypedArray(resId);
            iconCat.title = catInfo.getString(0);
            int entriesResId = catInfo.getResourceId(1, 0);

            if (entriesResId > 0) {
                TypedArray icons = res.obtainTypedArray(entriesResId);
                int numIcons = icons.length();

                iconCat.drawableIds = new ArrayList<Integer>(numIcons);
                for (int j = 0; j < numIcons; j++) {
                    int drawableId = icons.getResourceId(j, 0);
                    iconCat.drawableIds.add(drawableId);
                }//from   w w w .  j a  va2 s  . co  m

                icons.recycle();
            } else {
                Log.e("TMM", "Error reading icon entries of cat with index " + i);
            }

            iconCategories.add(iconCat);
        } else {
            Log.e("TMM", "Error reading icon category with index " + i);
        }
    }

    iconCats.recycle();
    Collections.sort(iconCategories, new IconCategory.Comparator());
}

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

private void addExerciseModule(ArrayList<Exercise> exercises, int arrayResourceId) {
    TypedArray array = getResources().obtainTypedArray(arrayResourceId);

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

        Exercise exercise = new Exercise(getResources().getString(resourceId), resourceId);
        exercises.add(exercise);/*from  w  w w .  j a v a 2 s.c om*/
    }

    array.recycle();
}

From source file:es.uniovi.imovil.fcrtrainer.MainActivity.java

private void addSection(ArrayList<Group<String, Integer>> sections, int sectionNameId, int childrenArrayId) {
    Group<String, Integer> group;
    group = new Group<String, Integer>(getString(sectionNameId));

    TypedArray array = getResources().obtainTypedArray(childrenArrayId);

    group.children = new Integer[array.length()];
    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        group.children[i] = array.getResourceId(i, defaultId);
    }// www .j a v a 2  s. c  om

    array.recycle();

    sections.add(group);
}

From source file:org.iisgcp.waterwalk.fragment.FactViewPagerFragment.java

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Instantiate a ViewPager and a PagerAdapter.
    mAdapter = new FactPagerAdapter(getChildFragmentManager());
    mPager.setAdapter(mAdapter);/*from   w  ww  . ja  v a2 s .  c  o  m*/
    mPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrollStateChanged(int arg0) {

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageSelected(int position) {
            String title = null;

            int count = 0;

            int id = getArguments().getInt(INTENT_RESID);

            TypedArray details = FactViewPagerFragment.this.getResources().obtainTypedArray(id);

            for (int i = 0; i < details.length(); i = i + 3) {
                title = getString(details.getResourceId(i, -1));
                if (position == count) {
                    break;
                }
                count++;
            }

            details.recycle();

            FactViewPagerFragment.this.getActivity().setTitle(title);
        }

    });
    mPager.setCurrentItem(getArguments().getInt(INTENT_POSITION));
}

From source file:pt.ubi.di.pdm.swipe.MainActivity.java

private String[][] getExampleTexts() {
    Resources res = getResources();
    TypedArray ta = res.obtainTypedArray(R.array.text_examples);
    int n = ta.length();
    String[][] array = new String[n][];
    for (int i = 0; i < n; ++i) {
        int id = ta.getResourceId(i, 0);
        if (id > 0) {
            array[i] = res.getStringArray(id);
            WriteBtn(this, array[i][0].toString(), array[i][1].toString());
            Log.i("ARRAY", String.valueOf(array[i][0].toString() + "---->" + array[i][1].toString()));
        } else {/*from w  w  w.  j a  v a  2  s. c o m*/
            Log.e("GET EXAMPLES", "ESTA ALGO DE ERRADO COM O XAML");
        }
    }
    ta.recycle(); // Important!
    return array;
}