Example usage for android.content.res Resources getDimension

List of usage examples for android.content.res Resources getDimension

Introduction

In this page you can find the example usage for android.content.res Resources getDimension.

Prototype

public float getDimension(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID.

Usage

From source file:com.limewoodmedia.nsdroid.activities.WorldAssembly.java

private void setUpChartRenderer(XYMultipleSeriesRenderer chartRenderer, XYSeriesRenderer forRenderer,
        XYSeriesRenderer againstRenderer) {
    Log.d(TAG, "Set up chart renderer");
    Resources r = getResources();
    float legendTextSize = r.getDimension(R.dimen.area_chart_legend_size);
    float labelTextSize = r.getDimension(R.dimen.area_chart_label_size);

    // For renderer
    forRenderer.setColor(r.getColor(R.color.wa_for));
    forRenderer.setChartValuesTextSize(legendTextSize);
    forRenderer.setDisplayChartValues(true);
    XYSeriesRenderer.FillOutsideLine line = new XYSeriesRenderer.FillOutsideLine(
            XYSeriesRenderer.FillOutsideLine.Type.BELOW);
    line.setColor(r.getColor(R.color.wa_for_below));
    forRenderer.addFillOutsideLine(line);

    againstRenderer.setColor(r.getColor(R.color.wa_against));
    againstRenderer.setChartValuesTextSize(legendTextSize);
    againstRenderer.setDisplayChartValues(true);
    line = new XYSeriesRenderer.FillOutsideLine(XYSeriesRenderer.FillOutsideLine.Type.BELOW);
    line.setColor(r.getColor(R.color.wa_against_below));
    againstRenderer.addFillOutsideLine(line);

    chartRenderer.setZoomButtonsVisible(false);
    chartRenderer.setClickEnabled(true);
    chartRenderer.setInScroll(true);//w ww  .j  a  va  2 s.com
    chartRenderer.setAntialiasing(true);
    chartRenderer.setShowLegend(true);
    chartRenderer.setLegendTextSize(legendTextSize);
    chartRenderer.setLabelsTextSize(labelTextSize);
    chartRenderer.setTextTypeface(Typeface.DEFAULT);
    chartRenderer.setPanEnabled(false);
    chartRenderer.setShowLabels(true);
    chartRenderer.setXAxisMin(0);
    chartRenderer.setXAxisMax(24 * 4 + 1); // 1 per hour, 4 days, 1 at origo
    chartRenderer.setYAxisMin(0);
    chartRenderer.setXLabels(0);
    chartRenderer.setXLabelsAngle(-25);
    chartRenderer.setXLabelsAlign(Paint.Align.RIGHT);
    chartRenderer.setFitLegend(true);
    for (int i = 1; i < 5; i++) {
        chartRenderer.addXTextLabel(24 * i, i + " " + r.getQuantityString(R.plurals.days, i));
    }
    chartRenderer.setYLabels(0);
    chartRenderer.setGridColor(Color.WHITE);
    chartRenderer.setMarginsColor(Color.WHITE);
    chartRenderer.setMargins(new int[] { 0, 0, r.getDimensionPixelSize(R.dimen.area_chart_margin_bottom), 0 });
    chartRenderer.setBackgroundColor(Color.WHITE);
    chartRenderer.setApplyBackgroundColor(true);
    chartRenderer.removeAllRenderers();
    chartRenderer.addSeriesRenderer(forRenderer);
    chartRenderer.addSeriesRenderer(againstRenderer);
}

From source file:android.hqs.view.pager.indicator.LinePageIndicator.java

/**
 * ?/*from   w  w  w .  j  a v a 2  s  .c o  m*/
 * @param context
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:sk.gryfonnlair.priznaj.view.ui.LinePageIndicator.java

@SuppressWarnings("deprecation")
public LinePageIndicator(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;//from  www  .j av  a2s .  com
    }

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

    //Retrieve styles attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    final Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:io.bunnyblue.noticedog.app.ui.pageview.LinePageIndicator.java

public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    this.mPaintUnselected = new Paint(1);
    this.mPaintSelected = new Paint(1);
    this.mLastMotionX = -1.0f;
    this.mActivePointerId = -1;
    if (!isInEditMode()) {
        Resources res = getResources();
        int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
        int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
        float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
        float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
        float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
        boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);
        this.mCentered = a.getBoolean(1, defaultCentered);
        this.mLineWidth = a.getDimension(5, defaultLineWidth);
        this.mGapWidth = a.getDimension(6, defaultGapWidth);
        setStrokeWidth(a.getDimension(3, defaultStrokeWidth));
        this.mPaintUnselected.setColor(a.getColor(4, defaultUnselectedColor));
        this.mPaintSelected.setColor(a.getColor(2, defaultSelectedColor));
        Drawable background = a.getDrawable(0);
        if (background != null) {
            setBackgroundDrawable(background);
        }//from   ww w  . ja  va 2s.co  m
        a.recycle();
        this.mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfiguration.get(context));
    }
}

From source file:com.viewpagerindicator.as.library.indicator.RecyclerLinePageIndicator.java

public RecyclerLinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;// w  ww  .  j a va2  s  . com

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.androtex.viewpagerindicator.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke//from ww  w.java 2 s .  co m
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();
}

From source file:com.moblin.cellcomsms.utils.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.FILL_AND_STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke//from w  w  w. j  ava2 s  . c  o m
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();
}

From source file:org.xbmc.kore.ui.sections.video.TVShowDetailsFragment.java

