Skip to content

Commit

Permalink
Fix issue with widgets not actually getting tinted. Change setTint to…
Browse files Browse the repository at this point in the history
… tint
  • Loading branch information
Jawnnypoo committed Nov 7, 2016
1 parent a44f3a0 commit 9d0887a
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 214 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dependencies {
# Usage
See sample project for clear usage. Mostly looks like this:
```java
Easel.setTint(checkBox, color);
Easel.tint(checkBox, color);
```
If you are using Kotlin, extensions methods make it even easier:
```kotlin
checkbox.setTint(color)
checkbox.tint(color)
```

# Thanks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.EditText
import com.commit451.easel.kotlin.setCursorTint
import com.commit451.easel.kotlin.setTint
import com.commit451.easel.kotlin.tint
import com.commit451.easel.kotlin.tintCursor

class KotlinActivity : AppCompatActivity() {

Expand All @@ -15,9 +15,9 @@ class KotlinActivity : AppCompatActivity() {
setContentView(R.layout.activity_kotlin)

var editText = findViewById(R.id.editText) as EditText
editText.setCursorTint(Color.RED)
editText.tintCursor(Color.RED)

var button = findViewById(R.id.button_custom) as Button
button.setTint(Color.RED)
button.tint(Color.RED)
}
}
66 changes: 26 additions & 40 deletions app/src/main/java/com/commit451/easel/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.SeekBar;

import com.commit451.easel.Easel;
Expand All @@ -26,20 +26,37 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Easel");
toolbar.inflateMenu(R.menu.menu_main);
Easel.tint(toolbar.getMenu(), Color.MAGENTA);

ScrollView scrollView = (ScrollView) findViewById(R.id.scrollview);
Easel.tintEdgeEffect(scrollView, Color.MAGENTA);

final ViewTreeObserver viewTreeObserver = getWindow().getDecorView().getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Easel.tintOverflow(toolbar, Color.MAGENTA);
removeOnGlobalLayoutListener(getWindow().getDecorView(), this);
}
});

EditText editText = (EditText) findViewById(R.id.editText);
RadioButton radioButton = (RadioButton) findViewById(R.id.radioButton);
CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox);
SwitchCompat switchCompat = (SwitchCompat) findViewById(R.id.switchCompat);
ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
SeekBar seekBar = (SeekBar) findViewById(R.id.seekBar);
Button button = (Button) findViewById(R.id.button);
Easel.setTint(editText, Color.MAGENTA);
Easel.setTint(radioButton, Color.MAGENTA);
Easel.setTint(checkBox, Color.MAGENTA);
Easel.setTint(switchCompat, Color.MAGENTA);
Easel.setTint(progressBar, Color.MAGENTA);
Easel.setTint(seekBar, Color.MAGENTA);
Easel.setTint(button, Color.MAGENTA);
Easel.tint(editText, Color.MAGENTA);
Easel.tint(radioButton, Color.MAGENTA);
Easel.tint(checkBox, Color.MAGENTA);
Easel.tint(switchCompat, Color.MAGENTA);
Easel.tint(progressBar, Color.MAGENTA);
Easel.tint(seekBar, Color.MAGENTA);
Easel.tint(button, Color.MAGENTA);
findViewById(R.id.button_kotlin).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -48,23 +65,6 @@ public void onClick(View view) {
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
Easel.setTint(menu, Color.MAGENTA);

final ViewTreeObserver viewTreeObserver = getWindow().getDecorView().getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Easel.setOverflowTint(MainActivity.this, Color.MAGENTA);
removeOnGlobalLayoutListener(getWindow().getDecorView(), this);
}
});
return true;
}

public void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayoutListener listener) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
v.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
Expand All @@ -73,18 +73,4 @@ public void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayout
v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
case R.id.action_share:

return true;
}

return super.onOptionsItemSelected(item);
}
}
116 changes: 63 additions & 53 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,70 +1,80 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
android:orientation="vertical">

<LinearLayout
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"/>

<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New edit text" />
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New RadioButton" />
android:layout_margin="16dp"
android:orientation="vertical">

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New edit text" />

<android.support.v7.widget.SwitchCompat
android:id="@+id/switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Switch" />
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton" />

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox" />

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchCompat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Switch" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/button_kotlin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="See Kotlin" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button" />

<Button
android:id="@+id/button_kotlin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="See Kotlin" />

</LinearLayout>

</LinearLayout>
</ScrollView>

</ScrollView>
</LinearLayout>
5 changes: 4 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#2196F3</item>
<item name="colorPrimaryDark">#1976D2</item>
<item name="colorAccent">#8BC34A</item>
</style>

</resources>
40 changes: 20 additions & 20 deletions easel-kotlin/src/main/java/com/commit451/easel/kotlin/easel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,44 @@ import com.commit451.easel.R
* Kotlin bindings for Easel
*/

fun EditText.setCursorTint(@ColorInt color: Int) {
Easel.setCursorTint(this, color)
fun EditText.tintCursor(@ColorInt color: Int) {
Easel.tintCursor(this, color)
}

fun EditText.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun EditText.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun CheckBox.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun CheckBox.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun MenuItem.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun MenuItem.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun ProgressBar.setTint(@ColorInt color : Int, skipIndeterminate : Boolean = false) {
Easel.setTint(this, color, skipIndeterminate)
fun ProgressBar.tint(@ColorInt color : Int, skipIndeterminate : Boolean = false) {
Easel.tint(this, color, skipIndeterminate)
}

fun SwitchCompat.setTint(@ColorInt color : Int, @ColorInt unpressedColor : Int = Easel.getThemeAttrColor(this.context, R.attr.colorSwitchThumbNormal)) {
Easel.setTint(this, color, unpressedColor)
fun SwitchCompat.tint(@ColorInt color : Int, @ColorInt unpressedColor : Int = Easel.getThemeAttrColor(this.context, R.attr.colorSwitchThumbNormal)) {
Easel.tint(this, color, unpressedColor)
}

fun RadioButton.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun RadioButton.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun Button.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun Button.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun Menu.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun Menu.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun SeekBar.setTint(@ColorInt color : Int) {
Easel.setTint(this, color)
fun SeekBar.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}


Loading

0 comments on commit 9d0887a

Please sign in to comment.