Commit cef6183d by likorn

Design refactoring; removed CheckableCardView

parent 4ff3f1db
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
package com.example.quickmax package com.example.quickmax
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
class MainActivity: AppCompatActivity() { class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
...@@ -14,8 +14,10 @@ class MainActivity: AppCompatActivity() { ...@@ -14,8 +14,10 @@ class MainActivity: AppCompatActivity() {
seek_bar.setOnSeekbarChangeListener { seek_bar.setOnSeekbarChangeListener {
n -> seek_bar_value.text = resources.getString(R.string.time_to_solve, n.toString()) n -> seek_bar_value.text = resources.getString(R.string.time_to_solve, n.toString())
} }
seek_bar.setMinStartValue(4f).apply() seek_bar.setMinStartValue(4f).apply()
card_3_digits.setOnClickListener {
startActivity(Intent(this, TaskActivity::class.java))
}
} }
} }
\ No newline at end of file
...@@ -24,9 +24,9 @@ class ResponseFragment: Fragment() { ...@@ -24,9 +24,9 @@ class ResponseFragment: Fragment() {
val view = inflater.inflate(R.layout.fragment_response, container, false) val view = inflater.inflate(R.layout.fragment_response, container, false)
val correct = arguments!!.getBoolean("correct") val correct = arguments!!.getBoolean("correct")
return if (correct) return if (correct)
view(view, ContextCompat.getColor(activity!!, R.color.gradient_light), R.string.response_correct) view(view, ContextCompat.getColor(activity!!, R.color.colorAccent), R.string.response_correct)
else else
view(view, ContextCompat.getColor(activity!!, R.color.gradient_dark), R.string.response_wrong) view(view, ContextCompat.getColor(activity!!, R.color.colorPrimary), R.string.response_wrong)
} }
private fun view(view: View, color: Int, responseId: Int): View { private fun view(view: View, color: Int, responseId: Int): View {
......
...@@ -2,6 +2,7 @@ package com.example.quickmax ...@@ -2,6 +2,7 @@ package com.example.quickmax
import android.animation.ArgbEvaluator import android.animation.ArgbEvaluator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.graphics.Color
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.CountDownTimer import android.os.CountDownTimer
...@@ -54,8 +55,8 @@ class TaskActivity : AppCompatActivity() { ...@@ -54,8 +55,8 @@ class TaskActivity : AppCompatActivity() {
} }
private fun startProgressBarAnimation() { private fun startProgressBarAnimation() {
val colorFrom = ContextCompat.getColor(this, R.color.gradient_dark) val colorFrom = ContextCompat.getColor(this, R.color.colorPrimary)
val colorTo = ContextCompat.getColor(this, R.color.red) val colorTo = Color.RED
val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo) val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo)
colorAnimation.duration = timeToSolve colorAnimation.duration = timeToSolve
colorAnimation.addUpdateListener { animator -> colorAnimation.addUpdateListener { animator ->
......
...@@ -4,7 +4,6 @@ import android.os.Bundle ...@@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageButton
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
class TimeIsOverFragment: Fragment() { class TimeIsOverFragment: Fragment() {
...@@ -18,7 +17,7 @@ class TimeIsOverFragment: Fragment() { ...@@ -18,7 +17,7 @@ class TimeIsOverFragment: Fragment() {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_time_is_over, container, false) val view = inflater.inflate(R.layout.fragment_time_is_over, container, false)
view.findViewById<ImageButton>(R.id.btn_next).setOnClickListener { (activity as TaskActivity).reload() } view.setOnClickListener { (activity as TaskActivity).reload() }
return view return view
} }
} }
\ 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
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient <gradient
android:angle="90" android:angle="90"
android:endColor="@color/gradient_dark" android:endColor="@color/colorPrimary"
android:startColor="@color/gradient_light" android:startColor="@color/colorAccent"
android:type="linear" /> android:type="linear" />
</shape> </shape>
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
android:gravity="center" android:gravity="center"
android:text="@string/how_many_digits" android:text="@string/how_many_digits"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4" android:textAppearance="@style/TextAppearance.MaterialComponents.Headline4"
android:textColor="@color/white" android:textColor="@android:color/white"
app:layout_constraintBottom_toTopOf="@+id/layout_num_digits" app:layout_constraintBottom_toTopOf="@+id/layout_num_digits"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
app:layout_constraintStart_toStartOf="@+id/textView4" app:layout_constraintStart_toStartOf="@+id/textView4"
app:layout_constraintTop_toBottomOf="@+id/textView4"> app:layout_constraintTop_toBottomOf="@+id/textView4">
<com.example.quickmax.CheckableCardView <androidx.cardview.widget.CardView
android:id="@+id/card_2_digits" android:id="@+id/card_2_digits"
style="@style/MyCard" style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
...@@ -45,9 +45,9 @@ ...@@ -45,9 +45,9 @@
<TextView <TextView
style="@style/AnswerCardText" style="@style/AnswerCardText"
android:text="@string/number_digits_2" /> android:text="@string/number_digits_2" />
</com.example.quickmax.CheckableCardView> </androidx.cardview.widget.CardView>
<com.example.quickmax.CheckableCardView <androidx.cardview.widget.CardView
android:id="@+id/card_3_digits" android:id="@+id/card_3_digits"
style="@style/MyCard" style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
...@@ -59,9 +59,9 @@ ...@@ -59,9 +59,9 @@
<TextView <TextView
style="@style/AnswerCardText" style="@style/AnswerCardText"
android:text="@string/number_digits_3" /> android:text="@string/number_digits_3" />
</com.example.quickmax.CheckableCardView> </androidx.cardview.widget.CardView>
<com.example.quickmax.CheckableCardView <androidx.cardview.widget.CardView
android:id="@+id/card_4_digits" android:id="@+id/card_4_digits"
style="@style/MyCard" style="@style/MyCard"
android:foreground="?android:attr/selectableItemBackground" android:foreground="?android:attr/selectableItemBackground"
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
<TextView <TextView
style="@style/AnswerCardText" style="@style/AnswerCardText"
android:text="@string/number_digits_4" /> android:text="@string/number_digits_4" />
</com.example.quickmax.CheckableCardView> </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar <com.crystal.crystalrangeseekbar.widgets.CrystalSeekbar
...@@ -81,15 +81,15 @@ ...@@ -81,15 +81,15 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
app:bar_color="@color/white" app:bar_color="@android:color/white"
app:bar_highlight_color="@color/gradient_dark" app:bar_highlight_color="@color/colorPrimary"
app:corner_radius="10" app:corner_radius="10"
app:data_type="_integer" app:data_type="_integer"
app:layout_constraintEnd_toEndOf="@+id/layout_num_digits" app:layout_constraintEnd_toEndOf="@+id/layout_num_digits"
app:layout_constraintStart_toStartOf="@+id/layout_num_digits" app:layout_constraintStart_toStartOf="@+id/layout_num_digits"
app:layout_constraintTop_toBottomOf="@+id/layout_num_digits" app:layout_constraintTop_toBottomOf="@+id/layout_num_digits"
app:left_thumb_color="@color/white" app:left_thumb_color="@android:color/white"
app:left_thumb_color_pressed="@color/gradient_dark" app:left_thumb_color_pressed="@color/colorPrimary"
app:max_value="10" app:max_value="10"
app:min_value="2" /> app:min_value="2" />
...@@ -101,17 +101,8 @@ ...@@ -101,17 +101,8 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/time_to_solve" android:text="@string/time_to_solve"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption" android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
android:textColor="@color/white" android:textColor="@android:color/white"
app:layout_constraintStart_toStartOf="@+id/layout_num_digits" app:layout_constraintStart_toStartOf="@+id/layout_num_digits"
app:layout_constraintTop_toBottomOf="@+id/seek_bar" /> 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:button="@android:color/transparent"
android:text="@string/number_digits_2"
android:background="@color/cardview_light_background"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
android:id="@+id/img_view_timer" android:id="@+id/img_view_timer"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp" android:tint="@android:color/white"
android:tint="@color/white"
app:layout_constraintBottom_toTopOf="@id/textView" app:layout_constraintBottom_toTopOf="@id/textView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -22,33 +21,25 @@ ...@@ -22,33 +21,25 @@
android:id="@+id/textView" android:id="@+id/textView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/time_is_over" android:text="@string/time_is_over"
android:textAppearance="@style/TextAppearance.AppCompat.Large" android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@color/white" android:textColor="@android:color/white"
app:layout_constraintBottom_toTopOf="@+id/response_layout" app:layout_constraintBottom_toTopOf="@+id/textView2"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img_view_timer" /> app:layout_constraintTop_toBottomOf="@+id/img_view_timer" />
<androidx.constraintlayout.widget.ConstraintLayout <TextView
android:id="@+id/response_layout" android:id="@+id/textView2"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="54dp" android:layout_height="wrap_content"
android:background="@color/white" android:layout_marginBottom="32dp"
android:text="Tap to continue"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="#97000000"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="@+id/btn_next"
style="@style/ButtonNext"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_double_arrow_small" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="colorPrimary">#008577</color> <color name="colorPrimary">#4a148c</color>
<color name="colorPrimaryDark">#00574B</color> <color name="colorPrimaryDark">#12005e</color>
<color name="colorAccent">#FF4A148C</color> <color name="colorAccent">#4dd0e1</color>
<color name="transparent_black">#97000000</color>
<color name="colorBackground">#C4BFCC</color>
<color name="colorCorrect">#81C784</color>
<color name="gradient_dark">#FF4A148C</color>
<color name="gradient_light">#FF00BCD4</color>
<color name="white">#FFF</color>
<color name="red">#F00</color>
</resources> </resources>
...@@ -9,4 +9,5 @@ ...@@ -9,4 +9,5 @@
<string name="number_digits_4">4</string> <string name="number_digits_4">4</string>
<string name="how_many_digits">HOW MANY DIGITS?</string> <string name="how_many_digits">HOW MANY DIGITS?</string>
<string name="time_to_solve">Time to solve: %1$s seconds</string> <string name="time_to_solve">Time to solve: %1$s seconds</string>
<string name="btn_next">Next</string>
</resources> </resources>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<item name="android:layout_marginTop">8dp</item> <item name="android:layout_marginTop">8dp</item>
<item name="android:layout_marginEnd">24dp</item> <item name="android:layout_marginEnd">24dp</item>
<item name="android:layout_marginBottom">8dp</item> <item name="android:layout_marginBottom">8dp</item>
<item name="background">@android:color/transparent</item> <item name="android:background">@android:color/transparent</item>
<item name="tint">@color/white</item> <item name="tint">@android:color/white</item>
</style> </style>
</resources> </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