Androidはアリペイのパスワードを均等に入力してください。


Androidはアリペイのパスワードを均等に入力します。
これはAndroidプロジェクトで、絵を描き直すことによって、文字の均等配置を行います。
コードを直接貼り付ける:

package com.xxx.xxx;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.Editable;
import android.text.Selection;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.EditText;

/**
 *            
 *     :XML          ,     。    wrap_content  ,        
 * (                  )
 *              
 *            
 *          
 *         
 *
 * Created by yueer on 2015/10/22.
 */
public class ExcelEditView extends EditText {

  private int mMaxLength = 6;  //          
  private int mColorId = Color.BLACK;   //    
  private boolean isPassword = false;  //         
  private float mHeight = 0.0f;    //       
  private int mMaxLine = 0;     //     :   0,---            0,--    

  public ExcelEditView(Context context){
    super(context);
    init();
  }

  public ExcelEditView(Context context, AttributeSet set){
    super(context, set);
    init();
  }

  private void init(){
    this.addTextChangedListener(new TextWatcher() {
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {

      }

      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {
        // TODO Auto-generated method stub
        Editable editable = ExcelEditView.this.getText();
        int len = editable.length();

        if(mMaxLine > 0 && len > mMaxLength*mMaxLine)
        {
          int selEndIndex = Selection.getSelectionEnd(editable);
          String str = editable.toString();
          String newStr = str.substring(0,mMaxLength*mMaxLine);
          ExcelEditView.this.setText(newStr);
          editable = ExcelEditView.this.getText();

          //       
          int newLen = editable.length();
          //            
          if(selEndIndex > newLen)
          {
            selEndIndex = editable.length();
          }
          //          
          Selection.setSelection(editable, selEndIndex);

        }
      }

      @Override
      public void afterTextChanged(Editable s) {

      }
    });
  }

  public void setIsPassword(boolean isPassword){
    this.isPassword = isPassword;
  }

  public void setmMaxLine(int line){
    this.mMaxLine = line;
  }

  public void setmMaxLength(int leng){
    this.mMaxLength = leng;
  }

  @Override
  public void setTextColor(int color) {
    super.setTextColor(color);
    mColorId = color;
  }

  @Override
  protected void onDraw(Canvas canvas) {
    char[] txt = this.getText().toString().toCharArray();   //      
    int txtLine = getLineFromCharArray(txt);   //      
    if (mMaxLine > 0 && txtLine > mMaxLine){ //         
      txtLine = mMaxLine;
    }
    if (this.isPassword){  //      
      for (int i=0; i<txt.length; i++){
        txt[i] = '*';
      }
    }
    if (mHeight == 0){   //         
      mHeight = this.getHeight();
    }
    float width = this.getWidth();
    float height = mHeight * txtLine;
    ViewGroup.LayoutParams params = this.getLayoutParams();
    params.height = (int)height;
    this.setLayoutParams(params);    //        
    float per = width / (mMaxLength+1);     //    
    float perHeight = height / (txtLine + 1);  //    

    Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
    countPaint.setColor(mColorId);
    countPaint.setTextSize(this.getTextSize());
    countPaint.setTypeface(this.getTypeface());
    countPaint.setTextAlign(Paint.Align.CENTER);
    Rect textBounds = new Rect();
    String numberStr = "1";
    countPaint.getTextBounds(numberStr, 0, numberStr.length(), textBounds);//get text bounds, that can get the text width and height
    float textHeight = (float)(textBounds.bottom - textBounds.top);
    float textWidth = (float)(textBounds.right = textBounds.left);    //                     
    for (int line = 0; line < txtLine; line++) {
      for (int i = 0; i < mMaxLength && txt.length > (i+line*mMaxLength); i++) {
        canvas.drawText(String.valueOf(txt[i+line*mMaxLength]), (i + 1) * per - textWidth, perHeight * (line + 1) + textHeight / 2, countPaint);    //    
      }
    }
  }

  private int getLineFromCharArray(char[] txt){
    int line = ((txt.length - 1) / mMaxLength) + 1;
    return line;
  }
}

読んでくれてありがとうございます。みなさんのご協力をお願いします。ありがとうございます。