HintCase


Source link: https://github.com/Nescafemix/hintcase

HintCase

HintCase is a library for Android that will help you create really awesome hints/tips for your apps. You can find a secondary library (HintCaseAssets) with multiple content holders and animators that you can use with HintCase library. Take a look to how you would integrate HintCase into your app.

With HintCase library you can apply shape animations to highlight a specific view and show a HintBlock and/or multiple ExtraBlocks all of them with optional animations to show/hide them. All is very easy, but if you don't have time to implement shapes, blocks and animations, with the HintCaseAssets library you can use some predefined items.

      

Latest Version

How to use

1.- Configuring your Project Dependencies

Add the library dependency to your build.gradle file.

dependencies {

  ...
  compile 'com.joanfuentes:HintCase:1.0.4' 
}

1.1- Optional Project Dependency

You can add the optional assets library dependency to your build.gradle file.

dependencies {

  ...
  compile 'com.joanfuentes:HintCaseAssets:1.0.4' 
}

2.- Showing a Hint

All you need to do is create a new HintCase object, configure it and call the show() method.

2.1.- Passing a view to the constructor

You need to pass a view to the constructor of HintCase object. This view should be the parent where you want to show the Hint. For example, is you are executing it from an onClick event, you could use a view.getRootView(), and from an activity you can use getActivity().getWindow().getDecorView() to get the full screen view.

protected void showHint() {

  ...
  parentView = getActivity().getWindow().getDecorView();

  new HintCase(parentView)

  ...

  .show();
 
}

2.2.- Configuring a Target (OPTIONAL)

You can configure a target view which will be highlighted. You can then configure the shape type, a margin between the shape and the target view (named offset) and if the target should be clickable or not.

If no offset is specified, the default offset value is 10dp.

 .setTarget(findViewById(R.id.textView), new RectangularShape(), HintCase.TARGET_IS_NOT_CLICKABLE)

By default, if Target is not configured, a rectangular shape is used, the whole parent view is used as target, there is no offset and the target is not clickable.

In HintCaseAssets you can find an extra shape (CircularShape), which is ideal to use with action menu icons, and FAB buttons.

2.3.- Configure animations to show/hide shapes (OPTIONAL)

You can show animations when you show/hide a target with a shape. To do it, call the method setShapeAnimators(..). You can use a ShapeAnimator to show and another ShapeAnimator to hide. You can find some ShapeAnimators in HintCaseAssets library. Feel free to use them or create your own awesome animators.

FadeInShapeAnimator and FadeOutShapeAnimator

Fade in/out effects. You can set the time in the constructor. If no time is specified, 300ms are the default value. You can configure a delay for the animation with setStartDelay(long startDelayTimeInMillis).

RevealCircleShapeAnimator and UnrevealCircleShapeAnimator

Reveal/Unreveal effects to highlight a target with a circle shape. You can set the time in the constructor. If no time is specified, 300ms are the default value. You can configure a delay for the animation with setStartDelay(long startDelayTimeInMillis).

RevealRectangularShapeAnimator and UnrevealRectangularShapeAnimator

Reveal/Unreveal effects to highlight a target with a rectangular shape. You can set the time in the constructor. If no time is specified, 300ms are the default value. You can configure a delay for the animation with setStartDelay(long startDelayTimeInMillis).

Finally to configure shapeAnimators you need to call:

 .setShapeAnimators(new RevealRectangularShapeAnimator(), ShapeAnimator.NO_ANIMATOR)

If you don't want an animation you can use ShapeAnimator.NO_ANIMATOR

2.4.- Configure a Background color (OPTIONAL)

You can specify a background color for the shape of the hint. You can use:

 .setBackgroundColor(0x00000000)

or

  .setBackgroundColorByResourceId(R.color.colorPrimary)

2.4.- Configure to close the hint on click on it (OPTIONAL)

By default, the hint is closed when the user click on it. If you don't want it, you can change this behavior with:

 .setCloseOnTouchView(false)

2.5.- Configure the Hint Block (OPTIONAL)

You can create a hint block which depends on the target position to show itself. The hint block will be positioned on the biggest free space on the screen between the target view and the borders of the parent. If no target was configured, the hint block will be positioned in the center of the parent view. For example, if the parent view is the full screen, the hint block will be a view positioned in the center of the screen.

You can define your own HintContenHolder or use some of the existing in the HintCaseAssets library:

ByLayoutHintContentHolder

A HintContentHolder which inflates a specified layout. This is a fast way to create different hints with a specified layout for every hint.

 ByLayoutHintContentHolder hintBlock = new ByLayoutHintContentHolder(R.layout.hint_welcome)
