commit 3ca2356881053ce4cd0e1e54a3752659ed352d5c Author: Jenly Date: Fri Jun 29 18:01:00 2018 +0800 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5edb4ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml new file mode 100644 index 0000000..1d1e989 --- /dev/null +++ b/.idea/assetWizardSettings.xml @@ -0,0 +1,57 @@ + + + + + + \ No newline at end of file diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser new file mode 100644 index 0000000..4efb1d7 Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..c2bae49 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..d28b75a --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..99202cc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/GIF.gif b/GIF.gif new file mode 100644 index 0000000..ac7c178 Binary files /dev/null and b/GIF.gif differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1861d82 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ + + The MIT License (MIT) + Copyright (c) 2017 Jenly Yu + https://github.com/jenly1314 + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files + (the "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..73aaf9b --- /dev/null +++ b/README.md @@ -0,0 +1,142 @@ +# AppUpdater + +![Image](app/ic_launcher-web.png) + +[![Download](https://img.shields.io/badge/download-App-blue.svg)](https://raw.githubusercontent.com/jenly1314/AppUpdater/master/app/release/app-release.apk) +[![](https://jitpack.io/v/jenly1314/AppUpdater.svg)](https://jitpack.io/#jenly1314/AppUpdater) +[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/mit-license.php) +[![Blog](https://img.shields.io/badge/blog-Jenly-9933CC.svg)](http://blog.csdn.net/jenly121) + +AppUpdater for Android 是一个专注于App更新一键傻瓜式集成的开源库,主要包括app-updater和app-dialog。 +> 下载更新和弹框提示分开,是因为这本来就是两个逻辑。完全独立开来能有效的解耦。 +* app-updater 主要负责后台下载更新App,无需担心下载时各种配置相关的细节,一键傻瓜式升级。 +* app-dialog 主要是提供常用的Dialog和DialogFragment,简化弹框提示,样式支持高度自定义。 +> app-updater + app-dialog 配合使用,谁用谁知道。 + + +## 功能介绍 +- [x] 专注于App更新一键傻瓜式升级 +- [x] 支持下载监听 +- [x] 支持下载失败,重新下载 +- [x] 支持通知栏提示内容和过程全部可配置 +- [x] 支持Android O + + + +## Gif 展示 +![Image](GIF.gif) + +## 引入 + +### Maven: +```maven + //app-updater + + com.king.app + app-updater + 1.0 + pom + + + //app-dialog + + com.king.app + app-dialog + 1.0 + pom + +``` +### Gradle: +```gradle + //app-updater + compile 'com.king.app:app-updater:1.0' + + //app-dialog + compile 'com.king.app:app-dialog:1.0' +``` +### Lvy: +```lvy + //app-updater + + + + + //app-dialog + + + +``` + +###### 如果Gradle出现compile失败的情况,可以在Project的build.gradle里面添加如下:(也可以使用上面的GitPack来complie) +```gradle + allprojects { + repositories { + //... + maven { url 'https://dl.bintray.com/jenly/maven' } + } + } +``` + +## 示例 + +```Java + //一句代码,傻瓜式更新 + new AppUpdater(getContext(),url).start(); +``` +```Java + //简单弹框升级 + AppDialogConfig config = new AppDialogConfig(); + config.setTitle("简单弹框升级") + .setOk("升级") + .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") + .setOnClickOk(new View.OnClickListener() { + @Override + public void onClick(View v) { + new AppUpdater.Builder() + .serUrl(mUrl) + .setFilename("AppUpdater.apk") + .build(getContext()) + .start(); + AppDialog.INSTANCE.dismissDialog(); + } + }); + AppDialog.INSTANCE.showDialog(getContext(),config); +``` +```Java + //简单DialogFragment升级 + AppDialogConfig config = new AppDialogConfig(); + config.setTitle("简单DialogFragment升级") + .setOk("升级") + .setContent("1、新增某某功能、\n2、修改某某问题、\n3、优化某某BUG、") + .setOnClickOk(new View.OnClickListener() { + @Override + public void onClick(View v) { + new AppUpdater.Builder() + .serUrl(mUrl) + .setFilename("AppUpdater.apk") + .build(getContext()) + .start(); + AppDialog.INSTANCE.dismissDialogFragment(getSupportFragmentManager()); + } + }); + AppDialog.INSTANCE.showDialogFragment(getSupportFragmentManager(),config); + +``` + +更多使用示例请查看[App](app)。 + + +## 关于我 + Name: Jenly + + Email: jenly1314#gmail.com / jenly1314#vip.qq.com + + CSDN: jenly121 + + Github: jenly1314 + + 微信公众号: + + ![公众号](http://olambmg9j.bkt.clouddn.com/jenly666.jpg) + + 加入QQ群: 20867961 \ No newline at end of file diff --git a/app-dialog/.gitignore b/app-dialog/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app-dialog/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app-dialog/bintray.gradle b/app-dialog/bintray.gradle new file mode 100644 index 0000000..94c2c6a --- /dev/null +++ b/app-dialog/bintray.gradle @@ -0,0 +1,10 @@ +apply plugin: 'com.novoda.bintray-release' +//添加 +publish { + userOrg = 'jenly'//bintray.com用户名 + groupId = 'com.king.app'//jcenter上的路径 + artifactId = 'app-dialog'//项目名称 + publishVersion = '1.0'//版本号 + desc = 'AppDialog for Android'//描述 + website = 'https://github.com/jenly1314/AppUpdater'//网站 +} \ No newline at end of file diff --git a/app-dialog/build.gradle b/app-dialog/build.gradle new file mode 100644 index 0000000..cc80d34 --- /dev/null +++ b/app-dialog/build.gradle @@ -0,0 +1,42 @@ +apply plugin: 'com.android.library' +apply from: 'bintray.gradle' + +android { + compileSdkVersion 27 + + + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 27 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + compileOnly 'com.android.support:appcompat-v7:27.1.1' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} + + + + + + + diff --git a/app-dialog/proguard-rules.pro b/app-dialog/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app-dialog/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app-dialog/src/androidTest/java/com/king/app/dialog/ExampleInstrumentedTest.java b/app-dialog/src/androidTest/java/com/king/app/dialog/ExampleInstrumentedTest.java new file mode 100644 index 0000000..53c32e3 --- /dev/null +++ b/app-dialog/src/androidTest/java/com/king/app/dialog/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.king.app.dialog; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.king.app.dialog.test", appContext.getPackageName()); + } +} diff --git a/app-dialog/src/main/AndroidManifest.xml b/app-dialog/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9403020 --- /dev/null +++ b/app-dialog/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java new file mode 100644 index 0000000..b25f000 --- /dev/null +++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialog.java @@ -0,0 +1,194 @@ +package com.king.app.dialog; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.support.annotation.StyleRes; +import android.support.v4.app.DialogFragment; +import android.support.v4.app.FragmentManager; +import android.text.TextUtils; +import android.view.KeyEvent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.TextView; + +import com.king.app.dialog.fragment.AppDialogFragment; + +/** + * @author Jenly Jenly + */ +public enum AppDialog { + + INSTANCE; + + private final float DEFAULT_WIDTH_RATIO = 0.85f; + + private Dialog mDialog; + + private String mTag; + + //------------------------------------------- + + public View createAppDialogView(Context context,AppDialogConfig config){ + View view = null; + if(config!=null){ + view = LayoutInflater.from(context).inflate(config.getLayoutId(),null); + TextView tvDialogTitle = view.findViewById(config.getTitleId()); + setText(tvDialogTitle,config.getTitle()); + + TextView tvDialogContent = view.findViewById(config.getContentId()); + setText(tvDialogContent,config.getContent()); + + Button btnDialogCancel = view.findViewById(config.getCancelId()); + setText(btnDialogCancel,config.getCancel()); + btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : mOnClickDismissDialog); + btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); + + try{ + //不强制要求要有横线 + View line = view.findViewById(R.id.line); + line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); + }catch (Exception e){ + + } + + Button btnDialogOK = view.findViewById(config.getOkId()); + setText(btnDialogOK,config.getOk()); + btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : mOnClickDismissDialog); + } + + return view; + } + + //------------------------------------------- + + private View.OnClickListener mOnClickDismissDialog = new View.OnClickListener() { + @Override + public void onClick(View v) { + dismissDialog(); + } + }; + + private void setText(TextView tv,CharSequence text){ + if(!TextUtils.isEmpty(text)){ + tv.setText(text); + } + } + + //------------------------------------------- + + public void dismissDialogFragment(FragmentManager fragmentManager){ + dismissDialogFragment(fragmentManager,mTag); + } + + public void dismissDialogFragment(FragmentManager fragmentManager,String tag){ + if(tag!=null){ + DialogFragment dialogFragment = (DialogFragment) fragmentManager.findFragmentByTag(tag); + dismissDialogFragment(dialogFragment); + } + } + + public void dismissDialogFragment(DialogFragment dialogFragment){ + if(dialogFragment!=null){ + dialogFragment.dismiss(); + } + } + + //------------------------------------------- + + public String showDialogFragment(FragmentManager fragmentManager,AppDialogConfig config){ + AppDialogFragment dialogFragment = AppDialogFragment.newInstance(config); + String tag = dialogFragment.getTag() !=null ? dialogFragment.getTag() : dialogFragment.getClass().getSimpleName(); + showDialogFragment(fragmentManager,dialogFragment,tag); + mTag = tag; + return tag; + } + + public String showDialogFragment(FragmentManager fragmentManager,DialogFragment dialogFragment){ + String tag = dialogFragment.getTag() !=null ? dialogFragment.getTag() : dialogFragment.getClass().getSimpleName(); + showDialogFragment(fragmentManager,dialogFragment,tag); + mTag = tag; + return tag; + } + + public String showDialogFragment(FragmentManager fragmentManager,DialogFragment dialogFragment, String tag) { + dialogFragment.show(fragmentManager,tag); + mTag = tag; + return tag; + } + + //------------------------------------------- + + public void showDialog(Context context,AppDialogConfig config){ + showDialog(context,createAppDialogView(context,config)); + } + + public void showDialog(Context context,View contentView){ + showDialog(context,contentView,DEFAULT_WIDTH_RATIO); + } + + public void showDialog(Context context,View contentView,boolean isCancel){ + showDialog(context,contentView,R.style.app_dialog,DEFAULT_WIDTH_RATIO,isCancel); + } + + public void showDialog(Context context,View contentView,float widthRatio){ + showDialog(context,contentView,widthRatio,true); + } + + public void showDialog(Context context,View contentView,float widthRatio,boolean isCancel){ + showDialog(context,contentView,R.style.app_dialog,widthRatio,isCancel); + } + + public void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio){ + showDialog(context,contentView,resId,widthRatio,true); + } + + /** + * + * @param context + * @param contentView + * @param resId Dialog样式 + * @param widthRatio + * @param isCancel 是否可取消(默认为true,false则拦截back键) + */ + public void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){ + mDialog = new Dialog(context,resId); + mDialog.setContentView(contentView); + mDialog.setCanceledOnTouchOutside(false); + mDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { + @Override + public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { + if(keyCode == KeyEvent.KEYCODE_BACK && isCancel){ + dismissDialog(); + } + return true; + + } + }); + setDialogWindow(context,mDialog,widthRatio); + mDialog.show(); + } + + private void setDialogWindow(Context context,Dialog dialog,float widthRatio){ + Window window = dialog.getWindow(); + WindowManager.LayoutParams lp = window.getAttributes(); + lp.width = (int)(context.getResources().getDisplayMetrics().widthPixels * widthRatio); + window.setAttributes(lp); + } + + public void dismissDialog(){ + dismissDialog(mDialog); + } + + private void dismissDialog(Dialog dialog){ + if(dialog!=null){ + dialog.dismiss(); + } + } + + //------------------------------------------- + +} diff --git a/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java new file mode 100644 index 0000000..cdb4c32 --- /dev/null +++ b/app-dialog/src/main/java/com/king/app/dialog/AppDialogConfig.java @@ -0,0 +1,156 @@ +package com.king.app.dialog; + +import android.support.annotation.IdRes; +import android.support.annotation.LayoutRes; +import android.view.View; + +/** + * @author Jenly Jenly + */ +public class AppDialogConfig { + + private @LayoutRes int layoutId = R.layout.app_dialog; + + private @IdRes int titleId = R.id.tvDialogTitle; + + private @IdRes int contentId = R.id.tvDialogContent; + + private @IdRes int cancelId = R.id.btnDialogCancel; + + private @IdRes int okId = R.id.btnDialogOK; + + private @IdRes int line = R.id.line; + + private CharSequence title; + + private CharSequence content; + + private CharSequence cancel; + + private CharSequence ok; + + private boolean isHideCancel; + + private View.OnClickListener onClickCancel; + + private View.OnClickListener onClickOk; + + public int getLayoutId() { + return layoutId; + } + + public AppDialogConfig setLayoutId(int layoutId) { + this.layoutId = layoutId; + return this; + } + + public int getTitleId() { + return titleId; + } + + public AppDialogConfig setTitleId(int titleId) { + this.titleId = titleId; + return this; + } + + public int getContentId() { + return contentId; + } + + public AppDialogConfig setContentId(int contentId) { + this.contentId = contentId; + return this; + } + + public int getCancelId() { + return cancelId; + } + + public AppDialogConfig setCancelId(int cancelId) { + this.cancelId = cancelId; + return this; + } + + public int getOkId() { + return okId; + } + + public AppDialogConfig setOkId(int okId) { + this.okId = okId; + return this; + } + + public int getLine() { + return line; + } + + public AppDialogConfig setLine(int line) { + this.line = line; + return this; + } + + public CharSequence getTitle() { + return title; + } + + public AppDialogConfig setTitle(CharSequence title) { + this.title = title; + return this; + } + + public CharSequence getContent() { + return content; + } + + public AppDialogConfig setContent(CharSequence content) { + this.content = content; + return this; + } + + public CharSequence getCancel() { + return cancel; + } + + public AppDialogConfig setCancel(CharSequence cancel) { + this.cancel = cancel; + return this; + } + + public CharSequence getOk() { + return ok; + } + + public AppDialogConfig setOk(CharSequence ok) { + this.ok = ok; + return this; + } + + public boolean isHideCancel() { + return isHideCancel; + } + + public AppDialogConfig setHideCancel(boolean hideCancel) { + isHideCancel = hideCancel; + return this; + } + + public View.OnClickListener getOnClickCancel() { + return onClickCancel; + } + + public AppDialogConfig setOnClickCancel(View.OnClickListener onClickCancel) { + this.onClickCancel = onClickCancel; + return this; + } + + public View.OnClickListener getOnClickOk() { + return onClickOk; + } + + public AppDialogConfig setOnClickOk(View.OnClickListener onClickOk) { + this.onClickOk = onClickOk; + return this; + } + + +} diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java new file mode 100644 index 0000000..38461a5 --- /dev/null +++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/AppDialogFragment.java @@ -0,0 +1,61 @@ +package com.king.app.dialog.fragment; + +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.king.app.dialog.AppDialogConfig; +import com.king.app.dialog.R; + +/** + * @author Jenly Jenly + */ +public class AppDialogFragment extends BaseDialogFragment { + + private AppDialogConfig config; + + public static AppDialogFragment newInstance(AppDialogConfig config) { + + Bundle args = new Bundle(); + AppDialogFragment fragment = new AppDialogFragment(); + fragment.config = config; + fragment.setArguments(args); + return fragment; + } + + @Override + public int getRootLayoutId() { + if(config == null){ + config = new AppDialogConfig(); + } + return config.getLayoutId(); + } + + public void init(View rootView){ + if(config!=null){ + TextView tvDialogTitle = rootView.findViewById(config.getTitleId()); + setText(tvDialogTitle,config.getTitle()); + + TextView tvDialogContent = rootView.findViewById(config.getContentId()); + setText(tvDialogContent,config.getContent()); + + Button btnDialogCancel = rootView.findViewById(config.getCancelId()); + setText(btnDialogCancel,config.getCancel()); + btnDialogCancel.setOnClickListener(config.getOnClickCancel() != null ? config.getOnClickCancel() : getOnClickDismiss()); + btnDialogCancel.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); + + try{ + //不强制要求要有横线 + View line = rootView.findViewById(R.id.line); + line.setVisibility(config.isHideCancel() ? View.GONE : View.VISIBLE); + }catch (Exception e){ + + } + + Button btnDialogOK = rootView.findViewById(config.getOkId()); + setText(btnDialogOK,config.getOk()); + btnDialogOK.setOnClickListener(config.getOnClickOk() != null ? config.getOnClickOk() : getOnClickDismiss()); + } + } +} diff --git a/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java b/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java new file mode 100644 index 0000000..4e9b2b3 --- /dev/null +++ b/app-dialog/src/main/java/com/king/app/dialog/fragment/BaseDialogFragment.java @@ -0,0 +1,59 @@ +package com.king.app.dialog.fragment; + +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.DialogFragment; +import android.text.TextUtils; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.widget.TextView; + +/** + * @author Jenly Jenly + */ +public abstract class BaseDialogFragment extends DialogFragment { + + private View mRootView; + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + super.getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); + super.getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + + mRootView = inflater.inflate(getRootLayoutId(), container, false); + init(mRootView); + return mRootView; + } + + protected View getRootView(){ + return mRootView; + } + + protected void setText(TextView tv, CharSequence text){ + if(!TextUtils.isEmpty(text)){ + tv.setText(text); + } + } + + protected View.OnClickListener getOnClickDismiss(){ + return mOnClickDismissDialog; + } + + private View.OnClickListener mOnClickDismissDialog = new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }; + + public abstract int getRootLayoutId(); + + public abstract void init(View rootView); + +} diff --git a/app-dialog/src/main/res/anim/app_dialog_in.xml b/app-dialog/src/main/res/anim/app_dialog_in.xml new file mode 100644 index 0000000..847f7a0 --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_in.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/anim/app_dialog_out.xml b/app-dialog/src/main/res/anim/app_dialog_out.xml new file mode 100644 index 0000000..b6709a1 --- /dev/null +++ b/app-dialog/src/main/res/anim/app_dialog_out.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/color/app_dialog_button_color_selector.xml b/app-dialog/src/main/res/color/app_dialog_button_color_selector.xml new file mode 100644 index 0000000..3192378 --- /dev/null +++ b/app-dialog/src/main/res/color/app_dialog_button_color_selector.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/drawable/app_dialog_bg.xml b/app-dialog/src/main/res/drawable/app_dialog_bg.xml new file mode 100644 index 0000000..0c984ca --- /dev/null +++ b/app-dialog/src/main/res/drawable/app_dialog_bg.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/app-dialog/src/main/res/layout/app_dialog.xml b/app-dialog/src/main/res/layout/app_dialog.xml new file mode 100644 index 0000000..f5431f5 --- /dev/null +++ b/app-dialog/src/main/res/layout/app_dialog.xml @@ -0,0 +1,60 @@ + + + + + + +