微信公众号
使用方法
将libray模块复制到项目中,或者直接在build.gradle中依赖:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.AnJiaoDe:BaseDialog:V1.1.8'
}
1.Center
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/white_shape"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="80dp"
android:text="确定删除吗?"
android:textSize="16sp"
android:gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/line"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="48dp"
android:text="取消"
android:id="@+id/tv_cancel"
android:gravity="center"
android:textSize="16sp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/line"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:id="@+id/tv_confirm"
android:layout_height="48dp"
android:text="确定"
android:gravity="center"
android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>
2.Left
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Google Assistant: 一句 OK, Google,多少手指都用不上了
人工智能是今年的 Google I/O 的一大主题。在发布会一开始,Google CEO 桑达拉·皮蔡(Sundar Pichai)就强调机器学习在生活中扮演的重要角色。随后,一系列基于 Google 人工智能的产品纷至沓来。
OK, Google. 这句耳熟能详的命令,如今承载了 Google 全新的产品——Google Assistant.
之所以 Google Assistant 是发布会上首个亮相的产品,是因为后续登场的数个产品都基于这一技术。Google 用将近十年的时间,改善自己的语音识别技术,更强调自然语义和对话式搜索。"
android:textSize="16sp" />
</LinearLayout>
3.Top
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_photo"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="拍照"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/line" />
<TextView
android:id="@+id/tv_album"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="从相册选择"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@color/bg"/>
<TextView
android:id="@+id/tv_photo_cancel"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="取消"
android:textSize="16sp" />
</LinearLayout>
4.Right
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Google Assistant: 一句 OK, Google,多少手指都用不上了
人工智能是今年的 Google I/O 的一大主题。在发布会一开始,Google CEO 桑达拉·皮蔡(Sundar Pichai)就强调机器学习在生活中扮演的重要角色。随后,一系列基于 Google 人工智能的产品纷至沓来。
OK, Google. 这句耳熟能详的命令,如今承载了 Google 全新的产品——Google Assistant.
之所以 Google Assistant 是发布会上首个亮相的产品,是因为后续登场的数个产品都基于这一技术。Google 用将近十年的时间,改善自己的语音识别技术,更强调自然语义和对话式搜索。"
android:textSize="16sp" />
</LinearLayout>
5.Bottom
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_photo"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="拍照"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/line" />
<TextView
android:id="@+id/tv_album"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="从相册选择"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@color/bg"/>
<TextView
android:id="@+id/tv_photo_cancel"
android:layout_width="match_parent"
android:layout_height="56dp"
android:gravity="center"
android:text="取消"
android:textSize="16sp" />
</LinearLayout>
6.Progress
public class MainActivity extends BaseActivity {
private BaseDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_center).setOnClickListener(this);
findViewById(R.id.btn_left).setOnClickListener(this);
findViewById(R.id.btn_top).setOnClickListener(this);
findViewById(R.id.btn_right).setOnClickListener(this);
findViewById(R.id.btn_bottom).setOnClickListener(this);
findViewById(R.id.btn_progress).setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_center:
dialog = new BaseDialog(this);
dialog.contentView(R.layout.dialog_center)
.canceledOnTouchOutside(true).show();
dialog.findViewById(R.id.tv_confirm).setOnClickListener(this);
dialog.findViewById(R.id.tv_cancel).setOnClickListener(this);
break;
case R.id.btn_left:
BaseDialog dialog_left = new BaseDialog(this);
dialog_left.contentView(R.layout.dialog_left)
.layoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
.dimAmount(0.5f)
.gravity(Gravity.LEFT | Gravity.CENTER)
.animType(BaseDialog.AnimInType.LEFT)
.canceledOnTouchOutside(true).show();
break;
case R.id.btn_top:
BaseDialog dialog_top = new BaseDialog(this);
dialog_top.contentView(R.layout.dialog_photo)
.layoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
.dimAmount(0.5f)
.gravity(Gravity.TOP)
.offset(0, ScreenUtils.dpInt2px(this, 48))
.animType(BaseDialog.AnimInType.TOP)
.canceledOnTouchOutside(true).show();
break;
case R.id.btn_right:
BaseDialog dialog_right = new BaseDialog(this);
dialog_right.contentView(R.layout.dialog_right)
.layoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT))
.gravity(Gravity.RIGHT | Gravity.CENTER)
.animType(BaseDialog.AnimInType.RIGHT)
.offset(20, 0)
.canceledOnTouchOutside(true).show();
break;
case R.id.btn_bottom:
BaseDialog dialog_bottom = new BaseDialog(this);
dialog_bottom.contentView(R.layout.dialog_photo)
.gravity(Gravity.BOTTOM)
.animType(BaseDialog.AnimInType.BOTTOM)
.canceledOnTouchOutside(true).show();
break;
case R.id.btn_progress:
ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.color_iv(0xffffffff)
.color_bg_progress(0xffffffff)
.colors_progress(0xff2a5caa).show();
break;
case R.id.tv_confirm:
dialog.dismiss();
break;
case R.id.tv_cancel:
dialog.dismiss();
break;
}
}
}
源码:
BaseDialog
``` public class BaseDialog extends Dialog {
public BaseDialog(Context context) {
this(context, 0);
}
public BaseDialog(Context context, int themeResId) {
super(context, themeResId);
requestWindowFeature(Window.FEATURE_NO_TITLE);// 去除对话框的标题
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColor(0x00000000);
getWindow().setBackgroundDrawable(gradientDrawable);//设置对话框边框背景,必须在代码中设置对话框背景,不然对话框背景是黑色的
dimAmount(0.2f);
}
public BaseDialog contentView(@LayoutRes int layoutResID) {
getWindow().setContentView(layoutResID);
return this;
}
public BaseDialog contentView(@NonNull View view) {
getWindow().setContentView(view);
return this;
}
public BaseDialog contentView(@NonNull View view, @Nullable ViewGroup.LayoutParams params) {
getWindow().setContentView(view, params);
return this;
}
public BaseDialog layoutParams(@Nullable ViewGroup.LayoutParams params) {
getWindow().setLayout(params.width, params.height);
return this;
}
/**
* 点击外面是否能dissmiss
*
* @param canceledOnTouchOutside
* @return
*/
public BaseDialog canceledOnTouchOutside(boolean canceledOnTouchOutside) {
setCanceledOnTouchOutside(canceledOnTouchOutside);
return this;
}
/**
* 位置
*
* @param gravity
* @return
*/
public BaseDialog gravity(int gravity) {
getWindow().setGravity(gravity);
return this;
}
/**
* 偏移
*
* @param x
* @param y
* @return
*/
public BaseDialog offset(int x, int y) {
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.x = x;
layoutParams.y = y;
return this;
}
/*
设置背景阴影,必须setContentView之后调用才生效
*/
public BaseDialog dimAmount(float dimAmount) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.dimAmount = dimAmount;
return this;
}
/*
动画类型 */ public BaseDialog animType(BaseDialog.AnimInType animInType) {
switch (animInType.getIntType()) {
case 0:
getWindow().setWindowAnimations(R.style.dialog_zoom);
break;
case 1:
getWindow().setWindowAnimations(R.style.dialog_anim_left);
break;
case 2:
getWindow().setWindowAnimations(R.style.dialog_anim_top);
break;
case 3:
getWindow().setWindowAnimations(R.style.dialog_anim_right);
break;
case 4:
getWindow().setWindowAnimations(R.style.dialog_anim_bottom);
$ claude mcp add BaseDialog \
-- python -m otcore.mcp_server <graph>