Skip to content

Commit f27f763

Browse files
authored
Merge pull request #5 from Yalantis/feature/changing_background
added posibility to change background
2 parents 30e2fd0 + 099b457 commit f27f763

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

app/src/main/java/com/yalantis/fitfilter/ExampleActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yalantis.fitfilter;
22

3+
import android.graphics.Color;
34
import android.os.Bundle;
45
import android.support.v4.content.ContextCompat;
56
import android.support.v7.app.AppCompatActivity;
@@ -52,6 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
5253
mFilter.setNoSelectedItemText(getString(R.string.str_all_selected));
5354
mFilter.build();
5455

56+
5557
mRecyclerView = (RecyclerView) findViewById(R.id.list);
5658
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
5759
mRecyclerView.setAdapter(mAdapter = new QuestionsAdapter(this, mAllQuestions = getQuestions()));

filter/src/main/java/com/yalantis/filter/widget/CollapsedFilterContainer.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.yalantis.filter.widget
22

33
import android.content.Context
4+
import android.graphics.Color
45
import android.util.AttributeSet
56
import android.view.LayoutInflater
67
import android.view.MotionEvent
@@ -19,6 +20,12 @@ class CollapsedFilterContainer : RelativeLayout {
1920
private var mStartX = 0f
2021
private var mStartY = 0f
2122

23+
var containerBackground = Color.WHITE
24+
set(value) {
25+
field = value
26+
relative_container.setBackgroundColor(value)
27+
}
28+
2229
constructor(context: Context) : this(context, null)
2330
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
2431
constructor(context: Context, attrs: AttributeSet?, defStyleRes: Int) : super(context, attrs, defStyleRes) {

filter/src/main/java/com/yalantis/filter/widget/Filter.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import kotlinx.android.synthetic.main.collapsed_container.view.*
2020
import kotlinx.android.synthetic.main.filter.view.*
2121
import java.io.Serializable
2222
import java.util.*
23+
import android.content.res.TypedArray
24+
import android.graphics.Color
25+
import android.support.annotation.ColorInt
26+
2327

2428
/**
2529
* Created by galata on 08.09.16.
@@ -43,6 +47,20 @@ class Filter<T : FilterModel> : FrameLayout, FilterItemListener, CollapseListene
4347
collapseView.setHasText(value)
4448
}
4549

50+
var collapsedBackground: Int = Color.WHITE
51+
set(value) {
52+
field = value
53+
collapsedContainer.containerBackground = value
54+
collapsedContainer.invalidate()
55+
}
56+
57+
var expandedBackground: Int = Color.WHITE
58+
set(value) {
59+
field = value
60+
expandedFilter.setBackgroundColor(value)
61+
expandedFilter.invalidate()
62+
}
63+
4664
private var mIsBusy = false
4765

4866
private var isCollapsed: Boolean? = null
@@ -66,6 +84,13 @@ class Filter<T : FilterModel> : FrameLayout, FilterItemListener, CollapseListene
6684
collapsedFilter.scrollListener = this
6785
collapsedContainer.listener = this
6886
expandedFilter.listener = this
87+
val attributes = context.obtainStyledAttributes(attrs, R.styleable.Filter, 0, 0)
88+
try {
89+
collapsedContainer.containerBackground = attributes.getColor(R.styleable.Filter_collapsedBackground, Color.WHITE)
90+
expandedFilter.setBackgroundColor(attributes.getColor(R.styleable.Filter_expandedBackground, Color.WHITE))
91+
} finally {
92+
attributes.recycle()
93+
}
6994
}
7095

7196
fun build() {

filter/src/main/res/layout/collapsed_container.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/relative_container"
45
android:layout_width="match_parent"
56
android:layout_height="wrap_content"
67
android:background="@android:color/white">
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<declare-styleable name="Filter">
4+
<attr name="expandedBackground" format="color"/>
5+
<attr name="collapsedBackground" format="color"/>
6+
</declare-styleable>
7+
</resources>

0 commit comments

Comments
 (0)