Skip to content

Commit

Permalink
Add more of the Kotlin extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jawnnypoo committed Nov 7, 2016
1 parent 9d0887a commit 0cbb975
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 147 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ If you are using Kotlin, extensions methods make it even easier:
checkbox.tint(color)
```

# Currently Supported Views
Currently, you can tint the following views at run time:
- Button
- Checkbox
- EditText
- ProgressBar
- RadioButton
- SeekBar
- SwitchCompat

In addition, you can also tint other things which are somewhat difficult to tint in Android, such as:
- Drawable
- EditText cursor
- MenuItem
- Toolbar overflow
- View Edget effect (on scroll)

# Thanks
Props to the project [Material Dialogs](https://github.com/afollestad/material-dialogs/blob/master/core/src/main/java/com/afollestad/materialdialogs/internal/MDTintHelper.java) where a lot of the tinting code came from.

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
21 changes: 1 addition & 20 deletions app/src/main/java/com/commit451/easel/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
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;
Expand All @@ -30,19 +28,11 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar.setTitle("Easel");
toolbar.inflateMenu(R.menu.menu_main);
Easel.tint(toolbar.getMenu(), Color.MAGENTA);
Easel.tintOverflow(toolbar, 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);
Expand All @@ -64,13 +54,4 @@ public void onClick(View view) {
}
});
}

public void removeOnGlobalLayoutListener(View v, ViewTreeObserver.OnGlobalLayoutListener listener) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
v.getViewTreeObserver().removeGlobalOnLayoutListener(listener);
}
else {
v.getViewTreeObserver().removeOnGlobalLayoutListener(listener);
}
}
}
5 changes: 0 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@
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"
Expand Down
20 changes: 16 additions & 4 deletions easel-kotlin/src/main/java/com/commit451/easel/kotlin/easel.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.commit451.easel.kotlin

import android.annotation.TargetApi
import android.support.annotation.ColorInt
import android.support.v7.widget.SwitchCompat
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.*
import com.commit451.easel.Easel
import com.commit451.easel.R
Expand All @@ -12,10 +15,6 @@ import com.commit451.easel.R
* Kotlin bindings for Easel
*/

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

fun EditText.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}
Expand Down Expand Up @@ -52,4 +51,17 @@ fun SeekBar.tint(@ColorInt color : Int) {
Easel.tint(this, color)
}

fun Toolbar.tintOverflow(@ColorInt color : Int) {
Easel.tintOverflow(this, color)
}

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

@TargetApi(21)
fun View.tintEdgeEffect(@ColorInt color :Int) {
Easel.tintEdgeEffect(this, color)
}


Loading

0 comments on commit 0cbb975

Please sign in to comment.