SimpleHintContentHolder

A HintContentHolder which can show a title, an image and a description. all 3 items are optional.

 SimpleHintContentHolder hintBlock = new SimpleHintContentHolder.Builder(context)

 .setContentTitle(R.string.title)

 .setContentText(R.string.description)

 .setTitleStyle(R.style.title)

 .setContentStyle(R.style.content)

 .setImageDrawableId(R.drawable.happy_welcome)

 .build();

The image can be passed as an imageView instead of a drawable so, you can use awesome libraries as Glide to pass fabulous animated gifs. In that case you need to use the .setImageView(imageView) method.

Finally, you can configure ContentHolderAnimators to show or hide the hint block.

 .setHintBlock(hintBlock, new FadeInContentHolderAnimator(), new FadeOutContentHolderAnimator())

If you don't want to create your own ContentHolderAnimators, you can use some existing in HintCaseAssets library as:

FadeInContentHolderAnimator and FadeOutContentHolderAnimator

Fade in/out effects. You can set the time in the constructor. If no time is specified, 300ms are the default value. You can configure a delay for the animation with setStartDelay(long startDelayTimeInMillis).

SlideInFromRightContentHolderAnimator and SlideOutFromRightContentHolderAnimator

Slide in/out movements from right position. You can set the time in the constructor. If no time is specified, 300ms are the default value. You can configure a delay for the animation with setStartDelay(long startDelayTimeInMillis).

2.6.- Configure an Extra Block (OPTIONAL)

You can create multiple extra blocks which will be placed on a specified position of the parent view.

You can create your own ExtraContentHolders. You can find on HintCaseAssets library an example with SimpleButtonContentHolder:

SimpleButtonContentHolder

A HintContentHolder which show a button on the hint. It can be positioned based on rules of RelativeLayout.

SimpleButtonContentHolder okBlock = new SimpleButtonContentHolder.Builder(context)

 .setWidth(ViewGroup.LayoutParams.WRAP_CONTENT)

 .setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)

 .setRules(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.ALIGN_PARENT_RIGHT)

 .setButtonText(R.string.ok)

 .setCloseHintCaseOnClick(true)

 .setButtonStyle(R.style.buttonNice)

 .build();

You can configure the button to close the hint on clock with .setCloseHintCaseOnClick(true) and define the button style with .setButtonStyle(R.style.buttonNice).

Finally, you can configure ContentHolderAnimators to show or hide the extra block.

 .setExtraBlock(okBlock, new SlideInFromRightContentHolderAnimator(), new SlideOutFromRightContentHolderAnimator())

If you don't want to create your own ContentHolderAnimators, you can use some existing in HintCaseAssets library.

2.7.- Configure a listener when the hint is closed (OPTIONAL)

You can set a listener to execute when the hint is closed:

 .setOnClosedListener(new HintCase.OnClosedListener() {

@Override

public void onClosed() {

 Snackbar.make(view, "Hint closed", Snackbar.LENGTH_SHORT).show();

}

}
)

3.- Concatenate several hints (OPTIONAL)

You can concatenate several hints simply using the OnClosedListener to launch the next HintCase. Even you can configure hints to avoid some animations so that the user does not perceive that are different hints.

For example:

 SimpleHintContentHolder hintBlock = new SimpleHintContentHolder.Builder(view.getContext())

 .setContentTitle("Attention!")

 .setContentText("You can find here your notifications")

 .setTitleStyle(R.style.title)

 .setContentStyle(R.style.content)

 .build();

  new HintCase(view.getRootView())

 .setTarget(findViewById(R.id.textView), new CircularShape(), HintCase.TARGET_IS_NOT_CLICKABLE)

 .setBackgroundColor(getResources().getColor(R.color.colorPrimary))

 .setShapeAnimators(new RevealCircleShapeAnimator(), ShapeAnimator.NO_ANIMATOR)

 .setHintBlock(hintBlock, new FadeInContentHolderAnimator(), new SlideOutFromRightContentHolderAnimator())

 .setOnClosedListener(new HintCase.OnClosedListener() {

  @Override

  public void onClosed() {

SimpleHintContentHolder secondHintBlock = new SimpleHintContentHolder.Builder(view.getContext())

  .setContentTitle("Notifications center is your best friend")

  .setContentText("Every time you purchase a game, a notification will be generated")

  .setTitleStyle(R.style.title)

  .setContentStyle(R.style.content)

  .build();

new HintCase(view.getRootView())

  .setTarget(findViewById(R.id.textView), new CircularShape())

  .setBackgroundColor(getResources().getColor(R.color.colorPrimary))

  .setShapeAnimators(ShapeAnimator.NO_ANIMATOR, new UnrevealCircleShapeAnimator())

  .setHintBlock(secondHintBlock, new SlideInFromRightContentHolderAnimator())

  .show();

  
}

 
}
)

 .show();

