close

TextView.setTransformationMethod(new PersonalCapitalTransformationMethod(5, 12, '*'));

class PersonalCapitalTransformationMethod extends PasswordTransformationMethod
{
  private int m_Begin;
  private int m_End;
  private char m_Replacement;
  public PersonalCapitalTransformationMethod(int pBegin, int pEnd, char pReplacement)
  {
    super();
    m_Begin = pBegin;
    m_End = pEnd;
    m_Replacement = pReplacement;
  }

  @Override
  public CharSequence getTransformation(CharSequence pSource, View pView)
  {
    return new PersonalCapitalCharSequence(pSource);
  }

  private class PersonalCapitalCharSequence implements CharSequence
  {
    private CharSequence m_Source;

    public PersonalCapitalCharSequence(CharSequence pSource)
    {
      m_Source = pSource;
    }

    public char charAt(int pIndex)
    {
      if (pIndex < m_Begin || pIndex > m_End)
      { 
        return m_Source.charAt(pIndex);
      }
      return m_Replacement;
    }

    public int length()
    {
      return m_Source.length();
    }

    public CharSequence subSequence(int pStart, int pEnd)
    {
      return m_Source.subSequence(pStart, pEnd);
    }
  }
}

arrow
arrow
    文章標籤
    Android
    全站熱搜
    創作者介紹
    創作者 你是誰 的頭像
    你是誰

    你是誰的部落格

    你是誰 發表在 痞客邦 留言(0) 人氣()