Commit 4ff3f1db by likorn

Save CheckableCardView tries

parent 70ac0fd1
......@@ -32,6 +32,8 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
......
......@@ -8,9 +8,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".TaskActivity"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar">
<activity android:name=".TaskActivity">
</activity>
<activity android:name=".MainActivity">
<intent-filter>
......
package com.example.quickmax;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Checkable;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
public class CheckableCardView extends CardView implements Checkable {
private boolean isChecked = false;
private static final int[] CHECKED_STATE_SET = {android.R.attr.state_checked};
public CheckableCardView(@NonNull Context context) {
super(context);
setCardBackgroundColor(
ContextCompat.getColorStateList(
getContext(),
R.color.selector_card_view_colors
)
);
}
public CheckableCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setCardBackgroundColor(
ContextCompat.getColorStateList(
getContext(),
R.color.selector_card_view_colors
)
);
}
public CheckableCardView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setCardBackgroundColor(
ContextCompat.getColorStateList(
getContext(),
R.color.selector_card_view_colors
)
);
}
@Override
public boolean performClick() {
toggle();
return super.performClick();
}
@Override
public void setChecked(boolean checked) {
this.isChecked = checked;
ConstraintLayout parent = (ConstraintLayout) this.getParent();
for(int i = 0; i < 3; i++) {
CheckableCardView child = (CheckableCardView) parent.getChildAt(i);
if (child.getId() != this.getId()) {
child.isChecked = false;
child.onCreateDrawableState(0);
// ((TextView) child.getChildAt(0)).setTextColor(-1979711488);
}
}
}
@Override
public boolean isChecked() {
return isChecked;
}
@Override
public void toggle() {
setChecked(true);
}
@Override
protected int[] onCreateDrawableState(int extraSpace) {
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
TextView tv = (TextView) getChildAt(0);
if (isChecked()) {
mergeDrawableStates(drawableState, CHECKED_STATE_SET);
tv.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
} else {
if (tv!= null)
tv.setTextColor(-1979711488);
}
return drawableState;
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package com.example.quickmax
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity: AppCompatActivity() {
......@@ -9,5 +10,12 @@ class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
seek_bar.setOnSeekbarChangeListener {
n -> seek_bar_value.text = resources.getString(R.string.time_to_solve, n.toString())
}
seek_bar.setMinStartValue(4f).apply()
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gradient_dark" android:state_checked="true" />
<item android:color="@color/white" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/Base.CardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient">
......@@ -33,9 +33,10 @@
app:layout_constraintStart_toStartOf="@+id/textView4"
app:layout_constraintTop_toBottomOf="@+id/textView4">
<androidx.cardview.widget.CardView
<com.example.quickmax.CheckableCardView
android:id="@+id/card_2_digits"
style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/card_3_digits"
app:layout_constraintStart_toStartOf="parent"
......@@ -44,11 +45,12 @@
<TextView
style="@style/AnswerCardText"
android:text="@string/number_digits_2" />
</androidx.cardview.widget.CardView>
</com.example.quickmax.CheckableCardView>
<androidx.cardview.widget.CardView
<com.example.quickmax.CheckableCardView
android:id="@+id/card_3_digits"
style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/card_4_digits"
app:layout_constraintStart_toEndOf="@+id/card_2_digits"
......@@ -57,11 +59,12 @@
<TextView
style="@style/AnswerCardText"
android:text="@string/number_digits_3" />
</androidx.cardview.widget.CardView>
</com.example.quickmax.CheckableCardView>
<androidx.cardview.widget.CardView
<com.example.quickmax.CheckableCardView
android:id="@+id/card_4_digits"
style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/card_3_digits"
......@@ -70,25 +73,45 @@
<TextView
style="@style/AnswerCardText"
android:text="@string/number_digits_4" />
</androidx.cardview.widget.CardView>
</com.example.quickmax.CheckableCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
<SeekBar
android:id="@+id/seekBar"
android:layout_height="wrap_content"
<com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar
android:id="@+id/seek_bar"
android:layout_width="0dp"
android:layout_marginTop="32dp"
app:layout_constraintEnd_toEndOf="@+id/textView4"
app:layout_constraintStart_toStartOf="@+id/textView4"
app:layout_constraintTop_toBottomOf="@+id/layout_num_digits" >
</SeekBar>
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:bar_color="@color/white"
app:bar_highlight_color="@color/gradient_dark"
app:corner_radius="10"
app:data_type="_integer"
app:layout_constraintEnd_toEndOf="@+id/layout_num_digits"
app:layout_constraintStart_toStartOf="@+id/layout_num_digits"
app:layout_constraintTop_toBottomOf="@+id/layout_num_digits"
app:left_thumb_color="@color/white"
app:left_thumb_color_pressed="@color/gradient_dark"
app:max_value="10"
app:min_value="2" />
<TextView
android:id="@+id/textView8"
android:id="@+id/seek_bar_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/time_to_solve"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
android:textColor="@color/white"
app:layout_constraintStart_toStartOf="@+id/layout_num_digits"
app:layout_constraintTop_toBottomOf="@+id/seek_bar" />
<RadioButton
android:id="@+id/radioButton"
style="@style/CardView.Light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TIme to solve"
app:layout_constraintStart_toStartOf="@+id/seekBar"
app:layout_constraintTop_toBottomOf="@+id/seekBar" />
android:button="@android:color/transparent"
android:text="@string/number_digits_2"
android:background="@color/cardview_light_background"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -8,4 +8,5 @@
<string name="number_digits_3">3</string>
<string name="number_digits_4">4</string>
<string name="how_many_digits">HOW MANY DIGITS?</string>
<string name="time_to_solve">Time to solve: %1$s seconds</string>
</resources>
......@@ -35,5 +35,4 @@
<item name="background">@android:color/transparent</item>
<item name="tint">@color/white</item>
</style>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment