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:Main.java

@SuppressLint("UseSparseArrays")
@SuppressWarnings("ResourceType")
public static Map<Integer, Pair<String, String>> obtainBadgeMap(Context context, @ArrayRes int id) {

    TypedArray badgeArray = context.getResources().obtainTypedArray(id);

    Map<Integer, Pair<String, String>> badgeMap = new HashMap<>();
    for (int i = 0; i < badgeArray.length(); i++) {
        int resId = badgeArray.getResourceId(i, -1);
        if (resId != -1) {
            TypedArray array = context.getResources().obtainTypedArray(resId);
            badgeMap.put(resId, new Pair<>(array.getString(0), array.getString(1)));
            array.recycle();//www .  j ava 2s . c  o  m
        }
    }
    badgeArray.recycle();
    return badgeMap;
}

From source file:ca.marklauman.dominionpicker.CardAdapter.java

/** Retrieve an array of drawable resources from
 *  the xml of the provided {@link Context}.
 *  @param c The {@code Context} to search for the array.
 *  @param resourceId The resource id of an
 *  {@code <array>} containing a list of drawables.
 *  @return The resource ids of all the drawables
 *  in the array, in the order in which they appear
 *  in the xml.                                  */
public static int[] getDrawables(Context c, int resourceId) {
    TypedArray ta = c.getResources().obtainTypedArray(resourceId);
    if (ta == null)
        return null;

    int[] res = new int[ta.length()];
    for (int i = 0; i < ta.length(); i++)
        res[i] = ta.getResourceId(i, -1);

    ta.recycle();/*from  w w  w.j  ava 2 s . co m*/
    return res;
}

From source file:bander.notepad.Notepad.java

/**
 * Sets the color of the {@link android.support.v7.widget.Toolbar}
 *
 * @param activity Used similarly to {@link android.content.Context}
 *///from w w w  .j a v a 2  s  . co m
public static void setToolbarColor(final ActionBarActivity activity) {
    SharedPreferences mSettings = PreferenceManager.getDefaultSharedPreferences(activity);

    /**
     * The lighter toolbar color {@link com.devin.notepad.R.array.color500}
     */
    TypedArray m500ta = activity.getResources().obtainTypedArray(R.array.color500);
    final int[] mToolbarColors = new int[m500ta.length()];
    for (int i = 0; i < m500ta.length(); i++) {
        mToolbarColors[i] = m500ta.getColor(i, 0);
    }
    m500ta.recycle();

    /**
     * The darker status bar color. {@link com.devin.notepad.R.array.color700}
     */
    TypedArray m700ta = activity.getResources().obtainTypedArray(R.array.color700);
    int[] statusBarColors = new int[m700ta.length()];
    for (int i = 0; i < m700ta.length(); i++) {
        statusBarColors[i] = m700ta.getColor(i, 0);
    }
    m700ta.recycle();

    final int abc = mSettings.getInt("actionBarColor", 0);

    Toolbar mToolbar = (Toolbar) activity.findViewById(R.id.toolbar);

    if (mToolbar != null)
        mToolbar.setBackgroundColor(mToolbarColors[abc]);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(statusBarColors[abc]);
    }
}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void setImageHeader(Activity activity, ImageView imageView) {

    if (imageView != null) {
        TypedArray images = activity.getResources().obtainTypedArray(R.array.splash_images);
        int choice = (int) (Math.random() * images.length());
        imageView.setImageResource(images.getResourceId(choice, R.drawable.splash1));
        images.recycle();//from  www  . ja v a  2s  .  c om
    }
}

From source file:pl.charmas.android.tagview.example.MainActivity.java

public LinkedList<TagView.Tag> createTagList() {
    TypedArray typedArray = getResources().obtainTypedArray(R.array.colors);
    int[] colors = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); i++) {
        colors[i] = typedArray.getColor(i, 0);
    }/*from ww  w  .  ja  va2s  . c  om*/
    typedArray.recycle();

    String[] tagContents = getResources().getStringArray(R.array.tags);
    LinkedList<TagView.Tag> tags = new LinkedList<TagView.Tag>();
    int i = 0;
    for (String content : tagContents) {
        tags.add(new TagView.Tag(content, colors[i++ % colors.length]));
    }
    return tags;
}

From source file:org.gearvrf.keyboard.model.SphereStaticList.java

private void getSpheres(GVRContext gvrContext, int array) {
    listFlag = new ArrayList<GVRSceneObject>();
    Resources res = gvrContext.getContext().getResources();
    TypedArray spheres = res.obtainTypedArray(array);

    for (int i = 0; i < spheres.length(); i++) {
        int type = spheres.getResourceId(i, -1);
        TypedArray sphere = res.obtainTypedArray(type);
        SphereFlag objectSphere = new SphereFlag(gvrContext, sphere);
        Vector3D parentPosition = objectSphere.getInitialPositionVector();

        GVRSceneObject parent = new GVRSceneObject(gvrContext,
                new GVRAndroidResource(gvrContext, R.drawable.hit_area_half),
                new GVRAndroidResource(gvrContext, R.raw.empty));
        parent.setName(SceneObjectNames.SPHERE_FLAG_PARENT);
        parent.getTransform().setPosition((float) parentPosition.getX(), (float) parentPosition.getY(),
                (float) parentPosition.getZ());
        parent.addChildObject(objectSphere);
        listFlag.add(parent);/*from   w  w w  .j a v  a2 s . com*/
    }
}

From source file:jahirfiquitiva.iconshowcase.adapters.ChangelogAdapter.java

public ChangelogAdapter(Context context, int changelogArray) {
    // Save the context
    this.context = context;
    // Populate the two-dimensional array
    TypedArray typedArray = context.getResources().obtainTypedArray(changelogArray);
    mChangelog = new String[typedArray.length()][];
    for (int i = 0; i < typedArray.length(); i++) {
        int id = typedArray.getResourceId(i, 0);
        if (id > 0) {
            mChangelog[i] = context.getResources().getStringArray(id);
        }//from   w  w  w  .  j  av a2s.c o  m
    }
    typedArray.recycle();
}

From source file:com.manuelpeinado.fadingactionbar.demo.NavigationDrawerActivity.java

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

    mTitle = mDrawerTitle = getTitle();/*  w  w  w . j  av a2  s  . c  o 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);

    // 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, mCityNames));
    mDrawerList.setOnItemClickListener(this);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    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.yixi.window.view.CalculatorView.java

public void init() {
    // Disable IME for this application
    //        getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
    //                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    // Single page UI
    final TypedArray buttons = getResources().obtainTypedArray(R.array.simple_buttons);
    for (int i = 0; i < buttons.length(); i++) {
        setOnClickListener(null, buttons.getResourceId(i, 0));
    }//from w  w  w. java 2  s  . c om
    buttons.recycle();

    if (mClearButton == null) {
        mClearButton = findViewById(R.id.clear);
        mClearButton.setOnClickListener(mListener);
        mClearButton.setOnLongClickListener(mListener);
    }
    if (mBackspaceButton == null) {
        mBackspaceButton = findViewById(R.id.del);
        mBackspaceButton.setOnClickListener(mListener);
        mBackspaceButton.setOnLongClickListener(mListener);
    }

    mPersist = new Persist(mContext);
    mPersist.load();

    mHistory = mPersist.history;

    mDisplay = (CalculatorDisplay) findViewById(R.id.display);

    mLogic = new Logic(mContext, mHistory, mDisplay);
    mLogic.setListener(this);

    mLogic.setDeleteMode(mPersist.getDeleteMode());
    mLogic.setLineLength(mDisplay.getMaxDigits());

    HistoryAdapter historyAdapter = new HistoryAdapter(mContext, mHistory, mLogic);
    mHistory.setObserver(historyAdapter);

    mListener.setHandler(mLogic, mPager);
    mDisplay.setOnKeyListener(mListener);

    mLogic.resumeWithHistory();
    updateDeleteMode();
}

From source file:com.zftlive.android.sample.fadingactionbar.NavigationDrawerActivity.java

@SuppressLint("NewApi")
@Override/*from   w  w w  .jav a  2  s  .c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();
    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);

    // 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, mCityNames));
    mDrawerList.setOnItemClickListener(this);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    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);
    }
    //??
    ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}