Skip to content

Customizable gesture icon, animator, fade duration, top/bottom focus gravity, circle snapping to a view edge #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ We saw this kind of showcase on [Fabulous App](http://www.thefabulous.co/) and w
# Usage
```java
new MaterialIntroView.Builder(this)
.enableDotAnimation(true)
.enableIcon(false)
.setFocusGravity(FocusGravity.CENTER)
.setFocusType(Focus.MINIMUM)
Expand Down Expand Up @@ -51,6 +50,9 @@ dependencies {
.enableFadeAnimation(true) //View will appear/disappear with fade in/out animation
```
```java
.setFadeAnimation(200) //If enableFadeAnimation(true) is called view will fade in/out with 200 ms duration
```
```java
//ie. If your button's width has MATCH_PARENT.
//Focus.ALL is not a good option. You can use
//Focus.MINIMUM or Focus.NORMAL. See demos below.
Expand All @@ -63,6 +65,8 @@ dependencies {
.setFocusGravity(FocusGravity.LEFT)
.setFocusType(FocusGravity.CENTER)
.setFocusType(FocusGravity.RIGHT)
.setFocusType(FocusGravity.TOP)
.setFocusType(FocusGravity.BOTTOM)
```
```java
.setTarget(myButton) //Focus on myButton
Expand Down Expand Up @@ -95,7 +99,17 @@ dependencies {
.setUsageId("intro_fab_button") //Store intro view status whether it is learnt or not
```
```java
.enableDotAnimation(true) //Shows dot animation center of focus area
// Draws a gesture drawable at the center of focus area. The default drawable is a pulsating dot. It can be
// overriden with `setGestureDrawableResId()``.
.enableGestureDrawable(true)
```
```java
// Shows a custom drawable at the center of focus area. E.g. it could visually represent a specific gesture.
.setGestureDrawableResId(R.drawable.ic_cursor_hand)
```
```java
// Shows a custom animator for the gesture drawable if enabled.
.setGestureAnimatorResId(R.animator.ic_drag_from_right)
```
```java
.enableIcon(false) //Turn off helper icon, default is true
Expand Down Expand Up @@ -136,6 +150,9 @@ public class MyShape extends Shape {

.setCustomShape(MyShape shape)

// or you can use the built-in `CircleOnEdge` shape whose focus center snaps to an edge depending on the supplied `FocusGravity`:

.setCustomShape(new CircleOnEdge(new ViewTarget(view), FocusGravity.RIGHT, 0))
```

# Demos
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,7 +18,7 @@ allprojects {
maven {
url "https://jitpack.io"
}

google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
32 changes: 27 additions & 5 deletions materialintro/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

publishing {
publications {
aarDebug(MavenPublication) {
groupId "com.github.sevar83"
artifactId "MaterialIntroView"
version "1.6.0"
artifact("$buildDir/outputs/aar/materialintro-debug.aar")
// Add javadocs and sources artifact
// Add/Exclude project dependencies via pom.withXml
}
aarRelease(MavenPublication) {
groupId "com.github.sevar83"
artifactId "MaterialIntroView"
version "1.6.0"
artifact("$buildDir/outputs/aar/materialintro-release.aar")
// Add javadocs and sources artifact
// Add/Exclude project dependencies via pom.withXml
}
}
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 26
buildToolsVersion "26.0.1"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Expand All @@ -22,6 +44,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:appcompat-v7:26.0.1'
compile 'com.android.support:cardview-v7:26.0.1'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package co.mobiwise.materialintro;


import android.support.annotation.AnimatorRes;
import android.support.annotation.DrawableRes;

import co.mobiwise.materialintro.shape.Focus;
import co.mobiwise.materialintro.shape.FocusGravity;
import co.mobiwise.materialintro.utils.Constants;
Expand All @@ -23,10 +26,14 @@ public class MaterialIntroConfiguration {

private int colorTextViewInfo;

private boolean isDotViewEnabled;
private @DrawableRes int gestureDrawableResId;

private @AnimatorRes int gestureAnimatorResId;

private boolean isImageViewEnabled;

private @DrawableRes int iconDrawableResId;

public MaterialIntroConfiguration() {
maskColor = Constants.DEFAULT_MASK_COLOR;
delayMillis = Constants.DEFAULT_DELAY_MILLIS;
Expand All @@ -36,8 +43,8 @@ public MaterialIntroConfiguration() {
focusGravity = FocusGravity.CENTER;
isFadeAnimationEnabled = false;
dismissOnTouch = false;
isDotViewEnabled = false;
isImageViewEnabled = true;
iconDrawableResId = Constants.DEFAULT_ICON_DRAWABLE;
}

public int getMaskColor() {
Expand Down Expand Up @@ -104,15 +111,31 @@ public void setColorTextViewInfo(int colorTextViewInfo) {
this.colorTextViewInfo = colorTextViewInfo;
}

public boolean isDotViewEnabled() {
return isDotViewEnabled;
}

public boolean isImageViewEnabled(){
return isImageViewEnabled;
}

public void setDotViewEnabled(boolean dotViewEnabled) {
isDotViewEnabled = dotViewEnabled;
public void setIconDrawableResId(int iconDrawableResId) {
this.iconDrawableResId = iconDrawableResId;
}

public int getIconDrawableResId() {
return this.iconDrawableResId;
}

public int getGestureDrawableResId() {
return gestureDrawableResId;
}

public void setGestureDrawableResId(int gestureDrawableResId) {
this.gestureDrawableResId = gestureDrawableResId;
}

public int getGestureAnimatorResId() {
return gestureAnimatorResId;
}

public void setGestureAnimatorResId(int gestureAnimatorResId) {
this.gestureAnimatorResId = gestureAnimatorResId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public PreferencesManager(Context context) {
}

public boolean isDisplayed(String id){
return sharedPreferences.getBoolean(id, false);
return id != null && sharedPreferences.getBoolean(id, false);
}

public void setDisplayed(String id){
sharedPreferences.edit().putBoolean(id,true).apply();
if (id != null) {
sharedPreferences.edit().putBoolean(id, true).apply();
}
}

public void reset(String id){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.mobiwise.materialintro.shape;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import co.mobiwise.materialintro.target.Target;
Expand All @@ -22,10 +21,15 @@ public Circle(Target target, Focus focus, FocusGravity focusGravity, int padding
}

@Override
public void draw(Canvas canvas, Paint eraser, int padding){
calculateRadius(padding);
circlePoint = getFocusPoint();
canvas.drawCircle(circlePoint.x, circlePoint.y, radius, eraser);
public Path getPath(int padding) {
if (this.padding != padding || cachedPath == null) {
this.padding = padding;
Point center = getFocusPoint();
cachedPath = new Path();
cachedPath.addCircle((float) center.x, (float) center.y, getRadius() + padding, Path.Direction.CW);
}

return cachedPath;
}

@Override
Expand All @@ -34,7 +38,7 @@ public void reCalculateAll(){
circlePoint = getFocusPoint();
}

private void calculateRadius(int padding){
protected void calculateRadius(int padding){
int side;

if(focus == Focus.MINIMUM)
Expand All @@ -50,7 +54,11 @@ else if(focus == Focus.ALL)
radius = side + padding;
}

private int getRadius(){
protected void setRadius(int radius) {
this.radius = radius;
}

protected int getRadius(){
return radius;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package co.mobiwise.materialintro.shape;

import android.graphics.Point;

import co.mobiwise.materialintro.R;
import co.mobiwise.materialintro.target.Target;

public class CircleOnEdge extends Circle {

protected int radius = 0;

public CircleOnEdge(Target target, FocusGravity focusGravity, int padding) {
this(target, Focus.MINIMUM, focusGravity, padding, 0);
}

public CircleOnEdge(Target target, Focus focus, FocusGravity focusGravity, int padding, int radius) {
super(target, focus, focusGravity, padding);
if (radius <= 0) {
this.radius = this.target.getView().getContext().getResources().getDimensionPixelSize(R.dimen.gesture_circle_radius);
} else {
this.radius = radius;
}
calculateRadius(padding);
}

@Override
protected Point getFocusPoint() {
if (focusGravity == FocusGravity.LEFT) {
int xLeft = target.getRect().left + this.radius / 2;
return new Point(xLeft, target.getPoint().y);
} else if (focusGravity == FocusGravity.RIGHT) {
int xRight = target.getRect().right - this.radius / 2;
return new Point(xRight, target.getPoint().y);
} else if (focusGravity == FocusGravity.TOP) {
int yTop = target.getRect().top + this.radius / 2;
return new Point(target.getPoint().x, yTop);
} else if (focusGravity == FocusGravity.BOTTOM) {
int yBottom = target.getRect().bottom - this.radius / 2;
return new Point(target.getPoint().x, yBottom);
} else
return target.getPoint();
}

@Override
protected void calculateRadius(int padding) {
setRadius(radius);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public enum FocusGravity {
* ie. We may want to focus on
* left of recyclerview item
*/
LEFT, CENTER, RIGHT
LEFT, CENTER, RIGHT, TOP, BOTTOM
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.mobiwise.materialintro.shape;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.RectF;

Expand Down Expand Up @@ -30,8 +29,15 @@ public Rect(Target target, Focus focus, FocusGravity focusGravity, int padding)
}

@Override
public void draw(Canvas canvas, Paint eraser, int padding) {
canvas.drawRoundRect(adjustedRect, padding, padding, eraser);
public Path getPath(int padding) {
if (this.padding != padding || cachedPath == null) {
this.padding = padding;
calculateAdjustedRect();
cachedPath = new Path();
cachedPath.addRoundRect(adjustedRect, padding, padding, Path.Direction.CW);
}

return cachedPath;
}

private void calculateAdjustedRect() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package co.mobiwise.materialintro.shape;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Point;

import co.mobiwise.materialintro.target.Target;
Expand All @@ -20,6 +19,8 @@ public abstract class Shape {

protected int padding;

protected Path cachedPath;

public Shape(Target target) {
this(target, Focus.MINIMUM);
}
Expand All @@ -35,7 +36,7 @@ public Shape(Target target, Focus focus, FocusGravity focusGravity, int padding)
this.padding = padding;
}

public abstract void draw(Canvas canvas, Paint eraser, int padding);
public abstract Path getPath(int padding);

protected Point getFocusPoint(){
if(focusGravity == FocusGravity.LEFT){
Expand All @@ -46,8 +47,15 @@ else if(focusGravity == FocusGravity.RIGHT){
int xRight = target.getPoint().x + (target.getRect().right - target.getPoint().x) / 2;
return new Point(xRight, target.getPoint().y);
}
else
return target.getPoint();
else if(focusGravity == FocusGravity.TOP){
int yTop = target.getRect().top + (target.getPoint().y - target.getRect().bottom) / 2;
return new Point(target.getPoint().x, yTop);
}
else if(focusGravity == FocusGravity.BOTTOM){
int yBottom = target.getPoint().y + (target.getRect().bottom - target.getPoint().y) / 2;
return new Point(target.getPoint().x, yBottom);
}
return target.getPoint();
}

public abstract void reCalculateAll();
Expand Down
Loading