Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: fix Ti.UI.overrideUserInterfaceStyle #13267

Merged
merged 1 commit into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void setLargeIcon(Object icon)
@Kroll.setProperty
public void setColor(String color)
{
notificationBuilder.setColor(TiColorHelper.parseColor(color));
notificationBuilder.setColor(TiColorHelper.parseColor(color, getActivity()));
setProperty(TiC.PROPERTY_COLOR, color);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ public void handleCreationDict(KrollDict options)

private void launchVideoActivity(KrollDict options)
{
final Intent intent = new Intent(getActivity(), TiVideoActivity.class);
final Activity activity = getActivity();
final Intent intent = new Intent(activity, TiVideoActivity.class);

if (options.containsKey(TiC.PROPERTY_BACKGROUND_COLOR)) {
intent.putExtra(TiC.PROPERTY_BACKGROUND_COLOR, TiConvert.toColor(options, TiC.PROPERTY_BACKGROUND_COLOR));
int color = TiConvert.toColor(options, TiC.PROPERTY_BACKGROUND_COLOR, activity);
intent.putExtra(TiC.PROPERTY_BACKGROUND_COLOR, color);
}
videoActivityHandler = createControlHandler();
intent.putExtra(TiC.PROPERTY_MESSENGER, new Messenger(videoActivityHandler));
getActivity().startActivity(intent);
activity.startActivity(intent);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ public static Bundle toSpannableInBundle(AttributedStringProxy attrString, Activ
break;
case UIModule.ATTRIBUTE_BACKGROUND_COLOR:
spannableText.setSpan(
new BackgroundColorSpan(TiConvert.toColor(TiConvert.toString(attrValue))),
new BackgroundColorSpan(TiConvert.toColor(attrValue, activity)),
range[0], range[0] + range[1], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case UIModule.ATTRIBUTE_FOREGROUND_COLOR:
spannableText.setSpan(
new ForegroundColorSpan(TiConvert.toColor(TiConvert.toString(attrValue))),
new ForegroundColorSpan(TiConvert.toColor(attrValue, activity)),
range[0], range[0] + range[1], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case UIModule.ATTRIBUTE_STRIKETHROUGH_STYLE:
Expand All @@ -263,7 +263,7 @@ public static Bundle toSpannableInBundle(AttributedStringProxy attrString, Activ
break;
case UIModule.ATTRIBUTE_UNDERLINE_COLOR:
final UnderlineColorSpan underlineColorSpan = new UnderlineColorSpan(
TiConvert.toColor(TiConvert.toString(attrValue)));
TiConvert.toColor(attrValue, activity));

spannableText.setSpan(underlineColorSpan, range[0], range[0] + range[1],
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void onTintColorChanged(Object colorName)
if (colorName == null) {
this.tintColor = RefreshControlProxy.DEFAULT_TINT_COLOR;
} else if (colorName instanceof String) {
this.tintColor = TiColorHelper.parseColor((String) colorName);
this.tintColor = TiColorHelper.parseColor((String) colorName, getActivity());
} else {
Log.e(TAG, "Property '" + TiC.PROPERTY_TINT_COLOR + "' must be of type string.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ protected void doSetBackgroundColor(String color)
{
TiRootActivity root = TiApplication.getInstance().getRootActivity();
if (root != null) {
root.setBackgroundColor(color != null ? TiColorHelper.parseColor(color) : Color.TRANSPARENT);
root.setBackgroundColor(color != null ? TiColorHelper.parseColor(color, root) : Color.TRANSPARENT);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ public void windowCreated(TiBaseActivity activity, Bundle savedInstanceState)

// Handle barColor property.
if (hasProperty(TiC.PROPERTY_BAR_COLOR)) {
int colorInt = TiColorHelper.parseColor(TiConvert.toString(getProperty(TiC.PROPERTY_BAR_COLOR)));
int colorInt = TiColorHelper.parseColor(TiConvert.toString(getProperty(TiC.PROPERTY_BAR_COLOR)), activity);
ActionBar actionBar = activity.getSupportActionBar();
// Guard for using a theme with actionBar disabled.
if (actionBar != null) {
Expand Down Expand Up @@ -354,7 +354,7 @@ protected void fillIntent(Activity activity, Intent intent)
if (!modal && hasProperty(TiC.PROPERTY_OPACITY)) {
intent.setClass(activity, TiTranslucentActivity.class);
} else if (hasProperty(TiC.PROPERTY_BACKGROUND_COLOR)) {
int bgColor = TiConvert.toColor(properties, TiC.PROPERTY_BACKGROUND_COLOR);
int bgColor = TiConvert.toColor(properties, TiC.PROPERTY_BACKGROUND_COLOR, getActivity());
if (Color.alpha(bgColor) < 0xFF) {
intent.setClass(activity, TiTranslucentActivity.class);
}
Expand Down Expand Up @@ -396,12 +396,13 @@ public void onPropertyChanged(String name, Object value)
// Guard for activity being destroyed
if (windowActivity != null && windowActivity.get() != null) {
// Get a reference to the ActionBar.
ActionBar actionBar = ((AppCompatActivity) windowActivity.get()).getSupportActionBar();
AppCompatActivity activity = windowActivity.get();
ActionBar actionBar = activity.getSupportActionBar();
// Check if it is available ( app is using a theme with one or a Toolbar is used as one ).
if (actionBar != null) {
// Change to background to the new color.
actionBar.setBackgroundDrawable(
new ColorDrawable(TiColorHelper.parseColor(TiConvert.toString(value))));
new ColorDrawable(TiColorHelper.parseColor(TiConvert.toString(value), activity)));
} else {
// Log a warning if there is no ActionBar available.
Log.w(TAG, "There is no ActionBar available for this Window.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import ti.modules.titanium.ui.widget.webview.TiUIWebView;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.view.Gravity;
Expand Down Expand Up @@ -277,7 +278,11 @@ public ColorProxy getColorResource(Object idOrName)
// Color by resource id
if (idOrName instanceof Number) {
int colorResId = ((Number) idOrName).intValue();
@ColorInt int packedColorInt = ContextCompat.getColor(TiApplication.getInstance(), colorResId);
Context context = TiApplication.getAppRootOrCurrentActivity();
if (context == null) {
context = TiApplication.getInstance();
}
@ColorInt int packedColorInt = ContextCompat.getColor(context, colorResId);
return new ColorProxy(packedColorInt);
}
// Color by name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package ti.modules.titanium.ui.widget;

import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
Expand Down Expand Up @@ -400,8 +401,15 @@ public void setTintColor(String color)
imageView.clearColorFilter();
return;
}
Activity activity = null;
if (proxy != null) {
TiViewProxy p = proxy.get();
if (p != null) {
activity = p.getActivity();
}
}

this.tintColor = TiColorHelper.parseColor(color);
this.tintColor = TiColorHelper.parseColor(color, activity);
imageView.setColorFilter(this.tintColor, Mode.SRC_IN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void setItems(TiViewProxy[] proxies)
*/
public void setToolbarColor(String color)
{
toolbar.setBackgroundColor((TiColorHelper.parseColor(color)));
toolbar.setBackgroundColor((TiColorHelper.parseColor(color, proxy.getActivity())));
if (proxy.hasProperty(TiC.PROPERTY_TRANSLUCENT)) {
if ((Boolean) proxy.getProperty(TiC.PROPERTY_TRANSLUCENT)) {
toolbar.getBackground().setAlpha(BACKGROUND_TRANSLUCENT_VALUE);
Expand Down Expand Up @@ -324,7 +324,7 @@ private void setTitle(String value)
*/
private void setTitleTextColor(String value)
{
toolbar.setTitleTextColor(TiColorHelper.parseColor(value));
toolbar.setTitleTextColor(TiColorHelper.parseColor(value, proxy.getActivity()));
}

/**
Expand All @@ -342,7 +342,7 @@ private void setSubtitle(String value)
*/
private void setSubtitleTextColor(String value)
{
toolbar.setSubtitleTextColor(TiColorHelper.parseColor(value));
toolbar.setSubtitleTextColor(TiColorHelper.parseColor(value, proxy.getActivity()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class TiUIActivityIndicator extends TiUIView
private boolean visible;
private MaterialTextView label;
private CircularProgressIndicator progress;
private final int defaultTextColor;

public TiUIActivityIndicator(TiViewProxy proxy)
{
Expand All @@ -62,6 +63,7 @@ public TiUIActivityIndicator(TiViewProxy proxy)
view.addView(this.label);

setNativeView(view);
this.defaultTextColor = this.label.getCurrentTextColor();
}

@Override
Expand All @@ -81,7 +83,7 @@ public void processProperties(KrollDict d)
label.setText(TiConvert.toString(d, TiC.PROPERTY_MESSAGE));
}
if (d.containsKey(TiC.PROPERTY_COLOR)) {
label.setTextColor(TiConvert.toColor(d, TiC.PROPERTY_COLOR));
label.setTextColor(TiConvert.toColor(d, TiC.PROPERTY_COLOR, proxy.getActivity()));
}
updateIndicator();

Expand All @@ -102,7 +104,11 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
label.setText(TiConvert.toString(newValue));
label.requestLayout();
} else if (key.equals(TiC.PROPERTY_COLOR)) {
label.setTextColor(TiConvert.toColor((String) newValue));
if (newValue == null) {
label.setTextColor(defaultTextColor);
} else {
label.setTextColor(TiConvert.toColor(newValue, proxy.getActivity()));
}
} else if (key.equals(TiC.PROPERTY_INDICATOR_COLOR)) {
updateIndicator();
} else {
Expand Down Expand Up @@ -164,7 +170,7 @@ private void updateIndicator()

// Update indicator's color.
if (this.proxy.hasPropertyAndNotNull(TiC.PROPERTY_INDICATOR_COLOR)) {
int color = TiConvert.toColor(TiConvert.toString(this.proxy.getProperty(TiC.PROPERTY_INDICATOR_COLOR)));
int color = TiConvert.toColor(proxy.getProperty(TiC.PROPERTY_INDICATOR_COLOR), proxy.getActivity());
this.progress.getIndeterminateDrawable().setColorFilter(
new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
} else if ((styleId == DARK) || (styleId == BIG_DARK)) {
Expand Down
Loading