Animated Dialog and animated dialog

Source: Internet
Author: User

Animated Dialog and animated dialog

Question

The following full-featured DEMO code constructs a full-featured Dialog. For example, note that the bottom button is not displayed after the list is set by default. If you have special requirements, you only need to adjust the chain call sequence.
Note that the show operation must be performed before obtaining the ImageView. The initialization operation is added to the show operation. Otherwise, the get operation is null. ButtonText has a miraculous effect, which can be mixed in many places, but I hope
Set the developer to a normal Dialog:-D.

Click the button below to set drawable in the code, and set the corresponding type of corner position based on the position. If the method is not called, the corresponding type component is not displayed. Some methods force the corresponding method setting value, but adjusting the call sequence can overwrite the latest setting.
(Chestnut: when the list is displayed, the lower button is not displayed, but setDialogMenuItemList () is called first and then the lower button is not displayed. If setButtonTexts () is called later, the lower button is displayed, parameter reset occurs) custom View can achieve more functions. A single file is easy to transplant, and you need to define the font color or something to change on your own. There is no need to provide too many methods. Example: full-featured display (chain call order affects the specific display and function effect)
Public void test1 (View view) {final SuperDialog superDialog = new SuperDialog (this); ArrayList
 
  
MenuItems = new ArrayList <> (); menuItems. add (new SuperDialog. dialogMenuItem ("favorites", R. mipmap. ic_winstyle_favor); menuItems. add (new SuperDialog. dialogMenuItem ("Download", R. mipmap. ic_winstyle_download); menuItems. add (new SuperDialog. dialogMenuItem ("share", R. mipmap. ic_winstyle_share); menuItems. add (new SuperDialog. dialogMenuItem ("delete", R. mipmap. ic_winstyle_delete); menuItems. add (new SuperDialog. dialogMenuItem ("artist", R. mipmap. ic_winstyle_artist); menuItems. add (new SuperDialog. dialogMenuItem ("album", R. mipmap. ic_winstyle_album); superDialog. setTitle ("full-featured display Dialog "). setContent ("code-only, no XML. "). setListener (listener ). setShowImage (). setDialogMenuItemList (menuItems ). setButtonTexts (new String [] {"button 1", "button 2", "button 3", "button 4 "}). setImageListener (new SuperDialog. onDialogImageListener () {@ Override public void onInitImageView (ImageView imageView) {Glide. with (imageView ). load (" https://www.baidu.com/img/fnj_96d95207b4a706738f1b8be3b41ea9f3.gif "). Into (imageView );}}). setCustomViewListener (new SuperDialog. onDialogCustomViewListener () {@ Override public View onInitCustomView (LinearLayout viewGroup) {return new ProgressBar (viewGroup. getContext ());}}). setInputListener (new SuperDialog. onDialogInputListener () {@ Override public void onInitEditText (EditText inputView) {inputView. setHint ("custom settings") ;}@ Override public void onComplete (int buttonIndex, String text) {Toast. makeText (getApplicationContext (), "input box:" + text, Toast. LENGTH_SHORT ). show ();}}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
 


Common Dialog
Public void test2 (View view) {SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("prompt Box Type Dialog "). setContent ("code-only, no XML "). setListener (listener ). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
! Untitled Dialog
Public void test3 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setContent ("code-only, no XML \ r \ n, no title "). setListener (listener ). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
Two buttons
Public void test4 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("2 buttons "). setContent ("code-only, no XML "). setListener (listener ). setButtonTexts (new String [] {"button 1", "button 2 "}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
Three buttons
Public void test5 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("3 buttons "). setContent ("code-only, no XML "). setListener (listener ). setButtonTexts (new String [] {"button 1", "button 2", "button 3 "}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
Variable Parameter Setting multiple buttons
Public void test6 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("variable parameter N buttons "). setContent ("code-only, no XML \ r \ n. setButtonTexts (\ "button 1 \", \ "button 2 \", \ "button 3 \", \ "button 4 \", \ "button 5 \", \ "button 6 \")"). setListener (listener ). setButtonTexts ("button 1", "button 2", "button 3", "button 4", "button 5", "button 6 "). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
Callback onInitImageView () after addView with image text layout, and return ImageView to handle events and effects by yourself
Public void test7 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("with image Dialog "). setContent ("code-only, no XML "). setListener (listener ). setShowImage (). setImageListener (new SuperDialog. onDialogImageListener () {@ Override public void onInitImageView (ImageView imageView) {Glide. with (imageView ). load ("https://www.baidu.com/img/fnj_96d95207b4a706738f1b8be3b41ea9f3.gif "). into (imageView );}}). setButtonTexts (new String [] {"button 1", "button 2", "button 3", "button 4 "}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
List
Public void test8 (View view) {final SuperDialog superDialog = new SuperDialog (this); ArrayList
 
  
MenuItems = new ArrayList <> (); menuItems. add (new SuperDialog. dialogMenuItem ("favorites", R. mipmap. ic_winstyle_favor); menuItems. add (new SuperDialog. dialogMenuItem ("Download", R. mipmap. ic_winstyle_download); menuItems. add (new SuperDialog. dialogMenuItem ("share", R. mipmap. ic_winstyle_share); menuItems. add (new SuperDialog. dialogMenuItem ("delete", R. mipmap. ic_winstyle_delete); menuItems. add (new SuperDialog. dialogMenuItem ("artist", R. mipmap. ic_winstyle_artist); menuItems. add (new SuperDialog. dialogMenuItem ("album", R. mipmap. ic_winstyle_album); superDialog. setTitle ("List Dialog "). setContent ("code-only, no XML "). setListener (listener ). setDialogMenuItemList (menuItems ). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
 
The default style of a single button is input. The onInitEditText () is called back before the addView layout of the Dialog layout. You can set the event and effect by returning edittext. If setButtonTexts () is not set, the system enters the judgment. If the input mode is used and the text array is empty, the default text array is {"OK "}
Public void test9 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("input box Dialog "). setContent ("code-only, no XML "). setInputListener (new SuperDialog. onDialogInputListener () {@ Override public void onInitEditText (EditText inputView) {inputView. setHint ("Enter text") ;}@ Override public void onComplete (int buttonIndex, String text) {Toast. makeText (getApplicationContext (), "input box:" + text, Toast. LENGTH_SHORT ). show ();}}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
8.png custom multi-button input Dialog button is affected by setButtonTexts (). The set data is displayed in sequence, and the onComplete () callback returns the text and the position of the clicked button. The order is the same as the setting.
Public void test10 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("input box Dialog "). setContent ("code-only, no XML "). setButtonTexts ("cancel", "change "). setInputListener (new SuperDialog. onDialogInputListener () {@ Override public void onInitEditText (EditText inputView) {inputView. setHint ("Enter text") ;}@ Override public void onComplete (int buttonIndex, String text) {if (buttonIndex = 0) {Toast. makeText (getApplicationContext (), "cancel input box:" + text, Toast. LENGTH_SHORT ). show ();} else {Toast. makeText (getApplicationContext (), "input box:" + text, Toast. LENGTH_SHORT ). show ();}}}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}
9.png wait/progress custom ViewDialog
Public void test11 (View view) {final SuperDialog superDialog = new SuperDialog (this); superDialog. setTitle ("progress/Wait, custom View Dialog "). setContent ("processing progress 55% "). setShowButtonLayout (false ). setCustomViewListener (new SuperDialog. onDialogCustomViewListener () {@ Override public View onInitCustomView (LinearLayout viewGroup) {return new ProgressBar (viewGroup. getContext ());}}). show (); superDialog. setOnCancelListener (new DialogInterface. onCancelListener () {@ Override public void onCancel (DialogInterface dialog) {Toast. makeText (getApplicationContext (), "cancel", Toast. LENGTH_SHORT ). show ();}});}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.