全部 文章 问答 分享 共找到128个相关内容
[文章] 你的2019总结来了吗?【有奖征文】
活动名称【总结2019展望2020】活动时间征文时间:2019年12月22日~2019年12月31日评选时间:2020年1月1日~2020年1月10日征文内容文章标签包含:总结2019和展望2020可以是以下题材
[文章] 【总结2019 展望2020】(技术教程)简述GreenDao的一般使用步骤
简述GreenDao的一般使用步骤1.在bulid.gradle(Module:app)中添加greendao如下配置(添加依赖)greendao{schemaVersion1//TODO数据库版本号daoPackage'com.example.smart.greendaodemo.db'//TODO设置DaoMaster、DaoSession、Dao包名targetGenDir'src/main/java'//TODO设置DaoMaster、DaoSession、Dao目录}2.编写MyApplication继承至Applicationimportandroid.app.Application;importandroid.database.sqlite.SQLiteDatabase;importcom.example.smart.greendaodemo.db.DaoMaster;importcom.example.smart.greendaodemo.db.DaoSession;publicclassMyApplicationextendsApplication{privateDaoSessiondaoSession;publicstaticMyApplicationmyApplication;publicstaticMyApplicationgetInstance(){returnmyApplication;}@OverridepublicvoidonCreate(){super.onCreate();initGreenDao();}/***初始化GreenDao*/privatevoidinitGreenDao(){DaoMaster.DevOpenHelperopenHelper=newDaoMaster.DevOpenHelper(this,"Info.db");SQLiteDatabasedb=openHelper.getWritableDatabase();DaoMasterdaoMaster=newDaoMaster(db);daoSession=daoMaster.newSession();myApplication=this;}/***获取DaoSession**@return*/publicDaoSessiongetDaoSession(){returndaoSession;}}3.在AndroidManifest.xml清单文件中的application节点添加name属性,并指定为MyApplication的类名.包名。4.生成Bean类importorg.greenrobot.greendao.annotation.Entity;importorg.greenrobot.greendao.annotation.Generated;importorg.greenrobot.greendao.annotation.Id;importorg.greenrobot.greendao.annotation.Unique;//TODO在Bean类中需要在类中添加如下注解@EntitypublicclassGreenDaoBean{@Unique@IdprivateStringname;privateStringsex;privateintage;privateStringphone;//TODO如下构造方法皆为自动生成,一般不用自己生成@Generated(hash=1389179617)publicGreenDaoBean(Stringname,Stringsex,intage,Stringphone){this.name=name;this.sex=sex;this.age=age;this.phone=phone;}//TODO如下构造方法皆为自动生成,一般不用自己生成@Generated(hash=826843181)publicGreenDaoBean(){}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetSex(){returnsex;}publicvoidsetSex(Stringsex){this.sex=sex;}publicintgetAge(){returnage;}publicvoidsetAge(intage){this.age=age;}publicStringgetPhone(){returnphone;}publicvoidsetPhone(Stringphone){this.phone=phone;}//TODO看自己需不需要toString@OverridepublicStringtoString(){return"GreenDaoBean{"+"name='"+name+'\''+",sex='"+sex+'\''+",age="+age+",phone='"+phone+'\''+'}';}}5.使用时需要做的事情(固定写法)privateMyApplicationmyApplication=MyApplication.getInstance();privateDaoSessiondaoSession;privateList<GreenDaoBean>greenDaoBeans=newArrayList<>();@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_my_green_dao);daoSession=myApplication.getDaoSession();//TODO与数据库的相关操作请放到子线程中执行!(对数据库的操作为耗时操作)newThread(newRunnable(){@Overridepublicvoidrun(){greenDaoBeans=daoSession.getGreenDaoBeanDao().loadAll();}}).start();}
2019-12-27 13:28 · 数据库操作 / 总结2019 / 展望2020
[文章] 【总结2019 展望2020】(技术教程)自定义View之数字键盘
在实际开发中,我们通常会遇到自定义键盘输入内容的情况,比如微信中的输入支付密码,验证码等场景,往往这些键盘都比较简单,通常是输入数字和小数点等内容,本篇文章将通过组合已有控件,打造一款通用的数字键盘⌨️仓库地址:https://github.com/plain-dev/NumberKeyboardView库清单?首先列觉一下本控件所用到的库RecyclerView数字键盘本体,承载键盘的按键的显示,响应输入等BaseRecyclerViewAdapterHelper一个强大的RecyclerView适配器库,封装常用逻辑,让适配器更加简洁效果演示⌨️实现过程数字键盘View一开始想起来做数字键盘的时候,第一个想到的是GridLayout,然后想到了GridView,前者可以很好的实现这种需求,但扩展性不高,后者做这种网格布局是再适合不过了,但现在有了RecyclerView则不需要GridView了,因为RecyclerView通过指定布局管理器,可以实现多种布局效果,这里我们就用到了GridLayoutMananger这里我们继承RelativeLayout来承载此View,里面则是一个RecyclerViewclassNumberKeyboardView@JvmOverloadsconstructor(context:Context,attrs:AttributeSet?=null,defStyleAttr:Int=0):RelativeLayout(context,attrs,defStyleAttr){......}布局也非常简单,仅一个RecyclerView<?xmlversion="1.0"encoding="utf-8"?><android.support.v7.widget.RecyclerViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/rvKeyboard"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#fbfbfb"/>然后初始化我们的RecyclerView,做一些常规的配置,比如Adapter、LayoutManager等,然后UI上Item之间还有线段分割,这里用到了自定义ItemDecoration,这是RecyclerView非常方便的一个特性,可以自定义Item的装饰器。privatefuninitRv(context:Context){adapter=NumberKeyboardAdapter(keyValueList)rvKeyboard.layoutManager=GridLayoutManager(context,3)valdividerItemDecoration=GridDividerItemDecoration.Builder(context).setShowLastLine(false).setHorizontalSpan(R.dimen.SIZE_1).setVerticalSpan(R.dimen.SIZE_1).setColor(Color.parseColor("#ebebeb")).build()rvKeyboard.addItemDecoration(dividerItemDecoration)rvKeyboard.adapter=adapter}适配器这里用到了第三方库BaseRecyclerViewAdapterHelper,结构很清晰classNumberKeyboardAdapterinternalconstructor(data:List<Map<String,String>>?):BaseQuickAdapter<Map<String,String>,BaseViewHolder>(R.layout.item_number_keyboard,data){overridefunconvert(viewHolder:BaseViewHolder,item:Map<String,String>){valtvKey=viewHolder.getView<TextView>(R.id.tvKey)valrlDel=viewHolder.getView<RelativeLayout>(R.id.rlDel)valposition=viewHolder.layoutPositionif(position==Constant.KEYBOARD_DEL){rlDel.visibility=View.VISIBLEtvKey.visibility=View.INVISIBLE}else{rlDel.visibility=View.INVISIBLEtvKey.visibility=View.VISIBLEtvKey.text=item[Constant.MAP_KEY_NAME]}}}Item的布局如下,一个显示文字,一个是删除键的图片,通过不同数据,来控制两者的显示和隐藏,比较简单粗暴<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#fbfbfb"><TextViewandroid:id="@+id/tvKey"android:layout_width="match_parent"android:layout_height="60dp"android:layout_centerInParent="true"android:gravity="center"android:textStyle="bold"android:includeFontPadding="false"android:textColor="#333333"android:textSize="26sp"/><RelativeLayoutandroid:id="@+id/rlDel"android:layout_width="wrap_content"android:layout_height="60dp"android:layout_centerInParent="true"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:src="@drawable/icon_keyboard_del"/></RelativeLayout></RelativeLayout>接下来就是RecyclerView的数据了,我们这里的按键有0-9、小数点和删除,直接一个List集合就好privatefuninitKeyValueList(){if(null==keyValueList){keyValueList=ArrayList()for(iin1..12){valmap=HashMap<String,String>()when{i<Constant.KEYBOARD_ZERO->map[Constant.MAP_KEY_NAME]=i.toString()i==Constant.KEYBOARD_ZERO->map[Constant.MAP_KEY_NAME]="."i==Constant.KEYBOARD_DEL->map[Constant.MAP_KEY_NAME]=0.toString()else->map[Constant.MAP_KEY_NAME]=""}keyValueList!!.add(map)}}}这样,键盘部分就差不多了,然后将此View添加到容器中就好了valview=LayoutInflater.from(context).inflate(R.layout.layout_number_keyboard,this,false)addView(view)数字键盘帮助类以上我们的键盘就可以正常显示了,但还没有真正的点击操作。这里我们封装一个键盘帮助类KeyboardHelper,在这里实现键盘的操作,并封装一些常用的方法这里我们将本类设计为单例模式companionobject{@Volatileprivatevarinstance:KeyboardHelper?=nullget(){if(field==null){field=KeyboardHelper()}returnfield}@Synchronizedfunget():KeyboardHelper{returninstance!!}}我们要想使用自定义的键盘,首先就要屏蔽掉系统键盘,一般常用的方法就是通过反射,这里封装一个方法,暴露给外部使用@SuppressLint("ObsoleteSdkInt")funbanSystemKeyboard(context:Activity,editText:EditText){if(android.os.Build.VERSION.SDK_INT<=10){editText.inputType=InputType.TYPE_NULL}else{context.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)try{valcls=EditText::class.javavalsetShowSoftInputOnFocus:MethodsetShowSoftInputOnFocus=cls.getMethod("setShowSoftInputOnFocus",Boolean::class.javaPrimitiveType!!)setShowSoftInputOnFocus.isAccessible=truesetShowSoftInputOnFocus.invoke(editText,false)}catch(e:Exception){e.printStackTrace()}}}既然是键盘,那它的使用方肯定是输入框EditText,这里我们给外部暴露一个bind方法,绑定两者,并提供一个接口,回调输入的内容给外部funbind(editText:EditText,numberKeyboardView:NumberKeyboardView,listener:OnKeyboardChangeListener){editText.requestFocus()editText.isSaveEnabled=falsevalueList=numberKeyboardView.getKeyValueList()valadapter=numberKeyboardView.adapterif(null!=adapter&&!(null==valueList||valueList!!.isEmpty())){processKeyClick(editText,adapter)observedEditText(editText,listener)}}可以看到,方法里面主要调用了两个方法,processKeyClick是用来处理键盘点击的,observedEditText是用来观察EditText的,如果输入内容发生变化,则会通知外部刷新首先看processKeyClick,这里就是为adapter设置点击事件监听,BaseRecyclerViewAdapterHelper为我们提供了很好的方法,直接调用即可adapter.onItemClickListener=BaseQuickAdapter.OnItemClickListener{_,_,position->respondKeyClick(editText,position)}接下来就是对每一个键的处理,代码虽然长,但很好理解,主要就是拼接字符串、首位0和小数点的判断,如果光标不在末尾,则用到了插入和删除方法,进行处理privatefunrespondKeyClick(et:EditText,pos:Int){if(pos<11&&pos!=9){//clicknumber0-9varamount=et.text.toString().trim{it<=''}amount+=valueList!![pos][Constant.MAP_KEY_NAME]valindex=et.selectionStart//cannotenterzerointhefirstplaceif(pos==10&&index==0){return}if(index==amount.length-1){et.setText(amount)valea=et.textet.setSelection(ea.length)}else{valeditable=et.texteditable.insert(index,valueList!![pos][Constant.MAP_KEY_NAME])}}else{if(pos==9){//clickdotvaramount=et.text.toString().trim{it<=''}if(TextUtils.isEmpty(amount)){return}valindex=et.selectionStartif(index==amount.length&&!amount.contains(".")){amount+=valueList!![pos][Constant.MAP_KEY_NAME]!!et.setText(amount)valea=et.textet.setSelection(ea.length)}elseif(index>0&&!amount.contains(".")){valeditable=et.texteditable.insert(index,valueList!![pos][Constant.MAP_KEY_NAME])}}if(pos==11){//clickdeletevaramount=et.text.toString().trim{it<=''}if(amount.isNotEmpty()){valindex=et.selectionStartif(index==amount.length){amount=amount.substring(0,amount.length-1)et.setText(amount)valea=et.textet.setSelection(ea.length)}else{if(index!=0){valeditable=et.texteditable.delete(index-1,index)}}}}}}然后就是对输入内容的回调,这里用到了TextWatcher类,通过它就可以观察EditText输入框内容的变化privatefunobservedEditText(editText:EditText,listener:OnKeyboardChangeListener){if(null==watcher){watcher=object:TextWatcher{overridefunbeforeTextChanged(s:CharSequence,start:Int,count:Int,after:Int){//Empty}overridefunonTextChanged(s:CharSequence,start:Int,before:Int,count:Int){//Empty}overridefunafterTextChanged(s:Editable){valinputVal=editText.text.toString()valeffectiveVal=perfectDecimal(inputVal,3,2)if(effectiveVal!=inputVal){editText.setText(effectiveVal)valpos=editText.text.lengtheditText.setSelection(pos)}callBackInputResult(listener,effectiveVal)}}}editText.addTextChangedListener(watcher)}这里我们对输入的内容做一下限制,小数点前最多输入3位,小数点后最多输入2位privatefunperfectDecimal(inputVal:String,maxBeforeDot:Int,maxDecimal:Int):String{varinputVal=inputValif(inputVal.isEmpty())return""if(inputVal[0]=='.')inputVal="0$inputVal"valmax=inputVal.lengthvalrFinal=StringBuilder()varafter=falsevari=0varup=0vardecimal=0vart:Charwhile(i<max){t=inputVal[i]if(t!='.'&&!after){up++if(up>maxBeforeDot)returnrFinal.toString()}elseif(t=='.'){after=true}else{decimal++if(decimal>maxDecimal)returnrFinal.toString()}rFinal.append(t)i++}returnrFinal.toString()}这样我们只需回调合法的输入内容就可以了,然后对回调的内容也做一下限制,如果两次输入内容一致,就不回调了,通过lastCallbackResult来记录一下privatefuncallBackInputResult(listener:OnKeyboardChangeListener?,str:String){if(null!=listener){if(str!=lastCallbackResult){lastCallbackResult=strlistener.onTextChange(str)}}}使用方法通过上面的封装,我们的数字键盘就算完工了,而且使用起来也很方便使用数字键盘View<top.i97.numberkeyboard.view.NumberKeyboardViewandroid:id="@+id/numberKeyboard"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="#fbfbfb"/>通过KeyboardHelper帮助类,完成系统键盘的屏蔽以及EditText和NumberKeyboardView的绑定helper.banSystemKeyboard(activity,editText)helper.bind(editText,numberKeyboard,object:OnKeyboardChangeListener{overridefunonTextChange(text:String){inputContent=text}})总结通过上面的流程,可以感受到,开发一个简单的数字键盘还是很轻松的,借助自带的RecyclerView就可以轻松完成❤️项目已提交Github,欢迎点我进入仓库查看最后感谢大家的观看done
2019-12-27 11:41 · 总结2019 / 展望2020 / 技术教程
[问答] 2020安卓自定义控件基础课程第34集,视频中没处理padding,加上后省略号不见了
在【阳光沙滩】2020安卓开发自定义控件基础课程,自定义控件基础课程第34集,处理padding引发的问题。
2020-09-02 02:31 · Android
[文章] OpenSSH 命令注入漏洞(CVE-2020-15778)修复教程
漏洞概括OpenSSH输入验证错误漏洞(CVE-2019-16905)OpenSSH命令注入漏洞(CVE-2020-15778)OpenSSH安全漏洞(CVE-2021-28041)一般线上用的云主机的
1970-01-01 00:00 · 网络安全 / Linux运维
[文章] SearchRecommend
quot;:"1250358535347318784","keyword":"键盘","createTime":"2020
2020-11-27 14:56 · 阳光沙滩 / search / recommend / 搜索建议
[问答] Android Studio app崩溃
前辈们这怎么回事,打包到手机上之后运行就崩溃了2020-10-2109:32:08.35420747-1857/?
2020-10-20 09:30 · android报错
[问答] @Query(nativeQuery = true 报错
[2020/08/10-20:29:18][http-nio-2020-exec-4][WARN][org.hibernate.engine.jdbc.spi.SqlExceptionHelper]:SQLError
2020-08-10 20:31 · springboot / jpa报错
[问答] 用okhttp下载图片,在指定目录下没有图片?
log上没有报错2020-02-0617:28:05.3309460-9460/?
2020-02-06 17:46 · Android
[问答] 安卓网路编程sob-android-mini-web-1.0.0.jar问题
nbsp;███████ ███████ ██████████████www.sunofbeaches.com███████████████████████████████████2020
2020-05-01 19:39 · 网络编程 / Android
[问答] Android8.0用OkHttp3报错,而andoird9.0和10.0不报错
<init>()(AndroidPlatform.kt:44)2020-03-1412:33:18.7475759-5759/com.cxb.webshopI/zygote:  
2020-03-14 12:56 · OkHttp
[问答] 部署博客门户出现的错误
["http-nio-2020"][2020/10/18-19:41:36][main][INFO][org.apache.catalina.core.StandardService]:Startingservice
2020-10-19 10:20 · 门户
[问答] 使用javaApi请求图片失败
R.id.result_image);imageView.setImageBitmap(bitmap);}});}}catch(Exceptione){e.printStackTrace();}}}).start();}2020
2020-01-20 18:22 · android
[问答] docker-compose创建MySQL容器失败
ChengWei/docker/mysql/log:/var/log/mysql"用的是上面的docker-compose.yml,但是创建后mysql容器总是不断aborting而后重启,容器的log如下:2020
2020-09-17 21:32 · docker / mysql
[问答] 喜马拉雅项目中不显示 "加载中" 的fragment页面
-12-0518:43:52.85231623-31623/com.example.himalayaprojectD/[com.example.himalayaproject]UILoader:加载中2020
2020-12-05 18:32 · 喜马拉雅 / 加载
[问答] 喜马拉雅 从详情页面点击item跳转到播放界面闪退问题
2020-06-2415:05:59.73830306-30311/com.youngc.himalayaI/zygote:Dopartialcodecachecollection,code=118KB
2020-06-24 15:10 · 喜马拉雅 / 闪退
[问答] android studio的sqlite使用出现问题,是什么情况呢?
这是我觉得可能可以参考的log2020-03-2421:21:55.62310006-10006/?
2020-03-24 21:23 · sqlite
[问答] Android SQLite建库失败
from=search&seid=450616653032236832运行后建不了库,logcat有错误2020-06-1411:20:56.11824453-24453/?
2020-06-14 11:32 · SQL / Android
[文章] android判断一个时间是否在某个时间区间内
isNot=false;}returnisNot;}}Activity调用代码//测试代码,判断是否在一个时间区间内privatevoidtestTime(){StringnowTime="2020
2020-06-28 10:19 · 时间区间
[问答] 学习网络编程配置中Retrofit 解析请求到的数据 用到了RecyclerView,运行出现空指针异常
1343753738156515328","title":"Android加载大图片,解决OOM问题","viewCount":206,"commentCount":59,"publishTime":"2020
2020-12-29 12:48 · NullPointerException
[分享] 2020Java后端最新学习路线
写得还不错,主要还是后端的技术栈,还有学习路线。初学者可以参考一下,对着图文,看看自己什么方面可以提升一下。
2020-03-02 11:16 · java / web / 后台 / 技术栈 / 后端
[文章] 互联网企业一般有哪些职位?
展望未来-机遇我们从什么渠道去找工作呢?通常来说,互联网求职一般在网上投简历。常见的平台有Boss、有拉勾、其他的就不推荐了,鱼龙混杂,广告一大堆。总之一句话,要钱的就别看了。
2020-04-30 14:50 · 求职 / 职场 / 面试 / 工作 / 职位
[问答] android 通过AppWidgetProvider 启动的Service会自动销毁问题
D/xxxxxx:广播========onReceive:=======2020-08-1913:07:50.6299319-9319/?
2020-08-19 15:58 · andorid / AppWidget / service
[分享] 2020年,你必须知道的JS数组技巧
在Javascript中,数组是一个重要且常见的知识点,我们经常将数据存储在数组中。作为一名Javascript工程师,数组必须要运用自如。这篇文章,向大家展示了在日常开发中,数组有哪些奇淫技巧值得关注和学习,让我们开始吧!
2020-02-19 14:42 · js / 前端 / JavaScript / 技巧 / 经验
[文章] 服务端php接口获得app客户端post的json数据,读取方法
php/**@Author:yourname*@Date:2020-06-0615:32:58*@LastEditTime:2020-06-0616:25:11*@LastEditors:PleasesetLastEditors
2020-06-06 22:19 · php接口 / json / post / 服务端
[文章] 阳光沙滩-实现定时、监听功能
importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.scheduling.annotation.Scheduled;/***@Author:zhanghuan*@date:2020
2020-11-05 08:42 · schedule / listener
[问答] 喜马拉雅第三集配置问题
gt;api.ximalaya.com</domain></domain-config></network-security-config>这个也配置了但是还是报错误2020
2020-05-13 18:37 · 喜马拉雅
  • 1
  • 2
  • 3
  • 4
  • 5