Code Monkey home page Code Monkey logo

colorful's People

Contributors

garretyoder avatar mflisar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colorful's Issues

startSupportActionMode works not propertly with Colorful

I have added Colorful library into my app and ActionMode is broken now. Action toolbar appears above the toolbar. Looks like Colorful style doesn't have or ignore my windowActionModeOverlay.

Library initialized as:

 CustomThemeColor defaultTheme = new CustomThemeColor(
                this,
                R.style.my_default_primary_color,
                R.style.my_default_rimary_dark_color,
                R.color.colorPrimary,
                R.color.colorPrimary
        );
        Defaults themeDefaults = new Defaults(
                defaultTheme,
                defaultTheme,
                false,
                false,
                R.style.AppTheme
        );
        initColorful(this, themeDefaults);

Activity extends CAppCompatActivity. But startSupportActionMode leads to this:
screen

Do you know how to fix this?

ColorClickerPreference crash

I am using Colorful and want to allow users choose themes from settings. Added ColorClickerPreference to my preferences file and getting crash when trying to open settings now.

Log

FATAL EXCEPTION: main
Process: com.itemstudio.castro, PID: 22833
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itemstudio.castro/com.itemstudio.castro.settings.SettingsActivity}: java.lang.ClassCastException: org.polaric.colorful.ColorPickerPreference cannot be cast to android.preference.Preference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2680)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6176)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

Caused by: java.lang.ClassCastException: org.polaric.colorful.ColorPickerPreference cannot be cast to android.preference.Preference
at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:104)
at android.preference.GenericInflater.rInflate(GenericInflater.java:490)
at android.preference.GenericInflater.inflate(GenericInflater.java:327)
at android.preference.GenericInflater.inflate(GenericInflater.java:264)
at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:280)
at android.preference.PreferenceFragment.addPreferencesFromResource(PreferenceFragment.java:326)
at com.itemstudio.castro.settings.SettingsFragment.onCreate(SettingsFragment.java:23)
at android.app.Fragment.performCreate(Fragment.java:2336)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:949)
at android.app.BackStackRecord.setLastIn(BackStackRecord.java:861)
at android.app.BackStackRecord.calculateFragments(BackStackRecord.java:901)
at android.app.BackStackRecord.run(BackStackRecord.java:728)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentController.execPendingActions(FragmentController.java:371)
at android.app.Activity.performStart(Activity.java:6695)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2643)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2741) 
at android.app.ActivityThread.-wrap12(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:154) 
at android.app.ActivityThread.main(ActivityThread.java:6176) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

Use THEME_MATERIAL appear error log

@garretyoder If use THEME_MATERIAL or THEME_MATERIAL_COMPONETS, the following error will appear. What did i do wrong?

Code
ColorfulKt.Colorful().apply(this, true, BaseTheme.THEME_MATERIAL_COMPONETS);

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

Log

AppCompatDelegate: Failed to instantiate custom view inflater android.support.design.theme.MaterialComponentsViewInflater . Falling back to default.
    java.lang.ClassNotFoundException: Invalid name: android.support.design.theme.MaterialComponentsViewInflater 
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1014)
        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1092)

Feedback colorful problem

  1. How to get primary and accent color res?
  2. ThemeColor have't white and black color ThemeColor.WHITE, how to set primary or accent color to white or black color?

Not working after app restart

After trying this quite a while now, I can't get it working after restarting my app.