In this example, the fist hint is configured to show a reveal animation for the shape but with no animation to hide the hint. The next hint doesn't show an animation to show so, the effect is that the shape was fixed and there was no change with it. The hint block was showed with a fade in animation but to hide it was shown an slideOut animation, and the hint block in the next screen was showed with a slideIn animation. The result was this:

4.- Building your own ContentHolder (OPTIONAL)

Building your own content holder is really easy. If you want that you contentHolder was showed on the biggest free space in the screen you should extend from HintContentHolder. Otherwise, if you want that your ContentHolder can fill all the parent view extends from ExtraContentHolder. Both of the base classes (HintContentHolder and ExtraContentHolder) extends from ContentHolder and define its specific getParentLayoutParams to use in your custom ContentHolder.

In your custom ContentHolder you will need to define your own getView method to return the view that you generated for your hint. You receive the context, the parent viewgroup and the full hintcase so you can even know where the target is to mount your own contentHolder.

 @Override
  public View getView(Context context, final HintCase hintCase, ViewGroup parent) {

...
  
}

as an optional you can define the onLayout method that you listen when the layout is inflated so you can configure your contentHolder based on the calculated position for the HintContentHolder


 @Override
  public void onLayout() {

...
  
}
 

In the app example you can find a CustomHintContentHolder that override and use both methods.

5.- Building your own ContentHolderAnimator (OPTIONAL)

Building your own content holder animator is really easy. You should extend from ContentHolderAnimator.

In Your custom ContentHolderAnimator you will need to define your own getAnimator method to return the ValueAnimator of the contentHolder. You receive the view for which is the animator applied and a onFinishListener to call when the animator is finished.

 @Override
  public ValueAnimator getAnimator(View view, OnFinishListener onFinishListener) {

...
  
}

6.- Building your own Shape (OPTIONAL)

A rectangular and a Circular shape are provided with the main library and the assets library, but if you need to do your own shape, you can do it!.

In your Shape you will need to define some methods:

 @Override
  public void setMinimumValue() {

...
  
}

 @Override
  public void setShapeInfo(View targetView, ViewGroup parent, int offset, Context context) {

...
  
}

 public boolean isTouchEventInsideTheHint(MotionEvent event) {

...
  
}

 public void draw(Canvas canvas) {

...
  
}
 
  • setMinimumValue : you should set the minimum size of the shape in this method.
  • setShapeInfo : you should set all the necessary info of the shape for use on ShapeAnimators.
  • isTouchEventInsideTheHint: this method should return if the user performed a touch event inside the Highlighted item.
  • draw: this method should draw the shape in the canvas.

You can check the code of CircularShape & RectangularShape to se some examples.

7.- Building your own ShapeAnimator (OPTIONAL)

Building your own shape animator is really easy. You should extend from ShapeAnimator.

In Your custom ShapeAnimator wou will need to define your own getAnimator method to return the ValueAnimator of the contentHolder. You receive the view on which is the animator applied, the shape to animate and a onFinishListener to call when the animator is finished.

 @Override
  public ValueAnimator getAnimator(View view, Shape shape, OnFinishListener onFinishListener) {

...
  
}

Developers

Special Thanks to

Motivation

We created this view as a little piece of the Redbooth app for Android.

Currently using in

If you use this library in your project and you want to be in this section, please, let us know it at @Nescafemix.

License

Copyright Joan Fuentes 2016

This file is part of some open source application.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

A cute day night switch for android.

Android library to use android utils with annotations.

Combined both TedBottomPicker and Camera View, to get the View Similar to ImagePickers of Olx.

We can Pick Images From Gallery and Camera in two modes (Single, Multi), and pick multiple images from both Camera and Gallery.

This is the RxJava2 port of the RxGroups project developed by AirBnb. The branch rx-2.0 has the Rx2 changes. The changes have been done on master branch of RxGroups. The following documentation written for RxGroups by AirBnb applies to Rx2Groups as well. All the API and package names originally written by AirBnb remains as it is. I have transitioned all the RxJava APIs(including the unit tests) to RxJava2.

RxGroups lets you group RxJava Observables together in groups and tie them to your Android lifecycle. This is especially useful when used with Retrofit.

Logger is simple library, which will help you to find your logs easily, just clicking on log.

This is a collection of samples demonstrating the use of operators in RxJava 2.0 and RxKotlin.

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