android如何做自己的手写输入法
来源:互联网 发布:西安大数据分析 编辑:程序博客网 时间:2024/05/03 04:51
1、xml
<LinearLayout android:id="@+id/gesture_main_writepad_ll" android:layout_width="fill_parent" android:layout_height="330dip" android:layout_alignParentBottom="true" android:background="#262626" android:orientation="vertical" android:visibility="gone" > <Gallery android:id="@+id/gesture_main_writepad_glly" android:layout_width="fill_parent" android:layout_height="60dip" android:spacing="3dip" /> <TextView android:layout_width="fill_parent" android:layout_height="1px" android:background="@color/auto_color" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="230dip" > <LinearLayout android:id="@+id/search_no_input" android:layout_width="fill_parent" android:layout_height="230dip" android:background="@android:color/transparent" android:gravity="center" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:background="@android:color/transparent" /> </LinearLayout> <android.gesture.GestureOverlayView android:id="@+id/gesture_main_writepad_gs" android:layout_width="fill_parent" android:layout_height="230dip" android:fadeOffset="100000" android:gestureColor="#6B8E23" android:gestureStrokeType="multiple" android:gestureStrokeWidth="5" /> </RelativeLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="40dip" android:orientation="horizontal" > <Button android:id="@+id/gesture_main_hide_btn" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="3dip" android:layout_weight="2" android:background="#838B83" android:text="hide" /> <Button android:id="@+id/gesture_main_space_btn" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="3dip" android:layout_weight="1" android:background="#838B83" android:text="space" /> <Button android:id="@+id/gesture_main_del_btn" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="3dip" android:layout_weight="2" android:background="#838B83" android:text="del" /> </LinearLayout> </LinearLayout>
2、android
private View.OnClickListener handwritelistener = new View.OnClickListener() {@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.gesture_main_handwrite_btn:gesture_main_writepad_ll.setVisibility(View.VISIBLE);gesture_main_handwrite_btn.setVisibility(View.GONE);handInputLay.setVisibility(VISIBLE);TextView tv=(TextView)handInputLay.getChildAt(0);tv.setText(cont.getString(R.string.search_input));editText.setFocusable(true);editText.requestFocus();break;case R.id.gesture_main_hide_btn:closeHandwritePad();break;case R.id.gesture_main_space_btn:String spaceText = gesture_main_space_btn.getText().toString();if (spaceText.equals("space")) {editText.append(" ");} else {editText.append(spaceText);gesture_main_writepad_gs.clear(false);gesture_main_space_btn.setText("space");gesture_main_writepad_glly.setAdapter(new GalleryAdapter(new ArrayList<String>(), cont));}break;case R.id.gesture_main_del_btn:gesture_main_writepad_gs.clear(false);gesture_main_writepad_glly.setAdapter(new GalleryAdapter(new ArrayList<String>(), cont));gesture_main_space_btn.setText("space");break;default:break;}}};private GestureOverlayView.OnGestureListener gestureListener = new GestureOverlayView.OnGestureListener() {private ArrayList<ArrayList<int[]>> allLists = new ArrayList<ArrayList<int[]>>();private ArrayList<int[]> offsetList;@Overridepublic void onGestureStarted(GestureOverlayView overlay, MotionEvent event) {handInputLay.setVisibility(GONE);if(!CndicUtil.checkWifiConnected(cont)){handInputLay.setVisibility(VISIBLE);TextView tv=(TextView)handInputLay.getChildAt(0);tv.setText(cont.getString(R.string.search_no_network));}offsetList = new ArrayList<int[]>();if (overlay.getGesture().getStrokesCount() == 0) {allLists.clear();}}@Overridepublic void onGestureEnded(GestureOverlayView overlay, MotionEvent event) {allLists.add(offsetList);StringBuffer inputStr = new StringBuffer();inputStr.append("=R " + allLists.size() + "\n");for (ArrayList<int[]> list : allLists) {inputStr.append("=S " + list.size() + "\n");for (int[] offset : list) {inputStr.append(offset[0] + " " + offset[1] + " ");}inputStr.append("\n");}final String resUrl = gestureRecServerURL + URLEncoder.encode(inputStr.toString());new Thread() {@Overridepublic void run() {try {HttpGet hg = new HttpGet(resUrl);DefaultHttpClient dh = new DefaultHttpClient();HttpResponse hr = null;hr = dh.execute(hg);InputStream obtainedStr = hr.getEntity().getContent();BufferedReader br = new BufferedReader(new InputStreamReader(obtainedStr));StringBuffer brsb = new StringBuffer();String line = "";while ((line = br.readLine()) != null) {brsb.append(line);}JSONObject dataJson = new JSONObject(brsb.toString());String[] dataWithPinyin = dataJson.getString("content").split(";");StringBuffer tempStrBuf = new StringBuffer();ArrayList<String> tempStrForInputArray = new ArrayList<String>();for (int i = 0; i < dataWithPinyin.length; i++) {String tempStr = dataWithPinyin[i];tempStrBuf.append(tempStr.split(",")[0] + " ");tempStrForInputArray.add(tempStr.split(",")[0]);}strForInputArray = tempStrForInputArray;handler.sendEmptyMessage(10);} catch (Exception e) {e.printStackTrace();}}}.start();}@Overridepublic void onGestureCancelled(GestureOverlayView overlay, MotionEvent event) {}@Overridepublic void onGesture(GestureOverlayView overlay, MotionEvent event) {int curX = (int)event.getX();int curY = (int)event.getY();int[] offset = {curX, curY};offsetList.add(offset);}};private OnItemClickListener galleryItemListener = new OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {editText.append(strForInputArray.get(position));gesture_main_writepad_gs.clear(false);gesture_main_writepad_glly.setAdapter(new GalleryAdapter(new ArrayList<String>(), cont));gesture_main_space_btn.setText("space");}};private void alignGalleryToLeft(Gallery gallery) {int width = gesture_main_writepad_ll.getWidth();MarginLayoutParams mlp = (MarginLayoutParams)gallery.getLayoutParams();mlp.setMargins(-(int)(width / 1.1), mlp.topMargin, mlp.rightMargin, mlp.bottomMargin);gallery.setLayoutParams(mlp);}private void closeHandwritePad() {gesture_main_handwrite_btn.setVisibility(View.VISIBLE);gesture_main_writepad_gs.clear(false);gesture_main_writepad_ll.setVisibility(View.GONE);gesture_main_writepad_glly.setAdapter(new GalleryAdapter(new ArrayList<String>(), cont));gesture_main_space_btn.setText("space");editText.clearFocus();}private void setHandwritelistener() {gesture_main_handwrite_btn.setOnClickListener(handwritelistener);gesture_main_hide_btn.setOnClickListener(handwritelistener);gesture_main_space_btn.setOnClickListener(handwritelistener);gesture_main_del_btn.setOnClickListener(handwritelistener);gesture_main_writepad_gs.addOnGestureListener(gestureListener);gesture_main_writepad_glly.setOnItemClickListener(galleryItemListener);}
有问题的童鞋,回复后解答
- android如何做自己的手写输入法
- 如何在自己网站加入百度手写输入法?
- Wince下的手写输入法
- 手写自己的BufferedReader
- iPhone6手写输入法如何设置 方法详解
- caffe中如何训练自己的手写数字识别系统?
- android 输入法(包括手写界面)
- Android 输入法(包括手写)补充
- 如何帮助自己做最好的自己?
- 《我如何自己做自己的导师》
- Android 建立自己的手写笔画图案 Gesture Builder
- Android 建立自己的手写笔画图案 Gesture Builder
- 【原创】手写输入法的关节点拨
- INJECT_EVENTS权限与输入法的全屏手写
- 简易手写输入法软件的编写
- Android::做自己的Launch
- 自己手写简单的ArrayList
- 如何做一个自己的服务器网站
- PLSQL导入导出表的正确步骤
- C++内存泄露如何检测?
- 腾讯抄你肿么办
- VS错误提示:AjaxPro
- Salesforce公司简介
- android如何做自己的手写输入法
- Nhibernate到底是什么
- Lucence全文搜索框架
- 数据库系统,实例,让你看了就懂——轻松走进数据库系列之二
- Maven介绍(创建工程项目以及下载所需要的jar包)
- FreeMarker中的自定义指令和四种变量
- C++读取unicode文本
- omnet++ 4.0b8安装
- 关于PHP中数组递归遍历的一些见解