/**
 * Display the seasons list/*from  ww w .java2s . c  om*/
 *
 * @param cursor Cursor with the data
 */
private void displaySeasonList(Cursor cursor) {
    if (cursor.moveToFirst()) {
        seasonsListTitle.setVisibility(View.VISIBLE);
        seasonsList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener seasonListClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onSeasonSelected(tvshowId, (int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.seasonlist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.seasonlist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        seasonsList.removeAllViews();
        do {
            int seasonNumber = cursor.getInt(SeasonsListQuery.SEASON);
            String thumbnail = cursor.getString(SeasonsListQuery.THUMBNAIL);
            int numEpisodes = cursor.getInt(SeasonsListQuery.EPISODE);
            int watchedEpisodes = cursor.getInt(SeasonsListQuery.WATCHEDEPISODES);

            View seasonView = LayoutInflater.from(getActivity()).inflate(R.layout.grid_item_season, seasonsList,
                    false);

            ImageView seasonPictureView = (ImageView) seasonView.findViewById(R.id.art);
            TextView seasonNumberView = (TextView) seasonView.findViewById(R.id.season);
            TextView seasonEpisodesView = (TextView) seasonView.findViewById(R.id.episodes);
            ProgressBar seasonProgressBar = (ProgressBar) seasonView.findViewById(R.id.season_progress_bar);

            seasonNumberView
                    .setText(String.format(getActivity().getString(R.string.season_number), seasonNumber));
            seasonEpisodesView.setText(String.format(getActivity().getString(R.string.num_episodes),
                    numEpisodes, numEpisodes - watchedEpisodes));
            seasonProgressBar.setMax(numEpisodes);
            seasonProgressBar.setProgress(watchedEpisodes);

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail,
                    String.valueOf(seasonNumber), seasonPictureView, artWidth, artHeight);

            seasonView.setTag(seasonNumber);
            seasonView.setOnClickListener(seasonListClickListener);
            seasonsList.addView(seasonView);
        } while (cursor.moveToNext());
    } else {
        // No seasons, hide views
        seasonsListTitle.setVisibility(View.GONE);
        seasonsList.setVisibility(View.GONE);
    }
}

From source file:org.xbmc.kore.ui.sections.video.TVShowDetailsFragment.java

/**
 * Display next episode list//from   w  w  w  . j  av  a 2s . c o m
 *
 * @param cursor Cursor with the data
 */
private void displayNextEpisodeList(Cursor cursor) {
    if (cursor.moveToFirst()) {
        nextEpisodeTitle.setVisibility(View.VISIBLE);
        nextEpisodeList.setVisibility(View.VISIBLE);

        HostManager hostManager = HostManager.getInstance(getActivity());

        View.OnClickListener episodeClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listenerActivity.onNextEpisodeSelected((int) v.getTag());
            }
        };

        // Get the art dimensions
        Resources resources = getActivity().getResources();
        int artWidth = (int) (resources.getDimension(R.dimen.episodelist_art_width)
                / UIUtils.IMAGE_RESIZE_FACTOR);
        int artHeight = (int) (resources.getDimension(R.dimen.episodelist_art_heigth)
                / UIUtils.IMAGE_RESIZE_FACTOR);

        nextEpisodeList.removeAllViews();
        do {
            int episodeId = cursor.getInt(NextEpisodesListQuery.EPISODEID);
            String title = cursor.getString(NextEpisodesListQuery.TITLE);
            String seasonEpisode = String.format(getString(R.string.season_episode),
                    cursor.getInt(NextEpisodesListQuery.SEASON), cursor.getInt(NextEpisodesListQuery.EPISODE));
            int runtime = cursor.getInt(NextEpisodesListQuery.RUNTIME) / 60;
            String duration = runtime > 0
                    ? String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) + "  |  "
                            + cursor.getString(NextEpisodesListQuery.FIRSTAIRED)
                    : cursor.getString(NextEpisodesListQuery.FIRSTAIRED);
            String thumbnail = cursor.getString(NextEpisodesListQuery.THUMBNAIL);

            View episodeView = LayoutInflater.from(getActivity()).inflate(R.layout.list_item_next_episode,
                    nextEpisodeList, false);

            ImageView artView = (ImageView) episodeView.findViewById(R.id.art);
            TextView titleView = (TextView) episodeView.findViewById(R.id.title);
            TextView detailsView = (TextView) episodeView.findViewById(R.id.details);
            TextView durationView = (TextView) episodeView.findViewById(R.id.duration);

            titleView.setText(title);
            detailsView.setText(seasonEpisode);
            durationView.setText(duration);

            UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, thumbnail, title, artView,
                    artWidth, artHeight);
            episodeView.setTag(episodeId);
            episodeView.setOnClickListener(episodeClickListener);

            // For the popupmenu
            ImageView contextMenu = (ImageView) episodeView.findViewById(R.id.list_context_menu);
            contextMenu.setTag(episodeId);
            contextMenu.setOnClickListener(contextlistItemMenuClickListener);

            nextEpisodeList.addView(episodeView);
        } while (cursor.moveToNext());
    } else {
        // No episodes, hide views
        nextEpisodeTitle.setVisibility(View.GONE);
        nextEpisodeList.setVisibility(View.GONE);
    }
}

From source file:com.joy.ui.view.banner.indicator.CircleIndicator.java

public CircleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*from w w w. ja v  a2 s  .  co m*/
    }
    // Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator, defStyle, 0);

    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CircleIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CircleIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CircleIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CircleIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CircleIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CircleIndicator_snap, defaultSnap);
    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}