Skip to content
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
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,96 @@ This is the basic usage of a single showcase view, you should check out the samp

```

This is the advance usage of MaterialShowCase using Adapters, this will encapsulate everything for you.

**In your Activity**
```java

@Override
protected void onStart() {
super.onStart();
// With Pool Management to run 1 Sequence or 1 View at a time.
// Material Show Case Initialization
MaterialShowCaseAdapter.initialize(this, CustomAdapter.class);
// Simple Material Show Case Initialization
MaterialShowCaseAdapter.initialize(this, R.array.showcase_simple_activity_adapter_example, "SimpleActivityAdapterExample");
}

```

**If you're using custom adapter**
```java

public class CustomAdapter extends MaterialShowCaseAdapter {

public CustomAdapter(Activity activity) {
super(
activity,
MaterialShowCaseAdapter.SHOW_CASE_DELAY, // DELAY
"ActivityAdapterExample" // ID
);
}

@Override // Setup of all show cases views
public void setup() {
super.addToQueue(R.id.btn_one, "", "This is button one","GOT IT", MaterialShowCaseViewShape.CIRCLE);
super.addToQueue(R.id.btn_two, "", "This is button two","GOT IT", MaterialShowCaseViewShape.RECTANGLE);
super.addToQueue(R.id.btn_three, "", "This is button three","GOT IT", MaterialShowCaseViewShape.RECTANGLE);
}

@Override // Behavior
public void onDismiss(MaterialShowcaseView materialShowcaseView, int i) {
super.onDismiss(materialShowcaseView, i);
switch (currentQueueItemId){
case 1:
Toast.makeText(activity, "You GOT Button One, nice!", Toast.LENGTH_SHORT).show();
break;
}
}
}

```

**If you're using simple adapter, use a resource array**, you can use this for simple show cases.
```xml

<!--Simple Activity Adapter Example-->
<string-array name="showcase_simple_activity_adapter_example_titles">
<item></item>
<item></item>
<item></item>
</string-array>
<string-array name="showcase_simple_activity_adapter_example_views">
<item>@id/btn_one</item>
<item>@id/btn_two</item>
<item>@id/btn_three</item>
</string-array>
<string-array name="showcase_simple_activity_adapter_example_contents">
<item>This is button one</item>
<item>This is button two</item>
<item>This is button three</item>
</string-array>
<string-array name="showcase_simple_activity_adapter_example_buttons">
<item>GOT IT</item>
<item>GOT IT</item>
<item>GOT IT</item>
</string-array>
<string-array name="showcase_simple_activity_adapter_example_shapes">
<item>circle</item>
<item>rectangle</item>
<item>rectangle</item>
</string-array>
<array name="showcase_simple_activity_adapter_example">
<item>@array/showcase_simple_activity_adapter_example_views</item>
<item>@array/showcase_simple_activity_adapter_example_titles</item>
<item>@array/showcase_simple_activity_adapter_example_contents</item>
<item>@array/showcase_simple_activity_adapter_example_buttons</item>
<item>@array/showcase_simple_activity_adapter_example_shapes</item>
</array>
<!--Simple Activity Adapter Example-->

