This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix measure problems inside RecyclerView and ScrollView
- Loading branch information
Showing
20 changed files
with
688 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
.../src/main/java/com/shuhart/stepview/sample/examples/recyclerview/CurrentStepListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.shuhart.stepview.sample.examples.recyclerview; | ||
|
||
interface CurrentStepListener { | ||
void update(int adapterPosition, int step); | ||
} |
108 changes: 108 additions & 0 deletions
108
sample/src/main/java/com/shuhart/stepview/sample/examples/recyclerview/DummyAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.shuhart.stepview.sample.examples.recyclerview; | ||
|
||
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.Toast; | ||
|
||
import com.shuhart.stepview.StepView; | ||
import com.shuhart.stepview.sample.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DummyAdapter extends RecyclerView.Adapter<DummyAdapter.DummyHolder> implements CurrentStepListener { | ||
private List<Integer> currentSteps = new ArrayList<Integer>(){{ | ||
for (int i = 0; i < 20; i++){ | ||
add(0); | ||
} | ||
}}; | ||
|
||
@NonNull | ||
@Override | ||
public DummyAdapter.DummyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
return new DummyHolder( | ||
LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.item_dummy, parent, false) | ||
); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull DummyAdapter.DummyHolder holder, int position) { | ||
if (position % 2 == 0) { | ||
List<String> steps = new ArrayList<>(); | ||
for (int i = 0; i < 5; i++) { | ||
steps.add("Step " + (i + 1)); | ||
} | ||
holder.stepView.setSteps(steps); | ||
} else { | ||
holder.stepView.setStepsNumber(5); | ||
} | ||
holder.stepView.go(currentSteps.get(position), false); | ||
} | ||
|
||
@Override | ||
public void onViewAttachedToWindow(@NonNull DummyHolder holder) { | ||
super.onViewAttachedToWindow(holder); | ||
holder.listener = this; | ||
} | ||
|
||
@Override | ||
public void onViewDetachedFromWindow(@NonNull DummyHolder holder) { | ||
super.onViewDetachedFromWindow(holder); | ||
holder.listener = null; | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return currentSteps.size(); | ||
} | ||
|
||
@Override | ||
public void update(int adapterPosition, int step) { | ||
currentSteps.set(adapterPosition, step); | ||
} | ||
|
||
static class DummyHolder extends RecyclerView.ViewHolder { | ||
StepView stepView; | ||
CurrentStepListener listener; | ||
|
||
private int currentStep = 0; | ||
|
||
DummyHolder(final View itemView) { | ||
super(itemView); | ||
stepView = itemView.findViewById(R.id.step_view); | ||
stepView.setOnStepClickListener(new StepView.OnStepClickListener() { | ||
@Override | ||
public void onStepClick(int step) { | ||
Toast.makeText(itemView.getContext(), "Step " + step, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
itemView.findViewById(R.id.next).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentStep < stepView.getStepCount() - 1) { | ||
currentStep++; | ||
stepView.go(currentStep, true); | ||
listener.update(getAdapterPosition(), currentStep); | ||
} else { | ||
stepView.done(true); | ||
} | ||
} | ||
}); | ||
itemView.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentStep > 0) { | ||
currentStep--; | ||
listener.update(getAdapterPosition(), currentStep); | ||
} | ||
stepView.done(false); | ||
stepView.go(currentStep, true); | ||
} | ||
}); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...n/java/com/shuhart/stepview/sample/examples/recyclerview/RecyclerViewExampleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.shuhart.stepview.sample.examples.recyclerview; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.shuhart.stepview.sample.R; | ||
|
||
public class RecyclerViewExampleActivity extends AppCompatActivity { | ||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_recycler_view); | ||
RecyclerView recyclerView = findViewById(R.id.recycler_view); | ||
DummyAdapter adapter = new DummyAdapter(); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
sample/src/main/java/com/shuhart/stepview/sample/examples/simple/SimpleActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.shuhart.stepview.sample.examples.simple; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
import com.shuhart.stepview.StepView; | ||
import com.shuhart.stepview.sample.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SimpleActivity extends AppCompatActivity { | ||
private int currentStep = 0; | ||
private int currentStep2 = 0; | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_simple); | ||
final StepView stepView = findViewById(R.id.step_view); | ||
stepView.setOnStepClickListener(new StepView.OnStepClickListener() { | ||
@Override | ||
public void onStepClick(int step) { | ||
Toast.makeText(SimpleActivity.this, "Step " + step, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
findViewById(R.id.next).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentStep < stepView.getStepCount() - 1) { | ||
currentStep++; | ||
stepView.go(currentStep, true); | ||
} else { | ||
stepView.done(true); | ||
} | ||
} | ||
}); | ||
findViewById(R.id.back).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentStep > 0) { | ||
currentStep--; | ||
} | ||
stepView.done(false); | ||
stepView.go(currentStep, true); | ||
} | ||
}); | ||
List<String> steps = new ArrayList<>(); | ||
for (int i = 0; i < 5; i++) { | ||
steps.add("Step " + (i + 1)); | ||
} | ||
stepView.setSteps(steps); | ||
|
||
final StepView stepView2 = findViewById(R.id.step_view_2); | ||
stepView2.setOnStepClickListener(new StepView.OnStepClickListener() { | ||
@Override | ||
public void onStepClick(int step) { | ||
Toast.makeText(SimpleActivity.this, "Step " + step, Toast.LENGTH_SHORT).show(); | ||
} | ||
}); | ||
findViewById(R.id.next_2).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentStep2 < stepView2.getStepCount() - 1) { | ||
currentStep2++; | ||
stepView2.go(currentStep2, true); | ||
} else { | ||
stepView2.done(true); | ||
} | ||
} | ||
}); | ||
findViewById(R.id.back_2).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (currentStep2 > 0) { | ||
currentStep2--; | ||
} | ||
stepView2.done(false); | ||
stepView2.go(currentStep2, true); | ||
} | ||
}); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
sample/src/main/java/com/shuhart/stepview/sample/main/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.shuhart.stepview.sample.main; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.widget.ScrollView; | ||
import android.widget.Toast; | ||
|
||
import com.shuhart.stepview.StepView; | ||
import com.shuhart.stepview.sample.R; | ||
import com.shuhart.stepview.sample.examples.recyclerview.RecyclerViewExampleActivity; | ||
import com.shuhart.stepview.sample.examples.scrollview.ScrollViewExampleActivity; | ||
import com.shuhart.stepview.sample.examples.simple.SimpleActivity; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@SuppressLint("SetTextI18n") | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
MainAdapter adapter = new MainAdapter(); | ||
adapter.items = new ArrayList<MainAdapter.Item>() {{ | ||
add(MainAdapter.Item.SIMPLE); | ||
add(MainAdapter.Item.RECYCLER_VIEW); | ||
add(MainAdapter.Item.SCROLL_VIEW); | ||
}}; | ||
adapter.listener = new MainAdapter.ItemClickListener() { | ||
@Override | ||
public void onClick(MainAdapter.Item item) { | ||
switch (item) { | ||
case SIMPLE: | ||
startActivity(new Intent(MainActivity.this, SimpleActivity.class)); | ||
break; | ||
case RECYCLER_VIEW: | ||
startActivity(new Intent(MainActivity.this, RecyclerViewExampleActivity.class)); | ||
break; | ||
case SCROLL_VIEW: | ||
startActivity(new Intent(MainActivity.this, ScrollViewExampleActivity.class)); | ||
break; | ||
} | ||
} | ||
}; | ||
RecyclerView recyclerView = findViewById(R.id.recycler_view); | ||
recyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
recyclerView.setAdapter(adapter); | ||
} | ||
} |
Oops, something went wrong.