Selection Dialogs


Source link: https://github.com/coreORB/SelectionDialogs

Selection Dialogs

Selection Dialogs is Android library allowing quickly create colors and icons selection dialogs, and providing simple views to display selected items.

Current version is 0.9.1b

Download

Library is available as jcenter. Just make sure that grandle uses this repository:

 repositories {

jcenter()
  
}

And add dependency to module.

 dependencies {

compile 'pl.coreorb:selection-dialogs:0.9.1'
  
}

Usage

All code presented here shows all methods and properties available, so just remove parts you don't need.

Icon selection dialog

Include below method (or something similar), which builds and shows dialog, in your Fragment or Activity. Then, call it from onClick of some view.

 private void showIconSelectDialog() {

new IconSelectDialog.Builder(getContext())

  .setIcons(sampleIcons())

  .setIcons(R.array.icons_ids,

 R.array.icons_names,

 R.array.icons_colors)

  .setTitle(R.string.title)

  .setTitle("Title")

  .setSortIconsByName(true)

  .setOnIconSelectedListener(this)

  .build().show(getFragmentManager(), TAG_SELECT_ICON_DIALOG);

  
}

Color selection dialog

Include below method (or something similar), which builds and shows dialog, in your Fragment or Activity. Then, call it from onClick of some view.

 private void showColorSelectDialog() {

new ColorSelectDialog.Builder(getContext())

  .setColors(ColorPalettes.loadMaterialDesignColors500(getContext(), false))

  .setColors(R.array.colors_ids,

 R.array.colors_names,

 R.array.colors_colors)

  .setTitle(R.string.title)

  .setTitle("Title")

  .setSortColorsByName(true)

  .setOnColorSelectedListener(this)

  .build().show(getFragmentManager(), TAG_SELECT_COLOR_DIALOG);

  
}

Selected item view

View can be used to display selected item from dialogs (color, icon or text).

Include view in your Fragment or Activity layout.

 <pl.coreorb.selectiondialogs.views.SelectedItemView

 android:id="@+id/icon_siv"

 android:layout_width="match_parent"

 android:layout_height="wrap_content"

 app:hint="@string/icon_hint"

 app:itemId="green"

 app:itemName="Green"

 app:itemIcon="@drawable/selectiondialogs_dialog_default_icon"

 app:itemColor="@color/selectiondialogs_materialdesign500_green"/>

Then use findViewById() and add onClick() in onCreate() or onCreateView().

 colorSIV = (SelectedItemView) rootView.findViewById(R.id.color_siv);

  colorSIV.setOnClickListener(new View.OnClickListener() {

 @Override

 public void onClick(View v) {

  showColorSelectDialog();

 
}

}
);

Views has standard setters and getters.

 SelectedItemView selectedItemView = new SelectedItemView(getContext());

 selectedItemView.setHint("hint");

  selectedItemView.setHint(R.string.icon_hint);

  selectedItemView.setSelectedName("Android");

  selectedItemView.setSelectedName(R.string.icon_hint);

  selectedItemView.setSelectedIcon(new SelectableIcon());

  selectedItemView.setSelectedColor(new SelectableColor());

 String hint = selectedItemView.getHint();

  String name = selectedItemView.getSelectedName();

  SelectableIcon icon = selectedItemView.getSelectedIcon();

  SelectableColor color = selectedItemView.getSelectedColor();

Color palettes

Library has build in color palettes. Currently only Material Design primary colors (500). Contact me if You want more palettes added.

To obtain palette as ArrayList just call one of methods in ColorPalettes class. Note that palette can be sorted by name via second argument, e.g.:

 ColorPalettes.loadMaterialDesignColors500(getContext(), false)

Utils

Library delivers Utils class with convert methods:

 public static ArrayList<SelectableColor> convertResourceArraysToColorsArrayList(Context context, boolean sortByName, @ArrayRes int idsArray, @ArrayRes int namesArray, @ArrayRes int colorsArray)

 public static ArrayList<SelectableIcon> convertResourceArraysToIconsArrayList(Context context, boolean sortByName, @ArrayRes int idsArray, @ArrayRes int namesArray, @ArrayRes int drawablesArray)

##Handling device configuration changes If device is rotated with dialog opened, dialog will stay opened, but parent Activity/Fragment will no longer receive callback with selected item.

One way to handle this is to set listener to this(Activity/Fragment) and re-set listener in onResume() like this:

 public class MyFragment extends Fragment implements IconSelectDialog.OnIconSelectedListener {

private static final String TAG_SELECT_ICON_DIALOG = "TAG_SELECT_ICON_DIALOG";

//fragment code

private void showIconSelectDialog() {

 //set listener to this

 new IconSelectDialog.Builder(getContext())

.setIcons(sampleIcons())

.setOnIconSelectedListener(this)

.build().show(getFragmentManager(), TAG_SELECT_ICON_DIALOG);

}

@Override

public void onResume() {

 super.onResume();

 //find dialog and set listener

 IconSelectDialog iconDialog = (IconSelectDialog) getFragmentManager().findFragmentByTag(TAG_SELECT_ICON_DIALOG);

 if (iconDialog != null) {

  iconDialog.setOnIconSelectedListener(this);

 
}

}

  
}

For complete implementation take a look at MainActivityFragment.java.

JavaDoc

Coming soon...

Licence

Apache License, Version 2.0.

Change log

0.9.1b

  • "Handling device configuration changes" chapter filled
  • added new constructors to SelectableColor and SelectableIcon

0.9.1

  • SelectedIconView and SelectedColorView simplified into one view: SelectedItemView
  • ColorPalettes class added
  • Utils class added
  • updated sample with sane defaults

0.9.0

Initial release

Resources

Material progress circle to wrap around any FloatingActionButton. 100% Material Design guidelines from Google.

Mara is a library to provide traits or composition capabilities to your Android or Java projects.

Material design ProgressBar with consistent appearance on Android 4.0+.

Material image loading implementation.

Android Debug Drawer for faster development.

Simple "pull-to-update" layout.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes