Skip to content
Prev Previous commit
Next Next commit
Introduce light/dark theme / black/white primary-color-aware primary-…
…button theming

Signed-off-by: Andy Scherzinger <[email protected]>
  • Loading branch information
AndyScherzinger committed Jun 26, 2020
commit 7005cdef2e30f4e09bd66ed0c89859c780990701
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ private void setupContent() {
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));
}

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/owncloud/android/utils/ThemeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -435,6 +436,21 @@ private static float[] colorToHSL(int color) {
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.
*
Expand Down