Skip to content

Commit

Permalink
added interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Priyansh-Kedia committed Jun 20, 2020
1 parent 3f5a791 commit 93472cb
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.kedia.scaleselector;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -34,13 +33,14 @@ public class CircularScaleSelector extends FrameLayout implements CircularRecycl
private int maxValue;
private int arrowPointerTint;
private Boolean showArrowPointer;
private onClick listener;

private RecyclerView mRecycler;
private CircularRecyclerAdapter adapter;

private LinearLayoutManager linearLayoutManager ;

public int selectedValue;
private int selectedValue = 0;

public CircularScaleSelector(@NonNull Context context) {
super(context);
Expand All @@ -52,12 +52,17 @@ public CircularScaleSelector(@NonNull Context context, @Nullable AttributeSet at
initLayout(attrs);
}


public void setListener(onClick listener) {
this.listener = listener;
}

private void init(AttributeSet attributeSet) {
TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.CircularScaleSelector);
try {
mainLayoutId = R.layout.circular_recycler_view_layout;
selectedCircleColor = typedArray.getInt(R.styleable.CircularScaleSelector_selectedCircleColor, 5);
backGroundColor = typedArray.getColor(R.styleable.CircularScaleSelector_cricleBackgroundColor, Color.parseColor("#000000"));
backGroundColor = typedArray.getColor(R.styleable.CircularScaleSelector_circleBackgroundColor, Color.parseColor("#000000"));
minValue = typedArray.getInt(R.styleable.CircularScaleSelector_circleMinValue, 0);
maxValue = typedArray.getInt(R.styleable.CircularScaleSelector_circleMaxValue, 200);
defaultTextColor = typedArray.getColor(R.styleable.CircularScaleSelector_circleDefaultTextColor, Color.parseColor("#ffffff"));
Expand Down Expand Up @@ -138,5 +143,11 @@ public void onItemClick(int adapterPosition, @NotNull String ageNumber) {
int center = mRecycler.getWidth() / 2 - mRecycler.findViewHolderForAdapterPosition(adapterPosition).itemView.getWidth() / 2;
linearLayoutManager.scrollToPositionWithOffset(adapterPosition, center);
selectedValue = Integer.parseInt(ageNumber);
if (listener != null)
listener.onClick(selectedValue);
}

interface onClick {
void onClick(int selectedValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ public class ScaleSelector extends FrameLayout implements RecyclerAdapter.OnClic
private int defaultPointerColor;
private int maxValue;
private int arrowPointerTint;

private ScaleSelector.onClick listener;

private Boolean showArrowPointer;

private RecyclerView mRecycler;
private RecyclerAdapter adapter;

private LinearLayoutManager linearLayoutManager ;

public int selectedValue;
private int selectedValue;

public ScaleSelector(Context context) {
super(context);
Expand All @@ -49,6 +52,10 @@ public ScaleSelector(Context context, AttributeSet attributeSet) {
initLayout(attributeSet);
}

public void setListener(ScaleSelector.onClick listener) {
this.listener = listener;
}

private void init(AttributeSet attributeSet) {
TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.ScaleSelector);
try {
Expand Down Expand Up @@ -151,6 +158,12 @@ public void onHeightClicked(@NotNull String height, int adapterPosition) {
int center = mRecycler.getWidth() / 2 - mRecycler.findViewHolderForAdapterPosition(adapterPosition).itemView.getWidth() / 2;
linearLayoutManager.scrollToPositionWithOffset(adapterPosition, center);
selectedValue = Integer.parseInt(height);
if (listener != null)
listener.onScaleClicked(selectedValue);
}

interface onClick {
void onScaleClicked(int selectedValue);
}

}
8 changes: 4 additions & 4 deletions app/scaleselector/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<attr name="circleSelectedTextColor" format="color" />
<attr name="circleMinValue" format="integer" />
<attr name="circleMaxValue" format="integer" />
<attr name="cricleBackgroundColor" format="color" />
<attr name="selectedCircleColor" format="color" />
<!-- <attr name="showArrowPointer" format="boolean" />-->
<!-- <attr name="arrowPointerTint" format="color" />-->
<attr name="circleBackgroundColor" format="color" />
<attr name="selectedCircleColor" format="color" />
<!-- <attr name="showArrowPointer" format="boolean" />-->
<!-- <attr name="arrowPointerTint" format="color" />-->
</declare-styleable>
</resources>
14 changes: 12 additions & 2 deletions app/src/main/java/com/kedia/scaleselector/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
class MainActivity : AppCompatActivity(), CircularScaleSelector.onClick, ScaleSelector.onClick {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

//testRecycler.getSelectedValue()
Log.d("TAG!!!",demoId.selectedValue.toString() + "asdfasd " + testRecycler.selectedValue.toString())
demoId.setListener(this)
testRecycler.setListener(this)
}

override fun onClick(selectedValue: Int) {
Log.d("TAG!!!",selectedValue.toString())
}

override fun onScaleClicked(selectedValue: Int) {
Log.d("TAG!!!",selectedValue.toString())
}
}
38 changes: 19 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<!-- <com.kedia.scaleselector.ScaleSelector-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:id="@+id/testRecycler"-->
<!-- app:showArrowPointer="true"-->
<!-- app:minValue="100"-->
<!-- app:arrowPointerTint="#000000"-->
<!-- app:maxValue="200"-->
<!-- app:defaultPointerColor="#6F86D6"-->
<!-- app:stepValue="10"-->
<!-- app:selectedTextColor="#fff"-->
<!-- app:defaultTextColor="#fff"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- app:layout_constraintBottom_toBottomOf="parent" />-->
<com.kedia.scaleselector.ScaleSelector
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/testRecycler"
app:showArrowPointer="true"
app:minValue="100"
app:arrowPointerTint="#000000"
app:maxValue="200"
app:defaultPointerColor="#6F86D6"
app:stepValue="10"
app:selectedTextColor="#fff"
app:defaultTextColor="#fff"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

<com.kedia.scaleselector.CircularScaleSelector
android:layout_width="wrap_content"
Expand All @@ -30,11 +30,11 @@
app:circleMinValue="100"
app:circleSelectedTextColor="#000000"
app:selectedCircleColor="@color/blue"
app:cricleBackgroundColor="#fff"
app:circleDefaultTextColor="@color/blue"
app:circleBackgroundColor="@color/colorPrimaryDark"
app:circleMaxValue="200"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintTop_toBottomOf="@id/testRecycler"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 93472cb

Please sign in to comment.