首页 文章 精选 留言 我的

精选列表

搜索[demo],共10002篇文章
优秀的个人博客,低调大师

会员卡模板创建(alipay.marketing.card.template.create)JAVA版本demo

先附上官方接口文档地址:[url]https://docs.open.alipay.com/api_5/alipay.marketing.card.template.create[/url] 话不多说,我这里先将测试通过的核心代码贴上 //创建卡模板 public static void template_create(){ AlipayClient alipayClient=alipayclient(); AlipayMarketingCardTemplateCreateRequest request = new AlipayMarketingCardTemplateCreateRequest(); request.setBizContent("{" +

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

(ElasticsSearch学习)歌词检索Demo的实现:一. 爬取歌词信息,写入ES

1.说明 爬虫采用Java的Jsoup ElasticSearch请在阿里云官网购买,采用客户端x-pack-transport 歌词网站来源:http://www.kuwo.cn/artist/index 2. 歌词网站分析 此处采用了比较笨的一种方式,即逐个分析每个请求的url,这样可以方便代码编写,就不用模拟器了(如需使用模拟器可参考使用cdp4j模拟点击事件等,但简单试了下不是很好用,且效率低) a) 歌手获取分析 在http://www.kuwo.cn/artist/index 查看分页按钮的click事件,从js中找到分页请求的url从click事件的artist.js中找到相关url如下图所示其中pn参数即为页码参数 var b = host + "/artist/indexAjax?category=" + index + "&a

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

DEMO:呼吸灯按钮、smoothbutton、使用一组图片设置按钮背景、setLevel

