首页 文章 精选 留言 我的

精选列表

搜索[Linux版本],共10000篇文章
优秀的个人博客,低调大师

动手造轮子——用Builder模式撸一个通用版本的Dialog 前言

在Android开发中我们常常需要使用Dialog来处理一些弹窗操作。虽然Android系统本身为我们封装了一个自带的弹窗Dialog,但是由于Android操作系统的不同,导致了每个手机弹窗页面的不同,以至于我们很难用系统的去统一样式。并且UI会觉得系统的弹窗过于丑陋,希望自己来做一个于是我们便需要自己来处理一个Dialog弹窗。今天叫大家利用Builder构造者模式自己来封装一个弹窗Dialog。 需求分析 首先确定一下,弹窗我们需要哪些功能? 需要可以自己自定义样式。因为每个弹窗会根据逻辑和需求的不同拥有不同的样式。例如有些弹窗有title标题,有些只有message提示;有些有确定和取消按钮,有些又只有一个确定按钮。我们必须用一套代码来加载不同的样式才行。 设置title或者message的内容。这里可以根据传入的不同id设置不同文字内容。 设置按钮的点击事件 设置是否需要点击弹窗外部使得弹窗消失。 开始操作 分析完了需求之后我们便可以根据需求来撸代码了。 首先我们写一个CommonDialog类让他继承Dialog。此时我们必须复写onCreat(),在onCreat()我么进行一些设置操作。这里我们设置setContentView()加载布局样式,设置setCancelable()是否点击弹窗以外使得弹窗消失。 public class CommonDialog extends Dialog { private Context context; private View view; private boolean cancelTouchout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(view); setCancelable(cancelTouchout); } } 其实这时候我们就开始要编写Builder构造者模式的代码了。 构造者模式,顾名思义,就是根据我们的需要往代码上添加需求。例如,我们需要设置title标题的内容,此时我们就添加上这个功能,如果需要设置message内容的功能我们也设置上这个功能。如果不需要则不添加这段代码。 先根据不同样式加载不同的布局。此时我们利用LayoutInflater来处理。布局样式由参数传递进来。 public Builder view(int resView) { view = LayoutInflater.from(context).inflate(resView, null); return this; } 其次,再根据是否可以点击弹窗外部使得弹窗消失。 public Builder cancelTouchout(boolean val) { cancelTouchout = val; return this; } 传入的val若为true代表可以消失,如果传入的为false则代表不能消失。 紧接着我们再来看看如果根据title和message来设置不同的内容。这里我们的参数设置为两个,一个是需要设置内容的id,一个是设置内容的文字title/message。我们先通过findViewById去查找到这个View中的控件,之后再根据文字内容将文字设置到控件上去。 //设置标题title public Builder setTitle(int viewRes,String title){ TextView txtTitle = (TextView) view.findViewById(viewRes); txtTitle.setText(title); return this; } //设置内容message public Builder setMessage(int viewRes,String message){ TextView txtMessage = (TextView)view.findViewById(viewRes); txtMessage.setText(message); return this; } 然后我们就该去设置点击事件了。点击事件我们可以借鉴设置title和message的情况来处理,通过传入一个点击控件的id来查找id,之后通过View.OnClickListener来回调这个点击事件处理点击逻辑即可。 public Builder addViewOnclick(int viewRes,View.OnClickListener listener){ view.findViewById(viewRes).setOnClickListener(listener); return this; } 最后我们只需要把最后写一个build返回一个CommonDialog即可。但是如果此时我们调用使用这个CommonDialog时你会发现我们不管如何设置加载的View,发现大小其实都是不变的。这是怎么回事?其实这是因为我们的背景色一起被设置进入了View布局中。如果此时我们把我们加载的View背景设置为黑色(#000000),就会神奇的发现,在View旁边还有一些白色的存在。正是因为这些白色,导致了我们无论如何设置弹窗宽度都显示的是原来的大小。如果你要设置为圆角,那更是不太可能。 那该如何处理这种情况?其实很简单,我们仅仅需要设置一下将弹窗风格的style设置一个透明的背景即可处理好这种情况。 我们在value-style中设置一个style风格样式,将背景设置为透明即可。 <!--Dialog将白色背景变透明--> <style name="Dialog" parent="android:style/Theme.Dialog"> <item name="android:background">@android:color/transparent</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowNoTitle">true</item> </style> 此时我们再在CommonDialog中设置一个style样式,根据传入的样式来处理风格。 public Builder style(int resStyle) { this.resStyle = resStyle; return this; } 最后我们再写两个CommonDialog的构造方法,根据是否有传入style来调用不同父类。完成操作。 private CommonDialog(Builder builder) { super(builder.context); context = builder.context; cancelTouchout = builder.cancelTouchout; view = builder.view; } private CommonDialog(Builder builder, int resStyle) { super(builder.context, resStyle); context = builder.context; cancelTouchout = builder.cancelTouchout; view = builder.view; } 到此我们的整个代码就全部操作完毕。 使用 使用起来也非常简单,我们只需要创建一个CommonDialog.Builder根据不同的业务需求来添加不同操作即可。 CommonDialog build; //dialog弹窗 private void dialog(){ build = new CommonDialog.Builder(this) .view(R.layout.dialog)//设置弹窗的样式layout .style(R.style.Dialog) //设置主题,这里可以将背景设为透明,这样只显示你需要显示的dialog部分 .cancelTouchout(true) //设置点击dialog之外是否弹窗消失,true为消失,false为不消失 .setTitle(R.id.txt_title, "这是一个弹窗标题")//根据id来设置标题的显示文字 .setMessage(R.id.txt_message, "这是一个弹窗消息内容")//根据id来设置消息内容的显示文字 .addViewOnclick(R.id.txt_sure, new View.OnClickListener() {//处理确认点击事件 @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "点击了确定按钮", Toast.LENGTH_SHORT).show(); build.dismiss(); } }) .addViewOnclick(R.id.txt_cancel, new View.OnClickListener() {//处理取消的点击事件 @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "点击了取消按钮", Toast.LENGTH_SHORT).show(); build.dismiss(); } }).build(); build.show(); } 最后 更多Android进阶技术,面试资料系统整理分享,职业生涯规划,产品,思维,行业观察,谈天说地。可以加Android架构师群;701740775。

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

业余草 SpringCloud教程 | 第十一篇: 断路器监控(Hystrix Dashboard)(Finchley版本)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xmt1139057136/article/details/81413998 在我的第四篇文章断路器讲述了如何使用断路器,并简单的介绍了下Hystrix Dashboard组件,这篇文章更加详细的介绍Hystrix Dashboard。 一、Hystrix Dashboard简介 在微服务架构中为例保证程序的可用性,防止程序出错导致网络阻塞,出现了断路器模型。断路器的状况反应了一个程序的可用性和健壮性,它是一个重要指标。Hystrix Dashboard是作为断路器状态的一个组件,提供了数据监控和友好的图形化界面。 二、准备工作 本文的的工程栗子,来源于第一篇文章的栗子,在它的基础上进行改造。 三、开始改造service-hi 在pom的工程文件引入相应的依赖: <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> </dependency> </dependencies> 其中,这三个依赖是必须的,缺一不可。 在程序的入口ServiceHiApplication类,加上@EnableHystrix注解开启断路器,这个是必须的,并且需要在程序中声明断路点HystrixCommand;加上@EnableHystrixDashboard注解,开启HystrixDashboard @SpringBootApplication @EnableEurekaClient @EnableDiscoveryClient @RestController @EnableHystrix @EnableHystrixDashboard @EnableCircuitBreaker public class ServiceHiApplication { /** * 访问地址 http://localhost:8762/actuator/hystrix.stream * @param args */ public static void main(String[] args) { SpringApplication.run( ServiceHiApplication.class, args ); } @Value("${server.port}") String port; @RequestMapping("/hi") @HystrixCommand(fallbackMethod = "hiError") public String home(@RequestParam(value = "name", defaultValue = "forezp") String name) { return "hi " + name + " ,i am from port:" + port; } public String hiError(String name) { return "hi,"+name+",sorry,error!"; } } 运行程序: 依次开启eureka-server 和service-hi. 四、Hystrix Dashboard图形展示 打开http://localhost:8762/actuator/hystrix.stream,可以看到一些具体的数据: 打开locahost:8762/hystrix 可以看见以下界面: 在界面依次输入:http://localhost:8762/actuator/hystrix.stream、2000 、miya ;点确定。 在另一个窗口输入:http://localhost:8762/hi?name=forezp 重新刷新hystrix.stream网页,你会看到良好的图形化界面: 源码下载:https://github.com/forezp/SpringCloudLearning/tree/master/sc-f-chapter12 五、参考资料 hystrix-dashboard 感谢您的关注!可加QQ1群:135430763,QQ2群:454796847,QQ3群:187424846。QQ群进群密码:xttblog,想加微信群的朋友,可以微信搜索:xmtxtt,备注:“xttblog”,添加助理微信拉你进群。备注错误不会同意好友申请。再次感谢您的关注!后续有精彩内容会第一时间发给您!原创文章投稿请发送至532009913@qq.com邮箱。商务合作可添加助理微信进行沟通!

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

