Android Open Source - MagicViews Font Utils






From Project

Back to project page MagicViews.

License

The source code is released under:

Apache License

If you think the Android project MagicViews 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.ivankocijan.magicviews.utils;
/*ww  w  .  j a  v a  2  s  . c o m*/
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.TextView;

import com.ivankocijan.magicviews.MagicFont;
import com.ivankocijan.magicviews.R;
import com.ivankocijan.magicviews.enums.PreferenceType;

/**
 * Created by ivankocijan on 18.05.2014..
 */
public class FontUtils {

    /**
     * Set's typface on view
     *
     * @param ctx
     * @param attrs
     * @param view
     */
    public static void setTypeface (Context ctx, AttributeSet attrs, TextView view) {

        TypedArray a = ctx.obtainStyledAttributes(attrs, R.styleable.MagicFont);
        String fontStyle = a.getString(R.styleable.MagicFont_typeFace);

        if (fontStyle != null) {
            view.setTypeface(MagicFont.getInstance(ctx).getTypeface(ctx, fontStyle));
        }

        a.recycle();

    }

    /**
     * Set's font style for custom preference
     *
     * @param ctx
     * @param fontStyle
     * @param views
     */
    public static void setPreferenceTypeface (Context ctx, String fontStyle, TextView... views) {

        if (fontStyle != null) {

            for (TextView view : views) {

                view.setTypeface(MagicFont.getInstance(ctx).getTypeface(ctx, fontStyle));

            }

        }

    }

    /**
     * Returns font style from attribute set
     *
     * @param ctx
     * @param attrs
     * @return
     */
    public static String getPrefFontStyle (Context ctx, AttributeSet attrs, PreferenceType type) {

        switch (type) {
            case SIMPLE_PREFERENCE:
                TypedArray simple = ctx.obtainStyledAttributes(attrs, R.styleable.MagicPreference);
                return simple.getString(R.styleable.MagicPreference_prefTypeface);

            case SWITCH_PREFERENCE:

                TypedArray switchPref = ctx.obtainStyledAttributes(attrs, R.styleable.MagicSwitchPreference);
                return switchPref.getString(R.styleable.MagicSwitchPreference_switchPrefTypeface);

            case CHECKBOX_PREFERENCE:
                TypedArray checkBox = ctx.obtainStyledAttributes(attrs, R.styleable.MagicCheckBoxPreference);
                return checkBox.getString(R.styleable.MagicCheckBoxPreference_checkBoxTypeface);
            case PREFERENCE_GROUP:
                TypedArray prefGroup = ctx.obtainStyledAttributes(attrs, R.styleable.MagicPreferenceGroup);
                return prefGroup.getString(R.styleable.MagicPreferenceGroup_preferenceGroupTypeface);
            case EDIT_TEXT_PREFERENCE:
                TypedArray editText = ctx.obtainStyledAttributes(attrs, R.styleable.MagicEditTextPreference);
                return editText.getString(R.styleable.MagicEditTextPreference_editTextTypeface);
            default:
                return "";
        }

    }

}




Java Source Code List

com.ivankocijan.TestApp.ExamplePreferenceFragment.java
com.ivankocijan.TestApp.TestAppApplication.java
com.ivankocijan.TestApp.activites.MainActivity.java
com.ivankocijan.TestApp.activites.PreferenceExampleActivity.java
com.ivankocijan.magicviews.FontNotFoundException.java
com.ivankocijan.magicviews.MagicFont.java
com.ivankocijan.magicviews.MagicViewsNotInitializedException.java
com.ivankocijan.magicviews.MagicViews.java
com.ivankocijan.magicviews.enums.PreferenceType.java
com.ivankocijan.magicviews.preference.MagicCheckBoxPreference.java
com.ivankocijan.magicviews.preference.MagicEditTextPreference.java
com.ivankocijan.magicviews.preference.MagicPreferenceGroup.java
com.ivankocijan.magicviews.preference.MagicPreference.java
com.ivankocijan.magicviews.preference.MagicSwitchPreference.java
com.ivankocijan.magicviews.utils.FontUtils.java
com.ivankocijan.magicviews.views.MagicButton.java
com.ivankocijan.magicviews.views.MagicCheckBox.java
com.ivankocijan.magicviews.views.MagicCheckedTextView.java
com.ivankocijan.magicviews.views.MagicEditText.java
com.ivankocijan.magicviews.views.MagicTextView.java