1.attrs属性: 1 2 3 4 5 6 7 8 9 10 11 12 <?xmlversion= "1.0" encoding= "utf-8" ?> <resources> <stringname= "app_name" >EX_templete</string> <stringname= "action_settings" >Settings</string> <stringname= "hello_world" >Helloworld!</string> <declare-styleablename= "SmoothButton" > <attrname= "transitionDrawable" format= "reference" /> <attrname= "transitionDrawableLength" format= "integer" /> <attrname= "transitionTextColorUp" format= "color" /> <attrname= "transitionTextColorDown" format= "color" /> </declare-styleable> </resources> 2.layout设置: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <RelativeLayoutxmlns:android= "http://schemas.android.com/apk/res/android" xmlns:misc= "http://schemas.android.com/apk/res/com.example.ex_templete" xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "match_parent" android:paddingBottom= "@dimen/activity_vertical_margin" android:paddingLeft= "@dimen/activity_horizontal_margin" android:paddingRight= "@dimen/activity_horizontal_margin" android:paddingTop= "@dimen/activity_vertical_margin" tools:context= ".MainActivity" > <TextView android:id= "@+id/textView1" android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "@string/hello_world" /> <com.example.ex_templete.SmoothButton android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:background= "@drawable/red_button" android:text= "smoothbutton1" misc:transitionDrawable= "@drawable/red_transition_list" misc:transitionDrawableLength= "8" misc:transitionTextColorDown= "#aaa" misc:transitionTextColorUp= "#eee" /> </RelativeLayout> 3.自定义控件SmoothButton类: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.LevelListDrawable; import android.os.Handler; import android.os.Message; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.MotionEvent; import android.widget.Button; public class SmoothButton extends Button { private static final long DELAY= 25 ; private int transitionDrawableLength; private int level; private int []colors; private boolean wasPressed; private Drawablebackground; public SmoothButton(Contextcontext,AttributeSetattrs) { super (context,attrs); TypedArraya=context.obtainStyledAttributes(attrs,R.styleable.SmoothButton); LevelListDrawabletransitionDrawable=(LevelListDrawable)a.getDrawable(R.styleable.SmoothButton_transitionDrawable); transitionDrawableLength=a.getInt(R.styleable.SmoothButton_transitionDrawableLength, 0 ); int useTextColors= 0 ; int c0= 0 ; if (a.hasValue(R.styleable.SmoothButton_transitionTextColorUp)) { c0=a.getColor(R.styleable.SmoothButton_transitionTextColorUp, 0 ); useTextColors++; } int c1= 0 ; if (useTextColors== 1 &&a.hasValue(R.styleable.SmoothButton_transitionTextColorDown)) { c1=a.getColor(R.styleable.SmoothButton_transitionTextColorDown, 0 ); useTextColors++; } a.recycle(); if (transitionDrawable== null ) { throw new RuntimeException( "transitionDrawablemustbedefinedinXML(withvalidxmlns)" ); } if (transitionDrawableLength== 0 ) { throw new RuntimeException( "transitionDrawableLengthmustbedefinedinXML(withvalidxmlns)" ); } if (useTextColors== 2 ) { setTextColor(c0); int a0=Color.alpha(c0); int r0=Color.red(c0); int g0=Color.green(c0); int b0=Color.blue(c0); int a1=Color.alpha(c1); int r1=Color.red(c1); int g1=Color.green(c1); int b1=Color.blue(c1); colors= new int [transitionDrawableLength]; for ( int i= 0 ;i<transitionDrawableLength;i++) { int ai=a0+i*(a1-a0)/transitionDrawableLength; int ri=r0+i*(r1-r0)/transitionDrawableLength; int gi=g0+i*(g1-g0)/transitionDrawableLength; int bi=b0+i*(b1-b0)/transitionDrawableLength; colors[i]=Color.argb(ai,ri,gi,bi); } } int []viewAttrs= {android.R.attr.background}; a=context.obtainStyledAttributes(attrs,viewAttrs); boolean hasa.hasValue( 0 ); a.recycle(); if (!hasBackground) { int l=getPaddingLeft(); int t=getPaddingTop(); int r=getPaddingRight(); int b=getPaddingBottom(); setBackgroundDrawable(transitionDrawable); setPadding(l,t,r,b); } background=getBackground(); level= 0 ; background.setLevel(level); //通过此方法设置一组图片为背景************************************** } @Override public boolean onKeyDown( int keyCode,KeyEventevent) { boolean rc= super .onKeyDown(keyCode,event); if ((keyCode==KeyEvent.KEYCODE_ENTER||keyCode==KeyEvent.KEYCODE_DPAD_CENTER)&&event.getRepeatCount()== 0 &&level+ 1 <transitionDrawableLength) { handler.removeMessages(- 1 ); handler.sendEmptyMessageDelayed( 1 ,DELAY); } return rc; } @Override public boolean onKeyUp( int keyCode,KeyEventevent) { boolean rc= super .onKeyUp(keyCode,event); if ((keyCode==KeyEvent.KEYCODE_ENTER||keyCode==KeyEvent.KEYCODE_DPAD_CENTER)&&event.getRepeatCount()== 0 &&level> 0 ) { handler.removeMessages( 1 ); handler.sendEmptyMessageDelayed(- 1 ,DELAY); } return rc; } @Override public boolean onTouchEvent(MotionEventevent) { wasPressed=isPressed(); boolean rc= super .onTouchEvent(event); post(checkPressed); return rc; } RunnablecheckPressed= new Runnable() { public void run() { if (!wasPressed&&isPressed()) { if (level+ 1 <transitionDrawableLength) { handler.removeMessages(- 1 ); handler.sendEmptyMessageDelayed( 1 ,DELAY); } } else if (wasPressed&&!isPressed()) { if (level> 0 ) { handler.removeMessages( 1 ); handler.sendEmptyMessageDelayed(- 1 ,DELAY); } } } }; private Handlerhandler= new Handler() { @Override public void handleMessage(Messagemsg) { int what=msg.what; level+=what; if (level>= 0 &&level<transitionDrawableLength) { background.setLevel(level); if (colors!= null ) { setTextColor(colors[level]); } sendEmptyMessageDelayed(what,DELAY); } else { level=Math.max( 0 ,level); level=Math.min(transitionDrawableLength- 1 ,level); } } }; } 4.MainActivity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(BundlesavedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menumenu) { getMenuInflater().inflate(R.menu.main,menu); return true ; } } 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1228577,如需转载请自行联系原作者

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

DEMO:transition3d、运用动画实现图片3d翻转效果

模仿系统apiDemos里的范例,去掉了listview,修改为点击图片后,更新图片并播放3d翻转动画。 代码: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 package com.example.aexh_11_transition3d; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.view.animation.AccelerateInterpolator; import android.view.animation.Animation; import android.view.animation.DecelerateInterpolator; import android.view.animation.Animation.AnimationListener; import android.widget.ImageView; public class MainActivity extends Activity implements OnClickListener { /** * 仿照系统的范例,修改成点击图片播放动画更新图片。 * apiDemos范例: com.example.android.apis.animation * Transition3d */ private static final int [] PHOTOS_RESOURCES = new int [] { R.drawable.photo1, R.drawable.photo2, R.drawable.photo3, R.drawable.photo4, R.drawable.photo5, R.drawable.photo6 }; private ImageView mImageview; private ViewGroup mLayout; private int mPosition; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImageview = (ImageView) findViewById(R.id.imageView1); mImageview.setOnClickListener( this ); mLayout = (ViewGroup) findViewById(R.id.image_layout); // ViewGroup是所有layout的父类 /** * 下面这句应该是用来压缩大图的,没加上这句运行正常 */ // Since we are caching large views, we want to keep their cache // between each animation mLayout.setPersistentDrawingCache(ViewGroup.PERSISTENT_ANIMATION_CACHE); } @Override public void onClick(View v) { if (v.getId() == R.id.imageView1) { // Pre-load the image then start the animation mPosition++; applyRotation( 0 , 90 ); mImageview.setImageResource(PHOTOS_RESOURCES[mPosition % 6 ]); } } /** * Setup a new 3D rotation on the container view. * * @param position * the item that was clicked to show a picture, or -1 to show the * list * @param start * the start angle at which the rotation must begin * @param end * the end angle of the rotation */ private void applyRotation( float start, float end) { // Find the center of the container final float centerX = mLayout.getWidth() / 2 .0f; final float centerY = mLayout.getHeight() / 2 .0f; // Create a new 3D rotation with the supplied parameter // The animation listener is used to trigger the next animation final Rotate3dAnimation rotation = new Rotate3dAnimation(start, end, centerX, centerY, 310 .0f, true ); rotation.setDuration( 500 ); rotation.setFillAfter( true ); rotation.setInterpolator( new AccelerateInterpolator()); // 监听动画 rotation.setAnimationListener( new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mLayout.post(mAaction); // 刷新layout这个View } }); // 启动动画 mLayout.startAnimation(rotation); } Runnable mAaction = new Runnable() { @Override public void run() { final float centerX = mLayout.getWidth() / 2 .0f; final float centerY = mLayout.getHeight() / 2 .0f; Rotate3dAnimation rotation; // mImageView.requestFocus(); rotation = new Rotate3dAnimation( 90 , 180 , centerX, centerY, 310 .0f, false ); rotation.setDuration( 500 ); rotation.setFillAfter( true ); rotation.setInterpolator( new DecelerateInterpolator()); mLayout.startAnimation(rotation); } }; } 系统实现的动画方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 package com.example.aexh_11_transition3d; /* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.view.animation.Animation; import android.view.animation.Transformation; import android.graphics.Camera; import android.graphics.Matrix; /** * An animation that rotates the view on the Y axis between two specified * angles. This animation also adds a translation on the Z axis (depth) to * improve the effect. */ public class Rotate3dAnimation extends Animation { private final float mFromDegrees; private final float mToDegrees; private final float mCenterX; private final float mCenterY; private final float mDepthZ; private final boolean mReverse; private Camera mCamera; /** * Creates a new 3D rotation on the Y axis. The rotation is defined by its * start angle and its end angle. Both angles are in degrees. The rotation * is performed around a center point on the 2D space, definied by a pair of * X and Y coordinates, called centerX and centerY. When the animation * starts, a translation on the Z axis (depth) is performed. The length of * the translation can be specified, as well as whether the translation * should be reversed in time. * * @param fromDegrees * the start angle of the 3D rotation * @param toDegrees * the end angle of the 3D rotation * @param centerX * the X center of the 3D rotation * @param centerY * the Y center of the 3D rotation * @param reverse * true if the translation should be reversed, false otherwise */ public Rotate3dAnimation( float fromDegrees, float toDegrees, float centerX, float centerY, float depthZ, boolean reverse) { mFromDegrees = fromDegrees; mToDegrees = toDegrees; mCenterX = centerX; mCenterY = centerY; mDepthZ = depthZ; mReverse = reverse; } @Override public void initialize( int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); mCamera = new Camera(); } @Override protected void applyTransformation( float interpolatedTime, Transformation t) { final float fromDegrees = mFromDegrees; float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime); final float centerX = mCenterX; final float centerY = mCenterY; final Camera camera = mCamera; final Matrix matrix = t.getMatrix(); camera.save(); if (mReverse) { camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime); } else { camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime)); } camera.rotateY(degrees); camera.getMatrix(matrix); camera.restore(); matrix.preTranslate(-centerX, -centerY); matrix.postTranslate(centerX, centerY); } } 本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1226205,如需转载请自行联系原作者

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

如何基于开源 demo 在 Web 端实现一个多人数独游戏

本文作者是声网社区的开发者“tjss”。他基于Vue、声网的互动白板的代码模板,搭建出了一个支持多人互动的数独游戏。本文记录了他的实现过程,欢迎大家也可以尝试实现自己的小游戏或应用。 我基于声网互动白板的 SDK 与 Window Manager 开发了一个场景化窗口插件,实现了一个多人数独游戏。在游戏中,每个玩家进入白板房间,都能看到数独游戏插件,同时可以参与其中,与房间内的小伙伴一起完成数独解题。 前期准备 1、注册一个声网账号,并实名认证,以便在后台创建项目,获取开发时会用到的 Appid 和 Token 2、了解 Vue 开发的基础知识。 3、了解声网互动白板产品,一些基本的接口和功能,看官方文档就足够了。 4、搭建开发环境: NodeJs 版本 16.0.0 @Vue/cli 4.5.1 VSCode 代码开发工具 开启和配置互动白板服务 首先我们需要一个实名认证的声网账号,进入控制台(console.agora.io),在声网控制台开启互动白板服务。 这里需要注意的是互动白板是作为服务而显示的,而控制台中只是显示项目列表,并没有直接显示服务。 这时候我们就先创建一个项目,然后点击“配置”进入到项目详情中,在里面的页面就可以看到服务内容了。 这时候找到互动白板服务,点击开启就行。因为我的已经开启了,所以显示的是配置按钮。 使用官网提供的代码模板 场景化窗口插件目前我们不需要从零开始建立的,声网提供了一个代码模板,基于此模板我们可以很轻松就能实现一个在互动白板上使用的插件。 模板地址:https://github.com/netless-io/community-app-template 当搭建好开发环境后,便可以下载模板代码了,通过 Git 或者下载 Zip 都行。 需要注意 README.md 中的开发环境配置: 1、在 .env 文件里配置白板房间 UUID 和 Token请将本目录下的 .env.example 文件复制一份,重命名为 .env 或 .env.local 后,在里面填写必须的白板配置信息。你可以在声网互动白板官方的 Netless Workshop 申请专用的白板配置。 2、执行 npm install 安装依赖 3、执行 npm start 进行本地开发 项目结构 笔者是基于 Vue 版本的插件模板进行开发的,直接打开项目,修改 src 里的内容即可,基本上和 Vue 开发一致。如果是通过 Git 命令拉取的代码,需要切换分支为 Vue 分支。 项目结构如下: playground 目录是基本不用修改的,我们实现的插件是在 src 目录中完成的。 index.ts 文件是我们插件的一些数据设置,比如插件名称。其他逻辑基本不用修改。 onst Sudoku: NetlessApp = { kind: "Sudoku", setup(context) { const box = context.getBox(); box.mountStyles(styles); const $content = document.createElement("div"); $content.className = "app-counter"; box.mountContent($content); const app = createApp(App).provide("context", context); app.mount($content); context.emitter.on("destroy", () => { app.unmount(); }); }, }; export default Sudoku; 数独游戏规则 数独网格由 9x9 个空格组成。玩家只能使用数字 1 到 9,每个 3×3 宫只能包含数字 1 到 9,每一列只能包含数字 1 到 9,每一行只能包含数字 1 到 9,每个 3×3 宫、每一列或每一行中的每个数字只能使用一次。当所有数独网格都填入正确的数字时,游戏结束。(摘自网上) 数据同步核心思路 1、通过互动白板SDK提供的 createStorage 方法,初始化一个数独棋盘,并把数据存储起来,同时需要更新自己的 chessBoard。 const chessBoard = ref(); const context = inject<AppContext>("context"); const storage = context.createStorage("chessBoard", { chessBoard: ChessBoard.init() }); chessBoard.value = deepCopy(storage.state.chessBoard) 2、在 Vue 界面的 onMounted 回调函数中添加存储值的更新监听,这样玩家在填格子的时候广播了最新的格子数据,其他玩家就能收到更新的通知,然后重新渲染界面。 onMounted(() => { initAppData() storage.addStateChangedListener((diff) => { chessBoard.value = deepCopy(diff.chessBoard?.newValue) if (finish(chessBoard.value.gridItems)) { statistics(chessBoard.value.gridItems) finishTag.value = true } }) }); 3、填格子的时候,通过 SDK 的 setState 方法去更新数独棋盘的数据。 if (e.data && e.data > 0) { grid.number = parseInt(e.data) grid.userId = uid.value grid.color = rgb } else { grid.number = 0 grid.userId = '' grid.color = new Rgb(233, 233, 233) } storage.setState({ chessBoard: chessBoard.value }) 数独游戏界面 笔者是优先实现这个互动游戏的核心功能,所以设计出的游戏界面比较简陋。 数独的数据结构 export class ChessBoard { gridItems: GridItem[][] } 因为需要统计游戏结束后,各个玩家填写的个数,所以在更新格子数值的时候也记录一下是哪一位玩家填写了。default 字段表示该格子是自动生成的,不需要玩家填写了。 export class GridItem { number: number color: Rgb userId: string default: boolean } 运行项目 点击工具栏最下方的按钮,可以找到我们实现的插件icon,然后点击即可打开。 打开插件后,会初始化创建一个数独题目,并且通过 createStorage 方法储存起来,所有进入房间的玩家都能拿到这个数据,后续数独的更新都会同步给玩家去修改。因为这个项目重点是学习一下插件开发与数据同步,所以游戏界面以及内容这些做的比较简单。 接下来就要打开多个网页并且输入 localhost:3000 进入我们的互动白板房间了,因为模板的uid是随机生成的,也就表示有不同的玩家进入了。 别的玩家填写后,其他玩家是不能再填这个格子的,最后游戏结束的时候,会统计各个玩家所填对的数字并展示。 游戏结束 总结 通过官方提供的场景化插件模板,我们很容易实现一些好玩的互动场景的功能。在这个简单的项目中,由于时间仓促,还没来得及优化得更好,后续有时间的时候笔者再打磨一下。比如不同玩家填写的数字以不同的颜色区分,增加限时机制等等。感兴趣的朋友一起来开发一些好玩的实时互动功能吧~ 现注册声网账号下载 SDK,可获得每月免费 10000 分钟使用额度。如在开发过程中遇到疑问,可在声网开发者社区与官方工程师交流。

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

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

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Sublime Text

Sublime Text

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

用户登录
用户注册
修改密码
忘记密码