Android Studio 3.0 最新版本运行报错: Task 'package' is ambiguous in root proje...

09:52:22.876 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:52:22.877 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 09:52:22.877 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:52:22.877 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 09:52:22.877 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Task 'package' is ambiguous in root project 'MyRobot'. Candidates are: 'packageDebug', 'packageDebugAndroidTest', 'packageRelease'. 09:52:22.877 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:52:22.877 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 09:52:22.878 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. 09:52:22.878 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 09:52:22.878 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org 09:52:22.879 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 09:52:22.879 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 1m 2s 09:52:22.914 [DEBUG] [org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices] [KOTLIN] Skipping kotlin cleanup since compiler wasn't called 09:52:22.944 [DEBUG] [org.jetbrains.kotlin.gradle.plugin.KotlinGradleBuildServices] [KOTLIN] Disposed KotlinGradleBuildServices 09:52:22.945 [DEBUG] [org.gradle.internal.work.DefaultWorkerLeaseService] Worker lease root.1 completed (0 worker(s) in use) $ gradle tasks Task :tasks All tasks runnable from root project Android tasks androidDependencies - Displays the Android dependencies of the project. signingReport - Displays the signing info for each variant. sourceSets - Prints out all the source sets defined in this project. Build tasks assemble - Assembles all variants of all applications and secondary packages. assembleAndroidTest - Assembles all the Test applications. assembleDebug - Assembles all Debug builds. assembleRelease - Assembles all Release builds. build - Assembles and tests this project. buildDependents - Assembles and tests this project and all projects that depend on it. buildNeeded - Assembles and tests this project and all projects it depends on. clean - Deletes the build directory. cleanBuildCache - Deletes the build cache directory. compileDebugAndroidTestSources compileDebugSources compileDebugUnitTestSources compileReleaseSources compileReleaseUnitTestSources mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests. Build Setup tasks init - Initializes a new Gradle build. wrapper - Generates Gradle wrapper files. Help tasks buildEnvironment - Displays all buildscript dependencies declared in root project 'MyRobot'. components - Displays the components produced by root project 'MyRobot'. [incubating] dependencies - Displays all dependencies declared in root project 'MyRobot'. dependencyInsight - Displays the insight into a specific dependency in root project 'MyRobot'. dependentComponents - Displays the dependent components of components in root project 'MyRobot'. [incubating] help - Displays a help message. model - Displays the configuration model of root project 'MyRobot'. [incubating] projects - Displays the sub-projects of root project 'MyRobot'. properties - Displays the properties of root project 'MyRobot'. tasks - Displays the tasks runnable from root project 'MyRobot' (some of the displayed tasks may belong to subprojects). Install tasks installDebug - Installs the Debug build. installDebugAndroidTest - Installs the android (on device) tests for the Debug build. uninstallAll - Uninstall all applications. uninstallDebug - Uninstalls the Debug build. uninstallDebugAndroidTest - Uninstalls the android (on device) tests for the Debug build. uninstallRelease - Uninstalls the Release build. Verification tasks check - Runs all checks. connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices. connectedCheck - Runs all device checks on currently connected devices. connectedDebugAndroidTest - Installs and runs the tests for debug on connected devices. deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers. deviceCheck - Runs all device checks using Device Providers and Test Servers. lint - Runs lint on all variants. lintDebug - Runs lint on the Debug build. lintRelease - Runs lint on the Release build. lintVitalRelease - Runs lint on just the fatal issues in the release build. test - Run unit tests for all variants. testDebugUnitTest - Run unit tests for the debug build. testReleaseUnitTest - Run unit tests for the release build. To see all tasks and more detail, run gradle tasks --all To see more detail about a task, run gradle help --task <task> BUILD SUCCESSFUL in 2s 1 actionable task: 1 executed

资源下载

更多资源
Nacos

Nacos

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

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

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

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