Android Open Source - commit-android Commit Edit Text






From Project

Back to project page commit-android.

License

The source code is released under:

GNU General Public License

If you think the Android project commit-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.commit.view;
// ww w .j av  a 2s.  co  m
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;

import com.mauriciogiordano.commit.R;

public class CommitEditText extends android.widget.EditText
{
  private String SCHEMA = "http://schemas.android.com/apk/lib/com.mauriciogiordano.commit.view";
  private Context context = null;
  private int textThickness = 4;
  private String textFor = "";
  
    public CommitEditText(Context context, AttributeSet attrs)
    {
        super(context, attrs);

        this.context = context;
        
        isInEditMode();
        
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CommitTextView);

        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(), "fonts/roboto_black.ttf");
          break;
        case 1:
          typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_bold.ttf");
          break;
        case 2:
          typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_medium.ttf");
          break;
        case 3:
          typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_regular.ttf");
          break;
        case 4:
          typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_light.ttf");
          break;
        case 5:
          typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_thin.ttf");
          break;
        default:
          typeface = Typeface.createFromAsset(context.getAssets(), "fonts/roboto_light.ttf");
          break;
        }

        setTypeface(typeface);
    }
    
    private void setTextUtility(String textFor)
    {
      if(textFor.equals("goku"))
        setTextSize(getResources().getDimension(R.dimen.textview_goku));
      else if(textFor.equals("hero"))
        setTextSize(getResources().getDimension(R.dimen.textview_hero));
      else if(textFor.equals("h1"))
        setTextSize(getResources().getDimension(R.dimen.textview_h1));
      else if(textFor.equals("h2"))
        setTextSize(getResources().getDimension(R.dimen.textview_h2));
      else if(textFor.equals("h3"))
        setTextSize(getResources().getDimension(R.dimen.textview_h3));
      else if(textFor.equals("p"))
        setTextSize(getResources().getDimension(R.dimen.textview_p));
      else if(textFor.equals("small"))
        setTextSize(getResources().getDimension(R.dimen.textview_small));
      else
        setTextSize(getResources().getDimension(R.dimen.textview_p));
    }
}




Java Source Code List

com.mauriciogiordano.commit.CommitActivity.java
com.mauriciogiordano.commit.CommitAlarmIntent.java
com.mauriciogiordano.commit.CommitAlarmReceiver.java
com.mauriciogiordano.commit.CommitHelper.java
com.mauriciogiordano.commit.Constants.java
com.mauriciogiordano.commit.adapter.CommitAdapter.java
com.mauriciogiordano.commit.database.BaseModel.java
com.mauriciogiordano.commit.database.Commit.java
com.mauriciogiordano.commit.database.Commitment.java
com.mauriciogiordano.commit.database.DatabaseConfigUtil.java
com.mauriciogiordano.commit.database.DatabaseHelper.java
com.mauriciogiordano.commit.fragment.CommitFragment.java
com.mauriciogiordano.commit.fragment.CommitmentsFragment.java
com.mauriciogiordano.commit.view.CommitButton.java
com.mauriciogiordano.commit.view.CommitEditText.java
com.mauriciogiordano.commit.view.CommitTextView.java