mirror of https://github.com/iSoron/uhabits.git
parent
3bba75ff50
commit
dbcad9a5f4
@ -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,106 @@
|
|||||||
|
/*
|
||||||
|
* 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 HabitWidgetView(Context context)
|
||||||
|
{
|
||||||
|
super(context);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HabitWidgetView(Context context, AttributeSet attrs)
|
||||||
|
{
|
||||||
|
super(context, attrs);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
|
{
|
||||||
|
inflate(getContext(), getInnerLayoutId(), this);
|
||||||
|
initBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract @NonNull Integer getInnerLayoutId();
|
||||||
|
|
||||||
|
private void initBackground()
|
||||||
|
{
|
||||||
|
Context context = getContext();
|
||||||
|
context.setTheme(R.style.AppBaseThemeDark);
|
||||||
|
|
||||||
|
int shadowRadius = (int) UIHelper.dpToPixels(context, 2);
|
||||||
|
int shadowOffset = (int) UIHelper.dpToPixels(context, 1);
|
||||||
|
int shadowColor = Color.argb(96, 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));
|
||||||
|
|
||||||
|
frame = (ViewGroup) findViewById(R.id.frame);
|
||||||
|
frame.setBackgroundDrawable(background);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHabit(@NonNull Habit habit)
|
||||||
|
{
|
||||||
|
this.habit = habit;
|
||||||
|
}
|
||||||
|
}
|
@ -1,64 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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/>.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/frame"
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
xmlns:habit="http://isoron.org/android"
|
|
||||||
android:gravity="center"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<org.isoron.uhabits.views.RingView
|
|
||||||
android:id="@+id/scoreRing"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
habit:percentage="0.25"
|
|
||||||
habit:thickness="2"
|
|
||||||
habit:textSize="16"
|
|
||||||
habit:color="@color/white"
|
|
||||||
habit:inactiveColor="@color/white"
|
|
||||||
habit:enableFontAwesome="true"
|
|
||||||
habit:text="@string/fa_check"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginLeft="12dp"
|
|
||||||
android:layout_marginRight="12dp"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/label"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="0"
|
|
||||||
android:textSize="12sp"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:layout_marginLeft="6dp"
|
|
||||||
android:layout_marginRight="6dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:scrollHorizontally="true"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="2"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:layout_marginBottom="4dp"
|
|
||||||
android:fontFamily="sans-serif-condensed"
|
|
||||||
android:breakStrategy="balanced" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
Loading…
Reference in new issue