├── .gitignore ├── ColorDialog ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── refactor │ │ └── lib │ │ └── colordialog │ │ ├── AnimationLoader.java │ │ ├── ColorDialog.java │ │ ├── PromptDialog.java │ │ └── util │ │ └── DisplayUtil.java │ └── res │ ├── drawable │ ├── sel_btn.xml │ ├── sel_btn_help.xml │ ├── sel_btn_info.xml │ ├── sel_btn_success.xml │ ├── sel_btn_warning.xml │ ├── sel_btn_wrong.xml │ ├── sel_def_gray.xml │ ├── sel_def_gray_left.xml │ ├── sel_def_gray_right.xml │ ├── shape_corners_bottom.xml │ ├── shape_corners_bottom_normal.xml │ ├── shape_left_bottom.xml │ ├── shape_left_bottom_normal.xml │ ├── shape_right_bottom.xml │ ├── shape_right_bottom_normal.xml │ └── shape_top.xml │ ├── layout │ ├── layout_colordialog.xml │ └── layout_promptdialog.xml │ ├── mipmap │ ├── ic_help.png │ ├── ic_info.png │ ├── ic_success.png │ ├── ic_wrong.png │ └── icon_warning.png │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml ├── README.md ├── art ├── Screenshot_img.png ├── Screenshot_imgtext.png ├── Screenshot_setcolor.png ├── Screenshot_text.png ├── Screenshot_type_error.png ├── Screenshot_type_help.png ├── Screenshot_type_info.png ├── Screenshot_type_success.png └── Screenshot_type_warning.png ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── refactor │ │ └── sample │ │ └── colordialog │ │ └── MainActivity.java │ └── res │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── sample_img.jpg │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | *.DS_Store 3 | 4 | # Gradle files 5 | build/ 6 | .gradle/ 7 | */build/ 8 | 9 | 10 | # IDEA 11 | *.iml 12 | .idea/ 13 | 14 | # Built application files 15 | *.apk 16 | *.ap_ 17 | 18 | # Files for the Dalvik VM 19 | *.dex 20 | 21 | # Java class files 22 | *.class 23 | 24 | # Local configuration file (sdk path, etc) 25 | local.properties 26 | 27 | # Log Files 28 | *.log -------------------------------------------------------------------------------- /ColorDialog/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml -------------------------------------------------------------------------------- /ColorDialog/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group='com.github.andyxialm' 4 | 5 | android { 6 | compileSdkVersion 24 7 | buildToolsVersion "24.0.2" 8 | 9 | defaultConfig { 10 | minSdkVersion 14 11 | targetSdkVersion 24 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | } 26 | -------------------------------------------------------------------------------- /ColorDialog/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/andy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /ColorDialog/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /ColorDialog/src/main/java/cn/refactor/lib/colordialog/AnimationLoader.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.lib.colordialog; 2 | 3 | import android.content.Context; 4 | import android.view.animation.AlphaAnimation; 5 | import android.view.animation.Animation; 6 | import android.view.animation.AnimationSet; 7 | import android.view.animation.ScaleAnimation; 8 | 9 | /** 10 | * 作者 : andy 11 | * 日期 : 15/11/16 12:23 12 | * 邮箱 : andyxialm@gmail.com 13 | * 描述 : 默认动画效果 14 | */ 15 | public class AnimationLoader { 16 | public static AnimationSet getInAnimation(Context context) { 17 | AnimationSet in = new AnimationSet(context, null); 18 | 19 | AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f); 20 | alpha.setDuration(90); 21 | 22 | ScaleAnimation scale1 = new ScaleAnimation(0.8f, 1.05f, 0.8f, 1.05f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 23 | scale1.setDuration(135); 24 | 25 | ScaleAnimation scale2 = new ScaleAnimation(1.05f, 0.95f, 1.05f, 0.95f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 26 | scale2.setDuration(105); 27 | scale2.setStartOffset(135); 28 | 29 | ScaleAnimation scale3 = new ScaleAnimation(0.95f, 1f, 0.95f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 30 | scale3.setDuration(60); 31 | scale3.setStartOffset(240); 32 | 33 | in.addAnimation(alpha); 34 | in.addAnimation(scale1); 35 | in.addAnimation(scale2); 36 | in.addAnimation(scale3); 37 | 38 | return in; 39 | } 40 | 41 | public static AnimationSet getOutAnimation(Context context) { 42 | AnimationSet out = new AnimationSet(context, null); 43 | AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f); 44 | alpha.setDuration(150); 45 | ScaleAnimation scale = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 46 | scale.setDuration(150); 47 | out.addAnimation(alpha); 48 | out.addAnimation(scale); 49 | return out; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /ColorDialog/src/main/java/cn/refactor/lib/colordialog/ColorDialog.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.lib.colordialog; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.drawable.Drawable; 9 | import android.graphics.drawable.ShapeDrawable; 10 | import android.graphics.drawable.shapes.RoundRectShape; 11 | import android.os.Bundle; 12 | import android.text.TextUtils; 13 | import android.view.Gravity; 14 | import android.view.View; 15 | import android.view.animation.Animation; 16 | import android.view.animation.AnimationSet; 17 | import android.widget.FrameLayout; 18 | import android.widget.ImageView; 19 | import android.widget.TextView; 20 | 21 | import cn.refactor.lib.colordialog.util.DisplayUtil; 22 | 23 | /** 24 | * 作者 : andy 25 | * 日期 : 15/11/7 17:26 26 | * 邮箱 : andyxialm@gmail.com 27 | * 描述 : Dialog 28 | */ 29 | public class ColorDialog extends Dialog implements View.OnClickListener { 30 | 31 | private ImageView mContentIv; 32 | 33 | private Bitmap mContentBitmap; 34 | 35 | private View mBtnGroupView, mDividerView, mBkgView, mDialogView; 36 | 37 | private TextView mTitleTv, mContentTv, mPositiveBtn, mNegativeBtn; 38 | 39 | private Drawable mDrawable; 40 | 41 | private AnimationSet mAnimIn, mAnimOut; 42 | 43 | private int mResId, mBackgroundColor, mTitleTextColor, mContentTextColor; 44 | 45 | private OnPositiveListener mPositiveListener; 46 | 47 | private OnNegativeListener mNegativeListener; 48 | 49 | private CharSequence mTitleText, mContentText, mPositiveText, mNegativeText; 50 | 51 | private boolean mIsShowAnim; 52 | 53 | public ColorDialog(Context context) { 54 | this(context, 0); 55 | } 56 | 57 | public ColorDialog(Context context, int theme) { 58 | super(context, R.style.color_dialog); 59 | init(); 60 | } 61 | 62 | private void callDismiss() { 63 | super.dismiss(); 64 | } 65 | 66 | private void init() { 67 | mAnimIn = AnimationLoader.getInAnimation(getContext()); 68 | mAnimOut = AnimationLoader.getOutAnimation(getContext()); 69 | initAnimListener(); 70 | } 71 | 72 | @Override 73 | public void setTitle(CharSequence title) { 74 | mTitleText = title; 75 | } 76 | 77 | @Override 78 | public void setTitle(int titleId) { 79 | setTitle(getContext().getText(titleId)); 80 | } 81 | 82 | @Override 83 | protected void onCreate(Bundle savedInstanceState) { 84 | super.onCreate(savedInstanceState); 85 | View contentView = View.inflate(getContext(), R.layout.layout_colordialog, null); 86 | setContentView(contentView); 87 | 88 | mDialogView = getWindow().getDecorView().findViewById(android.R.id.content); 89 | mBkgView = contentView.findViewById(R.id.llBkg); 90 | mTitleTv = (TextView) contentView.findViewById(R.id.tvTitle); 91 | mContentTv = (TextView) contentView.findViewById(R.id.tvContent); 92 | mContentIv = (ImageView) contentView.findViewById(R.id.ivContent); 93 | 94 | mPositiveBtn = (TextView) contentView.findViewById(R.id.btnPositive); 95 | mNegativeBtn = (TextView) contentView.findViewById(R.id.btnNegative); 96 | 97 | mDividerView = contentView.findViewById(R.id.divider); 98 | mBtnGroupView = contentView.findViewById(R.id.llBtnGroup); 99 | 100 | mPositiveBtn.setOnClickListener(this); 101 | mNegativeBtn.setOnClickListener(this); 102 | 103 | mTitleTv.setText(mTitleText); 104 | mContentTv.setText(mContentText); 105 | mPositiveBtn.setText(mPositiveText); 106 | mNegativeBtn.setText(mNegativeText); 107 | 108 | if (null == mPositiveListener && null == mNegativeListener) { 109 | mBtnGroupView.setVisibility(View.GONE); 110 | } else if (null == mPositiveListener && null != mNegativeListener) { 111 | mPositiveBtn.setVisibility(View.GONE); 112 | mDividerView.setVisibility(View.GONE); 113 | mNegativeBtn.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.sel_def_gray)); 114 | } else if (null != mPositiveListener && null == mNegativeListener ) { 115 | mNegativeBtn.setVisibility(View.GONE); 116 | mDividerView.setVisibility(View.GONE); 117 | mPositiveBtn.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.sel_def_gray)); 118 | } 119 | 120 | if (null != mDrawable) { 121 | mContentIv.setBackgroundDrawable(mDrawable); 122 | } 123 | 124 | if (null != mContentBitmap) { 125 | mContentIv.setImageBitmap(mContentBitmap); 126 | } 127 | 128 | if (0 != mResId) { 129 | mContentIv.setBackgroundResource(mResId); 130 | } 131 | 132 | setTextColor(); 133 | 134 | setBackgroundColor(); 135 | 136 | setContentMode(); 137 | } 138 | 139 | @Override 140 | protected void onStart() { 141 | super.onStart(); 142 | startWithAnimation(mIsShowAnim); 143 | } 144 | 145 | @Override 146 | public void dismiss() { 147 | dismissWithAnimation(mIsShowAnim); 148 | } 149 | 150 | private void startWithAnimation(boolean showInAnimation) { 151 | if (showInAnimation) { 152 | mDialogView.startAnimation(mAnimIn); 153 | } 154 | } 155 | 156 | private void dismissWithAnimation(boolean showOutAnimation) { 157 | if (showOutAnimation) { 158 | mDialogView.startAnimation(mAnimOut); 159 | } else { 160 | super.dismiss(); 161 | } 162 | } 163 | 164 | private void initAnimListener() { 165 | mAnimOut.setAnimationListener(new Animation.AnimationListener() { 166 | @Override 167 | public void onAnimationStart(Animation animation) { 168 | } 169 | 170 | @Override 171 | public void onAnimationEnd(Animation animation) { 172 | mDialogView.post(new Runnable() { 173 | @Override 174 | public void run() { 175 | callDismiss(); 176 | } 177 | }); 178 | } 179 | 180 | @Override 181 | public void onAnimationRepeat(Animation animation) { 182 | } 183 | }); 184 | } 185 | 186 | private void setBackgroundColor() { 187 | 188 | if (0 == mBackgroundColor) { 189 | return; 190 | } 191 | 192 | int radius = DisplayUtil.dp2px(getContext(), 6); 193 | float[] outerRadii = new float[] { radius, radius, radius, radius, 0, 0, 0, 0 }; 194 | RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null); 195 | ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); 196 | shapeDrawable.getPaint().setColor(mBackgroundColor); 197 | shapeDrawable.getPaint().setStyle(Paint.Style.FILL); 198 | mBkgView.setBackgroundDrawable(shapeDrawable); 199 | } 200 | 201 | private void setTextColor() { 202 | 203 | if (0 != mTitleTextColor) { 204 | mTitleTv.setTextColor(mTitleTextColor); 205 | } 206 | 207 | if (0 != mContentTextColor) { 208 | mContentTv.setTextColor(mContentTextColor); 209 | } 210 | 211 | } 212 | 213 | private void setContentMode() { 214 | boolean isImageMode = (null != mDrawable | null != mContentBitmap | 0 != mResId); 215 | boolean isTextMode = (!TextUtils.isEmpty(mContentText)); 216 | 217 | if (isImageMode && isTextMode) { 218 | FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mContentTv.getLayoutParams(); 219 | params.gravity = Gravity.BOTTOM; 220 | mContentTv.setLayoutParams(params); 221 | mContentTv.setBackgroundColor(Color.BLACK); 222 | mContentTv.getBackground().setAlpha(0x28); 223 | mContentTv.setVisibility(View.VISIBLE); 224 | mContentIv.setVisibility(View.VISIBLE); 225 | return; 226 | } 227 | 228 | if (isTextMode) { 229 | FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mContentTv.getLayoutParams(); 230 | params.gravity = Gravity.NO_GRAVITY; 231 | mContentTv.setLayoutParams(params); 232 | mContentIv.setVisibility(View.GONE); 233 | mContentTv.setVisibility(View.VISIBLE); 234 | return; 235 | } 236 | 237 | if (isImageMode) { 238 | mContentTv.setVisibility(View.GONE); 239 | mContentIv.setVisibility(View.VISIBLE); 240 | return; 241 | } 242 | 243 | } 244 | 245 | @Override 246 | public void onClick(View v) { 247 | int id = v.getId(); 248 | 249 | if (R.id.btnPositive == id) { 250 | mPositiveListener.onClick(this); 251 | } else if (R.id.btnNegative == id) { 252 | mNegativeListener.onClick(this); 253 | } else { 254 | } 255 | } 256 | 257 | public ColorDialog setAnimationEnable(boolean enable) { 258 | mIsShowAnim = enable; 259 | return this; 260 | } 261 | 262 | public ColorDialog setAnimationIn(AnimationSet animIn) { 263 | mAnimIn = animIn; 264 | return this; 265 | } 266 | 267 | public ColorDialog setAnimationOut(AnimationSet animOut) { 268 | mAnimOut = animOut; 269 | initAnimListener(); 270 | return this; 271 | } 272 | 273 | public ColorDialog setColor(int color) { 274 | mBackgroundColor = color; 275 | return this; 276 | } 277 | 278 | public ColorDialog setColor(String color) { 279 | try { 280 | setColor(Color.parseColor(color)); 281 | } catch (IllegalArgumentException e) { 282 | e.printStackTrace(); 283 | } 284 | return this; 285 | } 286 | 287 | public ColorDialog setTitleTextColor(int color) { 288 | mTitleTextColor = color; 289 | return this; 290 | } 291 | 292 | public ColorDialog setTitleTextColor(String color) { 293 | try { 294 | setTitleTextColor(Color.parseColor(color)); 295 | } catch (IllegalArgumentException e) { 296 | e.printStackTrace(); 297 | } 298 | return this; 299 | } 300 | 301 | public ColorDialog setContentTextColor(int color) { 302 | mContentTextColor = color; 303 | return this; 304 | } 305 | 306 | public ColorDialog setContentTextColor(String color) { 307 | try { 308 | setContentTextColor(Color.parseColor(color)); 309 | } catch (IllegalArgumentException e) { 310 | e.printStackTrace(); 311 | } 312 | return this; 313 | } 314 | 315 | 316 | public ColorDialog setPositiveListener(CharSequence text, OnPositiveListener l) { 317 | mPositiveText = text; 318 | mPositiveListener = l; 319 | return this; 320 | } 321 | 322 | public ColorDialog setPositiveListener(int textId, OnPositiveListener l) { 323 | return setPositiveListener(getContext().getText(textId), l); 324 | } 325 | 326 | public ColorDialog setNegativeListener(CharSequence text, OnNegativeListener l) { 327 | mNegativeText = text; 328 | mNegativeListener = l; 329 | return this; 330 | } 331 | 332 | public ColorDialog setNegativeListener(int textId, OnNegativeListener l) { 333 | return setNegativeListener(getContext().getText(textId), l); 334 | } 335 | 336 | public ColorDialog setContentText(CharSequence text) { 337 | mContentText = text; 338 | return this; 339 | } 340 | 341 | public ColorDialog setContentText(int textId) { 342 | return setContentText(getContext().getText(textId)); 343 | } 344 | 345 | public ColorDialog setContentImage(Drawable drawable) { 346 | mDrawable = drawable; 347 | return this; 348 | } 349 | 350 | public ColorDialog setContentImage(Bitmap bitmap) { 351 | mContentBitmap = bitmap; 352 | return this; 353 | } 354 | 355 | public ColorDialog setContentImage(int resId) { 356 | mResId = resId; 357 | return this; 358 | } 359 | 360 | public CharSequence getContentText() { 361 | return mContentText; 362 | } 363 | 364 | public CharSequence getTitleText() { 365 | return mTitleText; 366 | } 367 | 368 | public CharSequence getPositiveText() { 369 | return mPositiveText; 370 | } 371 | 372 | public CharSequence getNegativeText() { 373 | return mNegativeText; 374 | } 375 | 376 | public interface OnPositiveListener { 377 | void onClick(ColorDialog dialog); 378 | } 379 | 380 | public interface OnNegativeListener { 381 | void onClick(ColorDialog dialog); 382 | } 383 | } 384 | -------------------------------------------------------------------------------- /ColorDialog/src/main/java/cn/refactor/lib/colordialog/PromptDialog.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.lib.colordialog; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.res.ColorStateList; 6 | import android.graphics.Bitmap; 7 | import android.graphics.Canvas; 8 | import android.graphics.Color; 9 | import android.graphics.Paint; 10 | import android.graphics.Path; 11 | import android.graphics.drawable.ShapeDrawable; 12 | import android.graphics.drawable.shapes.RoundRectShape; 13 | import android.os.Bundle; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.view.WindowManager; 17 | import android.view.animation.Animation; 18 | import android.view.animation.AnimationSet; 19 | import android.widget.ImageView; 20 | import android.widget.LinearLayout; 21 | import android.widget.TextView; 22 | 23 | import cn.refactor.lib.colordialog.util.DisplayUtil; 24 | 25 | /** 26 | * 作者 : andy 27 | * 日期 : 15/11/10 11:28 28 | * 邮箱 : andyxialm@gmail.com 29 | * 描述 : 提示性的Dialog 30 | */ 31 | public class PromptDialog extends Dialog { 32 | 33 | private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888; 34 | private static final int DEFAULT_RADIUS = 6; 35 | public static final int DIALOG_TYPE_INFO = 0; 36 | public static final int DIALOG_TYPE_HELP = 1; 37 | public static final int DIALOG_TYPE_WRONG = 2; 38 | public static final int DIALOG_TYPE_SUCCESS = 3; 39 | public static final int DIALOG_TYPE_WARNING = 4; 40 | public static final int DIALOG_TYPE_DEFAULT = DIALOG_TYPE_INFO; 41 | 42 | private AnimationSet mAnimIn, mAnimOut; 43 | private View mDialogView; 44 | private TextView mTitleTv, mContentTv, mPositiveBtn; 45 | private OnPositiveListener mOnPositiveListener; 46 | 47 | private int mDialogType; 48 | private boolean mIsShowAnim; 49 | private CharSequence mTitle, mContent, mBtnText; 50 | 51 | public PromptDialog(Context context) { 52 | this(context, 0); 53 | } 54 | 55 | public PromptDialog(Context context, int theme) { 56 | super(context, R.style.color_dialog); 57 | init(); 58 | } 59 | 60 | private void init() { 61 | mAnimIn = AnimationLoader.getInAnimation(getContext()); 62 | mAnimOut = AnimationLoader.getOutAnimation(getContext()); 63 | } 64 | 65 | 66 | @Override 67 | protected void onCreate(Bundle savedInstanceState) { 68 | super.onCreate(savedInstanceState); 69 | 70 | initView(); 71 | 72 | initListener(); 73 | 74 | } 75 | 76 | private void initView() { 77 | View contentView = View.inflate(getContext(), R.layout.layout_promptdialog, null); 78 | setContentView(contentView); 79 | resizeDialog(); 80 | 81 | mDialogView = getWindow().getDecorView().findViewById(android.R.id.content); 82 | mTitleTv = (TextView) contentView.findViewById(R.id.tvTitle); 83 | mContentTv = (TextView) contentView.findViewById(R.id.tvContent); 84 | mPositiveBtn = (TextView) contentView.findViewById(R.id.btnPositive); 85 | 86 | View llBtnGroup = findViewById(R.id.llBtnGroup); 87 | ImageView logoIv = (ImageView) contentView.findViewById(R.id.logoIv); 88 | logoIv.setBackgroundResource(getLogoResId(mDialogType)); 89 | 90 | LinearLayout topLayout = (LinearLayout) contentView.findViewById(R.id.topLayout); 91 | ImageView triangleIv = new ImageView(getContext()); 92 | triangleIv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DisplayUtil.dp2px(getContext(), 10))); 93 | triangleIv.setImageBitmap(createTriangel((int) (DisplayUtil.getScreenSize(getContext()).x * 0.7), DisplayUtil.dp2px(getContext(), 10))); 94 | topLayout.addView(triangleIv); 95 | 96 | setBtnBackground(mPositiveBtn); 97 | setBottomCorners(llBtnGroup); 98 | 99 | 100 | int radius = DisplayUtil.dp2px(getContext(), DEFAULT_RADIUS); 101 | float[] outerRadii = new float[] { radius, radius, radius, radius, 0, 0, 0, 0 }; 102 | RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null); 103 | ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); 104 | shapeDrawable.getPaint().setStyle(Paint.Style.FILL); 105 | shapeDrawable.getPaint().setColor(getContext().getResources().getColor(getColorResId(mDialogType))); 106 | LinearLayout llTop = (LinearLayout) findViewById(R.id.llTop); 107 | llTop.setBackgroundDrawable(shapeDrawable); 108 | 109 | mTitleTv.setText(mTitle); 110 | mContentTv.setText(mContent); 111 | mPositiveBtn.setText(mBtnText); 112 | } 113 | 114 | private void resizeDialog() { 115 | WindowManager.LayoutParams params = getWindow().getAttributes(); 116 | params.width = (int)(DisplayUtil.getScreenSize(getContext()).x * 0.7); 117 | getWindow().setAttributes(params); 118 | } 119 | 120 | @Override 121 | protected void onStart() { 122 | super.onStart(); 123 | startWithAnimation(mIsShowAnim); 124 | } 125 | 126 | @Override 127 | public void dismiss() { 128 | dismissWithAnimation(mIsShowAnim); 129 | } 130 | 131 | private void startWithAnimation(boolean showInAnimation) { 132 | if (showInAnimation) { 133 | mDialogView.startAnimation(mAnimIn); 134 | } 135 | } 136 | 137 | private void dismissWithAnimation(boolean showOutAnimation) { 138 | if (showOutAnimation) { 139 | mDialogView.startAnimation(mAnimOut); 140 | } else { 141 | super.dismiss(); 142 | } 143 | } 144 | 145 | private int getLogoResId(int mDialogType) { 146 | if (DIALOG_TYPE_DEFAULT == mDialogType) { 147 | return R.mipmap.ic_info; 148 | } 149 | if (DIALOG_TYPE_INFO == mDialogType) { 150 | return R.mipmap.ic_info; 151 | } 152 | if (DIALOG_TYPE_HELP == mDialogType) { 153 | return R.mipmap.ic_help; 154 | } 155 | if (DIALOG_TYPE_WRONG == mDialogType) { 156 | return R.mipmap.ic_wrong; 157 | } 158 | if (DIALOG_TYPE_SUCCESS == mDialogType) { 159 | return R.mipmap.ic_success; 160 | } 161 | if (DIALOG_TYPE_WARNING == mDialogType) { 162 | return R.mipmap.icon_warning; 163 | } 164 | return R.mipmap.ic_info; 165 | } 166 | 167 | private int getColorResId(int mDialogType) { 168 | if (DIALOG_TYPE_DEFAULT == mDialogType) { 169 | return R.color.color_type_info; 170 | } 171 | if (DIALOG_TYPE_INFO == mDialogType) { 172 | return R.color.color_type_info; 173 | } 174 | if (DIALOG_TYPE_HELP == mDialogType) { 175 | return R.color.color_type_help; 176 | } 177 | if (DIALOG_TYPE_WRONG == mDialogType) { 178 | return R.color.color_type_wrong; 179 | } 180 | if (DIALOG_TYPE_SUCCESS == mDialogType) { 181 | return R.color.color_type_success; 182 | } 183 | if (DIALOG_TYPE_WARNING == mDialogType) { 184 | return R.color.color_type_warning; 185 | } 186 | return R.color.color_type_info; 187 | } 188 | 189 | private int getSelBtn(int mDialogType) { 190 | if (DIALOG_TYPE_DEFAULT == mDialogType) { 191 | return R.drawable.sel_btn; 192 | } 193 | if (DIALOG_TYPE_INFO == mDialogType) { 194 | return R.drawable.sel_btn_info; 195 | } 196 | if (DIALOG_TYPE_HELP == mDialogType) { 197 | return R.drawable.sel_btn_help; 198 | } 199 | if (DIALOG_TYPE_WRONG == mDialogType) { 200 | return R.drawable.sel_btn_wrong; 201 | } 202 | if (DIALOG_TYPE_SUCCESS == mDialogType) { 203 | return R.drawable.sel_btn_success; 204 | } 205 | if (DIALOG_TYPE_WARNING == mDialogType) { 206 | return R.drawable.sel_btn_warning; 207 | } 208 | return R.drawable.sel_btn; 209 | } 210 | 211 | private void initAnimListener() { 212 | mAnimOut.setAnimationListener(new Animation.AnimationListener() { 213 | @Override 214 | public void onAnimationStart(Animation animation) { 215 | } 216 | 217 | @Override 218 | public void onAnimationEnd(Animation animation) { 219 | mDialogView.post(new Runnable() { 220 | @Override 221 | public void run() { 222 | callDismiss(); 223 | } 224 | }); 225 | } 226 | 227 | @Override 228 | public void onAnimationRepeat(Animation animation) { 229 | } 230 | }); 231 | } 232 | 233 | private void initListener() { 234 | mPositiveBtn.setOnClickListener(new View.OnClickListener() { 235 | @Override 236 | public void onClick(View v) { 237 | if (mOnPositiveListener != null) { 238 | mOnPositiveListener.onClick(PromptDialog.this); 239 | } 240 | } 241 | }); 242 | 243 | initAnimListener(); 244 | } 245 | 246 | private void callDismiss() { 247 | super.dismiss(); 248 | } 249 | 250 | private Bitmap createTriangel(int width, int height) { 251 | if (width <= 0 || height <= 0) { 252 | return null; 253 | } 254 | return getBitmap(width, height, getContext().getResources().getColor(getColorResId(mDialogType))); 255 | } 256 | 257 | private Bitmap getBitmap(int width, int height, int backgroundColor) { 258 | Bitmap bitmap = Bitmap.createBitmap(width, height, BITMAP_CONFIG); 259 | Canvas canvas = new Canvas(bitmap); 260 | 261 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); 262 | paint.setColor(backgroundColor); 263 | Path path = new Path(); 264 | path.moveTo(0, 0); 265 | path.lineTo(width, 0); 266 | path.lineTo(width / 2, height); 267 | path.close(); 268 | 269 | canvas.drawPath(path, paint); 270 | return bitmap; 271 | 272 | } 273 | 274 | 275 | private void setBtnBackground(final TextView btnOk) { 276 | btnOk.setTextColor(createColorStateList(getContext().getResources().getColor(getColorResId(mDialogType)), 277 | getContext().getResources().getColor(R.color.color_dialog_gray))); 278 | btnOk.setBackgroundDrawable(getContext().getResources().getDrawable(getSelBtn(mDialogType))); 279 | } 280 | 281 | 282 | private void setBottomCorners(View llBtnGroup) { 283 | int radius = DisplayUtil.dp2px(getContext(), DEFAULT_RADIUS); 284 | float[] outerRadii = new float[] { 0, 0, 0, 0, radius, radius, radius, radius }; 285 | RoundRectShape roundRectShape = new RoundRectShape(outerRadii, null, null); 286 | ShapeDrawable shapeDrawable = new ShapeDrawable(roundRectShape); 287 | shapeDrawable.getPaint().setColor(Color.WHITE); 288 | shapeDrawable.getPaint().setStyle(Paint.Style.FILL); 289 | llBtnGroup.setBackgroundDrawable(shapeDrawable); 290 | } 291 | 292 | private ColorStateList createColorStateList(int normal, int pressed) { 293 | return createColorStateList(normal, pressed, Color.BLACK, Color.BLACK); 294 | } 295 | 296 | private ColorStateList createColorStateList(int normal, int pressed, int focused, int unable) { 297 | int[] colors = new int[] { pressed, focused, normal, focused, unable, normal }; 298 | int[][] states = new int[6][]; 299 | states[0] = new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }; 300 | states[1] = new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }; 301 | states[2] = new int[] { android.R.attr.state_enabled }; 302 | states[3] = new int[] { android.R.attr.state_focused }; 303 | states[4] = new int[] { android.R.attr.state_window_focused }; 304 | states[5] = new int[] {}; 305 | ColorStateList colorList = new ColorStateList(states, colors); 306 | return colorList; 307 | } 308 | 309 | public PromptDialog setAnimationEnable(boolean enable) { 310 | mIsShowAnim = enable; 311 | return this; 312 | } 313 | 314 | public PromptDialog setTitleText(CharSequence title) { 315 | mTitle = title; 316 | return this; 317 | } 318 | 319 | public PromptDialog setTitleText(int resId) { 320 | return setTitleText(getContext().getString(resId)); 321 | } 322 | 323 | public PromptDialog setContentText(CharSequence content) { 324 | mContent = content; 325 | return this; 326 | } 327 | 328 | public PromptDialog setContentText(int resId) { 329 | return setContentText(getContext().getString(resId)); 330 | } 331 | 332 | public TextView getTitleTextView() { 333 | return mTitleTv; 334 | } 335 | 336 | public TextView getContentTextView() { 337 | return mContentTv; 338 | } 339 | 340 | public PromptDialog setDialogType(int type) { 341 | mDialogType = type; 342 | return this; 343 | } 344 | 345 | public int getDialogType() { 346 | return mDialogType; 347 | } 348 | 349 | public PromptDialog setPositiveListener(CharSequence btnText, OnPositiveListener l) { 350 | mBtnText = btnText; 351 | return setPositiveListener(l); 352 | } 353 | 354 | public PromptDialog setPositiveListener(int stringResId, OnPositiveListener l) { 355 | return setPositiveListener(getContext().getString(stringResId), l); 356 | } 357 | 358 | public PromptDialog setPositiveListener(OnPositiveListener l) { 359 | mOnPositiveListener = l; 360 | return this; 361 | } 362 | 363 | public PromptDialog setAnimationIn(AnimationSet animIn) { 364 | mAnimIn = animIn; 365 | return this; 366 | } 367 | 368 | public PromptDialog setAnimationOut(AnimationSet animOut) { 369 | mAnimOut = animOut; 370 | initAnimListener(); 371 | return this; 372 | } 373 | 374 | public interface OnPositiveListener { 375 | void onClick(PromptDialog dialog); 376 | } 377 | 378 | } 379 | -------------------------------------------------------------------------------- /ColorDialog/src/main/java/cn/refactor/lib/colordialog/util/DisplayUtil.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.lib.colordialog.util; 2 | 3 | import android.content.Context; 4 | import android.graphics.Point; 5 | import android.view.WindowManager; 6 | 7 | /** 8 | * 作者 : andy 9 | * 日期 : 15/11/8 20:42 10 | * 邮箱 : andyxialm@gmail.com 11 | * 描述 : 换算工具类 12 | */ 13 | public class DisplayUtil { 14 | 15 | /** 16 | * 根据分辨率从 dp 的单位 转成为 px(像素) 17 | */ 18 | public static int dp2px(Context context, float dpValue) { 19 | final float scale = context.getResources().getDisplayMetrics().density; 20 | return (int) (dpValue * scale + 0.5f); 21 | } 22 | 23 | /** 24 | * 根据分辨率从 px(像素) 的单位 转成为 dp 25 | */ 26 | public static int px2dp(Context context, float pxValue) { 27 | final float scale = context.getResources().getDisplayMetrics().density; 28 | return (int) (pxValue / scale + 0.5f); 29 | } 30 | 31 | /** 32 | * 获得屏幕尺寸 33 | * @param context 34 | * @return 35 | */ 36 | public static Point getScreenSize(Context context) { 37 | Point point = new Point(); 38 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 39 | wm.getDefaultDisplay().getSize(point); 40 | return point; 41 | } 42 | } -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_btn_help.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_btn_info.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_btn_success.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_btn_warning.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_btn_wrong.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_def_gray.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_def_gray_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/sel_def_gray_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_corners_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_corners_bottom_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_left_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_left_bottom_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_right_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_right_bottom_normal.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/drawable/shape_top.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/layout/layout_colordialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 18 | 19 | 29 | 30 | 37 | 38 | 42 | 43 | 50 | 51 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 74 | 75 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/layout/layout_promptdialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | 34 | 35 | 36 | 37 | 44 | 56 | 57 | 68 | 69 | 70 | 71 | 78 | 79 | 90 | 91 | 92 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/mipmap/ic_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/ColorDialog/src/main/res/mipmap/ic_help.png -------------------------------------------------------------------------------- /ColorDialog/src/main/res/mipmap/ic_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/ColorDialog/src/main/res/mipmap/ic_info.png -------------------------------------------------------------------------------- /ColorDialog/src/main/res/mipmap/ic_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/ColorDialog/src/main/res/mipmap/ic_success.png -------------------------------------------------------------------------------- /ColorDialog/src/main/res/mipmap/ic_wrong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/ColorDialog/src/main/res/mipmap/ic_wrong.png -------------------------------------------------------------------------------- /ColorDialog/src/main/res/mipmap/icon_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/ColorDialog/src/main/res/mipmap/icon_warning.png -------------------------------------------------------------------------------- /ColorDialog/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | #ededf3 3 | #ed7861 4 | #303030 5 | #343434 6 | 7 | #79b3e4 8 | #e8bd4b 9 | #ed7861 10 | #e8bd4b 11 | #90b06e 12 | 13 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ColorDialog 3 | 4 | -------------------------------------------------------------------------------- /ColorDialog/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #ColorDialog & PromptDialog 2 | [![](https://jitpack.io/v/andyxialm/ColorDialog.svg)](https://jitpack.io/#andyxialm/ColorDialog) 3 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ColorDialog-brightgreen.svg?style=flat)]() 4 | 5 | * ColorDialog support: Text Mode, Image Mode, Text & Image Mode 6 | * PromptDialog support: Success, Info, Error, Warning, Help 7 | * Support custom in/out animation 8 | * PromptDialog's UI from Dribbble[@Diego Faria](https://dribbble.com/shots/1626595-Feedback-dialogs-collection-FREE-PSD "Title"), Thanks. 9 | 10 | ### Usage 11 | 12 | #### Gradle 13 | ##### Step 1. Add the JitPack repository to your build file 14 | ~~~ xml 15 | allprojects { 16 | repositories { 17 | ... 18 | maven { url "https://jitpack.io" } 19 | } 20 | } 21 | ~~~ 22 | 23 | ##### Step 2. Add the dependency 24 | ~~~ xml 25 | dependencies { 26 | compile 'com.github.andyxialm:ColorDialog:1.0.0' 27 | } 28 | ~~~ 29 | 30 | #### Maven 31 | ##### Step 1. Add the JitPack repository to your build file 32 | ~~~ xml 33 | 34 | 35 | jitpack.io 36 | https://jitpack.io 37 | 38 | 39 | ~~~ 40 | 41 | ##### Step 2. Add the dependency 42 | ~~~ xml 43 | 44 | com.github.andyxialm 45 | ColorDialog 46 | 1.0.0 47 | 48 | ~~~ 49 | 50 | ##### Java Code: 51 | 52 |

 53 | ColorDialog dialog = new ColorDialog(this);
 54 | dialog.setTitle(getString(R.string.operation));
 55 | dialog.setContentText(getString(R.string.content_text));
 56 | dialog.setContentImage(getResources().getDrawable(R.mipmap.sample_img));
 57 | dialog.setPositiveListener(getString(R.string.delete), new ColorDialog.OnPositiveListener() {
 58 |     @Override
 59 |     public void onClick(ColorDialog dialog) {
 60 |         Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show();
 61 |     }
 62 | })
 63 | .setNegativeListener(getString(R.string.cancel), new ColorDialog.OnNegativeListener() {
 64 |     @Override
 65 |     public void onClick(ColorDialog dialog) {
 66 |         Toast.makeText(MainActivity.this, dialog.getNegativeText().toString(), Toast.LENGTH_SHORT).show();
 67 |         dialog.dismiss();
 68 |     }
 69 | }).show();
 70 | 
