Skip to content

Commit

Permalink
Version 2.0.0
Browse files Browse the repository at this point in the history
Kotlin 1.3.11.
Migrate to AndroidX.
Refactor attributes.
MDC-Android 1.1.0-alpha02.
Improve javadocs generation.
Add text colors and corner support.
All new theme engine with json support.
Add proguard rules to theme the app properly.
  • Loading branch information
pranavpandey committed Dec 16, 2018
1 parent c12774e commit 9ebb058
Show file tree
Hide file tree
Showing 343 changed files with 18,223 additions and 8,948 deletions.
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ A complete library to build apps for Android 14+ (ICS or above) devices with a b
engine. It is built on top of the latest [app compat library](https://developer.android.com/topic/libraries/support-library/features.html)
to provide best compatibility.

>Since v2.0.0, it uses [AndroidX](https://developer.android.com/jetpack/androidx/) so, first
[migrate](https://developer.android.com/jetpack/androidx/migrate) your project to AndroidX.

<img src="https://raw.githubusercontent.com/pranavpandey/dynamic-support/master/graphics/ads-screen-1.png" width="280" height="486"><img src="https://raw.githubusercontent.com/pranavpandey/dynamic-support/master/graphics/ads-screen-3.png" width="280" height="486"><img src="https://raw.githubusercontent.com/pranavpandey/dynamic-support/master/graphics/ads-screen-4.png" width="280" height="486">

<img src="https://raw.githubusercontent.com/pranavpandey/dynamic-support/master/graphics/ads-screen-5.png" width="280" height="486"><img src="https://raw.githubusercontent.com/pranavpandey/dynamic-support/master/graphics/ads-screen-6.png" width="280" height="486"><img src="https://raw.githubusercontent.com/pranavpandey/dynamic-support/master/graphics/ads-screen-7.png" width="280" height="486">
Expand All @@ -23,6 +26,7 @@ to provide best compatibility.
- [Theme engine](https://github.com/pranavpandey/dynamic-support#theme-engine)
- [Background aware](https://github.com/pranavpandey/dynamic-support#background-aware)
- [Sample](https://github.com/pranavpandey/dynamic-support#sample)
- [Proguard](https://github.com/pranavpandey/dynamic-support#proguard)
- [License](https://github.com/pranavpandey/dynamic-support#license)

---
Expand All @@ -33,7 +37,11 @@ It can be installed by adding the following dependency to your `build.gradle` fi

```groovy
dependencies {
implementation 'com.pranavpandey.android:dynamic-support:1.3.0'
// For AndroidX enabled projects.
implementation 'com.pranavpandey.android:dynamic-utils:2.0.0'
// For legacy projects.
implementation 'com.pranavpandey.android:dynamic-utils:1.3.0'
}
```

Expand Down Expand Up @@ -65,6 +73,57 @@ documentation. Basic documentation will be available soon.

Checkout the `sample` to know more about the basic implementation.

### Proguard
This library uses reflection at some places to theme widgets at runtime. So, their original name
must be preserved to theme them properly. It will automatically apply the appropriate rules if
proguard is enabled in the project.

The following rules will be applied by this library:

```yml
dependencies {
# Keep application class.
-keep public class * extends android.app.Application

# Keep methods in Activity that could be used in the XML.
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

# Keep support library classes.
#-keep class androidx.appcompat.widget.** { *; }
#-keep class android.support.v4.widget.** { *; }
#-keep class android.support.v7.widget.** { *; }
#-keep class android.support.design.widget.** { *; }
#-keep class android.support.design.internal.** { *; }

# Keep AndroidX classes.
-keep class androidx.core.widget.** { *; }
-keep class androidx.appcompat.view.menu.** { *; }
-keep class androidx.recyclerview.widget.** { *; }
-keep class androidx.viewpager.widget.** { *; }

# Keep Material Components classes.
-keep class com.google.android.material.internal.** { *; }
-keep class com.google.android.material.navigation.** { *; }
-keep class com.google.android.material.textfield.** { *; }

# Keep all the Dynamic Support models.
-keep class com.pranavpandey.android.dynamic.support.model.** { *; }

# 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 @Expose annotation
-keepattributes *Annotation*

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

---

## Apps using Dynamic Support
Expand Down
19 changes: 11 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

buildscript {
ext.versions = [
'compileSdk' : 28,
'minSdk' : 14,
'targetSdk' : 28,
'buildTools' : '28.0.3',
'androidSupport': '28.0.0',
'kotlin' : '1.3.10'
'compileSdk': 28,
'minSdk' : 14,
'targetSdk' : 28,
'buildTools': '28.0.3',
'androidx' : '1.1.0-alpha02',
'dynamic' : '2.1.0',
'gson' : '2.8.5',
'kotlin' : '1.3.11',
'material' : '1.1.0-alpha02'
]

repositories {
Expand Down Expand Up @@ -64,8 +67,8 @@ ext {
mavenGroup = 'com.pranavpandey.android'
mavenArtifactId = 'dynamic-support'
mavenInceptionYear = 2018
mavenVersion = '1.3.0'
mavenVersionCode = 14
mavenVersion = '2.0.0'
mavenVersionCode = 15

developerId = 'pranavpandey'
developerName = 'Pranav Pandey'
Expand Down
2 changes: 1 addition & 1 deletion dynamic-support/bintray.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Pranav Pandey
* Copyright 2018 Pranav Pandey
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
14 changes: 8 additions & 6 deletions dynamic-support/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ android {
versionName mavenVersion

vectorDrawables.useSupportLibrary = true
consumerProguardFiles 'proguard-rules.pro'
}

sourceSets {
Expand All @@ -35,9 +36,9 @@ android {
}

dependencies {
api "com.pranavpandey.android:dynamic-toasts:$mavenVersion"
api "com.android.support:design:${versions.androidSupport}"
api "com.android.support:cardview-v7:${versions.androidSupport}"
api "com.pranavpandey.android:dynamic-toasts:${versions.dynamic}"
api "com.google.android.material:material:${versions.material}"
api "com.google.code.gson:gson:${versions.gson}"
}

if (project.rootProject.file('local.properties').exists()) {
Expand All @@ -52,8 +53,9 @@ project.afterEvaluate {
description = "Generates javadocs"
failOnError = false
destinationDir = new File(destinationDir, variant.baseName)
source = files(variant.javaCompiler.source)
classpath = files(variant.javaCompiler.classpath.files) + files(android.bootClasspath)
source = android.sourceSets.main.java.srcDirs
classpath += configurations.compile
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
options.windowTitle(referenceTitle)
options.docTitle(referenceTitle)
options.header(referenceTitle)
Expand All @@ -63,4 +65,4 @@ project.afterEvaluate {
}
}
}
}
}
2 changes: 1 addition & 1 deletion dynamic-support/maven.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 Pranav Pandey
* Copyright 2018 Pranav Pandey
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
40 changes: 40 additions & 0 deletions dynamic-support/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,43 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Keep application class.
-keep public class * extends android.app.Application

# Keep methods in Activity that could be used in the XML.
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

# Keep support library classes.
#-keep class androidx.appcompat.widget.** { *; }
#-keep class android.support.v4.widget.** { *; }
#-keep class android.support.v7.widget.** { *; }
#-keep class android.support.design.widget.** { *; }
#-keep class android.support.design.internal.** { *; }

# Keep AndroidX classes.
-keep class androidx.core.widget.** { *; }
-keep class androidx.appcompat.view.menu.** { *; }
-keep class androidx.recyclerview.widget.** { *; }
-keep class androidx.viewpager.widget.** { *; }

# Keep Material Components classes.
-keep class com.google.android.material.internal.** { *; }
-keep class com.google.android.material.navigation.** { *; }
-keep class com.google.android.material.textfield.** { *; }

# Keep all the Dynamic Support models.
-keep class com.pranavpandey.android.dynamic.support.model.** { *; }

# 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 @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.** { *; }
1 change: 0 additions & 1 deletion dynamic-support/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
-->

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pranavpandey.android.dynamic.support">

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,28 @@
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;

import com.pranavpandey.android.dynamic.support.listener.DynamicListener;
import com.pranavpandey.android.dynamic.support.locale.DynamicLocale;
import com.pranavpandey.android.dynamic.support.locale.DynamicLocaleUtils;
import com.pranavpandey.android.dynamic.support.model.DynamicAppTheme;
import com.pranavpandey.android.dynamic.support.preference.DynamicPreferences;
import com.pranavpandey.android.dynamic.support.theme.DynamicTheme;
import com.pranavpandey.android.dynamic.support.utils.DynamicResourceUtils;
import com.pranavpandey.android.dynamic.utils.DynamicVersionUtils;

import java.util.Locale;

/**
* Base application class which can be extended to initialize the
* {@link DynamicTheme} and to perform theme change operations.
* Base application class which can be extended to initialize the {@link DynamicTheme} and to
* perform theme change operations.
*/
public abstract class DynamicApplication extends Application implements
DynamicLocale, DynamicListener,
SharedPreferences.OnSharedPreferenceChangeListener {
public abstract class DynamicApplication extends Application implements DynamicLocale,
DynamicListener, SharedPreferences.OnSharedPreferenceChangeListener {

/**
* Dynamic context used by this application.
Expand Down Expand Up @@ -70,7 +72,7 @@ public void onCreate() {
.registerOnSharedPreferenceChangeListener(this);

onInitialize();
setThemeRes();
setDynamicTheme();
onCustomiseTheme();
}

Expand All @@ -79,30 +81,24 @@ public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

int diff = mConfiguration.diff(new Configuration(newConfig));
if ((diff & ActivityInfo.CONFIG_LOCALE) != 0) {
if ((diff & ActivityInfo.CONFIG_LOCALE) != 0
|| (diff & ActivityInfo.CONFIG_ORIENTATION) != 0
|| (DynamicVersionUtils.isJellyBeanMR1()
&& (diff & ActivityInfo.CONFIG_DENSITY) != 0)) {
DynamicTheme.getInstance().onDynamicChange(true, false);
mConfiguration = new Configuration(newConfig);
}
}

/**
* Set the current theme resource for this application.
*/
protected void setThemeRes() {
if (getThemeRes() != DynamicResourceUtils.ADS_DEFAULT_RESOURCE_ID) {
DynamicTheme.getInstance().setTheme(getThemeRes(), true);
}
}

/**
* This method will be Called inside the {@link #onCreate()} method
* before applying the theme. Do any initializations in this method.
* This method will be called inside the {@link #onCreate()} method before applying the theme.
* <p>Do any initializations in this method.
*/
protected abstract void onInitialize();

/**
* Get the style resource file to apply theme on ths application.
* Override this method to supply your own customised style.
* Get the style resource to apply theme on this application.
* <p>Override this method to supply your own customised style.
*
* @return Style resource to be applied on this activity.
*/
Expand All @@ -111,19 +107,41 @@ protected void setThemeRes() {
}

/**
* This method will be called inside the {@link #onCreate()} method
* after applying the theme. Override this method to customise the theme
* further.
* Get the dynamic app theme to be applied on this application.
* <p>Override this method to supply your own customised theme.
*
* @return The dynamic app theme for this application.
*/
protected @Nullable DynamicAppTheme getDynamicTheme() {
return null;
}

/**
* This method will be called inside the {@link #onCreate()} method after applying the theme.
* <p>Override this method to customise the theme further.
*/
protected void onCustomiseTheme() { }

/**
* Returns the dynamic context used by this application.
*
* @return The dynamic context used by this application.
*/
public @NonNull Context getContext() {
return mContext;
}

/**
* Set the dynamic app theme and style resource for this application.
*/
protected void setDynamicTheme() {
if (getDynamicTheme() == null) {
DynamicTheme.getInstance().setThemeRes(getThemeRes(), true);
} else {
DynamicTheme.getInstance().setTheme(getDynamicTheme(), true);
}
}

@Override
public @Nullable String[] getSupportedLocales() {
return null;
Expand All @@ -149,7 +167,7 @@ public void onDynamicChange(boolean context, boolean recreate) {
DynamicTheme.getInstance().setContext(getContext());
}

setThemeRes();
setDynamicTheme();
onCustomiseTheme();
}

Expand Down
Loading

0 comments on commit 9ebb058

Please sign in to comment.