Introduce light/dark theme / black/white primary-color-aware primary-button theming

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2020-06-23 11:10:43 +02:00
parent 643454c1d7
commit 7005cdef2e
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 17 additions and 2 deletions

View file

@ -92,8 +92,7 @@ public class CommunityActivity extends FileActivity {
getString(R.string.contributing_link)))));
MaterialButton reportButton = findViewById(R.id.community_testing_report);
reportButton.setBackgroundColor(ThemeUtils.primaryColor(this,true));
reportButton.setTextColor(ThemeUtils.fontColor(this, false));
ThemeUtils.colorPrimaryButton(reportButton, this);
reportButton.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.report_issue_link));
}

View file

@ -38,6 +38,7 @@ import android.text.style.ForegroundColorSpan;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
@ -435,6 +436,21 @@ public final class ThemeUtils {
return hsl;
}
public static void colorPrimaryButton(Button button, Context context) {
int primaryColor = ThemeUtils.primaryColor(null, true, false, context);
int fontColor = ThemeUtils.fontColor(context, false);
button.setBackgroundColor(primaryColor);
if (Color.BLACK == primaryColor) {
button.setTextColor(Color.WHITE);
} else if (Color.WHITE == primaryColor) {
button.setTextColor(Color.BLACK);
} else {
button.setTextColor(fontColor);
}
}
/**
* sets the tinting of the given ImageButton's icon to color_accent.
*