ZamanTextView
https://github.com/Morxander/Zaman
Text Decorator
https://github.com/nntuyen/text-decorator
Build valid HTML for Android TextView.
https://github.com/jrummyapps/html-builder
Buffer Text Input Layout
https://github.com/bufferapp/BufferTextInputLayout
DateKeyListener For entering dates in a text field. DateTimeKeyListener For entering dates and times in the same text field. DialerKeyListener For dialing-only text entry DigitsKeyListener For digits-only text entry InputFilter.AllCaps This filter will capitalize all the lower case letters that are added through edits. InputFilter.LengthFilter This filter will constrain edits not to make the length of the text greater than the specified length. LoginFilter Abstract class for filtering login-related text (user names and passwords) LoginFilter.PasswordFilterGMail This filter is compatible with GMail passwords which restricts characters to the Latin-1 (ISO8859-1) char set. LoginFilter.UsernameFilterGMail This filter rejects characters in the user name that are not compatible with GMail account creation. LoginFilter.UsernameFilterGeneric This filter rejects characters in the user name that are not compatible with Google login. NumberKeyListener For numeric text entry TimeKeyListener For entering times in a text field. 根据解释应该不难理解,根据你自己的需要选择吧。
实例:
EditText与InputFilter实现文本对比
此功能类似于临摹。已知被临摹的字符串,将字符串与EditText中输入进行
对比,输入错误,则用“×”替换所输入的字符。
import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.Spanned;
import android.util.Log;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MyFilterTest extends Activity {
/** Called when the activity is first created. */
TextView myText;
EditText myEdit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final String str = "Hello,Android!";
myText=(TextView)findViewById(R.id.myText);
myText.setText(str);
myEdit=(EditText)findViewById(R.id.myEdit);
myEdit.setFilters(new InputFilter[]{ new MyInputFilter(str) });
}
public class MyInputFilter implements InputFilter{
String str=null;
public MyInputFilter(String str){
this.str=str;
}
@Override
public CharSequence filter(CharSequence src, int start, int end,
Spanned dest, int dstart, int dend) {
// TODO Auto-generated method stub
String ch=null;
String TAG="Filter";
Log.w(TAG,"src:"+src+";start:"+start+";end:"+end);
Log.w(TAG,"dest:"+dest+";dstart:"+dstart+";dend:"+dend);
if(dest.length()
final EditText input = new EditText(this);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.AllCaps();
input.setFilters(FilterArray);
import java.util.Vector;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;
import android.util.AttributeSet;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MyView extends TextView {
private final String namespace="http://www.nearmobile.net";
private int resourceId=0;
/* 声明Paint对象 */
private Paint mPaint = null;
/* 声明TextUtil对象 */
private TextUtil mTextUtil = null;
public static int m_iTextHeight;
private WindowManager wm=null;
private String string="";
public MyView(Context context, AttributeSet set) {
super(context,set);
resourceId=set.getAttributeResourceValue(namespace, "text", 0);
if(resourceId==0)
string=set.getAttributeValue(null,"text");
else
string=this.getResources().getString(resourceId);
wm=(WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
/* 构建对象 */
m_iTextHeight=2000;
mPaint = new Paint();
mPaint.setColor(Color.RED);
mPaint.setStrokeWidth(40);
mPaint.setTextSize(20);
int m_iTextWidth=wm.getDefaultDisplay().getWidth();
FontMetrics fm = mPaint.getFontMetrics();
int m_iFontHeight = (int) Math.ceil(fm.descent - fm.top) + 4;
int line=0;
int istart=0;
int w=0;
for (int i = 0; i < string.length(); i++)
{
char ch = string.charAt(i);
float[] widths = new float[1];
String srt = String.valueOf(ch);
mPaint.getTextWidths(srt, widths);
if (ch == '\n')
{
line++;
istart = i + 1;
w = 0;
}
else
{
w += (int) (Math.ceil(widths[0]));
if (w > m_iTextWidth)
{
line++;
istart = i;
i--;
w = 0;
}
else
{
if (i == (string.length() - 1))
{
line++;
}
}
}
}
m_iTextHeight=(line+2)*m_iFontHeight+2;
//用反射机制得到 m_iTextHeight 值
/* 实例化TextUtil
mTextUtil = new TextUtil(string,5,25,wm.getDefaultDisplay().getWidth(),this.getHeight(),0x0,0xffffff,255,15);
初始化TextUtil
mTextUtil.InitText(string,5,25,wm.getDefaultDisplay().getWidth(),wm.getDefaultDisplay().getHeight(),0x0,0xffffff,255,15);*/
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
/* 设置背景颜色 */
canvas.drawColor(Color.BLACK);
mPaint.setAntiAlias(true);
char ch;
int w = 0;
int istart = 0;
int m_iFontHeight;
int m_iRealLine=0;
int x=2;
int y=60;
Vector m_String=new Vector();
int m_iTextWidth=wm.getDefaultDisplay().getWidth();
FontMetrics fm = mPaint.getFontMetrics();
m_iFontHeight = (int) Math.ceil(fm.descent - fm.top) + 4;
//m_ipageLineNum = m_iTextHeight / m_iFontHeight;
for (int i = 0; i < string.length(); i++)
{
ch = string.charAt(i);
float[] widths = new float[1];
String srt = String.valueOf(ch);
mPaint.getTextWidths(srt, widths);
if (ch == '\n')
{
m_iRealLine++;
m_String.addElement(string.substring(istart, i));
istart = i + 1;
w = 0;
}
else
{
w += (int) (Math.ceil(widths[0]));
if (w > m_iTextWidth)
{
m_iRealLine++;
m_String.addElement(string.substring(istart, i));
istart = i;
i--;
w = 0;
}
else
{
if (i == (string.length() - 1))
{
m_iRealLine++;
m_String.addElement(string.substring(istart, string.length()));
}
}
}
}
m_iTextHeight=m_iRealLine*m_iFontHeight+2;
System.out.println("m_iTextHeight----->"+m_iTextHeight);
canvas.setViewport(m_iTextWidth, m_iTextWidth);
for (int i = 0, j = 0; i < m_iRealLine; i++, j++)
{
canvas.drawText((String) (m_String.elementAt(i)), x, y+m_iFontHeight * j, mPaint);
}
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measuredHeight = measureHeight(heightMeasureSpec);
int measuredWidth = measureWidth(widthMeasureSpec);
this.setMeasuredDimension(measuredWidth, measuredHeight);
this.setLayoutParams(new LinearLayout.LayoutParams(measuredWidth,measuredHeight));
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
private int measureHeight(int measureSpec) {
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
// Default size if no limits are specified.
int result = m_iTextHeight;
if (specMode == MeasureSpec.AT_MOST)
{
// Calculate the ideal size of your
// control within this maximum size.
// If your control fills the available
// space return the outer bound.
result = specSize;
}
else if (specMode == MeasureSpec.EXACTLY)
{
// If your control can fit within these bounds return that value.
result = specSize;
}
return result;
}
private int measureWidth(int measureSpec) {
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
// Default size if no limits are specified.
int result = 500;
if (specMode == MeasureSpec.AT_MOST)
{
// Calculate the ideal size of your control
// within this maximum size.
// If your control fills the available space
// return the outer bound.
result = specSize;
}
else if (specMode == MeasureSpec.EXACTLY)
{
// If your control can fit within these bounds return that value.
result = specSize;
}
return result;
}
}
/*
*处理例外
*/
--例外简介
--处理例外-传递例外
declare
v_ename emp.ename%TYPE;
begin
SELECT ename INTO v_ename FROM emp
where empno=&no;
dbms_output.put_line('雇员名:'||v_ename);
exceptio
import java.util.ArrayList;
import java.util.List;
public class KickOutBadGuys {
/**
* 题目:13个坏人和13个好人站成一圈,数到7就从圈里面踢出一个来,要求把所有坏人都给踢出来,所有好人都留在圈里。请找出初始时坏人站的位置。
* Maybe you can find out
Redis.conf配置文件及相关项说明
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
public static String convertInputStreamToString(InputStream is) {
StringBuilder result = new StringBuilder();
if (is != null)
try {
InputStreamReader inputReader = new InputStreamRead
原文:
http://www.sitepoint.com/3-new-javascript-apis-may-want-follow/?utm_source=html5weekly&utm_medium=email
本文中,介绍3个仍然处于草稿阶段,但应该值得关注的Javascript API.
1) Web Alarm API
&