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.h6ah4i.android.materialshadowninepatch.MaterialShadowContainerView.java

private int[] getResourceIdArray(Resources resources, int id) {
    if (id == 0) {
        return null;
    }/*from www  .ja v a 2 s  .c  o  m*/
    if (isInEditMode()) {
        return null;
    }

    TypedArray ta = resources.obtainTypedArray(id);
    int[] array = new int[ta.length()];

    for (int i = 0; i < array.length; i++) {
        array[i] = ta.getResourceId(i, 0);
    }

    ta.recycle();

    return array;
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

private void setupAutoSizeUniformPresetSizes(TypedArray textSizes) {
    final int textSizesLength = textSizes.length();
    final int[] parsedSizes = new int[textSizesLength];

    if (textSizesLength > 0) {
        for (int i = 0; i < textSizesLength; i++) {
            parsedSizes[i] = textSizes.getDimensionPixelSize(i, -1);
        }/*w  w  w. j  a va  2s .c o  m*/
        mAutoSizeTextSizesInPx = cleanupAutoSizePresetSizes(parsedSizes);
        setupAutoSizeUniformPresetSizesConfiguration();
    }
}

From source file:org.gnucash.android.ui.account.AccountFormFragment.java

/**
 * Returns an array of colors used for accounts.
 * The array returned has the actual color values and not the resource ID.
 * @return Integer array of colors used for accounts
 *//* w  w  w  .j  a  v a2 s.c  om*/
private int[] getAccountColorOptions() {
    Resources res = getResources();
    TypedArray colorTypedArray = res.obtainTypedArray(R.array.account_colors);
    int[] colorOptions = new int[colorTypedArray.length()];
    for (int i = 0; i < colorTypedArray.length(); i++) {
        int color = colorTypedArray.getColor(i, R.color.title_green);
        colorOptions[i] = color;
    }
    return colorOptions;
}

From source file:io.github.yavski.fabspeeddial.FabSpeedDial.java

private void resolveOptionalAttributes(TypedArray typedArray) {
    fabDrawable = typedArray.getDrawable(R.styleable.FabSpeedDial_fabDrawable);
    if (fabDrawable == null) {
        fabDrawable = ContextCompat.getDrawable(getContext(), R.drawable.fab_add_clear_selector);
    }// ww w  . j  av a 2  s . co m

    fabDrawableTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_fabDrawableTint);
    if (fabDrawableTint == null) {
        fabDrawableTint = getColorStateList(R.color.fab_drawable_tint);
    }

    if (typedArray.hasValue(R.styleable.FabSpeedDial_fabBackgroundTint)) {
        fabBackgroundTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_fabBackgroundTint);
    }

    miniFabBackgroundTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_miniFabBackgroundTint);
    if (miniFabBackgroundTint == null) {
        miniFabBackgroundTint = getColorStateList(R.color.fab_background_tint);
    }

    if (typedArray.hasValue(R.styleable.FabSpeedDial_miniFabBackgroundTintList)) {
        int miniFabBackgroundTintListId = typedArray
                .getResourceId(R.styleable.FabSpeedDial_miniFabBackgroundTintList, 0);
        TypedArray miniFabBackgroundTintRes = getResources().obtainTypedArray(miniFabBackgroundTintListId);
        miniFabBackgroundTintArray = new int[miniFabBackgroundTintRes.length()];
        for (int i = 0; i < miniFabBackgroundTintRes.length(); i++) {
            miniFabBackgroundTintArray[i] = miniFabBackgroundTintRes.getResourceId(i, 0);
        }
        miniFabBackgroundTintRes.recycle();
    }

    miniFabDrawableTint = typedArray.getColorStateList(R.styleable.FabSpeedDial_miniFabDrawableTint);
    if (miniFabDrawableTint == null) {
        miniFabDrawableTint = getColorStateList(R.color.mini_fab_drawable_tint);
    }

    miniFabTitleBackgroundTint = typedArray
            .getColorStateList(R.styleable.FabSpeedDial_miniFabTitleBackgroundTint);
    if (miniFabTitleBackgroundTint == null) {
        miniFabTitleBackgroundTint = getColorStateList(R.color.mini_fab_title_background_tint);
    }

    miniFabTitlesEnabled = typedArray.getBoolean(R.styleable.FabSpeedDial_miniFabTitlesEnabled, true);

    miniFabTitleTextColor = typedArray.getColor(R.styleable.FabSpeedDial_miniFabTitleTextColor,
            ContextCompat.getColor(getContext(), R.color.title_text_color));

    if (typedArray.hasValue(R.styleable.FabSpeedDial_miniFabTitleTextColorList)) {
        int miniFabTitleTextColorListId = typedArray
                .getResourceId(R.styleable.FabSpeedDial_miniFabTitleTextColorList, 0);
        TypedArray miniFabTitleTextColorTa = getResources().obtainTypedArray(miniFabTitleTextColorListId);
        miniFabTitleTextColorArray = new int[miniFabTitleTextColorTa.length()];
        for (int i = 0; i < miniFabTitleTextColorTa.length(); i++) {
            miniFabTitleTextColorArray[i] = miniFabTitleTextColorTa.getResourceId(i, 0);
        }
        miniFabTitleTextColorTa.recycle();
    }

    touchGuardDrawable = typedArray.getDrawable(R.styleable.FabSpeedDial_touchGuardDrawable);

    useTouchGuard = typedArray.getBoolean(R.styleable.FabSpeedDial_touchGuard, true);
}

