Easy Tag Write(3.1)
package skyseraph.android.util; import skyseraph.easytagwrite.R;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; public class CustomDialog extends Dialog {
public CustomDialog(Context context, int theme) {
super(context, theme);
} public CustomDialog(Context context) {
super(context);
} /**
* Helper class for creating a custom dialog
*/
public static class Builder { private Context context; private String title; private String message; private String positiveButtonText; private String negativeButtonText; private View contentView; private Drawable drawable; private DialogInterface.OnClickListener positiveButtonClickListener,
negativeButtonClickListener; public Builder(Context context) {
this.context = context;
} /**
* Set the Dialog message from String
*
* @param title
* @return
*/
public Builder setMessage(String message) {
this.message = message;
return this;
} /**
* Set the Dialog message from resource
*
* @param title
* @return
*/
public Builder setMessage(int message) {
this.message = (String)context.getText(message);
return this;
} /**
* Set the Dialog title from resource
*
* @param title
* @return
*/
public Builder setTitle(int title) {
this.title = (String)context.getText(title);
return this;
} /**
* Set the Dialog title from String
*
* @param title
* @return
*/
public Builder setTitle(String title) {
this.title = title;
return this;
} /***
* Set the Dialog Icon from resource
*
* @param imageres
* @return
*/
public Builder setIcon(int imageres) { this.drawable = context.getResources().getDrawable(imageres); return this;
} /***
* Set the Dialog Icon from Drawable
*
* @param drawable
* @return
*/
public Builder setIcon(Drawable drawable) {
this.drawable = drawable;
return this;
} /**
* Set a custom content view for the Dialog. If a message is set, the
* contentView is not added to the Dialog...
*
* @param v
* @return
*/
public Builder setContentView(View v) {
this.contentView = v;
return this;
} /**
* Set the positive button resource and it's listener
*
* @param positiveButtonText
* @param listener
* @return
*/
public Builder setPositiveButton(int positiveButtonText,
DialogInterface.OnClickListener listener) {
this.positiveButtonText = (String)context.getText(positiveButtonText);
this.positiveButtonClickListener = listener;
return this;
} /**
* Set the positive button text and it's listener
*
* @param positiveButtonText
* @param listener
* @return
*/
public Builder setPositiveButton(String positiveButtonText,
DialogInterface.OnClickListener listener) {
this.positiveButtonText = positiveButtonText;
this.positiveButtonClickListener = listener;
return this;
} /**
* Set the negative button resource and it's listener
*
* @param negativeButtonText
* @param listener
* @return
*/
public Builder setNegativeButton(int negativeButtonText,
DialogInterface.OnClickListener listener) {
this.negativeButtonText = (String)context.getText(negativeButtonText);
this.negativeButtonClickListener = listener;
return this;
} /**
* Set the negative button text and it's listener
*
* @param negativeButtonText
* @param listener
* @return
*/
public Builder setNegativeButton(String negativeButtonText,
DialogInterface.OnClickListener listener) {
this.negativeButtonText = negativeButtonText;
this.negativeButtonClickListener = listener;
return this;
} /**
* Create the custom dialog
*/
public CustomDialog create() {
LayoutInflater inflater = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// instantiate the dialog with the custom Theme
final CustomDialog dialog = new CustomDialog(context, R.style.Dialog);
View layout = inflater.inflate(R.layout.dialog, null);
dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
// set the dialog title
((TextView)layout.findViewById(R.id.title)).setText(title);
if (drawable != null) {
((ImageView)layout.findViewById(R.id.imageView1)).setImageDrawable(drawable);
} else {
((ImageView)layout.findViewById(R.id.imageView1)).setVisibility(View.GONE);
}
// set the confirm button
if (positiveButtonText != null) {
((Button)layout.findViewById(R.id.positiveButton)).setText(positiveButtonText);
if (positiveButtonClickListener != null) {
((Button)layout.findViewById(R.id.positiveButton))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
positiveButtonClickListener.onClick(dialog,
DialogInterface.BUTTON_POSITIVE);
}
});
}
} else {
// if no confirm button just set the visibility to GONE
layout.findViewById(R.id.positiveButton).setVisibility(View.GONE);
}
// set the cancel button
if (negativeButtonText != null) {
((Button)layout.findViewById(R.id.negativeButton)).setText(negativeButtonText);
if (negativeButtonClickListener != null) {
((Button)layout.findViewById(R.id.negativeButton))
.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
negativeButtonClickListener.onClick(dialog,
DialogInterface.BUTTON_NEGATIVE);
}
});
}
} else {
// if no confirm button just set the visibility to GONE
layout.findViewById(R.id.negativeButton).setVisibility(View.GONE);
}
// set the content message
if (message != null) {
((TextView)layout.findViewById(R.id.message)).setText(message);
} else if (contentView != null) {
// if no message set
// add the contentView to the dialog body
((LinearLayout)layout.findViewById(R.id.content)).removeAllViews();
((LinearLayout)layout.findViewById(R.id.content)).addView(contentView,
new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
dialog.setContentView(layout); return dialog;
} } }
Easy Tag Write(3.1)的更多相关文章
- Easy Tag Write(3.3)
package skyseraph.android.util; /** * @Title : Constant.java * @Package : tcl.nfc.tv.util * @ClassNa ...
- Easy Tag Write(3.2)
package skyseraph.android.util; /** * @Title : LogUtil.java * @Package : tcl.nfc.phone.util * @Class ...
- Easy Tag Write(2)
package skyseraph.android.util.nfc; import com.google.common.collect.BiMap; import com.google.common ...
- Easy Tag Write(1)
package skyseraph.easytagwrite; import skyseraph.android.util.CustomDialog; import skyseraph.android ...
- [LeetCode] 70. Climbing Stairs_ Easy tag: Dynamic Programming
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] 437. Path Sum III_ Easy tag: DFS
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
- [LeetCode] 257. Binary Tree Paths_ Easy tag: DFS
Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...
- [LeetCode] 101. Symmetric Tree_ Easy tag: BFS
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- JUnit5学习之五:标签(Tag)和自定义注解
欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...
随机推荐
- [转]如何解决外边距margin叠加的问题探讨
两个或多个毗邻的普通流中的块元素垂直方向上的 margin 会折叠,那么如何使元素上下margin不折叠呢?下面的方法或许对大家有所帮助 一.首先你要知道什么情况下会触发:两个或多个毗邻的普通流中的块 ...
- ARM大学计划全球经理到访华清远见,深入交流教育合作
来源:华清远见嵌入式学院 10月20日,ARM大学计划全球经理Khaled Benkrid,高级内容主编洪川博士在ARM大学计划亚太经理陈炜博士的陪同下到访华清远见,就最新嵌入式技术.ARM处理器在教 ...
- JavaScript第一天
1.静态的网页技术和动态的网页技术 静态网页是相对于动态网页而言,是指没有后台数据库.不含程序和不可交互的网页.你编的是什么它显示的就是什么.不会有任何改变.静态网页相对更新起来比较麻烦,适用于一般更 ...
- php5.6+apache2.4环境配置
Apache2.4 环境:https://www.microsoft.com/en-US/download/details.aspx?id=48145php5.6 环境:http://www.micr ...
- Unity -- EventSystem完全掌握
Event System 组成 系统生成的Event System里面主要有两个Components,分别是Event System和Standalone Input Module. 其中Standa ...
- Hibernate加载数据失败failed to lazily initialize a collection of role
在测试获取数据库中的数据或者在页面获取时,有时会遇到这样的错误提示: failed to lazily initialize a collection of role: com.exam.entity ...
- Windows 7无法卸载及安装IE11的解决方法
1. 清空 C:\Windows\TEMP\ 中的所有内容 2. 以管理员身份运行命令行,在命令中行输入下面的代码: FORFILES /P %WINDIR%\servicing\Packages ...
- PHP 使用 curl_* 系列函数和 curl_multi_* 系列函数进行多接口调用时的性能对比
在页面中调用的服务较多时,使用并行方式,即使用 curl_multi_* 系列函数耗时要小于 curl_* 系列函数. 测试环境 操作系统:Windows x64 Server:Apache PHP: ...
- Android开发环境搭建之Eclipse/AndroidStudio
时隔两年之后,回头来整理曾经走过的Android开发之路.记录下开发环境的配置,也方便与新入门的小伙伴们快速搭建自己的Android平台. 一.Android SDK Manager 1.下载与安装[ ...
- Oracle数据库基础知识2
字符操作相关_1 1.CONCAT关键字作用:连接字符串语法:CONCAT(字串1, 字串2)例如: CONCAT('hello','world') FROM DUAL; 注意:Oracle的CONC ...