[Gradle] Extract cafebar dependency.

This commit is contained in:
Kuba Szczodrzyński 2021-03-20 19:26:58 +01:00
parent 50e7bf14d4
commit 75b3485ab4
26 changed files with 5 additions and 1743 deletions

View File

@ -168,7 +168,7 @@ dependencies {
implementation "uk.co.samuelwall:material-tap-target-prompt:2.14.0"
implementation project(":agendacalendarview")
implementation project(":cafebar")
implementation "eu.szkolny:cafebar:5bf0c618de"
implementation "eu.szkolny:material-about-library:0534abf316"
implementation project(":mhttp")
implementation project(":nachos")

View File

@ -532,12 +532,12 @@ class MainActivity : AppCompatActivity(), CoroutineScope {
app.config.appRateSnackbarTime = 0
}
.onNegative { cafeBar ->
Toast.makeText(this, "Szkoda, opinie innych pomagają mi rozwijać aplikację.", Toast.LENGTH_LONG).show()
Toast.makeText(this, R.string.rate_snackbar_negative_message, Toast.LENGTH_LONG).show()
cafeBar.dismiss()
app.config.appRateSnackbarTime = 0
}
.onNeutral { cafeBar ->
Toast.makeText(this, "OK", Toast.LENGTH_LONG).show()
Toast.makeText(this, R.string.ok, Toast.LENGTH_LONG).show()
cafeBar.dismiss()
app.config.appRateSnackbarTime = System.currentTimeMillis() + 7 * 24 * 60 * 60 * 1000
}

View File

@ -1386,4 +1386,5 @@
<string name="login_chooser_mode_testing">{cmd-alert-circle-outline} Wersja testowa</string>
<string name="login_chooser_mode_dev_only">{cmd-android-studio} Wersja deweloperska</string>
<string name="eggs">\???</string>
<string name="rate_snackbar_negative_message">Szkoda, opinie innych pomagają mi rozwijać aplikację.</string>
</resources>

View File

@ -1,64 +0,0 @@
apply plugin: 'com.android.library'
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
group = 'com.github.danimahardhika'
android {
compileSdkVersion setup.compileSdk
defaultConfig {
minSdkVersion 16
targetSdkVersion setup.targetSdk
versionCode 132
versionName "1.3.2"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debugMinify {
debuggable = true
minifyEnabled = true
proguardFiles 'proguard-android.txt'
}
}
lintOptions {
abortOnError false
}
sourceSets {
main.res.srcDirs = [
'src/main/res',
'src/main/res-public'
]
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.google.android.material:material:${versions.material}"
implementation "androidx.cardview:cardview:${versions.cardview}"
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
}

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
-->
<manifest package="com.danimahardhika.cafebar">
<application />
</manifest>

View File

@ -1,712 +0,0 @@
package com.danimahardhika.cafebar;
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import androidx.annotation.BoolRes;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.IntRange;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.cardview.widget.CardView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
@SuppressWarnings("unused")
public class CafeBar {
static final String FONT_CONTENT = "content";
static final String FONT_POSITIVE = "positive";
static final String FONT_NEGATIVE = "negative";
static final String FONT_NEUTRAL = "neutral";
private Builder mBuilder;
private Snackbar mSnackBar;
private CafeBar(@NonNull Builder builder) {
mBuilder = builder;
View baseLayout = mBuilder.mCustomView;
if (baseLayout == null) {
LogUtil.d("CafeBar doesn't have customView, preparing it ...");
baseLayout = CafeBarUtil.getBaseCafeBarView(mBuilder);
}
mSnackBar = CafeBarUtil.getBaseSnackBar(baseLayout, mBuilder);
if (mSnackBar == null) {
mBuilder = null;
throw new IllegalStateException("CafeBar base is null");
}
if (mBuilder.mCustomView != null) {
LogUtil.d("CafeBar has custom view, set buttons ignored");
return;
}
if (mBuilder.mPositiveText == null && mBuilder.mNegativeText == null) {
//Only contains neutral button
if (mBuilder.mNeutralText != null) {
int neutralColor = CafeBarUtil.getAccentColor(mBuilder.mContext, mBuilder.mNegativeColor);
setAction(mBuilder.mNeutralText, neutralColor, mBuilder.mNeutralCallback);
}
} else {
//Contains positive or negative button
LinearLayout root = (LinearLayout) getView();
LinearLayout buttonBase = root.findViewById(R.id.cafebar_button_base);
if (mBuilder.mNeutralText != null) {
TextView neutral = buttonBase.findViewById(R.id.cafebar_button_neutral);
neutral.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mBuilder.mNeutralCallback != null) {
mBuilder.mNeutralCallback.OnClick(getCafeBar());
return;
}
dismiss();
}
});
}
if (mBuilder.mNegativeText != null) {
TextView negative = buttonBase.findViewById(R.id.cafebar_button_negative);
negative.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mBuilder.mNegativeCallback != null) {
mBuilder.mNegativeCallback.OnClick(getCafeBar());
return;
}
dismiss();
}
});
}
if (mBuilder.mPositiveText != null) {
TextView positive = buttonBase.findViewById(R.id.cafebar_button_positive);
positive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mBuilder.mPositiveCallback != null) {
mBuilder.mPositiveCallback.OnClick(getCafeBar());
return;
}
dismiss();
}
});
}
}
}
public static void enableLogging(boolean enableLogging) {
LogUtil.sEnableLogging = enableLogging;
}
@NonNull
public static CafeBar make(@NonNull Context context, @StringRes int res, @Snackbar.Duration int duration) {
String string = context.getResources().getString(res);
return create(context, null, string, duration);
}
@NonNull
public static CafeBar make(@NonNull Context context, @NonNull String content, @Snackbar.Duration int duration) {
return create(context, null, content, duration);
}
@NonNull
public static CafeBar make(@NonNull View to, @StringRes int res, @Snackbar.Duration int duration) {
Context context = to.getContext();
if (context instanceof ContextThemeWrapper) {
context = ((ContextThemeWrapper) context).getBaseContext();
}
String string = context.getResources().getString(res);
return create(context, to, string, duration);
}
@NonNull
public static CafeBar make(@NonNull View to, @NonNull String content, @Snackbar.Duration int duration) {
Context context = to.getContext();
if (context instanceof ContextThemeWrapper) {
context = ((ContextThemeWrapper) context).getBaseContext();
}
return create(context, to, content, duration);
}
@NonNull
private static CafeBar create(@NonNull Context context, @Nullable View to, @NonNull String content, @Snackbar.Duration int duration) {
CafeBar.Builder builder = new Builder(context);
builder.to(to);
builder.content(content);
builder.duration(duration);
if (duration == Snackbar.LENGTH_INDEFINITE) {
builder.autoDismiss(false);
}
return new CafeBar(builder);
}
public CafeBar setAction(@StringRes int res, @Nullable CafeBarCallback callback) {
String string = mBuilder.mContext.getResources().getString(res);
int actionColor = CafeBarUtil.getAccentColor(mBuilder.mContext, mBuilder.mTheme.getTitleColor());
setButtonAction(string, actionColor, callback);
return this;
}
public CafeBar setAction(@NonNull String action, @Nullable CafeBarCallback callback) {
int actionColor = CafeBarUtil.getAccentColor(mBuilder.mContext, mBuilder.mTheme.getTitleColor());
setButtonAction(action, actionColor, callback);
return this;
}
public CafeBar setAction(@StringRes int res, int color, @Nullable CafeBarCallback callback) {
String string = mBuilder.mContext.getResources().getString(res);
setButtonAction(string, color, callback);
return this;
}
public CafeBar setAction(@NonNull String action, int color, @Nullable CafeBarCallback callback) {
setButtonAction(action, color, callback);
return this;
}
private void setButtonAction(@NonNull String action, int color, @Nullable final CafeBarCallback callback) {
if (mBuilder.mCustomView != null) {
LogUtil.d("CafeBar has customView, setAction ignored.");
return;
}
LogUtil.d("preparing action view");
mBuilder.mNeutralText = action;
mBuilder.mNeutralColor = color;
LinearLayout root = (LinearLayout) getView();
boolean longAction = CafeBarUtil.isLongAction(action);
if (root.getChildCount() > 1) {
LogUtil.d("setAction already set from builder via neutralText");
return;
}
TextView content = root.findViewById(R.id.cafebar_content);
int side = mBuilder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_side);
int top = mBuilder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_top);
int buttonPadding = mBuilder.mContext.getResources().getDimensionPixelSize(
R.dimen.cafebar_button_padding);
int bottom = 0;
if (longAction) {
bottom = buttonPadding;
root.setOrientation(LinearLayout.VERTICAL);
content.setPadding(0, 0, buttonPadding, 0);
} else {
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) content.getLayoutParams();
params.width = 0;
params.weight = 1f;
content.setLayoutParams(params);
}
int navBar = 0;
if (mBuilder.mFitSystemWindow && !mBuilder.mFloating) {
navBar = CafeBarUtil.getNavigationBarHeight(mBuilder.mContext);
}
Configuration configuration = mBuilder.mContext.getResources().getConfiguration();
boolean tabletMode = mBuilder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode);
if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
if (mBuilder.mLongContent) {
LogUtil.d("content has multi lines");
root.setPadding(side, side, (side - buttonPadding), (side - bottom + navBar));
} else if (longAction){
LogUtil.d("content only 1 line with longAction");
root.setPadding(side, top, (side - buttonPadding), (top - buttonPadding + navBar));
} else {
LogUtil.d("content only 1 line");
root.setPadding(side, (top - buttonPadding), (side - buttonPadding), (top - buttonPadding + navBar));
}
} else {
if (mBuilder.mLongContent) {
LogUtil.d("content has multi lines");
root.setPadding(side, side, (side - buttonPadding + navBar), (side - bottom));
} else if (longAction) {
LogUtil.d("content only 1 line with longAction");
root.setPadding(side, top, (side - buttonPadding + navBar), (top - buttonPadding));
} else {
LogUtil.d("content only 1 line");
root.setPadding(side, (top - buttonPadding), (side - buttonPadding + navBar), (top - buttonPadding));
}
}
TextView button = CafeBarUtil.getActionView(mBuilder, action, color);
if (mBuilder.getTypeface(FONT_NEUTRAL) != null) {
button.setTypeface(mBuilder.getTypeface(FONT_NEUTRAL));
}
if (!longAction) {
boolean multiLines = CafeBarUtil.isContentMultiLines(mBuilder);
if (multiLines) {
if (mBuilder.mFitSystemWindow && !mBuilder.mFloating) {
if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
root.setPadding(side, side, (side - buttonPadding), (side + navBar));
} else {
root.setPadding(side, side, (side - buttonPadding + navBar), side);
}
} else {
root.setPadding(side, side, (side - buttonPadding), side);
}
}
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (callback != null) {
callback.OnClick(getCafeBar());
return;
}
LogUtil.d("callback = null, CafeBar dismissed");
dismiss();
}
});
root.addView(button);
}
@NonNull
private CafeBar getCafeBar() {
return this;
}
@NonNull
public View getView() {
Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) mSnackBar.getView();
boolean tabletMode = mBuilder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode);
if (tabletMode || mBuilder.mFloating) {
CardView cardView = (CardView) snackBarLayout.getChildAt(0);
return cardView.getChildAt(0);
}
LinearLayout linearLayout = (LinearLayout) snackBarLayout.getChildAt(0);
if (mBuilder.mShowShadow) return linearLayout.getChildAt(1);
return linearLayout.getChildAt(0);
}
public void dismiss() {
if (mSnackBar == null) return;
mSnackBar.dismiss();
}
public void show() {
mSnackBar.show();
if (mBuilder.mSwipeToDismiss) return;
if (mSnackBar.getView().getLayoutParams() instanceof CoordinatorLayout.LayoutParams) {
mSnackBar.getView().getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
mSnackBar.getView().getViewTreeObserver().removeOnPreDrawListener(this);
((CoordinatorLayout.LayoutParams) mSnackBar.getView().getLayoutParams()).setBehavior(null);
return true;
}
});
}
}
@NonNull
public static Builder builder(@NonNull Context context) {
return new Builder(context);
}
@SuppressWarnings("unused")
public static class Builder {
Context mContext;
@NonNull View mTo;
@Nullable View mCustomView;
CafeBarTheme.Custom mTheme = CafeBarTheme.Custom(CafeBarTheme.DARK.getColor());
CafeBarGravity mGravity = CafeBarGravity.CENTER;
@Snackbar.Duration
int mDuration = Snackbar.LENGTH_SHORT;
int mMaxLines = 2;
@ColorInt
int mPositiveColor = mTheme.getTitleColor();
@ColorInt int mNegativeColor = mTheme.getTitleColor();
@ColorInt int mNeutralColor = mTheme.getTitleColor();
boolean mLongContent = false;
boolean mAutoDismiss = true;
boolean mShowShadow = true;
boolean mFitSystemWindow = false;
boolean mFloating = false;
boolean mTintIcon = true;
boolean mSwipeToDismiss = true;
private HashMap<String, WeakReference<Typeface>> mTypefaces;
@Nullable Drawable mIcon = null;
String mContent = "";
@Nullable String mPositiveText = null;
@Nullable String mNegativeText = null;
@Nullable String mNeutralText = null;
@Nullable SpannableStringBuilder mSpannableBuilder = null;
@Nullable CafeBarCallback mPositiveCallback;
@Nullable CafeBarCallback mNegativeCallback;
@Nullable CafeBarCallback mNeutralCallback;
public Builder(@NonNull Context context) {
mContext = context;
mTypefaces = new HashMap<>();
mTo = ((Activity) mContext).getWindow().getDecorView()
.findViewById(android.R.id.content);
}
public Builder to(@Nullable View view) {
if (view != null) {
mTo = view;
return this;
}
LogUtil.e("to(View): view is null, ignored");
return this;
}
public Builder customView(@LayoutRes int res) {
View view = View.inflate(mContext, res, null);
return customView(view);
}
public Builder customView(@Nullable View customView) {
mCustomView = customView;
return this;
}
public Builder content(@StringRes int res) {
return content(mContext.getResources().getString(res));
}
public Builder content(@NonNull String content) {
mContent = content;
return this;
}
public Builder content(@NonNull SpannableStringBuilder spannableBuilder) {
mSpannableBuilder = spannableBuilder;
return this;
}
public Builder maxLines(@IntRange(from = 1, to = 6) int maxLines) {
mMaxLines = maxLines;
return this;
}
public Builder duration(@Snackbar.Duration int duration) {
mDuration = duration;
return this;
}
public Builder theme(@NonNull CafeBarTheme theme) {
return theme(CafeBarTheme.Custom(theme.getColor()));
}
public Builder theme(@NonNull CafeBarTheme.Custom customTheme) {
mTheme = customTheme;
mPositiveColor = mTheme.getTitleColor();
mNegativeColor = mNeutralColor = mTheme.getSubTitleColor();
return this;
}
public Builder icon(@Nullable Bitmap icon) {
return icon(CafeBarUtil.toDrawable(mContext, icon), true);
}
public Builder icon(@DrawableRes int res) {
return icon(CafeBarUtil.getDrawable(mContext, res), true);
}
public Builder icon(@Nullable Drawable icon) {
return icon(icon, true);
}
public Builder icon(@Nullable Bitmap icon, boolean tintIcon) {
return icon(CafeBarUtil.toDrawable(mContext, icon), tintIcon);
}
public Builder icon(@DrawableRes int res, boolean tintIcon) {
return icon(CafeBarUtil.getDrawable(mContext, res), tintIcon);
}
public Builder icon(@Nullable Drawable icon, boolean tintIcon) {
mIcon = icon;
mTintIcon = tintIcon;
return this;
}
public Builder showShadow(@BoolRes int res) {
return showShadow(mContext.getResources().getBoolean(res));
}
public Builder showShadow(boolean showShadow) {
mShowShadow = showShadow;
return this;
}
public Builder autoDismiss(@BoolRes int res) {
return autoDismiss(mContext.getResources().getBoolean(res));
}
public Builder autoDismiss(boolean autoDismiss) {
mAutoDismiss = autoDismiss;
return this;
}
public Builder swipeToDismiss(@BoolRes int res) {
return swipeToDismiss(mContext.getResources().getBoolean(res));
}
public Builder swipeToDismiss(boolean swipeToDismiss) {
mSwipeToDismiss = swipeToDismiss;
return this;
}
public Builder floating(@BoolRes int res) {
return floating(mContext.getResources().getBoolean(res));
}
public Builder floating(boolean floating) {
mFloating = floating;
return this;
}
public Builder gravity(@NonNull CafeBarGravity gravity) {
mGravity = gravity;
return this;
}
public Builder fitSystemWindow() {
Activity activity = (Activity) mContext;
Window window = activity.getWindow();
if (window == null) {
LogUtil.d("fitSystemWindow() window is null");
return this;
}
WindowManager.LayoutParams params = window.getAttributes();
int navigationBarHeight = CafeBarUtil.getNavigationBarHeight(mContext);
boolean isInMultiWindowMode = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
isInMultiWindowMode = activity.isInMultiWindowMode();
}
if ((params.flags & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) ==
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) {
mFitSystemWindow = navigationBarHeight > 0 && !isInMultiWindowMode;
}
return this;
}
public Builder typeface(String contentFontName, String buttonFontName) {
return typeface(CafeBarUtil.getTypeface(mContext, contentFontName),
CafeBarUtil.getTypeface(mContext, buttonFontName));
}
public Builder typeface(@Nullable Typeface content, @Nullable Typeface button) {
addTypeface(FONT_CONTENT, content);
addTypeface(FONT_POSITIVE, button);
addTypeface(FONT_NEGATIVE, button);
addTypeface(FONT_NEUTRAL, button);
return this;
}
public Builder contentTypeface(String fontName) {
return contentTypeface(CafeBarUtil.getTypeface(mContext, fontName));
}
public Builder contentTypeface(@Nullable Typeface typeface) {
addTypeface(FONT_CONTENT, typeface);
return this;
}
public Builder positiveTypeface(String fontName) {
return positiveTypeface(CafeBarUtil.getTypeface(mContext, fontName));
}
public Builder positiveTypeface(@Nullable Typeface typeface) {
addTypeface(FONT_POSITIVE,typeface);
return this;
}
public Builder negativeTypeface(String fontName) {
return negativeTypeface(CafeBarUtil.getTypeface(mContext, fontName));
}
public Builder negativeTypeface(@Nullable Typeface typeface) {
addTypeface(FONT_NEGATIVE, typeface);
return this;
}
public Builder neutralTypeface(String fontName) {
return neutralTypeface(CafeBarUtil.getTypeface(mContext, fontName));
}
public Builder neutralTypeface(@Nullable Typeface typeface) {
addTypeface(FONT_NEUTRAL, typeface);
return this;
}
public Builder buttonTypeface(String fontName) {
return buttonTypeface(CafeBarUtil.getTypeface(mContext, fontName));
}
public Builder buttonTypeface(@Nullable Typeface typeface) {
addTypeface(FONT_POSITIVE, typeface);
addTypeface(FONT_NEGATIVE, typeface);
addTypeface(FONT_NEUTRAL, typeface);
return this;
}
public Builder positiveColor(int positiveColor) {
mPositiveColor = CafeBarUtil.getColor(mContext, positiveColor);
return this;
}
public Builder negativeColor(int negativeColor) {
mNegativeColor = CafeBarUtil.getColor(mContext, negativeColor);
return this;
}
public Builder neutralColor(int neutralColor) {
mNeutralColor = CafeBarUtil.getColor(mContext, neutralColor);
return this;
}
public Builder buttonColor(int buttonColor) {
int color = CafeBarUtil.getColor(mContext, buttonColor);
mNeutralColor = mPositiveColor = mNegativeColor = color;
return this;
}
public Builder positiveText(@StringRes int res) {
return positiveText(mContext.getResources().getString(res));
}
public Builder positiveText(@NonNull String positiveText) {
mPositiveText = positiveText;
return this;
}
public Builder negativeText(@StringRes int res) {
return negativeText(mContext.getResources().getString(res));
}
public Builder negativeText(@NonNull String negativeText) {
mNegativeText = negativeText;
return this;
}
public Builder neutralText(@StringRes int res) {
return neutralText(mContext.getResources().getString(res));
}
public Builder neutralText(@NonNull String neutralText) {
mNeutralText = neutralText;
return this;
}
public Builder onPositive(@Nullable CafeBarCallback positiveCallback) {
mPositiveCallback = positiveCallback;
return this;
}
public Builder onNegative(@Nullable CafeBarCallback negativeCallback) {
mNegativeCallback = negativeCallback;
return this;
}
public Builder onNeutral(@Nullable CafeBarCallback neutralCallback) {
mNeutralCallback = neutralCallback;
return this;
}
public CafeBar build() {
return new CafeBar(this);
}
public void show() {
build().show();
}
private void addTypeface(String name, Typeface typeface) {
if (!mTypefaces.containsKey(name) || mTypefaces.get(name) == null) {
mTypefaces.put(name, new WeakReference<>(typeface));
}
}
@Nullable
Typeface getTypeface(String name) {
if (mTypefaces.get(name) != null) {
return mTypefaces.get(name).get();
}
return null;
}
}
}

View File

@ -1,27 +0,0 @@
package com.danimahardhika.cafebar;
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import androidx.annotation.NonNull;
public interface CafeBarCallback {
void OnClick(@NonNull CafeBar cafeBar);
}

View File

@ -1,39 +0,0 @@
package com.danimahardhika.cafebar;
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.view.Gravity;
@SuppressWarnings("unused")
public enum CafeBarGravity {
START(Gravity.START),
CENTER(Gravity.CENTER),
END(Gravity.END);
private int mGravity;
CafeBarGravity(int gravity) {
mGravity = gravity;
}
int getGravity() {
return mGravity;
}
}

View File

@ -1,70 +0,0 @@
package com.danimahardhika.cafebar;
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.graphics.Color;
import androidx.annotation.ColorInt;
@SuppressWarnings("unused")
public enum CafeBarTheme {
LIGHT(Color.parseColor("#F5F5F5")),
DARK(Color.parseColor("#323232")),
CLEAR_BLACK(Color.BLACK);
private int mColor;
CafeBarTheme(@ColorInt int color) {
mColor = color;
}
@ColorInt
int getColor() {
return mColor;
}
public static Custom Custom(@ColorInt int color) {
return new Custom(color);
}
public static class Custom {
private int mColor;
private Custom(int color) {
mColor = color;
}
@ColorInt
int getColor() {
return mColor;
}
@ColorInt
int getTitleColor() {
return CafeBarUtil.getTitleTextColor(mColor);
}
@ColorInt
int getSubTitleColor() {
return CafeBarUtil.getSubTitleTextColor(mColor);
}
}
}

View File

@ -1,593 +0,0 @@
package com.danimahardhika.cafebar;
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
import java.util.Locale;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
class CafeBarUtil {
@NonNull
static View getBaseCafeBarView(@NonNull CafeBar.Builder builder) {
int color = builder.mTheme.getColor();
int titleColor = builder.mTheme.getTitleColor();
//Creating LinearLayout as rootView
LinearLayout root = new LinearLayout(builder.mContext);
root.setId(R.id.cafebar_root);
root.setOrientation(LinearLayout.HORIZONTAL);
root.setGravity(Gravity.CENTER_VERTICAL);
root.setBackgroundColor(color);
root.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
root.setClickable(true);
//Creating TextView for content
TextView content = new TextView(builder.mContext);
content.setId(R.id.cafebar_content);
content.setMaxLines(builder.mMaxLines);
content.setEllipsize(TextUtils.TruncateAt.END);
content.setTextColor(titleColor);
content.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.mContext.getResources()
.getDimensionPixelSize(R.dimen.cafebar_content_text));
if (builder.getTypeface(CafeBar.FONT_CONTENT) != null) {
content.setTypeface(builder.getTypeface(CafeBar.FONT_CONTENT));
}
content.setText(builder.mContent);
if (builder.mSpannableBuilder != null) {
content.setText(builder.mSpannableBuilder, TextView.BufferType.SPANNABLE);
}
content.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
content.setGravity(Gravity.CENTER_VERTICAL);
boolean tabletMode = builder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode);
if (tabletMode || builder.mFloating) {
content.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
content.setMinWidth(builder.mContext.getResources()
.getDimensionPixelSize(R.dimen.cafebar_floating_min_width));
content.setMaxWidth(builder.mContext.getResources()
.getDimensionPixelSize(R.dimen.cafebar_floating_max_width));
}
int side = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_side);
int top = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_top);
if (builder.mIcon != null) {
Drawable drawable = getResizedDrawable(
builder.mContext,
builder.mIcon,
titleColor,
builder.mTintIcon);
if (drawable != null) {
content.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
content.setCompoundDrawablePadding(top);
}
}
boolean multiLines = isContentMultiLines(builder);
boolean containsPositive = builder.mPositiveText != null;
boolean containsNegative = builder.mNegativeText != null;
boolean longNeutralAction = isLongAction(builder.mNeutralText);
if (multiLines || containsPositive || containsNegative || longNeutralAction) {
top = side;
builder.mLongContent = true;
}
root.setPadding(side, top, side, top);
if (builder.mPositiveText == null && builder.mNegativeText == null) {
if (builder.mFitSystemWindow && !builder.mFloating) {
Configuration configuration = builder.mContext.getResources().getConfiguration();
int navBar = getNavigationBarHeight(builder.mContext);
if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
root.setPadding(side, top, side, (top + navBar));
} else {
root.setPadding(side, top, (side + navBar), top);
}
}
//Adding childView to rootView
root.addView(content);
//Returning rootView
return root;
}
//Change root orientation to vertical
root.setOrientation(LinearLayout.VERTICAL);
//Creating another linear layout for button container
LinearLayout buttonBase = new LinearLayout(builder.mContext);
buttonBase.setId(R.id.cafebar_button_base);
buttonBase.setOrientation(LinearLayout.HORIZONTAL);
buttonBase.setGravity(Gravity.END);
buttonBase.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
//Adding button
String neutralText = builder.mNeutralText;
if (neutralText != null) {
TextView neutral = getActionView(builder, neutralText, builder.mNeutralColor);
neutral.setId(R.id.cafebar_button_neutral);
if (builder.getTypeface(CafeBar.FONT_NEUTRAL) != null) {
neutral.setTypeface(builder.getTypeface(CafeBar.FONT_NEUTRAL));
}
buttonBase.addView(neutral);
}
String negativeText = builder.mNegativeText;
if (negativeText != null) {
TextView negative = getActionView(builder, negativeText, builder.mNegativeColor);
negative.setId(R.id.cafebar_button_negative);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) negative.getLayoutParams();
params.setMargins(
params.leftMargin + builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_margin),
params.topMargin,
params.rightMargin,
params.bottomMargin);
if (builder.getTypeface(CafeBar.FONT_NEGATIVE) != null) {
negative.setTypeface(builder.getTypeface(CafeBar.FONT_NEGATIVE));
}
buttonBase.addView(negative);
}
String positiveText = builder.mPositiveText;
if (positiveText != null) {
int positiveColor = CafeBarUtil.getAccentColor(builder.mContext, builder.mPositiveColor);
TextView positive = getActionView(builder, positiveText, positiveColor);
positive.setId(R.id.cafebar_button_positive);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) positive.getLayoutParams();
params.setMargins(
params.leftMargin + builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_margin),
params.topMargin,
params.rightMargin,
params.bottomMargin);
if (builder.getTypeface(CafeBar.FONT_POSITIVE) != null) {
positive.setTypeface(builder.getTypeface(CafeBar.FONT_POSITIVE));
}
buttonBase.addView(positive);
}
//Adjust padding
int buttonPadding = builder.mContext.getResources().getDimensionPixelSize(
R.dimen.cafebar_button_padding);
root.setPadding(side, top, (side - buttonPadding), (top - buttonPadding));
if (builder.mFitSystemWindow && !builder.mFloating) {
Configuration configuration = builder.mContext.getResources().getConfiguration();
int navBar = getNavigationBarHeight(builder.mContext);
if (tabletMode || configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
root.setPadding(side, top, (side - buttonPadding), (top - buttonPadding + navBar));
} else {
root.setPadding(side, top, (side - buttonPadding + navBar), top);
}
}
//Adding content to container
content.setPadding(0, 0, buttonPadding, 0);
//Adding childView to rootView
root.addView(content);
//Adding button container to root
root.addView(buttonBase);
//Returning rootView
return root;
}
static Snackbar getBaseSnackBar(@NonNull View cafeBarLayout,
@NonNull CafeBar.Builder builder) {
View view = builder.mTo;
Snackbar snackBar = Snackbar.make(view, "", builder.mAutoDismiss ?
builder.mDuration : Snackbar.LENGTH_INDEFINITE);
Snackbar.SnackbarLayout snackBarLayout = (Snackbar.SnackbarLayout) snackBar.getView();
snackBarLayout.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
snackBarLayout.setPadding(0, 0, 0, 0);
snackBarLayout.setBackgroundColor(Color.TRANSPARENT);
snackBarLayout.setClickable(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
snackBarLayout.setElevation(0);
}
TextView textView = snackBarLayout.findViewById(
R.id.snackbar_text);
if (textView != null) textView.setVisibility(View.INVISIBLE);
boolean tabletMode = builder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode);
if (tabletMode || builder.mFloating) {
int shadow = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cardview_default_elevation);
int padding = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_floating_padding);
CardView cardView = new CardView(builder.mContext);
cardView.setUseCompatPadding(false);
Snackbar.SnackbarLayout.LayoutParams params = new Snackbar.SnackbarLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.gravity = builder.mGravity.getGravity();
int bottom = builder.mFloating ? padding : 0;
snackBarLayout.setClipToPadding(false);
snackBarLayout.setPadding(padding, shadow, padding, bottom);
if (builder.mFitSystemWindow && builder.mFloating) {
Configuration configuration = builder.mContext.getResources().getConfiguration();
int navBar = getNavigationBarHeight(builder.mContext);
if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
snackBarLayout.setPadding(padding, shadow, padding, bottom + navBar);
} else {
snackBarLayout.setPadding(padding, shadow, padding + navBar, bottom);
}
}
cardView.setLayoutParams(params);
cardView.setClickable(true);
if (!builder.mShowShadow) {
cardView.setCardElevation(0f);
}
cardView.addView(cafeBarLayout);
snackBarLayout.addView(cardView, 0);
return snackBar;
}
LinearLayout root = new LinearLayout(builder.mContext);
root.setOrientation(LinearLayout.VERTICAL);
root.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
if (builder.mShowShadow) {
View shadow = new View(builder.mContext);
shadow.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
builder.mContext.getResources().getDimensionPixelSize(
R.dimen.cafebar_shadow_top)));
shadow.setBackgroundResource(R.drawable.cafebar_shadow_top);
root.addView(shadow);
}
root.addView(cafeBarLayout);
snackBarLayout.addView(root, 0);
return snackBar;
}
@NonNull
static TextView getActionView(@NonNull CafeBar.Builder builder, @NonNull String action, int color) {
boolean longAction = isLongAction(action);
int res = R.layout.cafebar_action_button_dark;
CafeBarTheme.Custom customTheme = builder.mTheme;
int titleColor = customTheme.getTitleColor();
boolean dark = titleColor != Color.WHITE;
if (dark) {
res = R.layout.cafebar_action_button;
}
int padding = builder.mContext.getResources().getDimensionPixelSize(
R.dimen.cafebar_button_padding);
TextView button = (TextView) View.inflate(builder.mContext, res, null);
button.setText(action.toUpperCase(Locale.getDefault()));
button.setMaxLines(1);
button.setEllipsize(TextUtils.TruncateAt.END);
button.setTextColor(color);
button.setPadding(padding, padding, padding, padding);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int side = builder.mContext.getResources().getDimensionPixelSize(
R.dimen.cafebar_content_padding_side);
int margin = builder.mContext.getResources().getDimensionPixelSize(
R.dimen.cafebar_button_margin_start);
params.setMargins(margin, 0, 0, 0);
if (longAction) {
params.setMargins(0, (side - padding), 0, 0);
}
if (builder.mPositiveText != null || builder.mNegativeText != null) {
longAction = true;
params.setMargins(0, (side - padding), 0, 0);
} else {
params.gravity = Gravity.CENTER_VERTICAL | Gravity.END;
}
button.setLayoutParams(params);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
button.setBackgroundResource(dark ? R.drawable.cafebar_action_button_selector_dark :
R.drawable.cafebar_action_button_selector);
return button;
}
TypedValue outValue = new TypedValue();
builder.mContext.getTheme().resolveAttribute(longAction ?
R.attr.selectableItemBackground : R.attr.selectableItemBackgroundBorderless,
outValue, true);
button.setBackgroundResource(outValue.resourceId);
return button;
}
static boolean isContentMultiLines(@NonNull CafeBar.Builder builder) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity) builder.mContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
boolean tabletMode = builder.mContext.getResources().getBoolean(R.bool.cafebar_tablet_mode);
int padding = (builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_side) * 2);
if (builder.mNeutralText != null && builder.mNegativeText == null && builder.mPositiveText == null &&
!isLongAction(builder.mNeutralText)) {
padding += builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_margin_start);
int actionPadding = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_button_padding);
TextView action = new TextView(builder.mContext);
action.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.mContext.getResources()
.getDimensionPixelSize(R.dimen.cafebar_content_text));
if (builder.getTypeface(CafeBar.FONT_NEUTRAL) != null) {
action.setTypeface(builder.getTypeface(CafeBar.FONT_CONTENT));
}
action.setPadding(actionPadding, 0, actionPadding, 0);
action.setText(builder.mNeutralText.substring(0,
builder.mNeutralText.length() > 10 ? 10 : builder.mNeutralText.length()));
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(metrics.widthPixels, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
action.measure(widthMeasureSpec, heightMeasureSpec);
LogUtil.d("measured action width: " +action.getMeasuredWidth());
padding += action.getMeasuredWidth();
}
if (builder.mIcon != null) {
int icon = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_icon_size);
icon += builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_content_padding_top);
padding += icon;
}
TextView textView = new TextView(builder.mContext);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, builder.mContext.getResources()
.getDimension(R.dimen.cafebar_content_text));
textView.setPadding(padding, 0, 0, 0);
if (builder.getTypeface(CafeBar.FONT_CONTENT) != null) {
textView.setTypeface(builder.getTypeface(CafeBar.FONT_CONTENT));
}
if (builder.mSpannableBuilder != null) {
textView.setText(builder.mSpannableBuilder, TextView.BufferType.SPANNABLE);
} else {
textView.setText(builder.mContent);
}
int maxWidth = metrics.widthPixels;
if (builder.mFloating || tabletMode) {
maxWidth = builder.mContext.getResources().getDimensionPixelSize(R.dimen.cafebar_floating_max_width);
}
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(maxWidth, View.MeasureSpec.AT_MOST);
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(widthMeasureSpec, heightMeasureSpec);
return textView.getLineCount() > 1;
}
@Nullable
static Drawable getDrawable(@NonNull Context context, @DrawableRes int res) {
try {
Drawable drawable = context.getResources().getDrawable(res);
return drawable.mutate();
} catch (OutOfMemoryError e) {
return null;
}
}
@Nullable
static Drawable toDrawable(@NonNull Context context, @Nullable Bitmap bitmap) {
try {
if (bitmap == null) return null;
return new BitmapDrawable(context.getResources(), bitmap);
} catch (OutOfMemoryError e) {
return null;
}
}
@Nullable
private static Drawable getResizedDrawable(@NonNull Context context, @Nullable Drawable drawable,
int color, boolean tint) {
try {
if (drawable == null) {
LogUtil.d("drawable: null");
return null;
}
if (tint) {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
drawable.mutate();
}
int size = context.getResources().getDimensionPixelSize(R.dimen.cafebar_icon_size);
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return new BitmapDrawable(context.getResources(),
Bitmap.createScaledBitmap(bitmap, size, size, true));
} catch (Exception | OutOfMemoryError e) {
LogUtil.e(Log.getStackTraceString(e));
return null;
}
}
static int getNavigationBarHeight(@NonNull Context context) {
Point appUsableSize = getAppUsableScreenSize(context);
Point realScreenSize = getRealScreenSize(context);
if (appUsableSize.x < realScreenSize.x) {
Point point = new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
return point.x;
}
if (appUsableSize.y < realScreenSize.y) {
Point point = new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
return point.y;
}
return 0;
}
private static Point getAppUsableScreenSize(@NonNull Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}
private static Point getRealScreenSize(@NonNull Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
try {
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (Exception e) {
LogUtil.e(Log.getStackTraceString(e));
}
}
return size;
}
static boolean isLongAction(@Nullable String action) {
return action != null && action.length() > 10;
}
static int getAccentColor(Context context, int defaultColor) {
if (context == null) {
LogUtil.e("getAccentColor() context is null");
return defaultColor;
}
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
return typedValue.data;
}
static int getTitleTextColor(@ColorInt int color) {
double darkness = 1-(0.299*Color.red(color) + 0.587*Color.green(color) + 0.114*Color.blue(color))/255;
return (darkness < 0.35) ? getDarkerColor(color) : Color.WHITE;
}
static int getSubTitleTextColor(@ColorInt int color) {
int titleColor = getTitleTextColor(color);
int alpha2 = Math.round(Color.alpha(titleColor) * 0.7f);
int red = Color.red(titleColor);
int green = Color.green(titleColor);
int blue = Color.blue(titleColor);
return Color.argb(alpha2, red, green, blue);
}
private static int getDarkerColor(@ColorInt int color) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= 0.25f;
return Color.HSVToColor(hsv);
}
static int getColor(@NonNull Context context, int color) {
try {
return ContextCompat.getColor(context, color);
} catch (Exception e) {
LogUtil.e(Log.getStackTraceString(e));
return color;
}
}
@Nullable
static Typeface getTypeface(@NonNull Context context, String fontName) {
try {
return Typeface.createFromAsset(context.getAssets(), "fonts/" +fontName);
} catch (Exception e) {
LogUtil.e(Log.getStackTraceString(e));
}
return null;
}
}

