Android Open Source - sms-smap-gateway Fontable Text View






From Project

Back to project page sms-smap-gateway.

License

The source code is released under:

GNU General Public License

If you think the Android project sms-smap-gateway 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.android.smap.ui.views;
//from  w w w  .j a v a  2 s  .  co  m
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.TextView;

import com.android.smap.R;
import com.android.smap.utils.MWAssetsUtils;

/**
 * TextView implementation for setting the custom font in resources.<br/>
 * The font has to be set in the in styles.xml using the customTextFont
 * attribute. <br/>
 * This class checks if the font file is inside "assets/fonts/" and if the font
 * is present initializes the text with the specified font.
 * 
 * @author Matt Witherow
 */
public class FontableTextView extends TextView {

  public FontableTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setCustomFont(context, attrs);
  }

  public FontableTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setCustomFont(context, attrs);
  }

  public FontableTextView(Context context) {
    super(context);
  }

  private void setCustomFont(Context ctx, AttributeSet attrs) {
    TypedArray a = ctx.obtainStyledAttributes(attrs,
        R.styleable.MWCustomFontView);
    String customFont = a
        .getString(R.styleable.MWCustomFontView_customFont);
    String editorText = a
        .getString(R.styleable.MWCustomFontView_editorText);

    if (isInEditMode()) {
      // set editor text value
      if (!TextUtils.isEmpty(editorText)) {
        setText(editorText);
      } else {
        setText(FontableTextView.class.getSimpleName());
      }
    } else {
      // set font only when not in editor mode
      setCustomAssetFont(customFont);
    }

    a.recycle();

    setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
  }

  /**
   * @param ctx
   * @param font
   * @return
   */
  public boolean setCustomAssetFont(String font) {
    Context ctx = getContext();
    Typeface tf = MWAssetsUtils.getCachedFont(ctx, font);
    // check if could not find font
    if (tf == null) {
      return false;
    }

    setTypeface(tf);
    return true;
  }

}




Java Source Code List

com.android.smap.AppConfig.java
com.android.smap.GatewayApp.java
com.android.smap.PhoneStateWrapper.java
com.android.smap.activities.BaseActivity.java
com.android.smap.activities.FragmentWrapperActivity.java
com.android.smap.activities.MainActivity.java
com.android.smap.adapters.MenuDrawerAdapter.java
com.android.smap.api.ApiConstants.java
com.android.smap.api.models.Gojo.java
com.android.smap.api.models.Node.java
com.android.smap.api.models.SmapException.java
com.android.smap.api.models.Status.java
com.android.smap.api.models.validator.ModelValidator.java
com.android.smap.api.models.validator.Required.java
com.android.smap.api.requests.ApiRequest.java
com.android.smap.api.requests.GojoRequest.java
com.android.smap.api.requests.StatusRequest.java
com.android.smap.commonsware.wakefull.AlarmReceiver.java
com.android.smap.commonsware.wakefull.WakefulIntentService.java
com.android.smap.controllers.ControllerErrorListener.java
com.android.smap.controllers.ControllerError.java
com.android.smap.controllers.ControllerFactory.java
com.android.smap.controllers.ControllerListener.java
com.android.smap.controllers.Controller.java
com.android.smap.controllers.EmailController.java
com.android.smap.controllers.GojoController.java
com.android.smap.controllers.UIPagingController.java
com.android.smap.controllers.UIRequestController.java
com.android.smap.fragments.BaseFragment.java
com.android.smap.fragments.HomeFragment.java
com.android.smap.models.MenuDrawerItem.java
com.android.smap.models.TextMessage.java
com.android.smap.samuel.Samuel.java
com.android.smap.sms.CellularModem.java
com.android.smap.sms.GatewayService.java
com.android.smap.sms.MonitorService.java
com.android.smap.sms.ScheduleMonitoringListener.java
com.android.smap.sms.ServiceRebooter.java
com.android.smap.ui.ArrayVelocAdapter.java
com.android.smap.ui.OnErrorTouchedListener.java
com.android.smap.ui.Operation.java
com.android.smap.ui.VelocAdapter.java
com.android.smap.ui.ViewBinder.java
com.android.smap.ui.ViewQuery.java
com.android.smap.ui.views.AnimatedNetworkImageView.java
com.android.smap.ui.views.ErrorView.java
com.android.smap.ui.views.FontableTextView.java
com.android.smap.utils.BitmapLruCache.java
com.android.smap.utils.MWAPNUtils.java
com.android.smap.utils.MWAnimUtil.java
com.android.smap.utils.MWAssetsUtils.java
com.android.smap.utils.MWConnectionUtils.java
com.android.smap.utils.MWEmailUtils.java
com.android.smap.utils.MWUiUtils.java
com.android.smap.utils.PreferenceWrapper.java
com.android.smap.utils.Refresher.java
com.android.smap.utils.UriBuilder.java