From source file:com.ruesga.rview.SearchActivity.java

private int[] loadSearchIcons() {
    TypedArray ta = getResources().obtainTypedArray(R.array.search_options_icons);
    int count = ta.length();
    int[] icons = new int[count];
    for (int i = 0; i < count; i++) {
        icons[i] = ta.getResourceId(i, -1);
    }//from   w  w w. j  a va  2  s. c o m
    ta.recycle();
    return icons;
}

From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java

private JSONObject defaultValuesToJSON(TypedArray keys, int[] presetValues) {

    JSONObject parameters = new JSONObject();
    for (int i = 0; i < keys.length(); i++) {
        try {//w ww .j a  v  a2 s. c om
            int arrayID = keys.getResourceId(i, 0);
            parameters.put(getString(arrayID), (presetValues[i]));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return parameters;
}

From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java

private void setUpControls() {
    TypedArray arrays = getResources().obtainTypedArray(R.array.tr_default_set);
    TypedArray arrayType = getResources().obtainTypedArray(R.array.tr_default_array);
    for (int i = 0; i < arrays.length(); i++) {

        int titleID = arrays.getResourceId(i, 0);
        int arrayID = arrayType.getResourceId(i, 0);
        if (arrayID == R.string.tr_set_key_location) {
            TaskRabbitLocationControlSet set = new TaskRabbitLocationControlSet(this, R.layout.task_rabbit_row,
                    titleID, i);//from   ww w  .  j ava  2 s  . c om
            set.location = currentLocation;
            controls.add(set);
        } else if (arrayID == R.string.tr_set_key_deadline) {

            TaskRabbitDeadlineControlSet deadlineControl = new TaskRabbitDeadlineControlSet(this,
                    R.layout.control_set_deadline, R.layout.task_rabbit_row);
            controls.add(deadlineControl);
            deadlineControl.readFromTask(model);
        } else if (arrayID == R.string.tr_set_key_name) {
            TaskRabbitNameControlSet nameControlSet = new TaskRabbitNameControlSet(this,
                    R.layout.control_set_notes, R.layout.task_rabbit_row, titleID);
            controls.add(nameControlSet);
        } else if (arrayID == R.string.tr_set_key_description) {
            TaskRabbitNameControlSet descriptionControlSet = new TaskRabbitNameControlSet(this,
                    R.layout.control_set_notes, R.layout.task_rabbit_row_description, titleID);
            try {
                descriptionControlSet.readFromModel(
                        new JSONObject().put(getString(arrayID), model.getValue(Task.NOTES)),
                        getString(arrayID), currentSelectedItem);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            controls.add(descriptionControlSet);
        } else {
            TaskRabbitSpinnerControlSet set = new TaskRabbitSpinnerControlSet(this,
                    R.layout.task_rabbit_spinner, titleID, i);
            controls.add(set);
        }
    }
    if (TextUtils.isEmpty(taskTitle.getText())) {
        taskTitle.setText(model.getValue(Task.TITLE));
    }
    populateFields(taskRabbitTask);

    displayViewsForMode(currentSelectedItem);
}

From source file:ir.actfun.toofan.activities.NowWeatherPage.java

private String setWeatherIcon(int actualId, int hourOfDay) {

    movingImageView = (MovingImageView) findViewById(R.id.movingimageview);

    int id = actualId / 100;
    String icon = "";
    if (actualId == 800) {
        if (hourOfDay >= 7 && hourOfDay < 20) {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.sunny_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.sun1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.sunny_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.sunny_icon));

                    }/*from  w  ww .  j av a2  s .  c om*/
                });
                universal_flag = false;
            }

            icon = this.getString(R.string.weather_sunny);
        } else {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.night_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.night1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.night_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.night_icon));
                    }
                });
                universal_flag = false;
            }

            icon = this.getString(R.string.weather_clear_night);
        }
    } else {
        switch (id) {
        case 2: {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.thunder_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.thunder1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.rainy_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.rainy_icon));
                    }
                });
                universal_flag = false;
            }
            icon = this.getString(R.string.weather_thunder);
            break;
        }

        case 3: {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.rainy_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.rain1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.rainy_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.rainy_icon));
                    }
                });
                universal_flag = false;
            }
            icon = this.getString(R.string.weather_drizzle);
            break;
        }

        case 7: {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.fog_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.fog1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.cloudy_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.cloudy_icon));
                    }
                });
                universal_flag = false;
            }
            icon = this.getString(R.string.weather_foggy);
            break;
        }

        case 8: {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.cloudy_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.cloud2));
                        todayTemperature.setTextColor(getResources().getColor(R.color.cloudy_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.cloudy_icon));
                    }
                });
                universal_flag = false;
            }
            icon = this.getString(R.string.weather_cloudy);
            break;
        }

        case 6: {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.snowy_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.snow1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.snowy_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.snowy_icon));
                    }
                });
                universal_flag = false;
            }
            icon = this.getString(R.string.weather_snowy);
            break;
        }

        case 5: {
            if (universal_flag) {
                final TypedArray images = getResources().obtainTypedArray(R.array.rainy_images);
                final int choice = (int) (Math.random() * images.length());
                NowWeatherPage.this.runOnUiThread(new Runnable() {
                    public void run() {
                        movingImageView.setImageResource(images.getResourceId(choice, R.drawable.rain1));
                        todayTemperature.setTextColor(getResources().getColor(R.color.rainy_icon));
                        todayIcon.setTextColor(getResources().getColor(R.color.rainy_icon));
                    }
                });
                universal_flag = false;
            }
            icon = this.getString(R.string.weather_rainy);
            break;
        }

        }
    }

    return icon;
}

