Skip to content

Commit

Permalink
Merge pull request #5 from Yalantis/feature/changing_background
Browse files Browse the repository at this point in the history
added posibility to change background
  • Loading branch information
igalata authored Mar 10, 2017
2 parents 30e2fd0 + 099b457 commit f27f763
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/yalantis/fitfilter/ExampleActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yalantis.fitfilter;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -52,6 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
mFilter.setNoSelectedItemText(getString(R.string.str_all_selected));
mFilter.build();


mRecyclerView = (RecyclerView) findViewById(R.id.list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
mRecyclerView.setAdapter(mAdapter = new QuestionsAdapter(this, mAllQuestions = getQuestions()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yalantis.filter.widget

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.MotionEvent
Expand All @@ -19,6 +20,12 @@ class CollapsedFilterContainer : RelativeLayout {
private var mStartX = 0f
private var mStartY = 0f

var containerBackground = Color.WHITE
set(value) {
field = value
relative_container.setBackgroundColor(value)
}

constructor(context: Context) : this(context, null)
constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
constructor(context: Context, attrs: AttributeSet?, defStyleRes: Int) : super(context, attrs, defStyleRes) {
Expand Down
25 changes: 25 additions & 0 deletions filter/src/main/java/com/yalantis/filter/widget/Filter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import kotlinx.android.synthetic.main.collapsed_container.view.*
import kotlinx.android.synthetic.main.filter.view.*
import java.io.Serializable
import java.util.*
import android.content.res.TypedArray
import android.graphics.Color
import android.support.annotation.ColorInt


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

var collapsedBackground: Int = Color.WHITE
set(value) {
field = value
collapsedContainer.containerBackground = value
collapsedContainer.invalidate()
}

var expandedBackground: Int = Color.WHITE
set(value) {
field = value
expandedFilter.setBackgroundColor(value)
expandedFilter.invalidate()
}

private var mIsBusy = false

private var isCollapsed: Boolean? = null
Expand All @@ -66,6 +84,13 @@ class Filter<T : FilterModel> : FrameLayout, FilterItemListener, CollapseListene
collapsedFilter.scrollListener = this
collapsedContainer.listener = this
expandedFilter.listener = this
val attributes = context.obtainStyledAttributes(attrs, R.styleable.Filter, 0, 0)
try {
collapsedContainer.containerBackground = attributes.getColor(R.styleable.Filter_collapsedBackground, Color.WHITE)
expandedFilter.setBackgroundColor(attributes.getColor(R.styleable.Filter_expandedBackground, Color.WHITE))
} finally {
attributes.recycle()
}
}

fun build() {
Expand Down
1 change: 1 addition & 0 deletions filter/src/main/res/layout/collapsed_container.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
Expand Down
7 changes: 7 additions & 0 deletions filter/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Filter">
<attr name="expandedBackground" format="color"/>
<attr name="collapsedBackground" format="color"/>
</declare-styleable>
</resources>

0 comments on commit f27f763

Please sign in to comment.