What I do:

  1. Init colorful with the values from my own preferences (had some theming already before I tried your library):

     fun init(app: Application) {
     	var primaryColor = when (AppPrefs.themeColor) {
     		"0" -> ThemeColor.GREEN
     		"1" -> ThemeColor.RED
     		"2" -> ThemeColor.PINK
     		"3" -> ThemeColor.BLUE
     		else -> ThemeColor.GREEN
     	}
     	var accentColor = when (AppPrefs.themeColor) {
     		"0" -> ThemeColor.ORANGE
     		"1" -> ThemeColor.BLUE
     		"2" -> ThemeColor.BLUE
     		"3" -> ThemeColor.RED
     		else -> ThemeColor.GREEN
     	}
     	val defaults = Defaults(
     			primaryColor = primaryColor,
     			accentColor = accentColor,
     			useDarkTheme = darkTheme(),
     			translucent = false,
     			customTheme = baseActivityTheme()
     	)
     	initColorful(app, defaults)
     }
    
  2. Update colorful whenever my preferences change:

     fun update(context: Context) {
     	var primaryColor = when (themeColor()) {
     		Color.Green -> ThemeColor.GREEN
     		Color.Red -> ThemeColor.RED
     		Color.Rosa -> ThemeColor.PINK
     		Color.Blue -> ThemeColor.BLUE
     	}
     	var accentColor = when (themeColor()) {
     		Color.Green -> ThemeColor.ORANGE
     		Color.Red -> ThemeColor.BLUE
     		Color.Rosa -> ThemeColor.BLUE
     		Color.Blue -> ThemeColor.RED
     	}
     	Colorful().edit()
     			.setPrimaryColor(primaryColor)
     			.setAccentColor(accentColor)
     			.setDarkTheme(darkTheme())
     			.setTranslucent(false)
     			.setCustomThemeOverride(baseActivityTheme())
     			.apply(context)
     }
    

Observations

  • my own prefs are correct, your's as well
  • theme is not applied on app start (task description works though)
  • if I change the theme in my app and call the above update function, all my activities are themed correctly until I kill my app and restart it

Any ideas why?

Load style resources by name not by id

Resource IDs are not 100% guaranteed to never change and this could potentially cause problems. We should be loading style resources internally by string name over res id int.

"Dynamically"

What does "dynamically" mean?

Is an Activity restart required?

Should be added to the readme.

How to customize views in theme?

I have forced to load an style by calling:

            Colorful().edit()
                .setPrimaryColor(ThemeColor.RED)
                .setAccentColor(ThemeColor.BLUE)
                .setDarkTheme(false)
                .setTranslucent(false)
                .setCustomThemeOverride(R.style.AppThemeDark)
                .apply(activity!!) { activity!!.recreate() }

And set a textAppearance in my style:
Screen Shot 1397-12-21 at 15 11 45

But nothing seems to take a change in text color of my textviews or buttons.

Is there any guide to how to customize widgets?

Sample code for use without kotlin

Is is possible to use this without having to use kotlin? just Java
Kindly share some sample code on the README.
I tried some Kotlin decompiling but it didn't work

Realtime accent color change ?

Can we have the accent colors change immediately after apply? That is without leaving the current screen? I tried to trigger a color change from color picker dialog but it doesn't do anything to the current screen

Colorful has error when start strict mode

Colorful has error when start strict mode

image

    override fun onCreate() {
        if (BuildConfig.DEBUG) {
            setStrictMode()
        }
        super.onCreate()
    }

    private fun setStrictMode() {
        StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()   // or .detectAll() for all detectable problems
                .penaltyLog()
                .build())
        StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects()
                .penaltyLog()
                .penaltyDeath()
                .build())
    }

Use custom color

How to set custom color codes for Accent and Primary colors, such as#FFFFFF?

If not support now, can you add a method to set the color code for Primary and Accent? This is useful, thanks.

Support dynamic configs

Instead of always loading the saved preferences, could you add support for a dynamic config?

E.g. I would like to pass in a custom Defaults to Colorful().apply(this, override = true, appcompat = false) which should be used instead of the saved one if present

R styles not found on API 19

Hello,
I am encountering an issue when running the library on API 19 (Android 4.1)...
R seems to not be created correctly on compile.

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: dev.defvs.chatterz, PID: 2735
    java.lang.NoClassDefFoundError: io.multimoon.colorful.R$style
        at io.multimoon.colorful.ThemeColor.<clinit>(ThemeColor.kt:60)
        at dev.defvs.chatterz.MainApplication.onCreate(MainApplication.kt:13)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4344)
        at android.app.ActivityThread.access$1500(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5017)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)

Attribute "dialogTitle" already defined with incompatible format

There should be a conflict between your library and another one. When adding Colorful it shows a Gradle problem that say:

Error:(723) Attribute "dialogTitle" already defined with incompatible format.

As soon as I delete the dependency the error disappears. I hope you can fix this.

Some times primaryColor and accentColor are not used

@garretyoder I want to use "customTheme", because only in this way can I change textColorPrimary color, but now primaryColor and accentColor are not used, this may be misunderstood, but these two values are non-null.

    val defaults:Defaults = Defaults(
            primaryColor = ThemeColor.GREEN,
            accentColor = ThemeColor.BLUE,
            useDarkTheme = false,
            translucent = false,
            customTheme = R.style.AppTheme)
    initColorful(this, defaults)

What is the use of "override" and "appcompat"?

Hi, thankyou your library, I'm useing 2.0 version now, I want know what is the use of override and appcompat?

ColorfulKt.Colorful().apply(activity, override, appcompat);

When should I use true and when should I use false?

translucent makes statusBar too dark

before
after
I use Colorful.config(this) .translucent(true) .apply(); to make my Drawerlayout's content translucent, but to find it makes it too dark, which didn't happen if I use custom Theme instead of this library.
FIY, my original theme contains these properties:

        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>

Does Proguard settings mentioned in document?

I tries build a release build of my app and app crashed while start:

Fatal Exception: java.lang.AssertionError: impossible
       at java.lang.Enum$1.create(Enum.java:272)
       at java.lang.Enum$1.create(Enum.java:263)
       at libcore.util.BasicLruCache.get(BasicLruCache.java:58)
       at java.lang.Enum.getSharedConstants(Enum.java:289)
       at java.lang.Enum.valueOf(Enum.java:244)
       at io.multimoon.colorful.ThemeColor.valueOf(Unknown Source:2)
       at io.multimoon.colorful.ThemeColorInterface$Companion.parse(ThemeColor.kt:18)
       at io.multimoon.colorful.ColorfulKt.initColorful(Colorful.kt:29)
       at com.noodoe.nexlogistics.LogisticsApp.onCreate(LogisticsApp.kt:53)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
       at android.app.ActivityThread.-wrap1(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6494)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Caused by java.lang.NoSuchMethodException: values []
       at java.lang.Class.getMethod(Class.java:2068)
       at java.lang.Class.getDeclaredMethod(Class.java:2047)
       at java.lang.Enum$1.create(Enum.java:268)
       at java.lang.Enum$1.create(Enum.java:263)
       at libcore.util.BasicLruCache.get(BasicLruCache.java:58)
       at java.lang.Enum.getSharedConstants(Enum.java:289)
       at java.lang.Enum.valueOf(Enum.java:244)
       at io.multimoon.colorful.ThemeColor.valueOf(Unknown Source:2)
       at io.multimoon.colorful.ThemeColorInterface$Companion.parse(ThemeColor.kt:18)
       at io.multimoon.colorful.ColorfulKt.initColorful(Colorful.kt:29)
       at com.noodoe.nexlogistics.LogisticsApp.onCreate(LogisticsApp.kt:53)
       at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
       at android.app.ActivityThread.-wrap1(Unknown Source)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:164)
       at android.app.ActivityThread.main(ActivityThread.java:6494)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

So I added these proguard settings to make app open successfully:

-keep class io.multimoon.colorful.** { *; }
-dontwarn io.multimoon.colorful.**

Does anyone have other ideas?

Performing pause of activity that is not resumed

When I apply theme in my setting activity, return to MainActivity, then go to setting activity, I got the following error log(which seems not influence my app):