View File

@ -1,40 +0,0 @@
package com.danimahardhika.cafebar;
/*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import android.util.Log;
import androidx.annotation.NonNull;
class LogUtil {
static boolean sEnableLogging = false;
private static final String TAG = "CafeBar";
static void d(@NonNull String message) {
if (LogUtil.sEnableLogging)
Log.d(TAG, message);
}
static void e(@NonNull String message) {
if (LogUtil.sEnableLogging)
Log.e(TAG, message);
}
}

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<public />
</resources>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@color/cafebar_action_button_ripple" />
<item android:state_pressed="true" android:drawable="@color/cafebar_action_button_ripple" />
<item android:drawable="@android:color/transparent" />
</selector>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@color/cafebar_action_button_ripple_dark" />
<item android:state_pressed="true" android:drawable="@color/cafebar_action_button_ripple_dark" />
<item android:drawable="@android:color/transparent" />
</selector>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="#24000000"
android:centerColor="#04000000"
android:endColor="#00000000"
android:angle="90"/>
</shape>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="@dimen/cafebar_content_text"
android:textStyle="bold"
android:theme="@style/CafeBarRippleStyle"/>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
*
* CafeBar
*
* Copyright (c) 2017 Dani Mahardhika
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
-->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="@dimen/cafebar_content_text"
android:textStyle="bold"
android:theme="@style/CafeBarRippleStyleDark"/>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Floating Size -->
<dimen name="cafebar_floating_min_width">288dp</dimen>
</resources>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Tablet Mode -->
<bool name="cafebar_tablet_mode">true</bool>
</resources>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="cafebar_button_margin_start">48dp</dimen>
<!-- Floating Size -->
<dimen name="cafebar_floating_min_width">188dp</dimen>
<dimen name="cafebar_floating_max_width">568dp</dimen>
<dimen name="cafebar_floating_padding">24dp</dimen>
</resources>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Tablet Mode -->
<bool name="cafebar_tablet_mode">false</bool>
</resources>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="cafebar_action_button_ripple">#44000000</color>
<color name="cafebar_action_button_ripple_dark">#44FFFFFF</color>
</resources>

View File

@ -1,21 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="cafebar_icon_size">24dp</dimen>
<dimen name="cafebar_content_padding_side">24dp</dimen>
<dimen name="cafebar_content_padding_top">14dp</dimen>
<dimen name="cafebar_button_margin_start">24dp</dimen>
<dimen name="cafebar_button_padding">10dp</dimen>
<dimen name="cafebar_button_margin">8dp</dimen>
<dimen name="cafebar_shadow_top">4dp</dimen>
<dimen name="cafebar_content_text">14sp</dimen>
<!-- Floating Size -->
<dimen name="cafebar_floating_min_width">108dp</dimen>
<dimen name="cafebar_floating_max_width">368dp</dimen>
<dimen name="cafebar_floating_padding">16dp</dimen>
</resources>

View File

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="cafebar_root" type="id"/>
<item name="cafebar_content_base" type="id"/>
<item name="cafebar_content" type="id"/>
<item name="cafebar_button_base" type="id"/>
<item name="cafebar_button_positive" type="id"/>
<item name="cafebar_button_negative" type="id"/>
<item name="cafebar_button_neutral" type="id"/>
</resources>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CafeBarRippleStyle">
<item name="colorControlHighlight">@color/cafebar_action_button_ripple</item>
</style>
<style name="CafeBarRippleStyleDark">
<item name="colorControlHighlight">@color/cafebar_action_button_ripple_dark</item>
</style>
</resources>

View File

@ -3,7 +3,7 @@ include ':wear'
include ':codegen'
include ':annotation'
rootProject.name='Szkolny.eu'
include ':app', ':agendacalendarview', ':mhttp', ':cafebar', ':szkolny-font', ':nachos'
include ':app', ':agendacalendarview', ':mhttp', ':szkolny-font', ':nachos'
/*
include ':Navigation'
project(':Navigation').projectDir = new File(settingsDir, '../Navigation/navlib')*/