71 | 72 |

 73 | new PromptDialog(this)
 74 |     .setDialogType(PromptDialog.DIALOG_TYPE_SUCCESS)
 75 |     .setAnimationEnable(true)
 76 |     .setTitleText(getString(R.string.success))
 77 |     .setContentText(getString(R.string.text))
 78 |     .setPositiveListener(getString(R.string.ok), new PromptDialog.OnPositiveListener() {
 79 |         @Override
 80 |         public void onClick(PromptDialog dialog) {
 81 |             dialog.dismiss();
 82 |         }
 83 |     }).show();
 84 | 
85 | 86 | 87 | 88 | 89 | ### Screenshots: 90 | 91 | * PromptDialog Success 92 | 93 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_type_success.png?raw=true ) 94 | 95 | * PromptDialog Info 96 | 97 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_type_info.png?raw=true) 98 | 99 | * PromptDialog Help 100 | 101 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_type_help.png?raw=true) 102 | 103 | * PromptDialog Error 104 | 105 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_type_error.png?raw=true) 106 | 107 | * PromptDialog Warning 108 | 109 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_type_warning.png?raw=true) 110 | 111 | 112 | * ColorDialog Text Mode 113 | 114 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_text.png?raw=true) 115 | 116 | * ColorDialog Image Mode 117 | 118 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_img.png?raw=true) 119 | 120 | * ColorDialog Text&Image Mode 121 | 122 | ![](https://github.com/andyxialm/ColorDialog/blob/master/art/Screenshot_imgtext.png?raw=true) 123 | 124 | 125 | #License 126 |

