Android Open Source - TaigIME-android Custom Key Icon






From Project

Back to project page TaigIME-android.

License

The source code is released under:

GNU General Public License

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

/**
 * /*from w ww .  j  a va  2 s.c o  m*/
 */
package fr.magistry.taigime;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.Keyboard.Key;
import android.graphics.Typeface;
/**
 * @author pierre
 *
 */
public class CustomKeyIcon extends Drawable {
  
  
  private final String text;
    private final Paint paint;
    private final Key key;
    private Typeface mfont;
    

    public CustomKeyIcon(Key k, Typeface font ) {
      this.mfont= font;
        this.text = String.valueOf(k.label);
        this.key = k;
        this.paint = new Paint();
        paint.setColor(Color.WHITE);
        paint.setTextSize(k.height/2);
        paint.setAntiAlias(true);
        //paint.setFakeBoldText(true);
        //paint.setShadowLayer(6f, 0, 0, Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextAlign(Paint.Align.CENTER);
        
        
    }
 
    public void setTypeface(Typeface tf){
      paint.setTypeface(tf);
      mfont = tf;
    }
    @Override
    public void draw(Canvas canvas) {
      Rect bounds = new Rect();
      paint.getTextBounds("?", 0, 1, bounds);
      int h = key.height;
      
      float factor = 0.45f * h / bounds.height();
      //paint.setTextSize(25);//paint.getTextSize() * factor);
      paint.setTypeface(mfont);
      
        canvas.drawText(text,0, 5 , paint);
    }

    @Override
    public void setAlpha(int alpha) {
        paint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(ColorFilter cf) {
        paint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }

}




Java Source Code List

fr.magistry.taigime.CandidateView.java
fr.magistry.taigime.Candidate.java
fr.magistry.taigime.CommunityActivity.java
fr.magistry.taigime.Composer.java
fr.magistry.taigime.Converter.java
fr.magistry.taigime.CustomKeyIcon.java
fr.magistry.taigime.MyKeyboard.java
fr.magistry.taigime.OptionsActivity.java
fr.magistry.taigime.TaigIMEService.java
fr.magistry.taigime.TaigiSyl.java
fr.magistry.taigime.TaigiWord.java