Skip to content

Commit

Permalink
fix(android): Ti.UI.Android.ProgressIndicator dialog not using theme'…
Browse files Browse the repository at this point in the history
…s "colorPrimary" (#13167)

* fix(android): progress indicator dialog not using theme's "colorPrimary"

Fixes TIMOB-28576

* chore(android): add null check to ProgressIndicator onShow()

Co-authored-by: Gary Mathews <contact@garymathews.com>
  • Loading branch information
jquick-axway and garymathews committed Nov 5, 2021
1 parent da00331 commit 71ce0e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;

public class TiUIProgressIndicator
extends TiUIView implements DialogInterface.OnCancelListener, DialogInterface.OnDismissListener
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.os.Build;
import android.widget.ProgressBar;
import com.google.android.material.color.MaterialColors;

public class TiUIProgressIndicator extends TiUIView implements
DialogInterface.OnShowListener, DialogInterface.OnCancelListener, DialogInterface.OnDismissListener
{
private static final String TAG = "TiUIProgressDialog";

Expand Down Expand Up @@ -194,6 +200,7 @@ protected void handleShow()
progressDialog, true, new WeakReference<>(baseActivity)));
progressDialog.setOwnerActivity(a);
}
progressDialog.setOnShowListener(this);
progressDialog.setOnCancelListener(this);
progressDialog.setOnDismissListener(this);
}
Expand Down Expand Up @@ -276,6 +283,31 @@ protected void handleHide()
this.visible = false;
}

@Override
public void onShow(DialogInterface dialog)
{
// Fetch progress dialog reference.
// Note: Argument won't match "progressDialog" member variable if hide() was called before dialog was shown.
if ((dialog instanceof ProgressDialog) == false) {
return;
}
ProgressDialog progressDialog = (ProgressDialog) dialog;

// Work-around Android 5.x and older issue where it ignores "indeterminateTint" color in theme.
// Only happens to the indeterminate type. The determinate type is okay.
if ((Build.VERSION.SDK_INT < 23) && progressDialog.isIndeterminate()) {
var view = progressDialog.findViewById(android.R.id.progress);
if (view instanceof ProgressBar) {
int colorValue = MaterialColors.getColor(
progressDialog.getContext(), android.R.attr.indeterminateTint, Color.TRANSPARENT);
var drawable = ((ProgressBar) view).getIndeterminateDrawable();
if ((colorValue != Color.TRANSPARENT) && (drawable != null)) {
drawable.setColorFilter(new PorterDuffColorFilter(colorValue, PorterDuff.Mode.SRC_IN));
}
}
}
}

@Override
public void onCancel(DialogInterface dialog)
{
Expand Down
4 changes: 4 additions & 0 deletions android/titanium/res/values/values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
<item name="colorAccent">@color/ti_dark_accent</item>
<item name="colorSurface">@color/ti_dark_surface</item>
<item name="android:colorBackground">@color/ti_dark_background</item>
<item name="android:indeterminateTint">?attr/colorPrimary</item>
<item name="android:navigationBarColor">?attr/colorPrimaryDark</item>
<item name="android:progressTint">?attr/colorPrimary</item>
<item name="android:statusBarColor">?attr/colorPrimaryDark</item>
<item name="android:textAllCaps">false</item>
<item name="textAllCaps">false</item>
Expand Down Expand Up @@ -93,7 +95,9 @@
<item name="colorAccent">@color/ti_light_accent</item>
<item name="colorSurface">@color/ti_light_surface</item>
<item name="android:colorBackground">@color/ti_light_background</item>
<item name="android:indeterminateTint">?attr/colorPrimary</item>
<item name="android:navigationBarColor">?attr/colorPrimaryDark</item>
<item name="android:progressTint">?attr/colorPrimary</item>
<item name="android:statusBarColor">?attr/colorPrimaryDark</item>
<item name="android:textAllCaps">false</item>
<item name="textAllCaps">false</item>
Expand Down

0 comments on commit 71ce0e9

Please sign in to comment.