ColorDialog is available under the MIT license.

127 | -------------------------------------------------------------------------------- /art/Screenshot_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_img.png -------------------------------------------------------------------------------- /art/Screenshot_imgtext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_imgtext.png -------------------------------------------------------------------------------- /art/Screenshot_setcolor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_setcolor.png -------------------------------------------------------------------------------- /art/Screenshot_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_text.png -------------------------------------------------------------------------------- /art/Screenshot_type_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_type_error.png -------------------------------------------------------------------------------- /art/Screenshot_type_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_type_help.png -------------------------------------------------------------------------------- /art/Screenshot_type_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_type_info.png -------------------------------------------------------------------------------- /art/Screenshot_type_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_type_success.png -------------------------------------------------------------------------------- /art/Screenshot_type_warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/art/Screenshot_type_warning.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.2' 9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | } 20 | } 21 | 22 | task clean(type: Delete) { 23 | delete rootProject.buildDir 24 | } 25 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andyxialm/ColorDialog/214608313c091c9ea7a8488b42c7c738fd6da728/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 07 14:24:53 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "22.0.1" 6 | 7 | defaultConfig { 8 | applicationId "cn.refactor.sample.colordialog" 9 | minSdkVersion 14 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:22.2.1' 26 | compile project(':ColorDialog') 27 | } 28 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/andy/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/java/cn/refactor/sample/colordialog/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.refactor.sample.colordialog; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.view.animation.AlphaAnimation; 8 | import android.view.animation.Animation; 9 | import android.view.animation.AnimationSet; 10 | import android.view.animation.ScaleAnimation; 11 | import android.widget.Toast; 12 | 13 | import cn.refactor.lib.colordialog.ColorDialog; 14 | import cn.refactor.lib.colordialog.PromptDialog; 15 | 16 | public class MainActivity extends AppCompatActivity { 17 | 18 | @Override 19 | protected void onCreate(Bundle savedInstanceState) { 20 | super.onCreate(savedInstanceState); 21 | setContentView(R.layout.activity_main); 22 | } 23 | 24 | public void showPromptDialog(View view) { 25 | showPromptDlg(); 26 | } 27 | 28 | private void showPromptDlg() { 29 | new PromptDialog(this) 30 | .setDialogType(PromptDialog.DIALOG_TYPE_SUCCESS) 31 | .setAnimationEnable(true) 32 | .setTitleText(getString(R.string.success)) 33 | .setContentText(getString(R.string.text_data)) 34 | .setPositiveListener(getString(R.string.ok), new PromptDialog.OnPositiveListener() { 35 | @Override 36 | public void onClick(PromptDialog dialog) { 37 | dialog.dismiss(); 38 | } 39 | }).show(); 40 | } 41 | 42 | public void showTextDialog(View view) { 43 | ColorDialog dialog = new ColorDialog(this); 44 | dialog.setColor("#8ECB54"); 45 | dialog.setAnimationEnable(true); 46 | dialog.setTitle(getString(R.string.operation)); 47 | dialog.setContentText(getString(R.string.content_text)); 48 | dialog.setPositiveListener(getString(R.string.text_iknow), new ColorDialog.OnPositiveListener() { 49 | @Override 50 | public void onClick(ColorDialog dialog) { 51 | Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show(); 52 | } 53 | }).show(); 54 | } 55 | 56 | public void showPicDialog(View v) { 57 | ColorDialog dialog = new ColorDialog(this); 58 | dialog.setTitle(getString(R.string.operation)); 59 | dialog.setAnimationEnable(true); 60 | dialog.setAnimationIn(getInAnimationTest(this)); 61 | dialog.setAnimationOut(getOutAnimationTest(this)); 62 | dialog.setContentImage(getResources().getDrawable(R.mipmap.sample_img)); 63 | dialog.setPositiveListener(getString(R.string.delete), new ColorDialog.OnPositiveListener() { 64 | @Override 65 | public void onClick(ColorDialog dialog) { 66 | Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show(); 67 | } 68 | }) 69 | .setNegativeListener(getString(R.string.cancel), new ColorDialog.OnNegativeListener() { 70 | @Override 71 | public void onClick(ColorDialog dialog) { 72 | Toast.makeText(MainActivity.this, dialog.getNegativeText().toString(), Toast.LENGTH_SHORT).show(); 73 | dialog.dismiss(); 74 | } 75 | }).show(); 76 | } 77 | 78 | public void showAllModeDialog(View view) { 79 | ColorDialog dialog = new ColorDialog(this); 80 | dialog.setTitle(getString(R.string.operation)); 81 | dialog.setAnimationEnable(true); 82 | dialog.setContentText(getString(R.string.content_text)); 83 | dialog.setContentImage(getResources().getDrawable(R.mipmap.sample_img)); 84 | dialog.setPositiveListener(getString(R.string.delete), new ColorDialog.OnPositiveListener() { 85 | @Override 86 | public void onClick(ColorDialog dialog) { 87 | Toast.makeText(MainActivity.this, dialog.getPositiveText().toString(), Toast.LENGTH_SHORT).show(); 88 | } 89 | }) 90 | .setNegativeListener(getString(R.string.cancel), new ColorDialog.OnNegativeListener() { 91 | @Override 92 | public void onClick(ColorDialog dialog) { 93 | Toast.makeText(MainActivity.this, dialog.getNegativeText().toString(), Toast.LENGTH_SHORT).show(); 94 | dialog.dismiss(); 95 | } 96 | }).show(); 97 | } 98 | 99 | public static AnimationSet getInAnimationTest(Context context) { 100 | AnimationSet out = new AnimationSet(context, null); 101 | AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f); 102 | alpha.setDuration(150); 103 | ScaleAnimation scale = new ScaleAnimation(0.6f, 1.0f, 0.6f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 104 | scale.setDuration(150); 105 | out.addAnimation(alpha); 106 | out.addAnimation(scale); 107 | return out; 108 | } 109 | 110 | public static AnimationSet getOutAnimationTest(Context context) { 111 | AnimationSet out = new AnimationSet(context, null); 112 | AlphaAnimation alpha = new AlphaAnimation(1.0f, 0.0f); 113 | alpha.setDuration(150); 114 | ScaleAnimation scale = new ScaleAnimation(1.0f, 0.6f, 1.0f, 0.6f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 115 | scale.setDuration(150); 116 | out.addAnimation(alpha); 117 | out.addAnimation(scale); 118 | return out; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 |