package com.jiuqi.ui.widget;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import com.jiuqi.ui.widget.EditorBase.LINE_HEIGHT;
import com.jiuqi.ui.widget.EditorBase.ROUND_STYLE;
import com.jiuqi.ui.widget.SearchBar.onSearchListener;
import com.jiuqi.util.UIUtil;
import com.jiuqi.util.ValidateRule;
import com.jqyd.uilib.R;
public class EditorTest extends Activity implements OnClickListener{
private LinearLayout linContent;
EditorButton eb1 = null;
EditorEditText et1 = null;
EditorEditText et2 = null;
EditorEditText et3 = null;
EditorEditText et4 = null;
EditorEditText et5 = null;
EditorMutlilineEditText et6 = null;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
doinit();
}
@Override
protected void onResume(){
super.onResume();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
// 输入法是否弹出
if(getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED
|| getWindow().getAttributes().softInputMode == WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
{
//关闭输入法
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
// imm.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken()
// ,InputMethodManager.HIDE_NOT_ALWAYS);
}
}
private void doinit(){
setContentView(R.layout.editor_test_activity);
View searchStub = findViewById(R.id.searchBarStub);
View searchStub2 = findViewById(R.id.searchBarStub2);
View searchStub3 = findViewById(R.id.searchBarStub3);
View searchStub4 = findViewById(R.id.searchBarStub4);
View searchStub5 = findViewById(R.id.searchBarStub5);
View searchStub6 = findViewById(R.id.searchBarStub6);
View searchStub7 = findViewById(R.id.searchBarStub7);
View searchStub8 = findViewById(R.id.searchBarStub8);
View searchStub9 = findViewById(R.id.searchBarStub9);
SearchBar ss = SearchBar.createSimpleSearchBar(searchStub);
ss.setOnSearchListener(new onSearchListener(){
@Override
public void onSearch(String key, View v){
// UIUtil.showMsg(EditorTest.this, "查询条件是:" + key);
Intent intent = new Intent();
intent.setClass(EditorTest.this, SearchBarActivity.class);
EditorTest.this.startActivity(intent);
}
});
SearchBar.createSearchBar(searchStub2);
SearchBar.createSearchBarWithLeftButton(searchStub3);
SearchBar sb3 = SearchBar.createSearchBarWithRightButton(searchStub4);
sb3.setOnSearchListener(new onSearchListener(){
@Override
public void onSearch(String key, View v){
UIUtil.showMsg(EditorTest.this, "key: " + key);
}
});
SearchBar sb2 = SearchBar.createSearchBarWithBothButtons(searchStub5);
sb2.setOnSearchListener(new onSearchListener(){
@Override
public void onSearch(String key, View v){
UIUtil.showMsg(EditorTest.this, "key: " + key);
}
});
sb2.getBtnRight().setText("自定义按钮的名称");
new SearchBar(searchStub6, SearchBar.ACTION_MIC | SearchBar.BUTTON_LEFT | SearchBar.ICON_ZOOM);
new SearchBar(searchStub7);
SearchBar sb =
new SearchBar(searchStub8, SearchBar.ICON_ZOOM | SearchBar.NO_BACKGROUND | SearchBar.BUTTON_CLEAR);
sb.getEtSearch().setHint("关键字");
SearchBar fillterBar = SearchBar.createFillterBar(searchStub9);
fillterBar.getEtSearch().addTextChangedListener(new TextWatcher(){
@Override
public void onTextChanged(CharSequence s, int start, int before, int count){
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
@Override
public void afterTextChanged(Editable s){
UIUtil.showMsg(EditorTest.this, s.toString());
}
});
linContent = (LinearLayout)findViewById(R.id.linContent);
EditorBase.Param param = null;
param = new EditorBase.Param();
param.labelText = "";
param.hintText = "button内容test";
param.round_style = ROUND_STYLE.ALL;
param.drawableRightId = R.drawable.arrow_sml;
eb1 = new EditorButton(this, param, linContent);
eb1.getInputWidget().setOnClickListener(this);
param = new EditorBase.Param();
param.labelText = "多行:";
param.hintText = "多行文本框";
param.round_style = ROUND_STYLE.ALL;
param.line_height = LINE_HEIGHT.HIGH;
et6 = new EditorMutlilineEditText(this, param, linContent);
et6.getInputWidget().setOnClickListener(this);
param = new EditorBase.Param();
param.labelText = "请输入:";
param.hintText = "请输入内容";
param.round_style = ROUND_STYLE.ALL;
param.rules = new ValidateRule[] {ValidateRule.IS_DIGITS_ONLY};
et1 = new EditorEditText(this, param, linContent);
et1.getInputWidget().setFilters(new InputFilter[] {new InputFilter.LengthFilter(5)});
et1.getInputWidget().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT);
param = new EditorBase.Param();
param.labelText = "请输入2:";
param.hintText = "请输入内容2";
param.round_style = ROUND_STYLE.TOP;
param.rules = new ValidateRule[] {ValidateRule.IS_CHINAUNICOM_MOBILE_NUMBER};
et2 = new EditorEditText(this, param, linContent);
et2.getInputWidget().setFilters(new InputFilter[] {new InputFilter.LengthFilter(11)});
et2.getInputWidget().setInputType(InputType.TYPE_CLASS_PHONE);
param = new EditorBase.Param();
param.labelText = "请输入3:";
param.hintText = "请输入内容3";
param.round_style = ROUND_STYLE.MIDDLE;
param.rules = new ValidateRule[] {ValidateRule.IS_VALID_EMAIL};
et3 = new EditorEditText(this, param, linContent);
et3.getInputWidget().setFilters(new InputFilter[] {new InputFilter.LengthFilter(12)});
et3.getInputWidget().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT);
param = new EditorBase.Param();
param.labelText = "请输入4:";
param.hintText = "请输入内容4";
param.round_style = ROUND_STYLE.BOTTOM;
param.rules = new ValidateRule[] {ValidateRule.IS_CHINAUNICOM_MOBILE_NUMBER};
et4 = new EditorEditText(this, param, linContent);
et4.getInputWidget().setFilters(new InputFilter[] {new InputFilter.LengthFilter(11)});
param = new EditorBase.Param();
param.labelText = "请输入5:";
param.hintText = "请输入内容5";
param.round_style = ROUND_STYLE.ALL;
param.rules = new ValidateRule[] {ValidateRule.IS_CHINAUNICOM_MOBILE_NUMBER};
et5 = new EditorEditText(this, param, linContent);
View btnSubmit = findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(this);
}
@Override
public void onClick(View v){
if(v.getId()==R.id.btnSubmit){
if(et1.validate()){
UIUtil.showMsg(this, "et1校验成功");
}
else{
UIUtil.showMsg(this, "只能输入数字");
}
if(et2.validate()){
UIUtil.showMsg(this, "et2校验成功");
}
else{
UIUtil.showMsg(this, "只能输入手机号");
}
}else if(R.id.btnInput==v.getId()){
UIUtil.showMsg(this, "呵呵");
}
// switch(v.getId()){
// case R.id.btnSubmit:
// if(et1.validate()){
// UIUtil.showMsg(this, "et1校验成功");
// }
// else{
// UIUtil.showMsg(this, "只能输入数字");
// }
// if(et2.validate()){
// UIUtil.showMsg(this, "et2校验成功");
// }
// else{
// UIUtil.showMsg(this, "只能输入手机号");
// }
// break;
//
// case R.id.btnInput:
// UIUtil.showMsg(this, "呵呵");
// break;
//
// default:
// break;
// }
}
}