Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Fix measure problems inside RecyclerView and ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhart committed Sep 11, 2018
1 parent d719bbc commit 1a29a0e
Show file tree
Hide file tree
Showing 20 changed files with 688 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Usage
-----

1. Add jcenter() to repositories block in your gradle file.
2. Add `implementation 'com.shuhart.stepview:stepview:1.3.1'` to your dependencies.
2. Add `implementation 'com.shuhart.stepview:stepview:1.3.2'` to your dependencies.
3. Add `StepView` into your layouts or view hierarchy.

Supported animations:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.1.4'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
3 changes: 2 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$supportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:recyclerview-v7:$supportVersion"
implementation project(':stepview')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
5 changes: 4 additions & 1 deletion sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".main.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".examples.recyclerview.RecyclerViewExampleActivity" />
<activity android:name=".examples.scrollview.ScrollViewExampleActivity" />
<activity android:name=".examples.simple.SimpleActivity" />
</application>

</manifest>
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);
}
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);
}
});
}
}
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,29 @@
package com.shuhart.stepview.sample;
package com.shuhart.stepview.sample.examples.scrollview;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.TextView;
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 MainActivity extends AppCompatActivity {
public class ScrollViewExampleActivity extends AppCompatActivity {
private int currentStep = 0;

@SuppressLint("SetTextI18n")
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setContentView(R.layout.activity_scrollview);
final StepView stepView = findViewById(R.id.step_view);
// stepView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
// @Override
// public void onGlobalLayout() {
// // still, it's very unlikely you are going to see this animation
// stepView.go(1, true);
// }
// });
stepView.go(1, true);
stepView.setOnStepClickListener(new StepView.OnStepClickListener() {
@Override
public void onStepClick(int step) {
Toast.makeText(MainActivity.this, "Step " + step, Toast.LENGTH_SHORT).show();
Toast.makeText(ScrollViewExampleActivity.this, "Step " + step, Toast.LENGTH_SHORT).show();
}
});
findViewById(R.id.next).setOnClickListener(new View.OnClickListener() {
Expand All @@ -57,5 +47,10 @@ public void onClick(View v) {
stepView.go(currentStep, true);
}
});
List<String> steps = new ArrayList<>();
for (int i = 0; i < 5; i++) {
steps.add("Step " + (i + 1));
}
stepView.setSteps(steps);
}
}
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);
}
});
}
}
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);
}
}
Loading

0 comments on commit 1a29a0e

Please sign in to comment.