12-28 17:37:49.563 23151-23151/com.dante.girls E/ActivityThread: Performing pause of activity that is not resumed: {com.dante.girls/com.dante.girls.MainActivity}
                                                                 java.lang.RuntimeException: Performing pause of activity that is not resumed: {com.dante.girls/com.dante.girls.MainActivity}
                                                                     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3352)
                                                                     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
                                                                     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315)
                                                                     at android.app.ActivityThread.-wrap13(ActivityThread.java)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Each time I do those actions I got that error, so it's not occasional.

Support user-defined color styles

Colorful uses a android's ability to mix style files together to build complex themes. Since these are stored in XML files in a standard naming format, the functionality could be added to allow users to provide additional colors via style files.

Support colorPrimaryDark (and maybe more)

At least to be able to set the colorPrimaryDark as well through Colorful would be very nice.

Additional text colors would be nice as well altough it's not that important...

Migrate to AndroidX

As the AndroidX version of AppCompat is stable now, I'd recommend to update.

"setPrimaryColor" and "setCustomThemeOverride" conflict

@garretyoder Using "setPrimaryColor" and "setCustomThemeOverride" at the same time, "setPrimaryColor" will not work when the application is restarted

Code

Activity.java

        Colorful().edit()
                .setAccentColor(ThemeColor.PINK)
                .setCustomThemeOverride(R.style.AppThemeWhite)
                .apply(getContext(), () -> {
                    recreate();
                    return null;
                });

BaseActivity.java

ColorfulKt.Colorful().apply(this, false, true);

Style.xml

    <style name="AppThemeWhite" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/white</item>
        <item name="toolbarStyle">@style/AppThemeWhite.Toolbar</item>
    </style>

    <style name="AppThemeWhite.Toolbar" parent="@style/Widget.AppCompat.Toolbar">
        <item name="titleTextAppearance">@style/AppThemeWhite.Toolbar.Title</item>
        <item name="subtitleTextAppearance">@style/AppThemeWhite.Toolbar.Subtitle</item>
    </style>

    <style name="AppThemeWhite.Toolbar.Title" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title">
        <item name="android:textColor">?attr/colorAccent</item>
    </style>

    <style name="AppThemeWhite.Toolbar.Subtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
        <item name="android:textColor">?attr/colorAccent</item>
    </style>

App bar and Statusbar need same color

i want app and status bar same color but its bot work

 ` Defaults defaults = new Defaults(
            ThemeColor.GREEN,
            ThemeColor.GREEN,
            false,
            false,
            0);
     initColorful(this, defaults);`

it show status bar different green ...

ThemeEditor public apply method needs null check

The Readme states:

The apply method optionally takes a high-order function as a argument. This serves as a callback that will be triggered once Colorful has finished it's theme changes

However, ThemeEditor#apply() infers a @nonnull annotation on both of its arguments.
If this is to match the readme, the callback should be optional, and therefore must have a null check before being called.

I believe this will also make things easier for non-Kotlin users to make use of.

Thanks

Compile issue error: style attribute 'attr/colorSecondary

I'm getting the error with the latest build 2.3.3 in my compiler
error: style attribute 'attr/colorSecondary (aka com.***.**:attr/colorSecondary)' not found.
Errors are pointing to the values.xml file in Colorful lib specifically accent1 to accent 20

Kindly assist.
I'm on android support lib 27.1.1

Disabled override how to use light/dark theme

@garretyoder Dark/Light themeing will not work when override is disable, I try using "setCustomThemeOverride" to set it in style , when I changed Light to the Dark theme, but it will not change immediately, Only change after restarting the app. What did i do wrong? How should I correct it?

Code

Activity.java

        Colorful().edit()
                .setCustomThemeOverride(darkTheme ? R.style.AppThemeDark: R.style.AppTheme)
                .apply(getContext(), () -> {
                    recreate();
                    return null;
                });

BaseActivity.java

ColorfulKt.Colorful().apply(this, false, true);

Style.xml

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    </style>

    <style name="AppThemeDark" parent="Theme.AppCompat.NoActionBar">
    </style>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.