Coder Social home page Coder Social logo

phoenix-626 / dynamic-theme Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pranavpandey/dynamic-theme

0.0 0.0 0.0 1.09 MB

A text (JSON) based theme engine for Android apps.

Home Page: https://theme.pranavpandey.com

License: Apache License 2.0

Java 100.00%

dynamic-theme's Introduction

Dynamic Theme

License Build Status Download

A text (JSON) based theme engine for apps supporting Android 4.0 (API 14) and above devices.

It uses AndroidX so, first migrate your project to AndroidX.

  

{
  "backgroundColor": "#37474F",
  "tintBackgroundColor": "auto",
  "surfaceColor": "auto",
  "tintSurfaceColor": "auto",
  "primaryColor": "#37474F",
  "tintPrimaryColor": "auto",
  "primaryColorDark": "auto",
  "tintPrimaryColorDark": "auto",
  "accentColor": "#CDDC39",
  "tintAccentColor": "auto",
  "accentColorDark": "auto",
  "tintAccentColorDark": "auto",
  "errorColor": "auto",
  "tintErrorColor": "auto",
  "textPrimaryColor": "auto",
  "textPrimaryColorInverse": "auto",
  "textSecondaryColor": "auto",
  "textSecondaryColorInverse": "auto",
  "fontScale": "auto",
  "cornerRadius": "auto",
  "backgroundAware": "auto",
  "style": "auto"
}

Contents


Format

A dynamic theme can be represented as a JSON, URL or a File with .theme extension containing the JSON text. Use the Palettes app for Android to create or share the dynamic themes in various formats. However, the most suitable way is to share it via a URL that can be imported easily on various platforms.

JSON

A JSON is the original format for the dynamic theme that provides cross-app functionality.

{
  "backgroundColor": "auto|color",
  "tintBackgroundColor": "auto|color",
  "surfaceColor": "auto|color",
  "tintSurfaceColor": "auto|color",
  "primaryColor": "auto|color",
  "tintPrimaryColor": "auto|color",
  "primaryColorDark": "auto|color",
  "tintPrimaryColorDark": "auto|color",
  "accentColor": "auto|color",
  "tintAccentColor": "auto|color",
  "accentColorDark": "auto|color",
  "tintAccentColorDark": "auto|color",
  "errorColor": "auto|color",
  "tintErrorColor": "auto|color",
  "textPrimaryColor": "auto|color",
  "textPrimaryColorInverse": "auto|color",
  "textSecondaryColor": "auto|color",
  "textSecondaryColorInverse": "auto|color",
  "fontScale": "auto|integer",
  "cornerRadius": "auto|integer",
  "backgroundAware": "auto|disable|enable",
  "style": "auto|custom",
  "header": "auto|hide|show",
  "opacity": "auto|integer"
}

URL

A URL is the short representation of the theme JSON that can be shared on the platforms having a character limit like Twitter. This is the most suitable way to share a dynamic theme that can be imported easily in various apps or platforms.

Mappings

JSON URL JSON URL
{,} ""
Split (Key) - Dark | Inverse Z
backgroundColor 0 tintBackgroundColor 1
surfaceColor 2 tintSurfaceColor 3
primaryColor 4 tintPrimaryColor 5
primaryColorDark 4Z tintPrimaryColorDark 7
accentColor 8 tintAccentColor 9
accentColorDark 8Z tintAccentColorDark 11
errorColor 21 tintErrorColor 22
textPrimaryColor 12 textPrimaryColorInverse 12Z
textSecondaryColor 14 textSecondaryColorInverse 14Z
fontScale 16 cornerRadius 17
backgroundAware 18 style 23
header 19 opacity 20

Values

JSON URL JSON URL
Split (Value) v # X
auto A
disable D enable E
hide H show S

Code

A QR code representation of the theme URL to easily share themes across various platforms and devices.

File

A File with .theme extension containing the JSON text. Currently, it is possible to export or import a dynamic theme file on the Android (Java) platform.


Installation

It can be installed by adding the following dependency to your build.gradle file:

dependencies {
    // For AndroidX enabled projects.
    implementation 'com.pranavpandey.android:dynamic-theme:2.0.1'
}

Usage

It can be used in raw JSON format or can be implemented on the Android (Java) platform.

For complete reference, please read the documentation.

Android (Java)

Just implement the AppTheme or AppWidgetTheme to create a dynamic theme. A possible implementation can be found here.

public class DynamicAppTheme implements AppTheme<DynamicAppTheme> {
    
    ...
    
    @Override
    public @StyleRes int getThemeRes() {
        return themeRes;
    }

    @Override
    public @NonNull DynamicAppTheme setThemeRes(@StyleRes int themeRes) {
        this.themeRes = themeRes;

        return this;
    }

    ...

    @Override
    public @NonNull String toJsonString() {
        return new Gson().toJson(new DynamicAppTheme(this));
    }

    @Override
    public @NonNull String toDynamicString() {
        return new GsonBuilder().setExclusionStrategies(new ExcludeStrategy())
                .registerTypeAdapter(DynamicAppTheme.class, new DynamicThemeTypeAdapter<>())
                .setPrettyPrinting().create().toJson(new DynamicAppTheme(this));
    }
}

Dependency

It depends on the dynamic-utils to perform various internal operations. So, its functions can also be used to perform other useful operations.

Proguard

This library uses Gson and has custom strategy to process the theme data. It will automatically apply the appropriate rules if proguard is enabled in the project.

The following rules will be applied by this library:

# Gson uses generic type information stored in a class file when working with fields.
# Proguard removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using Gson annotation.
-keepattributes *Annotation*

# Gson specific classes.
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.** { *; }

Palettes

Palettes is a universal manager for apps supporting the dynamic theme on Android. It provides some default configurations that can be extended to create custom ones. Let's give it a try to explore its other useful features.

  • A collection of theme presets that can be applied in the supported apps.
  • Extend them to create custom ones according to the requirement.
  • Preview them natively in the supported apps and widgets.
  • Experimental option to enable dark mode in devices that don't have a system setting.

Palettes - Theme Manager


Author

Pranav Pandey

GitHub Follow on Twitter Donate via PayPal


License

Copyright 2019-2021 Pranav Pandey

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

dynamic-theme's People

Contributors

pranavpandey avatar

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.