Android Open Source - fooplayer-android Text View






From Project

Back to project page fooplayer-android.

License

The source code is released under:

GNU General Public License

If you think the Android project fooplayer-android 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

package com.mauriciogiordano.fooplayer.view;
/*from w  w w. j ava 2s .  co  m*/
/**
 * Created by mauricio on 11/1/14.
 */

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.TypedValue;

import com.mauriciogiordano.fooplayer.R;

public class TextView extends android.widget.TextView
{
    private String SCHEMA = "http://schemas.android.com/apk/lib/com.mauriciogiordano.fooplayer.view";
    private Context context = null;
    private int textThickness = 4;
    private String textFor = "";

    public TextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        this.context = context;

        isInEditMode();

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextView);

        try {
            try
            {
                textThickness = Integer.parseInt(attrs.getAttributeValue(SCHEMA, "textThickness"));
            } catch(NumberFormatException e)
            {
                textThickness = 4;
            }

            textFor = attrs.getAttributeValue(SCHEMA, "textFor");

            if(textFor == null) textFor = "p";

            setThickness(textThickness);
            setTextUtility(textFor);

            invalidate();
            requestLayout();
        } finally {
            a.recycle();
        }
    }

    private void setThickness(int textThickness)
    {
        Typeface typeface = null;

        switch(textThickness)
        {
            case 0:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_black.ttf");
                break;
            case 1:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_bold.ttf");
                break;
            case 2:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_medium.ttf");
                break;
            case 3:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_regular.ttf");
                break;
            case 4:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_light.ttf");
                break;
            case 5:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_thin.ttf");
                break;
            default:
                typeface = Typeface.createFromAsset(context.getAssets(), "roboto_light.ttf");
                break;
        }

        setTypeface(typeface);
    }

    private void setTextUtility(String textFor)
    {
        if(textFor.equals("goku"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 40.0f);
        else if(textFor.equals("h1"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20.0f);
        else if(textFor.equals("h2"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
        else if(textFor.equals("h3"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16.0f);
        else if(textFor.equals("p"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14.0f);
        else if(textFor.equals("small"))
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12.0f);
        else
            setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14.0f);
    }
}




Java Source Code List

com.mauriciogiordano.fooplayer.AlbumsActivity.java
com.mauriciogiordano.fooplayer.ApplicationTest.java
com.mauriciogiordano.fooplayer.FooActivity.java
com.mauriciogiordano.fooplayer.TracksActivity.java
com.mauriciogiordano.fooplayer.adapter.AlbumsAdapter.java
com.mauriciogiordano.fooplayer.adapter.ArtistsAdapter.java
com.mauriciogiordano.fooplayer.adapter.TracksAdapter.java
com.mauriciogiordano.fooplayer.config.Constants.java
com.mauriciogiordano.fooplayer.database.Album.java
com.mauriciogiordano.fooplayer.database.Artist.java
com.mauriciogiordano.fooplayer.database.Bean.java
com.mauriciogiordano.fooplayer.database.DatabaseHelper.java
com.mauriciogiordano.fooplayer.database.Track.java
com.mauriciogiordano.fooplayer.fragment.AlbumsFragment.java
com.mauriciogiordano.fooplayer.fragment.ArtistsFragment.java
com.mauriciogiordano.fooplayer.fragment.TracksFragment.java
com.mauriciogiordano.fooplayer.network.Delegate.java
com.mauriciogiordano.fooplayer.network.Endpoints.java
com.mauriciogiordano.fooplayer.network.HttpClientHelper.java
com.mauriciogiordano.fooplayer.network.ImageHelper.java
com.mauriciogiordano.fooplayer.network.Network.java
com.mauriciogiordano.fooplayer.network.YouTubeUtility.java
com.mauriciogiordano.fooplayer.view.TextView.java