From source file:com.dm.material.dashboard.candybar.fragments.ApplyFragment.java

private void getLaunchers() {
    mGetLaunchers = new AsyncTask<Void, Void, Boolean>() {

        List<Icon> launchers;

        @Override// w ww  .j  a v  a2 s . c  o m
        protected void onPreExecute() {
            super.onPreExecute();
            launchers = new ArrayList<>();
        }

        @Override
        protected Boolean doInBackground(Void... voids) {
            while (!isCancelled()) {
                try {
                    Thread.sleep(1);
                    String[] launcherNames = getActivity().getResources()
                            .getStringArray(R.array.launcher_names);
                    TypedArray launcherIcons = getActivity().getResources()
                            .obtainTypedArray(R.array.launcher_icons);
                    String[] launcherPackages1 = getActivity().getResources()
                            .getStringArray(R.array.launcher_packages_1);
                    String[] launcherPackages2 = getActivity().getResources()
                            .getStringArray(R.array.launcher_packages_2);
                    String[] launcherPackages3 = getActivity().getResources()
                            .getStringArray(R.array.launcher_packages_3);

                    List<Icon> installed = new ArrayList<>();
                    List<Icon> supported = new ArrayList<>();

                    for (int i = 0; i < launcherNames.length; i++) {
                        boolean isInstalled = isLauncherInstalled(launcherPackages1[i], launcherPackages2[i],
                                launcherPackages3[i]);

                        int icon = R.drawable.ic_app_default;
                        if (i < launcherIcons.length())
                            icon = launcherIcons.getResourceId(i, icon);

                        String launcherPackage = launcherPackages1[i];
                        if (launcherPackages1[i].equals("com.lge.launcher2")) {
                            boolean lghome3 = isPackageInstalled(launcherPackages2[i]);
                            if (lghome3)
                                launcherPackage = launcherPackages2[i];
                        }

                        Icon launcher = new Icon(launcherNames[i], icon, launcherPackage);
                        if (isInstalled)
                            installed.add(launcher);
                        else
                            supported.add(launcher);
                    }

                    try {
                        Collections.sort(installed, new AlphanumComparator() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                String s1 = ((Icon) o1).getTitle();
                                String s2 = ((Icon) o2).getTitle();
                                return super.compare(s1, s2);
                            }
                        });
                    } catch (Exception ignored) {
                    }

                    try {
                        Collections.sort(supported, new AlphanumComparator() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                String s1 = ((Icon) o1).getTitle();
                                String s2 = ((Icon) o2).getTitle();
                                return super.compare(s1, s2);
                            }
                        });
                    } catch (Exception ignored) {
                    }

                    if (installed.size() > 0) {
                        launchers.add(new Icon(getActivity().getResources().getString(R.string.apply_installed),
                                -1, null));
                    }

                    launchers.addAll(installed);
                    launchers.add(new Icon(getActivity().getResources().getString(R.string.apply_supported), -2,
                            null));
                    launchers.addAll(supported);

                    launcherIcons.recycle();
                    return true;
                } catch (Exception e) {
                    LogUtil.e(Log.getStackTraceString(e));
                    return false;
                }
            }
            return false;
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            super.onPostExecute(aBoolean);
            if (aBoolean) {
                mRecyclerView.setAdapter(new LauncherAdapter(getActivity(), launchers));
                resetSpanSizeLookUp();
            }
            mGetLaunchers = null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

From source file:com.seatgeek.placesautocompletedemo.MainFragment.java

/**
 * chooses a random color from array.xml
 *///w ww  .  j a v  a 2  s.com
private int getRandomMaterialColor(String typeColor) {
    int returnColor = Color.GRAY;
    int arrayId = getResources().getIdentifier("mdcolor_" + typeColor, "array", getContext().getPackageName());

    if (arrayId != 0) {
        TypedArray colors = getResources().obtainTypedArray(arrayId);
        int index = (int) (Math.random() * colors.length());
        returnColor = colors.getColor(index, Color.GRAY);
        colors.recycle();
    }
    return returnColor;
}