如果需要做一个定制化键盘(以外型为主)的创业,请问如何设计代码来知道目前
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如果需要做一个定制化键盘(以外型为主)的创业,请问如何设计代码来知道目前相关的知识,希望对你有一定的参考价值。
参考技术A 1.自定义数字键盘2.切换到随机数字键盘
3.自定义确定和删除等键(向外抛出接口)
使用方法:
1.在项目build.gradle文件中添加jitpack,添加jitpcak就够了。allprojectsundefinedrepositoriesundefinedjcenter()mavenurl\'https://jitpack.io\'2.在module的build.gradle文件添加依赖compile\'com.github.Simon986793021:NumberKeyboard:v1.0\'3.在布局文件中添加布局android:id="@+id/keyboard_view"xmlns:android="http://schemas.android.com/apk/res/android"android:layout_android:layout_android:focusable="true"android:paddingTop="0dp"android:focusableInTouchMode="true"android:keyBackground="@drawable/bg_keyboardview"android:keyPreviewOffset="0dp"android:keyTextColor="#000"android:shadowColor="#fff"android:shadowRadius="0.0"android:layout_alignParentBottom="true"/>4.在MainActivity调用。editText=(EditText)findViewById(R.id.et_numberplate);changebutton=(Button)findViewById(R.id.bt_change_keyboard);finalOfoKeyboardkeyboard=newOfoKeyboard(MainActivity.this);//获取到keyboard对象changebutton.setOnClickListener(newView.OnClickListener()undefined@OverridepublicvoidonClick(Viewv)undefinedkeyboard.attachTo(editText,true);//eiditext绑定keyboard,true表示随机数字);editText.setOnClickListener(newView.OnClickListener()undefined@OverridepublicvoidonClick(Viewv)undefinedkeyboard.attachTo(editText,false);//eiditext绑定keyboard,false表示普通数字键盘);/*确定按钮*/keyboard.setOnOkClick(newOfoKeyboard.OnOkClick()undefined@OverridepublicvoidonOkClick()undefinedLog.i(">>>>>>","点击了确定");Toast.makeText(MainActivity.this,editText.getText().toString(),Toast.LENGTH_SHORT).show(););//隐藏键盘按钮keyboard.setOnCancelClick(newOfoKeyboard.OnCancelClcik()undefined@OverridepublicvoidonCancelClick()undefinedToast.makeText(MainActivity.this,"隐藏键盘",Toast.LENGTH_SHORT).show(););只需要这些简单的代码就能够实现一个自己定义的键盘了。实现过程1.新建一个keyboard布局在看这个代码之前需要了解keyboard的属性:不清楚属性,怎么画页面,不懂的请移步这篇博客在res新建一个xml文件,然后在xml新建一个keyboard.xml里面代码如下xmlns:android="http://schemas.android.com/apk/res/android"android:keyHeight="9%p"android:keyWidth="25%p"android:horizontalGap="0dp">android:codes="49"android:keyLabel="1"/>android:codes="50"android:keyLabel="2"/>android:codes="51"android:keyLabel="3"/>android:codes="-5"android:keyHeight="18%p"android:keyEdgeFlags="right"android:isRepeatable="true"android:keyIcon="@drawable/icon_delete_32dp"/>android:codes="52"android:keyLabel="4"/>android:codes="53"android:keyLabel="5"/>android:codes="54"android:keyLabel="6"/>android:codes="55"android:keyLabel="7"/>android:codes="56"android:keyLabel="8"/>android:codes="57"android:keyLabel="9"/>android:codes="-4"android:keyLabel="确定"android:keyEdgeFlags="right"android:keyHeight="18%p"/>android:codes="46"android:keyLabel="."/>android:codes="48"android:keyLabel="0"/>android:codes="-3"android:keyIcon="@drawable/icon_hide_keyboard"/>这个布局就是自己自定义键盘的布局实现,有了布局,显然是不够的。2.自定义KeyboardViewpackagecom.wind.keyboard;importandroid.content.Context;importandroid.graphics.Canvas;importandroid.graphics.Color;importandroid.graphics.Paint;importandroid.graphics.Rect;importandroid.graphics.Typeface;importandroid.graphics.drawable.Drawable;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.util.AttributeSet;importandroid.util.Log;importjava.lang.reflect.Field;importjava.util.List;/***Createdbyzhangcongon2017/8/24.*/publicclassOfoKeyboardViewextendsKeyboardViewundefinedprivateContextcontext;privateKeyboardkeyboard;publicOfoKeyboardView(Contextcontext,AttributeSetattrs)undefinedsuper(context,attrs);this.context=context;Log.i(">>>>>","构造函数被调用了");/***重新画一些按键*/@OverridepublicvoidonDraw(Canvascanvas)undefinedsuper.onDraw(canvas);keyboard=this.getKeyboard();Listkeys=null;if(keyboard!=null)undefinedkeys=keyboard.getKeys();if(keys!=null)undefinedfor(Keyboard.Keykey:keys)undefined//数字键盘的处理if(key.codes[0]==-4)undefineddrawKeyBackground(R.drawable.bg_keyboardview_yes,canvas,key);drawText(canvas,key);privatevoiddrawKeyBackground(intdrawableId,Canvascanvas,Keyboard.Keykey)undefinedDrawablenpd=context.getResources().getDrawable(drawableId);int[]drawableState=key.getCurrentDrawableState();if(key.codes[0]!=0)undefinednpd.setState(drawableState);npd.setBounds(key.x,key.y,key.x+key.width,key.y+key.height);npd.draw(canvas);privatevoiddrawText(Canvascanvas,Keyboard.Keykey)undefinedRectbounds=newRect();Paintpaint=newPaint();paint.setTextAlign(Paint.Align.CENTER);paint.setAntiAlias(true);paint.setColor(Color.WHITE);if(key.label!=null)undefinedStringlabel=key.label.toString();Fieldfield;if(label.length()>1&&key.codes.length<2)undefinedintlabelTextSize=0;tryundefinedfield=KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);labelTextSize=(int)field.get(this);catch(NoSuchFieldExceptione)undefinede.printStackTrace();catch(IllegalAccessExceptione)undefinede.printStackTrace();paint.setTextSize(labelTextSize);paint.setTypeface(Typeface.DEFAULT_BOLD);elseundefinedintkeyTextSize=0;tryundefinedfield=KeyboardView.class.getDeclaredField("mLabelTextSize");field.setAccessible(true);keyTextSize=(int)field.get(this);catch(NoSuchFieldExceptione)undefinede.printStackTrace();catch(IllegalAccessExceptione)undefinede.printStackTrace();paint.setTextSize(keyTextSize);paint.setTypeface(Typeface.DEFAULT);paint.getTextBounds(key.label.toString(),0,key.label.toString().length(),bounds);canvas.drawText(key.label.toString(),key.x+(key.width/2),(key.y+key.height/2)+bounds.height()/2,paint);elseif(key.icon!=null)undefinedkey.icon.setBounds(key.x+(key.width-key.icon.getIntrinsicWidth())/2,key.y+(key.height-key.icon.getIntrinsicHeight())/2,key.x+(key.width-key.icon.getIntrinsicWidth())/2+key.icon.getIntrinsicWidth(),key.y+(key.height-key.icon.getIntrinsicHeight())/2+key.icon.getIntrinsicHeight());key.icon.draw(canvas);3.KeyBoard的对象的创建:packagecom.wind.keyboard;importandroid.app.Activity;importandroid.content.Context;importandroid.inputmethodservice.Keyboard;importandroid.inputmethodservice.KeyboardView;importandroid.os.Build;importandroid.text.Editable;importandroid.text.InputType;importandroid.util.Log;importandroid.view.View;importandroid.view.inputmethod.InputMethodManager;importandroid.widget.EditText;importjava.lang.reflect.Method;importjava.util.ArrayList;importjava.util.LinkedList;importjava.util.List;importjava.util.Random;/***Createdbyzhangcongon2017/8/28.*/publicclassOfoKeyboardundefinedprivateActivityactivity;privateKeyboardkeyboard;privateOfoKeyboardViewkeyboardView;privateEditTexteditText;privatebooleanisRandom=false;publicOfoKeyboard(Activityactivity)undefinedthis.activity=activity;keyboardView=(OfoKeyboardView)activity.findViewById(R.id.keyboard_view);//点击事件触发publicvoidattachTo(EditTexteditText,booleanisRandom)undefined/*切换键盘需要重新newKeyboard对象,否则键盘不会改变,keyboardView放到构造函数里面,避免每次点击重新new对象,提高性能*/keyboard=newKeyboard(activity,R.xml.keyboard);this.isRandom=isRandom;Log.i(">>>>>","attachTo");this.editText=editText;hideSystemSofeKeyboard(activity,editText);showSoftKeyboard();privatevoidshowSoftKeyboard()undefinedif(keyboard==null)undefinedkeyboard=newKeyboard(activity,R.xml.keyboard);if(keyboardView==null)undefinedkeyboardView=(OfoKeyboardView)activity.findViewById(R.id.keyboard_view);if(isRandom)undefinedrandomKeyboardNumber();elseundefinedkeyboardView.setKeyboard(keyboard);keyboardView.setEnabled(true);keyboardView.setPreviewEnabled(false);keyboardView.setVisibility(View.VISIBLE);keyboardView.setOnKeyboardActionListener(listener);privateKeyboardView.OnKeyboardActionListenerlistener=newKeyboardView.OnKeyboardActionListener()undefined@OverridepublicvoidonPress(intprimaryCode)undefined@OverridepublicvoidonRelease(intprimaryCode)undefined@OverridepublicvoidonKey(intprimaryCode,int[]keyCodes)undefinedEditableeditable=editText.getText();intstart=editText.getSelectionStart();if(primaryCode==Keyboard.KEYCODE_DELETE)//keycodes为-5undefinedif(editable!=null&&editable.length()>0)undefinedif(start>0)undefinededitable.delete(start-1,start);elseif(primaryCode==Keyboard.KEYCODE_CANCEL)undefinedhideKeyBoard();if(mCancelClick!=null)undefinedmCancelClick.onCancelClick();elseif(primaryCode==Keyboard.KEYCODE_DONE)undefinedhideKeyBoard();if(mOkClick!=null)undefinedmOkClick.onOkClick();elseundefinedLog.i(">>>>>>",primaryCode+"1");Log.i(">>>>>>",(char)primaryCode+"2");editable.insert(start,Character.toString((char)primaryCode));@OverridepublicvoidonText(CharSequencetext)undefined@OverridepublicvoidswipeLeft()undefined@OverridepublicvoidswipeRight()undefined@OverridepublicvoidswipeDown()undefined@OverridepublicvoidswipeUp()undefined;publicinterfaceOnOkClickundefinedvoidonOkClick();publicinterfaceOnCancelClcikundefinedvoidonCancelClick();publicOnOkClickmOkClick;publicOnCancelClcikmCancelClick;publicvoidsetOnOkClick(OnOkClickonOkClick)undefinedthis.mOkClick=onOkClick;publicvoidsetOnCancelClick(OnCancelClcikonCancelClick)undefinedthis.mCancelClick=onCancelClick;privatevoidhideKeyBoard()undefinedintvisibility=keyboardView.getVisibility();if(visibility==KeyboardView.VISIBLE)undefinedkeyboardView.setVisibility(KeyboardView.GONE);privatebooleanisNumber(Stringstr)undefinedStringwordstr="0123456789";returnwordstr.contains(str);privatevoidrandomKeyboardNumber()undefinedListkeyList=keyboard.getKeys();//查找出0-9的数字键ListnewkeyList=newArrayList();for(inti=0;i
做一个调节水流量的pid控制,需要让调节阀缓慢到达需求值,请问怎么做呢?
例如我想让这个阀门从0变为5立方米每小时的水量,在30秒后到达,请问该怎么去做???
将流量计、调节器、调节阀构成流量调节回路。如果对“30秒后到达”到达前的要求高于“稳定后的流量保持”,可选择具有“给定值SV曲线编程功能”的调节器;
如果对“30秒后到达”到达前的要求低于“稳定后的流量保持”,可选择“自动选择调节器”(超驰调节器); 参考技术A 这个要看你的阀门大小来定,但一般是只调节PID参数中的比例、积分就可以达到了!具体达到时间还需要以现场实际调节效果为准! 参考技术B 控制开度就行了,计算好水流量,然后控制开度就行,当然国外有一款阀门能够控制开启时间,不过很贵
以上是关于如果需要做一个定制化键盘(以外型为主)的创业,请问如何设计代码来知道目前的主要内容,如果未能解决你的问题,请参考以下文章
ZADAK 推出 SPARK M.2 RGB SSD兼具外型与性能
MWC上海| 用IT思维加速转型 中兴通讯Carrier DevOps打造定制化网络切片