首页 文章 精选 留言 我的

精选列表

搜索[人设自定义],共10006篇文章
优秀的个人博客,低调大师

自定义View——画板

今天实现的是画板效果 image 实现原理 image 根据触摸事件返回的坐标点绘制path路径 @Override public boolean onTouchEvent(MotionEvent event) { x = event.getX(); y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: //当触摸屏幕的时候将点移动到触摸的位置 path.moveTo(x, y); break; case MotionEvent.ACTION_MOVE: //当滑动的时候将滑动路径连接起来 path.lineTo(x, y); //在滑动的过程中不断更新界面 invalidate(); break; case MotionEvent.ACTION_UP: //当手抬起的时候更新界面 invalidate(); break; } return true; } canvas绘制路径 //绘制白色背景 canvas.drawColor(Color.WHITE); //绘制路径 canvas.drawPath(path, paint); 最后保存自己绘制的图像 public void save() { setDrawingCacheEnabled(false); setDrawingCacheEnabled(true); new Thread(new Runnable() { @Override public void run() { Bitmap drawingCache = getDrawingCache(true); File file = new File(getContext().getCacheDir() + "123.png"); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(file); drawingCache.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); fileOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); try { MediaStore.Images.Media.insertImage(getContext().getContentResolver(), file.getAbsolutePath(), "sad.png", null); } catch (FileNotFoundException e) { e.printStackTrace(); } // 最后通知图库更新 getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getPath()))); Log.e("测试", "保存成功"); } catch (IOException e) { e.printStackTrace(); } } } } }).start(); } 完整代码 package com.yuyigufen.customview; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.net.Uri; import android.provider.MediaStore; import android.support.annotation.Nullable; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; import android.view.View; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Random; /** * Created by Administrator on 2018/6/11 0011. */ public class MyPaintView extends View { private float x; private float y; private Path path; private Paint paint; private Random random; public MyPaintView(Context context) { super(context); } public MyPaintView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } private void init() { random = new Random(); paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(10); paint.setColor(Color.RED); path = new Path(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { setMeasuredDimension(measureSize(widthMeasureSpec), measureSize(heightMeasureSpec)); } private int measureSize(int size) { int mode = MeasureSpec.getMode(size); int s = MeasureSpec.getSize(size); if (mode == MeasureSpec.EXACTLY) { return s; } else if (mode == MeasureSpec.AT_MOST) { return Math.min(s, 200); } else { return 200; } } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(Color.WHITE); canvas.drawPath(path, paint); } @Override public boolean onTouchEvent(MotionEvent event) { x = event.getX(); y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: path.moveTo(x, y); break; case MotionEvent.ACTION_MOVE: path.lineTo(x, y); invalidate(); break; case MotionEvent.ACTION_UP: invalidate(); break; } return true; } public void clear() { path.reset(); invalidate(); } public void save() { setDrawingCacheEnabled(false); setDrawingCacheEnabled(true); new Thread(new Runnable() { @Override public void run() { Bitmap drawingCache = getDrawingCache(true); File file = new File(getContext().getCacheDir() + "123.png"); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(file); drawingCache.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); fileOutputStream.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); try { MediaStore.Images.Media.insertImage(getContext().getContentResolver(), file.getAbsolutePath(), "sad.png", null); } catch (FileNotFoundException e) { e.printStackTrace(); } // 最后通知图库更新 getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file.getPath()))); Log.e("测试", "保存成功"); } catch (IOException e) { e.printStackTrace(); } } } } }).start(); } } 个人博客https://myml666.github.io

优秀的个人博客,低调大师

Android——自定义Dialog

创建dialog实例: Dialog dialog = new Dialog(Context context,int theme); 一般大家都是想让Dialog显示自己的布局这里的theme写在style文件内具体内容如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 < style name = "dialog_tran" parent = "android:style/Theme.Dialog" > < item name = "android:windowFrame" >@null</ item > < item name = "android:windowNoTitle" >true</ item > < item name = "android:windowBackground" >@android:color/transparent</ item > < item name = "android:windowIsFloating" >true</ item > < item name = "android:windowContentOverlay" >@null</ item > < item name = "android:windowIsTranslucent" >true</ item > < item name = "android:backgroundDimEnabled" >false</ item > < item name = "android:backgroundDimAmount" >0.4</ item > </ style > < style name = "dialog_untran" parent = "dialog_tran" > < item name = "android:backgroundDimEnabled" >true</ item > </ style > 3.setContentView(): (1)setContentView(int layoutId):如果采用这个方法则可以在XML布局文件设置最外层布局的大小,这样dialog显示的大小就是在布局文件中设置的大小; (2)setContentView(View view):采用这个方法,不管在布局文件中最外层布局文件的宽高为何则均全屏显示,此时我们可以将布局文件次外层布局看做我们想要呈现的布局即可达到效果; 本文转自wauoen51CTO博客,原文链接:http://blog.51cto.com/7183397/1837920,如需转载请自行联系原作者

优秀的个人博客,低调大师

elasticsearch 自定义打分

curl -XGET 'http://localhost:9200/searchsuggestion/searchsuggestion/_search?pretty' -d '{ "fields" : ["company_full_name","id"], "size" : 10, "query": { "function_score": { "functions": [ { "filter": { "term": { "pinyin_name": "bx" } }, "weight": 100 }, { "filter": { "term": { "blurry": "bx" } }, "weight": 10 }, { "field_value_factor" : { "field" : "frequency", "factor" : 0.1, "modifier" : "ln" } } ], "score_mode": "sum" } } }' 解释 score=pinyin_name*100+blurry*10+ln(0.1*frequency) 本文转自whk66668888 51CTO博客,原文链接:http://blog.51cto.com/12597095/1903763

优秀的个人博客,低调大师

Phonegap 自定义插件

一、PhoneGap中js与Java之间相互调用分为同步和异步两种方式 1、同步:js调用Java类的方法,然后Java类的方法直接返回一个值给js端 2、异步:js调用Java类的方法,Java类的方法可能要处理一系列的事情。执行完后,通过回调把结果返回js端。 二、下面以Android为例,通过插件实现js调用java类中的方法 1.创建cordova 工程 2. 在Android Studio打开 3. 在Index.html 1 <button id= "showToast" >Show Toast</button> 4. 在Index.js中加入插件执行方法 1 exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]); 在onDeviceReady中加入 1 document.getElementById( "showToast" ).addEventListener( "click" ,app.showToast); showToast方法就是调用插件的方法 1 2 3 4 5 6 7 8 showToast: function (){ cordova.exec( function (){}, function (){}, "Toast" , "show" , [ "hello man" ]); }, 5. 创建插件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 public class MyToast extends CordovaPlugin{ @Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if ( "show" .equals(action)){ show(args, callbackContext); } return super .execute(action, args, callbackContext); } public void show(JSONArray args, CallbackContext callbackContext){ try { Toast.makeText(cordova.getActivity(),args.getString(0), Toast.LENGTH_LONG).show(); } catch (JSONException e){ e.printStackTrace(); } callbackContext.success(); } } 1 继承CordovaPlugin, 并实现execute方法。 action对应exec的第四个参数 6. xml中config.xml配置 1 2 3 <feature name= "Toast" > <param name= "android-package" value= "com.example.tostplugin.MyToast" /> </feature> Toast对应exec的第三个参数, value值com.example.tostplugin.MyToast 为插件的包名。 7. 效果图 本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/7081147.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

