blob: 0eea5bff622660c97870b91977f6ca4fc9e22724 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package it.niedermann.owncloud.notes.branding;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.Menu;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import it.niedermann.owncloud.notes.R;
import static it.niedermann.owncloud.notes.branding.BrandingUtil.tintMenuIcon;
public abstract class BrandedActivity extends AppCompatActivity implements Branded {
@ColorInt
protected int colorAccent;
public static void applyBrandToFAB(@ColorInt int mainColor, @ColorInt int textColor, @NonNull FloatingActionButton fab) {
fab.setSupportBackgroundTintList(ColorStateList.valueOf(mainColor));
fab.setColorFilter(textColor);
}
@Override
protected void onStart() {
super.onStart();
final TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
colorAccent = typedValue.data;
if (BrandingUtil.isBrandingEnabled(this)) {
@ColorInt final int mainColor = BrandingUtil.readBrandMainColor(this);
@ColorInt final int textColor = BrandingUtil.readBrandTextColor(this);
applyBrand(mainColor, textColor);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
for (int i = 0; i < menu.size(); i++) {
tintMenuIcon(menu.getItem(i), colorAccent);
}
return super.onCreateOptionsMenu(menu);
}
public void applyBrandToPrimaryToolbar(@NonNull Toolbar toolbar) {
final Drawable overflowDrawable = toolbar.getOverflowIcon();
if (overflowDrawable != null) {
overflowDrawable.setColorFilter(colorAccent, PorterDuff.Mode.SRC_ATOP);
toolbar.setOverflowIcon(overflowDrawable);
}
final Drawable navigationDrawable = toolbar.getNavigationIcon();
if (navigationDrawable != null) {
navigationDrawable.setColorFilter(colorAccent, PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(navigationDrawable);
}
}
}
|