From 0cbb97502833658703a539968f516bbf030e6c95 Mon Sep 17 00:00:00 2001 From: John Carlson Date: Sun, 6 Nov 2016 21:00:34 -0600 Subject: [PATCH] Add more of the Kotlin extensions --- README.md | 17 ++ app/src/main/AndroidManifest.xml | 3 +- .../commit451/easel/sample/MainActivity.java | 21 +- app/src/main/res/layout/activity_main.xml | 5 - .../java/com/commit451/easel/kotlin/easel.kt | 20 +- .../main/java/com/commit451/easel/Easel.java | 233 +++++++++--------- 6 files changed, 152 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index 2e1aa3f..28a7af0 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1592add..ca3ed18 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,8 @@ android:theme="@style/AppTheme"> + android:label="@string/app_name" + android:windowSoftInputMode="stateHidden"> diff --git a/app/src/main/java/com/commit451/easel/sample/MainActivity.java b/app/src/main/java/com/commit451/easel/sample/MainActivity.java index 1ddf07c..d8a9bc1 100644 --- a/app/src/main/java/com/commit451/easel/sample/MainActivity.java +++ b/app/src/main/java/com/commit451/easel/sample/MainActivity.java @@ -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; @@ -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); @@ -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); - } - } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 54804ec..57ffd54 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -62,11 +62,6 @@ android:layout_height="wrap_content" android:text="New Button" /> -