andorid 自定义seekbar

效果如图: [html] view plain copy <?xmlversion="1.0"encoding="utf-8"?> <resources> <stylename="Widget.SeekBar.Normal"parent="@android:style/Widget.SeekBar"> <itemname="android:maxHeight">8.0dip</item> <itemname="android:indeterminateOnly">false</item> <itemname="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item> <itemname="android:progressDrawable">@drawable/seekbar_horizontal</item> <itemname="android:minHeight">8.0dip</item> <itemname="android:thumb">@drawable/seek_thumb</item> <itemname="android:thumbOffset">10.0dip</item> </style> </resources> seekbar_horizontal.xml [html] view plain copy <?xmlversion="1.0"encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <itemandroid:id="@android:id/background"android:drawable="@drawable/seek_bkg"/> <itemandroid:id="@android:id/secondaryProgress"> <clip> <shape> <cornersandroid:radius="2.0dip"/> <gradientandroid:startColor="#80ffd300"android:endColor="#a0ffcb00"android:angle="270.0"android:centerY="0.75"android:centerColor="#80ffb600"/> </shape> </clip> </item> <itemandroid:id="@android:id/progress"> <clipandroid:drawable="@drawable/seek"/> </item> </layer-list> 使用方法main.xml [html] view plain copy <SeekBarandroid:id="@+android:id/progresss" android:layout_width="fill_parent"android:layout_height="wrap_content" android:layout_marginTop="50dip"style="@style/Widget.SeekBar.Normal"/> seek.9.png seek_bkg.9.png seek_thumb.png <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:useLevel="false"> <solidandroid:color="@color/red"/> <stroke android:width="1dp" android:color="@color/white"/> <sizeandroid:width="20dp" android:height="20dp"/> </shape> 本文转自 一点点征服 博客园博客,原文链接:http://www.cnblogs.com/ldq2016/p/5543371.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册