```

# Why Jitpack
------------
Publishing libraries to Maven is a chore that takes time and effort. Jitpack.io allows me to release without ever leaving GitHub so I can release easily and more often.
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:23.1.1'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package uk.co.deanwild.materialshowcaseview.adapter;

import android.app.Activity;
import android.os.Handler;
import android.support.annotation.ArrayRes;
import android.support.annotation.IdRes;
import android.support.annotation.StringRes;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

import uk.co.deanwild.materialshowcaseview.MaterialShowcaseSequence;
import uk.co.deanwild.materialshowcaseview.MaterialShowcaseView;
import uk.co.deanwild.materialshowcaseview.ShowcaseConfig;

/**
* Created by TurboCoder (Yamil García Hernández) on 7/7/16.
*/
public abstract class MaterialShowCaseAdapter implements MaterialShowcaseSequence.OnSequenceItemDismissedListener {

// Constants
protected String SHOW_CASE_ID;
public final static int SHOW_CASE_DELAY = 5;

public static final ArrayList<MaterialShowcaseSequence> POOL = new ArrayList<>();

// Variables
protected Activity activity;
private MaterialShowcaseSequence sequence;
protected ShowcaseConfig config;
private ArrayList<MaterialShowcaseView> queue = new ArrayList<>();
protected int currentQueueItemId = 0;

public MaterialShowCaseAdapter(Activity activity, int delay, String id) {
this.activity = activity;
this.config = new ShowcaseConfig();
this.SHOW_CASE_ID = id;
config.setDelay(SHOW_CASE_DELAY);
sequence = new MaterialShowcaseSequence(activity, id);
sequence.setConfig(config);
}

public abstract void setup();

public void start() {
setup();
MaterialShowCaseAdapter.POOL.add(sequence);
sequence.setOnItemDismissedListener(this);
if (POOL.size() <= 1)
sequence.start();
}

public static void initialize(Activity activity, Class clazz) {
try {
Constructor<?> constructor = clazz.getConstructor(Activity.class);
Object obj = constructor.newInstance(new Object[]{activity});

if (obj instanceof MaterialShowCaseAdapter)
((MaterialShowCaseAdapter) obj).start();

} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}

public static void initializeWithDelay(final Activity activity, final Class clazz, long delay) {
try {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
try {
Constructor<?> constructor = clazz.getConstructor(Activity.class);
Object obj = constructor.newInstance(new Object[]{activity});

if (obj instanceof MaterialShowCaseAdapter)
((MaterialShowCaseAdapter) obj).start();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}, delay);

} catch (Exception e) {
e.printStackTrace();
}
}


public static void initialize(Activity activity, @ArrayRes int config, String id) {
try {
(new SimpleMaterialShowCaseAdapter(activity, activity.getResources().obtainTypedArray(config), id)).start();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void initializeWithDelay(final Activity activity, @ArrayRes final int config, final String id, long delay) {
try {

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
(new SimpleMaterialShowCaseAdapter(activity, activity.getResources().obtainTypedArray(config), id)).start();
}
}, delay);
} catch (Exception e) {
e.printStackTrace();
}
}

public void addToQueue(MaterialShowcaseView v) {
queue.add(v);
sequence.addSequenceItem(v);
}

public void addToQueue(@IdRes int i, String title, String content, String button, MaterialShowCaseViewShape shape) {
MaterialShowcaseView.Builder msvb = new MaterialShowcaseView.Builder(activity)
.setTarget(activity.findViewById(i))
.setTitleText(title)
.setContentText(content)
.setDismissText(button);

switch (shape) {
case CIRCLE:
msvb.withCircleShape();
break;
case RECTANGLE:
msvb.withRectangleShape();
break;
}

MaterialShowcaseView msv = msvb.build();

queue.add(msv);
sequence.addSequenceItem(msv);
}

public void addToQueue(@IdRes int i, @StringRes int title, @StringRes int content, @StringRes int button, MaterialShowCaseViewShape shape) {
MaterialShowcaseView.Builder msvb = new MaterialShowcaseView.Builder(activity)
.setTarget(activity.findViewById(i))
.setTitleText(title)
.setContentText(content)
.setDismissText(button);

switch (shape) {
case CIRCLE:
msvb.withCircleShape();
break;
case RECTANGLE:
msvb.withRectangleShape();
break;
}

MaterialShowcaseView msv = msvb.build();

queue.add(msv);
sequence.addSequenceItem(msv);
}


@Override
public void onDismiss(MaterialShowcaseView materialShowcaseView, int i) {
if (currentQueueItemId == (queue.size() - 1)) {
MaterialShowCaseAdapter.POOL.remove(0);
if (POOL.size() > 0)
MaterialShowCaseAdapter.POOL.get(0).start();
}
currentQueueItemId++;
}

public enum MaterialShowCaseViewShape {
CIRCLE, RECTANGLE
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package uk.co.deanwild.materialshowcaseview.adapter;

import android.app.Activity;
import android.content.res.Resources;
import android.content.res.TypedArray;

/**
* Created by TurboCoder (Yamil García Hernández) on 7/7/16.
*/
public class SimpleMaterialShowCaseAdapter extends MaterialShowCaseAdapter {

public int[] ids;
public String[] titles;
public String[] contents;
public String[] buttons;
public String[] shapes;

public SimpleMaterialShowCaseAdapter(Activity activity, TypedArray array, String id) {
super(
activity,
MaterialShowCaseAdapter.SHOW_CASE_DELAY,
id
);
Resources res = activity.getResources();
TypedArray idz = res.obtainTypedArray(array.getResourceId(0, 0));
this.ids = new int[idz.length()];
for (int n = 0; n < idz.length(); n++)
this.ids[n] = idz.getResourceId(n, 0);
idz.recycle();
this.titles = res.getStringArray(array.getResourceId(1, 0));
this.contents = res.getStringArray(array.getResourceId(2, 0));
this.buttons = res.getStringArray(array.getResourceId(3, 0));
this.shapes = res.getStringArray(array.getResourceId(4, 0));
array.recycle();

}

@Override
public void setup() {

for (int n = 0; n < ids.length; n++) {
switch (shapes[n]) {
case "circle":
addToQueue(ids[n], titles[n], contents[n], buttons[n], MaterialShowCaseViewShape.CIRCLE);
break;
case "rectangle":
addToQueue(ids[n], titles[n], contents[n], buttons[n], MaterialShowCaseViewShape.RECTANGLE);
break;
}
}

}
}
4 changes: 4 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
android:name=".SequenceExample"
android:label="@string/title_activity_sequence_example" >
</activity>
<activity
android:name=".ActivityAdapterExample"
android:label="@string/title_activity_sequence_example" >
</activity>
</application>

</manifest>
Loading