Android Open Source - rss View Nav Item






From Project

Back to project page rss.

License

The source code is released under:

GNU General Public License

If you think the Android project rss listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.// w  w w . j ava2 s  .co m
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package com.poloure.simplerss;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;

public
class ViewNavItem extends View
{
    private static final Paint[] m_paints = new Paint[2];
    private static final Bitmap[] m_bitmaps_dark = new Bitmap[3];
    private static final Bitmap[] m_bitmaps_light = new Bitmap[3];
    private static final int[] FONT_SIZES = {
            R.dimen.navigation_main, R.dimen.navigation_tag,
    };
    private final int m_height;
    public String m_text = "";
    public String m_count = "";
    public int m_image = -1;

    public
    ViewNavItem(Context context)
    {
        super(context);
        Resources resources = context.getResources();

        if(null == m_bitmaps_dark[0])
        {
            int[] drawablesDark = {
                    R.drawable.ic_action_important,
                    R.drawable.ic_action_storage,
                    R.drawable.ic_action_settings,
            };

            int[] drawablesLight = {
                    R.drawable.ic_action_important_light,
                    R.drawable.ic_action_storage_light,
                    R.drawable.ic_action_settings_light,
            };

            for(int i = 0; i < m_bitmaps_dark.length; i++)
            {
                m_bitmaps_dark[i] = BitmapFactory.decodeResource(resources, drawablesDark[i]);
                m_bitmaps_light[i] = BitmapFactory.decodeResource(resources, drawablesLight[i]);
            }
        }

        m_height = Math.round(resources.getDimension(R.dimen.navigation_height));
        setBackgroundResource(R.drawable.navigation_item_background);
        initPaints(resources);
    }

    private static
    void initPaints(Resources resources)
    {
        for(int i = 0; m_paints.length > i; i++)
        {
            m_paints[i] = configurePaint(resources, FONT_SIZES[i]);
        }
    }

    private static
    Paint configurePaint(Resources resources, int dimenResource)
    {
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setTextSize(resources.getDimension(dimenResource));
        return paint;
    }

    @Override
    public
    boolean hasOverlappingRendering()
    {
        return false;
    }

    @Override
    public
    void onDraw(Canvas canvas)
    {
        Resources resources = getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();

      /* If our paints have been cleared from memory, remake them. */
        if(null == m_paints[0])
        {
            initPaints(resources);
        }

      /* Padding top. */
        float width = getWidth();

        int hPadding = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16.0F, metrics));
        int paddingStart = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8.0F, metrics));

        Paint paint = -1 == m_image ? m_paints[1] : m_paints[0];
        long verticalPosition = Math.round(m_height / 2.0 - (paint.descent() + paint.ascent()) / 2.0);

        boolean rtl = Utilities.isTextRtl(m_text);

        paint.setColor(isActivated() ? Color.WHITE : resources.getColor(R.color.text_navigation_main));

      /* Draw the count. */
        if(-1 == m_image)
        {
            paint.setTextAlign(rtl ? Paint.Align.LEFT : Paint.Align.RIGHT);
            canvas.drawText(m_count, rtl ? hPadding : width - hPadding, verticalPosition, paint);
        }

        paint.setTextAlign(rtl ? Paint.Align.RIGHT : Paint.Align.LEFT);

      /* Draw the image. */
        if(-1 != m_image)
        {
            Bitmap icon = isActivated() ? m_bitmaps_light[m_image] : m_bitmaps_dark[m_image];
            int imageWidth = icon.getWidth();
            int paddingTop = Constants.s_eightDp;
            canvas.drawBitmap(icon, rtl ? width - paddingStart - imageWidth : paddingStart, Math.round(paddingTop), m_paints[0]);
            hPadding = (paddingStart << 1) + imageWidth;
        }

      /* Draw the main text. */
        canvas.drawText(m_text, rtl ? width - hPadding : hPadding, verticalPosition, paint);
    }

    @Override
    protected
    void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        setMeasuredDimension(widthMeasureSpec, m_height);
    }
}




Java Source Code List

com.poloure.simplerss.AsyncCheckFeed.java
com.poloure.simplerss.AsyncLoadImage.java
com.poloure.simplerss.AsyncManageAdapter.java
com.poloure.simplerss.AsyncNavigationAdapter.java
com.poloure.simplerss.AsyncNewTagAdapters.java
com.poloure.simplerss.Constants.java
com.poloure.simplerss.DialogConfirm.java
com.poloure.simplerss.DialogEditFeed.java
com.poloure.simplerss.FeedItem.java
com.poloure.simplerss.FeedsActivity.java
com.poloure.simplerss.FragmentFeeds.java
com.poloure.simplerss.FragmentNavigationDrawer.java
com.poloure.simplerss.FragmentSettings.java
com.poloure.simplerss.IndexItem.java
com.poloure.simplerss.ListFragmentFavourites.java
com.poloure.simplerss.ListFragmentManage.java
com.poloure.simplerss.ListFragmentTag.java
com.poloure.simplerss.ObjectIO.java
com.poloure.simplerss.PagerAdapterTags.java
com.poloure.simplerss.RssLogger.java
com.poloure.simplerss.ServiceUpdate.java
com.poloure.simplerss.Utilities.java
com.poloure.simplerss.ViewFeedItem.java
com.poloure.simplerss.ViewNavItem.java
com.poloure.simplerss.ViewPagerDelegate.java
com.poloure.simplerss.adapters.AdapterFeedItems.java
com.poloure.simplerss.adapters.AdapterManageItems.java
com.poloure.simplerss.adapters.AdapterNavigationDrawer.java
com.poloure.simplerss.adapters.LinkedMapAdapter.java
com.poloure.simplerss.asynctasks.AsyncTaskSaveImage.java
com.poloure.simplerss.fragments.FragmentWebView.java
com.poloure.simplerss.listeners.MultiModeListenerFavourites.java
com.poloure.simplerss.listeners.MultiModeListenerManage.java
com.poloure.simplerss.listeners.MultiModeListener.java
com.poloure.simplerss.ui.ListViewFeeds.java