Before Width: | Height: | Size: 7.4 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 8.3 KiB |
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 8.3 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 16 KiB |
@ -1,203 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
|
||||||
*
|
|
||||||
* This file is part of Loop Habit Tracker.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or (at your
|
|
||||||
* option) any later version.
|
|
||||||
*
|
|
||||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along
|
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.isoron.uhabits.views;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.Typeface;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.text.Layout;
|
|
||||||
import android.text.StaticLayout;
|
|
||||||
import android.text.TextPaint;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
|
||||||
import org.isoron.uhabits.helpers.ColorHelper;
|
|
||||||
import org.isoron.uhabits.models.Habit;
|
|
||||||
|
|
||||||
public class CheckmarkView extends View implements HabitDataView
|
|
||||||
{
|
|
||||||
private Paint pCard;
|
|
||||||
private Paint pIcon;
|
|
||||||
|
|
||||||
private int primaryColor;
|
|
||||||
private int timesColor;
|
|
||||||
private int darkGrey;
|
|
||||||
|
|
||||||
private int width;
|
|
||||||
private int height;
|
|
||||||
private float leftMargin;
|
|
||||||
private float topMargin;
|
|
||||||
private float padding;
|
|
||||||
private String label;
|
|
||||||
|
|
||||||
private String fa_check;
|
|
||||||
private String fa_times;
|
|
||||||
|
|
||||||
private int check_status;
|
|
||||||
|
|
||||||
private Rect rect;
|
|
||||||
private TextPaint textPaint;
|
|
||||||
private StaticLayout labelLayout;
|
|
||||||
private Habit habit;
|
|
||||||
|
|
||||||
public CheckmarkView(Context context)
|
|
||||||
{
|
|
||||||
super(context);
|
|
||||||
init(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CheckmarkView(Context context, AttributeSet attrs)
|
|
||||||
{
|
|
||||||
super(context, attrs);
|
|
||||||
init(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(Context context)
|
|
||||||
{
|
|
||||||
Typeface fontawesome =
|
|
||||||
Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
|
|
||||||
|
|
||||||
pCard = new Paint();
|
|
||||||
pCard.setAntiAlias(true);
|
|
||||||
|
|
||||||
pIcon = new Paint();
|
|
||||||
pIcon.setAntiAlias(true);
|
|
||||||
pIcon.setTypeface(fontawesome);
|
|
||||||
pIcon.setTextAlign(Paint.Align.CENTER);
|
|
||||||
|
|
||||||
textPaint = new TextPaint();
|
|
||||||
textPaint.setColor(Color.WHITE);
|
|
||||||
textPaint.setAntiAlias(true);
|
|
||||||
|
|
||||||
fa_check = context.getString(R.string.fa_check);
|
|
||||||
fa_times = context.getString(R.string.fa_times);
|
|
||||||
|
|
||||||
primaryColor = ColorHelper.getColor(getContext(), 10);
|
|
||||||
timesColor = Color.argb(128, 255, 255, 255);
|
|
||||||
darkGrey = Color.argb(64, 0, 0, 0);
|
|
||||||
|
|
||||||
rect = new Rect();
|
|
||||||
check_status = 0;
|
|
||||||
label = "Habit";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHabit(Habit habit)
|
|
||||||
{
|
|
||||||
this.habit = habit;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDraw(Canvas canvas)
|
|
||||||
{
|
|
||||||
super.onDraw(canvas);
|
|
||||||
|
|
||||||
drawBackground(canvas);
|
|
||||||
drawCheckmark(canvas);
|
|
||||||
drawLabel(canvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawBackground(Canvas canvas)
|
|
||||||
{
|
|
||||||
int color = (check_status == 2 ? primaryColor : darkGrey);
|
|
||||||
|
|
||||||
pCard.setColor(color);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
canvas.drawRoundRect(leftMargin, topMargin, width - leftMargin, height - topMargin, padding,
|
|
||||||
padding, pCard);
|
|
||||||
else
|
|
||||||
canvas.drawRect(leftMargin, topMargin, width - leftMargin, height - topMargin, pCard);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawCheckmark(Canvas canvas)
|
|
||||||
{
|
|
||||||
String text = (check_status == 0 ? fa_times : fa_check);
|
|
||||||
int color = (check_status == 2 ? Color.WHITE : timesColor);
|
|
||||||
|
|
||||||
pIcon.setColor(color);
|
|
||||||
pIcon.setTextSize(width * 0.5f);
|
|
||||||
pIcon.getTextBounds(text, 0, 1, rect);
|
|
||||||
|
|
||||||
int y = (int) ((0.67f * height - rect.bottom - rect.top) / 2);
|
|
||||||
canvas.drawText(text, width / 2, y, pIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawLabel(Canvas canvas)
|
|
||||||
{
|
|
||||||
canvas.save();
|
|
||||||
float y;
|
|
||||||
int nLines = labelLayout.getLineCount();
|
|
||||||
|
|
||||||
if(nLines == 1)
|
|
||||||
y = height * 0.8f - padding;
|
|
||||||
else
|
|
||||||
y = height * 0.7f - padding;
|
|
||||||
|
|
||||||
canvas.translate(leftMargin + padding, y);
|
|
||||||
|
|
||||||
labelLayout.draw(canvas);
|
|
||||||
canvas.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
|
||||||
{
|
|
||||||
int width = MeasureSpec.getSize(widthMeasureSpec);
|
|
||||||
setMeasuredDimension(width, (int) (width * 1.25));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
|
|
||||||
{
|
|
||||||
this.width = getMeasuredWidth();
|
|
||||||
this.height = getMeasuredHeight();
|
|
||||||
|
|
||||||
leftMargin = (width * 0.015f);
|
|
||||||
topMargin = (height * 0.015f);
|
|
||||||
padding = 8 * leftMargin;
|
|
||||||
textPaint.setTextSize(0.15f * width);
|
|
||||||
|
|
||||||
updateLabel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refreshData()
|
|
||||||
{
|
|
||||||
this.check_status = habit.checkmarks.getTodayValue();
|
|
||||||
int color = ColorHelper.getColor(getContext(), habit.color);
|
|
||||||
this.primaryColor = Color.argb(230, Color.red(color), Color.green(color),
|
|
||||||
Color.blue(color));
|
|
||||||
this.label = habit.name;
|
|
||||||
|
|
||||||
updateLabel();
|
|
||||||
postInvalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateLabel()
|
|
||||||
{
|
|
||||||
textPaint.setColor(Color.WHITE);
|
|
||||||
labelLayout = new StaticLayout(label, textPaint,
|
|
||||||
(int) (width - 2 * leftMargin - 2 * padding),
|
|
||||||
Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.helpers.ColorHelper;
|
||||||
|
import org.isoron.uhabits.helpers.UIHelper;
|
||||||
|
import org.isoron.uhabits.models.Checkmark;
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
import org.isoron.uhabits.models.Score;
|
||||||
|
|
||||||
|
public class CheckmarkWidgetView extends HabitWidgetView implements HabitDataView
|
||||||
|
{
|
||||||
|
private int activeColor;
|
||||||
|
private float percentage;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private RingView ring;
|
||||||
|
private TextView label;
|
||||||
|
private int checkmarkValue;
|
||||||
|
|
||||||
|
public CheckmarkWidgetView(Context context)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckmarkWidgetView(Context context, AttributeSet attrs)
|
||||||
|
{
|
||||||
|
super(context, attrs);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
ring = (RingView) findViewById(R.id.scoreRing);
|
||||||
|
label = (TextView) findViewById(R.id.label);
|
||||||
|
|
||||||
|
if(ring != null) ring.setIsTransparencyEnabled(true);
|
||||||
|
|
||||||
|
if(isInEditMode())
|
||||||
|
{
|
||||||
|
percentage = 0.75f;
|
||||||
|
name = "Wake up early";
|
||||||
|
activeColor = ColorHelper.CSV_PALETTE[6];
|
||||||
|
checkmarkValue = Checkmark.CHECKED_EXPLICITLY;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHabit(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
super.setHabit(habit);
|
||||||
|
this.name = habit.name;
|
||||||
|
this.activeColor = ColorHelper.getColor(getContext(), habit.color);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh()
|
||||||
|
{
|
||||||
|
if (backgroundPaint == null || frame == null || ring == null) return;
|
||||||
|
|
||||||
|
Context context = getContext();
|
||||||
|
|
||||||
|
String text;
|
||||||
|
int backgroundColor;
|
||||||
|
int foregroundColor;
|
||||||
|
|
||||||
|
switch (checkmarkValue)
|
||||||
|
{
|
||||||
|
case Checkmark.CHECKED_EXPLICITLY:
|
||||||
|
text = getResources().getString(R.string.fa_check);
|
||||||
|
backgroundColor = activeColor;
|
||||||
|
foregroundColor =
|
||||||
|
UIHelper.getStyledColor(context, R.attr.highContrastReverseTextColor);
|
||||||
|
|
||||||
|
setShadowAlpha(0x4f);
|
||||||
|
rebuildBackground();
|
||||||
|
|
||||||
|
backgroundPaint.setColor(backgroundColor);
|
||||||
|
frame.setBackgroundDrawable(background);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Checkmark.CHECKED_IMPLICITLY:
|
||||||
|
text = getResources().getString(R.string.fa_check);
|
||||||
|
backgroundColor = UIHelper.getStyledColor(context, R.attr.cardBackgroundColor);
|
||||||
|
foregroundColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Checkmark.UNCHECKED:
|
||||||
|
default:
|
||||||
|
text = getResources().getString(R.string.fa_times);
|
||||||
|
backgroundColor = UIHelper.getStyledColor(context, R.attr.cardBackgroundColor);
|
||||||
|
foregroundColor = UIHelper.getStyledColor(context, R.attr.mediumContrastTextColor);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ring.setPercentage(percentage);
|
||||||
|
ring.setColor(foregroundColor);
|
||||||
|
ring.setBackgroundColor(backgroundColor);
|
||||||
|
ring.setText(text);
|
||||||
|
|
||||||
|
label.setText(name);
|
||||||
|
label.setTextColor(foregroundColor);
|
||||||
|
|
||||||
|
requestLayout();
|
||||||
|
postInvalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||||
|
{
|
||||||
|
int width = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
||||||
|
|
||||||
|
float w = width;
|
||||||
|
float h = width * 1.25f;
|
||||||
|
float scale = Math.min(width / w, height / h);
|
||||||
|
|
||||||
|
w *= scale;
|
||||||
|
h *= scale;
|
||||||
|
|
||||||
|
widthMeasureSpec = MeasureSpec.makeMeasureSpec((int) w, MeasureSpec.EXACTLY);
|
||||||
|
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) h, MeasureSpec.EXACTLY);
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshData()
|
||||||
|
{
|
||||||
|
if(habit == null) return;
|
||||||
|
this.percentage = (float) habit.scores.getTodayValue() / Score.MAX_VALUE;
|
||||||
|
this.checkmarkValue = habit.checkmarks.getTodayValue();
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected Integer getInnerLayoutId()
|
||||||
|
{
|
||||||
|
return R.layout.widget_checkmark;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
|
public class GraphWidgetView extends HabitWidgetView implements HabitDataView
|
||||||
|
{
|
||||||
|
|
||||||
|
private final HabitDataView dataView;
|
||||||
|
private TextView title;
|
||||||
|
|
||||||
|
public GraphWidgetView(Context context, HabitDataView dataView)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
this.dataView = dataView;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
ViewGroup.LayoutParams params =
|
||||||
|
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
((View) dataView).setLayoutParams(params);
|
||||||
|
|
||||||
|
ViewGroup innerFrame = (ViewGroup) findViewById(R.id.innerFrame);
|
||||||
|
innerFrame.addView(((View) dataView));
|
||||||
|
|
||||||
|
title = (TextView) findViewById(R.id.title);
|
||||||
|
title.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHabit(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
super.setHabit(habit);
|
||||||
|
dataView.setHabit(habit);
|
||||||
|
title.setText(habit.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshData()
|
||||||
|
{
|
||||||
|
if(habit == null) return;
|
||||||
|
dataView.refreshData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
protected Integer getInnerLayoutId()
|
||||||
|
{
|
||||||
|
return R.layout.widget_graph;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of Loop Habit Tracker.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.isoron.uhabits.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.drawable.InsetDrawable;
|
||||||
|
import android.graphics.drawable.ShapeDrawable;
|
||||||
|
import android.graphics.drawable.shapes.RoundRectShape;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.helpers.UIHelper;
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public abstract class HabitWidgetView extends FrameLayout implements HabitDataView
|
||||||
|
{
|
||||||
|
@Nullable
|
||||||
|
protected InsetDrawable background;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected Paint backgroundPaint;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
protected Habit habit;
|
||||||
|
protected ViewGroup frame;
|
||||||
|
|
||||||
|
public void setShadowAlpha(int shadowAlpha)
|
||||||
|
{
|
||||||
|
this.shadowAlpha = shadowAlpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int shadowAlpha;
|
||||||
|
|
||||||
|
public HabitWidgetView(Context context)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HabitWidgetView(Context context, AttributeSet attrs)
|
||||||
|
{
|
||||||
|
super(context, attrs);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
inflate(getContext(), getInnerLayoutId(), this);
|
||||||
|
shadowAlpha = (int) (255 * UIHelper.getStyledFloat(getContext(), R.attr.widgetShadowAlpha));
|
||||||
|
rebuildBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract @NonNull Integer getInnerLayoutId();
|
||||||
|
|
||||||
|
protected void rebuildBackground()
|
||||||
|
{
|
||||||
|
Context context = getContext();
|
||||||
|
context.setTheme(R.style.TransparentWidgetTheme);
|
||||||
|
|
||||||
|
int backgroundAlpha =
|
||||||
|
(int) (255 * UIHelper.getStyledFloat(context, R.attr.widgetBackgroundAlpha));
|
||||||
|
|
||||||
|
int shadowRadius = (int) UIHelper.dpToPixels(context, 2);
|
||||||
|
int shadowOffset = (int) UIHelper.dpToPixels(context, 1);
|
||||||
|
int shadowColor = Color.argb(shadowAlpha, 0, 0, 0);
|
||||||
|
|
||||||
|
float cornerRadius = UIHelper.dpToPixels(context, 5);
|
||||||
|
float[] radii = new float[8];
|
||||||
|
Arrays.fill(radii, cornerRadius);
|
||||||
|
|
||||||
|
RoundRectShape shape = new RoundRectShape(radii, null, null);
|
||||||
|
ShapeDrawable innerDrawable = new ShapeDrawable(shape);
|
||||||
|
|
||||||
|
int insetLeftTop = Math.max(shadowRadius - shadowOffset, 0);
|
||||||
|
int insetRightBottom = shadowRadius + shadowOffset;
|
||||||
|
|
||||||
|
background = new InsetDrawable(innerDrawable, insetLeftTop, insetLeftTop, insetRightBottom,
|
||||||
|
insetRightBottom);
|
||||||
|
backgroundPaint = innerDrawable.getPaint();
|
||||||
|
backgroundPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, shadowColor);
|
||||||
|
backgroundPaint.setColor(UIHelper.getStyledColor(context, R.attr.cardBackgroundColor));
|
||||||
|
backgroundPaint.setAlpha(backgroundAlpha);
|
||||||
|
|
||||||
|
frame = (ViewGroup) findViewById(R.id.frame);
|
||||||
|
if(frame != null) frame.setBackgroundDrawable(background);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHabit(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 610 B |
After Width: | Height: | Size: 610 B |
After Width: | Height: | Size: 183 B |
After Width: | Height: | Size: 198 B |
After Width: | Height: | Size: 388 B |
After Width: | Height: | Size: 403 B |
After Width: | Height: | Size: 122 B |
After Width: | Height: | Size: 133 B |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 20 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 7.6 KiB |
@ -0,0 +1,39 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
~
|
||||||
|
~ This file is part of Loop Habit Tracker.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by the
|
||||||
|
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
~ option) any later version.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
~ more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License along
|
||||||
|
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item
|
||||||
|
android:top="1dp"
|
||||||
|
android:left="1dp"
|
||||||
|
android:bottom="3dp"
|
||||||
|
android:right="3dp">
|
||||||
|
<ripple
|
||||||
|
android:color="#60ffffff">
|
||||||
|
|
||||||
|
<item android:id="@android:id/mask">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<corners android:radius="5dp"/>
|
||||||
|
<solid android:color="?android:colorPrimary"/>
|
||||||
|
</shape>
|
||||||
|
<color android:color="@color/white"/>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
||||||
|
</item>
|
||||||
|
|
||||||
|
</layer-list>
|
After Width: | Height: | Size: 798 B |
After Width: | Height: | Size: 821 B |
After Width: | Height: | Size: 168 B |
After Width: | Height: | Size: 185 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 214 B |
After Width: | Height: | Size: 234 B |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 243 B |
After Width: | Height: | Size: 257 B |
@ -0,0 +1,34 @@
|
|||||||
|
<!--
|
||||||
|
~ Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||||
|
~
|
||||||
|
~ This file is part of Loop Habit Tracker.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||||
|
~ it under the terms of the GNU General Public License as published by the
|
||||||
|
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
~ option) any later version.
|
||||||
|
~
|
||||||
|
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||||
|
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
~ more details.
|
||||||
|
~
|
||||||
|
~ You should have received a copy of the GNU General Public License along
|
||||||
|
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:state_enabled="true" android:state_pressed="true">
|
||||||
|
<layer-list>
|
||||||
|
<item android:bottom="3dp"
|
||||||
|
android:left="1dp"
|
||||||
|
android:right="3dp"
|
||||||
|
android:top="1dp">
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<corners android:radius="5dp"/>
|
||||||
|
<solid android:color="#30ffffff"/>
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
||||||
|
</item>
|
||||||
|
</selector>
|
Before Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 33 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 54 KiB |
Before Width: | Height: | Size: 70 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 72 KiB |
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.2 MiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 144 KiB After Width: | Height: | Size: 137 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 26 KiB |