Skip to content

Commit

Permalink
feat(android): material you themes (#13597)
Browse files Browse the repository at this point in the history
* feat(android): material you themes

* lint docs

* move to android namespace

* undo mediamodule
  • Loading branch information
m1ga committed Oct 9, 2022
1 parent 73c4af4 commit 3ef9b66
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.appcelerator.titanium.TiApplication;
import org.appcelerator.titanium.proxy.ColorProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

Expand All @@ -32,6 +33,8 @@
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;

import com.google.android.material.color.MaterialColors;

@SuppressWarnings("deprecation")
@Kroll.module(parentModule = UIModule.class)
@Kroll.dynamicApis(properties = { "currentActivity" })
Expand Down Expand Up @@ -297,6 +300,14 @@ public ColorProxy getColorResource(Object idOrName)
return null;
}

@Kroll.method
public String harmonizedColor(String value)
{
int color = TiConvert.toColor(value);
return String.format("#%06X",
(0xFFFFFF & MaterialColors.harmonizeWithPrimary(TiApplication.getAppCurrentActivity(), color)));
}

@Override
public String getApiName()
{
Expand Down
17 changes: 17 additions & 0 deletions android/titanium/res/values/values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,23 @@
<item name="android:windowFullscreen">true</item>
</style>

<!-- Titanium style supporting dark/light theme switching with an action bar. -->
<style name="Theme.Titanium.Material3.DayNight" parent="Theme.Material3.DynamicColors.DayNight"/>

<!-- Titanium style supporting dark/light theme switching without an action bar. -->
<style name="Theme.Titanium.Material3.DayNight.NoTitleBar" parent="Theme.Titanium.Material3.DayNight">
<item name="android:windowActionBar">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<!-- Titanium style supporting dark/light theme switching without an action bar and status bar. -->
<style name="Theme.Titanium.Material3.DayNight.Fullscreen" parent="Theme.Titanium.Material3.DayNight.NoTitleBar">
<item name="android:windowFullscreen">true</item>
</style>

<!-- The default theme Titanium applies to the <application/> in the manifest. -->
<!-- Our "_build.js" will replace parent with ".NoTitleBar" or ".Fullscreen" if set in "tiapp.xml". -->
<style name="Theme.Titanium.App" parent="Theme.Titanium.DayNight.Solid"/>
Expand Down
14 changes: 14 additions & 0 deletions apidoc/Titanium/UI/Android/Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ extends: Titanium.Module
since: "1.0"
platforms: [android]
methods:
- name: harmonizedColor
summary: Creates a harmonizing color
description: |
Shifts the hue of the input color towards the hue of colorPrimary and returns a new color
as a hex string. Usage: `Ti.UI.Android.harmonizedColor("#ff0000");`
parameters:
- name: color
summary: Input Color
type: [ String, Titanium.UI.Color ]
platforms: [android]
returns:
type: String
since: { android: "12.0.0" }

- name: hideSoftKeyboard
summary: |
Hides the soft keyboard.
Expand Down

0 comments on commit 3ef9b66

Please sign in to comment.