Skip to content
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

How to use for RecyclerView #199

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 12
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
3 changes: 2 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {

defaultConfig {
applicationId "uk.co.deanwild.materialshowcaseviewsample"
minSdkVersion 14
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -23,4 +23,5 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation project(':library')
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
26 changes: 12 additions & 14 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.co.deanwild.materialshowcaseviewsample" >
package="uk.co.deanwild.materialshowcaseviewsample">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -18,22 +18,20 @@
</activity>
<activity
android:name=".SimpleSingleExample"
android:label="@string/title_activity_simple_single_example" >
</activity>
android:label="@string/title_activity_simple_single_example"></activity>
<activity
android:name=".CustomExample"
android:label="@string/title_activity_custom_example" >
</activity>
android:label="@string/title_activity_custom_example"></activity>
<activity
android:name=".SequenceExample"
android:label="@string/title_activity_sequence_example" >
</activity>

android:label="@string/title_activity_sequence_example"></activity>
<activity
android:name=".TooltipExample"
android:theme="@style/ToolTipTheme"
android:label="@string/title_activity_sequence_example" >
</activity>
android:label="@string/title_activity_sequence_example"
android:theme="@style/ToolTipTheme"></activity>
<activity
android:name=".RecyclerViewExample"
android:label="@string/title_activity_recyclerview_example"></activity>
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ protected void onCreate(Bundle savedInstanceState) {
button.setOnClickListener(this);
button = findViewById(R.id.btn_tooltip_example);
button.setOnClickListener(this);
button = findViewById(R.id.btn_recyclerview_example);
button.setOnClickListener(this);
button = findViewById(R.id.btn_reset_all);
button.setOnClickListener(this);

Expand Down Expand Up @@ -51,6 +53,10 @@ public void onClick(View v) {
intent = new Intent(this, TooltipExample.class);
break;

case R.id.btn_recyclerview_example:
intent = new Intent(this, RecyclerViewExample.class);
break;

case R.id.btn_reset_all:
MaterialShowcaseView.resetAll(this);
Toast.makeText(this, "All Showcases reset", Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package uk.co.deanwild.materialshowcaseviewsample;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;

/**
* Created by Resul Rıza DOLANER on 20.08.2020.
*/

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder> {

private Context context;
private ArrayList<String> arrayList;

public RecyclerViewAdapter(Context context, ArrayList<String> arrayList) {
this.context = context;
this.arrayList = arrayList;
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_recyclerview, viewGroup, false);
return new MyViewHolder(view);
}

@NonNull
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int position) {

myViewHolder.textView.setText(arrayList.get(position));

}

@Override
public int getItemCount() {
return arrayList.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {

public TextView textView;
public RelativeLayout relativeLayout;
public ImageView imageView;

public MyViewHolder(View itemView) {
super(itemView);

textView = itemView.findViewById(R.id.text_view);
relativeLayout = itemView.findViewById(R.id.relative_layout);
imageView = itemView.findViewById(R.id.image_view);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package uk.co.deanwild.materialshowcaseviewsample;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewTreeObserver;

import java.util.ArrayList;
import java.util.Objects;

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

public class RecyclerViewExample extends AppCompatActivity {

RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view_example);

ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("How to show on recycler view?");
arrayList.add("How to show on recycler view?");
arrayList.add("How to show on recycler view?");

recyclerView = findViewById(R.id.recyclerview);
recyclerView.setHasFixedSize(true);

layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new RecyclerViewAdapter(this, arrayList));

checkedFillAllData();

}

private void checkedFillAllData() {

// It is used to run all the data in the list after it is filled.
// Otherwise, it will not work because it cannot find the first line in direct use, and it will give an empty object error.
recyclerView.getViewTreeObserver()
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {

// I want to get the first line
RecyclerViewAdapter.MyViewHolder myViewHolder = (RecyclerViewAdapter.MyViewHolder) recyclerView.findViewHolderForAdapterPosition(0);

// I catch ImageView object of the first line
View targetImageView = myViewHolder.imageView;
// I catch RelativeLayout object of the first line
View targetRelativeLayout = myViewHolder.relativeLayout;

// We show the objects we obtain sequentially
createShowCaseView(targetImageView, targetRelativeLayout);

// If you don't do it, it will always create
// Minimum Sdk Version should be 16
recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}

private void createShowCaseView(View imageView, View relativeLayout) {
ShowcaseConfig config = new ShowcaseConfig();
MaterialShowcaseSequence sequence = new MaterialShowcaseSequence(this);
sequence.setConfig(config);

sequence.addSequenceItem(new MaterialShowcaseView.Builder(this)
.setTarget(relativeLayout)
.withRectangleShape()
.setContentText("This shows the whole line")
.setDismissText("Next")
.setDismissOnTouch(true)
.build());

sequence.addSequenceItem(new MaterialShowcaseView.Builder(this)
.setTarget(imageView)
.withCircleShape()
.setContentText("OK")
.setDismissText("This shows the imageView object in the entire row")
.setDismissOnTouch(true)
.build());

sequence.start();
}
}
8 changes: 8 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
android:text="Tooltip Style Example"
android:layout_margin="10dp"/>

<Button
android:id="@+id/btn_recyclerview_example"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Example of display on recyclerview"
android:layout_margin="10dp"/>

<Button
android:id="@+id/btn_reset_all"
android:layout_width="match_parent"
Expand Down
15 changes: 15 additions & 0 deletions sample/src/main/res/layout/activity_recycler_view_example.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RecyclerViewExample">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</RelativeLayout>
32 changes: 32 additions & 0 deletions sample/src/main/res/layout/item_recyclerview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp">


<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:padding="5dp"
android:text="@string/title_activity_recyclerview_example"
android:textColor="@color/design_default_color_primary"
android:textSize="16sp" />

<ImageView
android:id="@+id/image_view"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:padding="6dp"
android:src="@drawable/ic_edit"
android:tint="@color/design_default_color_primary" />

</RelativeLayout>
1 change: 1 addition & 0 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<string name="title_activity_custom_example">CustomExample</string>
<string name="title_activity_sequence_example">SequenceExample</string>
<string name="title_activity_tooltip_example">ToolTipExample</string>
<string name="title_activity_recyclerview_example">RecyclerView Example</string>
</resources>