mirror of https://github.com/iSoron/uhabits.git
parent
c41e71003b
commit
11d6bbd6f6
@ -1,19 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/llOuter"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#10000000"
|
||||
android:background="@color/windowBackground"
|
||||
android:baselineAligned="false"
|
||||
android:clipToPadding="false"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="0dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:paddingLeft="6dp"
|
||||
android:paddingRight="6dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llInner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/ripple_background"
|
@ -0,0 +1,125 @@
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fillViewport="true" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/windowBackground"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="4dp"
|
||||
android:paddingTop="0dp"
|
||||
android:transitionName="mainWindow"
|
||||
tools:context="org.isoron.uhabits.ShowHabitActivity" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@color/white"
|
||||
android:elevation="2dp"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvOverview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="Overview"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginTop="4dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Habit strength" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvStrength"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" >
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
<!--
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginTop="4dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Current streak" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="12 days\nJun 11, 2015 — Jun 23, 2015" >
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginTop="4dp" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Best streak" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="30 days\nMar 12, 2015 — Apr 12, 2015" >
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
-->
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
android:elevation="2dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="4dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvHistory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="History"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/llHistory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
@ -0,0 +1,15 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="org.isoron.uhabits.ShowHabitActivity"
|
||||
tools:ignore="MergeRootFrame" >
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment2"
|
||||
android:name="org.isoron.uhabits.dialogs.ShowHabitFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</FrameLayout>
|
@ -0,0 +1,11 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="org.isoron.uhabits.ShowHabitActivity" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/action_settings"/>
|
||||
|
||||
</menu>
|
@ -0,0 +1,25 @@
|
||||
package org.isoron.helpers;
|
||||
|
||||
public class ColorHelper
|
||||
{
|
||||
public static int mixColors(int color1, int color2, float amount)
|
||||
{
|
||||
final byte ALPHA_CHANNEL = 24;
|
||||
final byte RED_CHANNEL = 16;
|
||||
final byte GREEN_CHANNEL = 8;
|
||||
final byte BLUE_CHANNEL = 0;
|
||||
|
||||
final float inverseAmount = 1.0f - amount;
|
||||
|
||||
int a = ((int) (((float) (color1 >> ALPHA_CHANNEL & 0xff) * amount) +
|
||||
((float) (color2 >> ALPHA_CHANNEL & 0xff) * inverseAmount))) & 0xff;
|
||||
int r = ((int) (((float) (color1 >> RED_CHANNEL & 0xff) * amount) +
|
||||
((float) (color2 >> RED_CHANNEL & 0xff) * inverseAmount))) & 0xff;
|
||||
int g = ((int) (((float) (color1 >> GREEN_CHANNEL & 0xff) * amount) +
|
||||
((float) (color2 >> GREEN_CHANNEL & 0xff) * inverseAmount))) & 0xff;
|
||||
int b = ((int) (((float) (color1 & 0xff) * amount) +
|
||||
((float) (color2 & 0xff) * inverseAmount))) & 0xff;
|
||||
|
||||
return a << ALPHA_CHANNEL | r << RED_CHANNEL | g << GREEN_CHANNEL | b << BLUE_CHANNEL;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
public class ReminderAlarmDismissReceiver extends BroadcastReceiver
|
||||
{
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent)
|
||||
{
|
||||
createNotification(context, intent.getData(), intent.getDataString());
|
||||
}
|
||||
|
||||
|
||||
private void createNotification(Context context, Uri data, String text)
|
||||
{
|
||||
for(Habit h : Habit.getHighlightedHabits())
|
||||
{
|
||||
Log.d("Alarm", String.format("Removing highlight from: %s", h.name));
|
||||
h.highlight = 0;
|
||||
h.save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package org.isoron.uhabits;
|
||||
|
||||
import org.isoron.uhabits.dialogs.ListHabitsFragment;
|
||||
import org.isoron.uhabits.dialogs.ShowHabitFragment;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentUris;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class ShowHabitActivity extends Activity
|
||||
{
|
||||
|
||||
public Habit habit;
|
||||
private ShowHabitFragment showHabitFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getActionBar().setElevation(5);
|
||||
Uri data = getIntent().getData();
|
||||
habit = Habit.get(ContentUris.parseId(data));
|
||||
getActionBar().setTitle(habit.name);
|
||||
getActionBar().setBackgroundDrawable(new ColorDrawable(habit.color));
|
||||
|
||||
setContentView(R.layout.show_habit_activity);
|
||||
showHabitFragment = (ShowHabitFragment) getFragmentManager().findFragmentById(
|
||||
R.id.fragment2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
getMenuInflater().inflate(R.menu.show_habit, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
int id = item.getItemId();
|
||||
if(id == R.id.action_settings)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package org.isoron.uhabits.dialogs;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ShowHabitActivity;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.views.HabitHistoryView;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class ShowHabitFragment extends Fragment
|
||||
{
|
||||
protected ShowHabitActivity activity;
|
||||
private Habit habit;
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
Log.d("ShowHabitActivity", "Creating view...");
|
||||
|
||||
View view = inflater.inflate(R.layout.show_habit, container, false);
|
||||
activity = (ShowHabitActivity) getActivity();
|
||||
habit = activity.habit;
|
||||
|
||||
int darkerHabitColor = ColorHelper.mixColors(habit.color, Color.BLACK, 0.75f);
|
||||
activity.getWindow().setStatusBarColor(darkerHabitColor);
|
||||
|
||||
TextView tvHistory = (TextView) view.findViewById(R.id.tvHistory);
|
||||
TextView tvOverview = (TextView) view.findViewById(R.id.tvOverview);
|
||||
tvHistory.setTextColor(habit.color);
|
||||
tvOverview.setTextColor(habit.color);
|
||||
|
||||
TextView tvStrength = (TextView) view.findViewById(R.id.tvStrength);
|
||||
tvStrength.setText(String.format("%.2f%%", ((float) habit.getScore() / Habit.MAX_SCORE) * 100));
|
||||
|
||||
LinearLayout llHistory = (LinearLayout) view.findViewById(R.id.llHistory);
|
||||
|
||||
HabitHistoryView hhv = new HabitHistoryView(activity, habit, 40);
|
||||
llHistory.addView(hhv);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
@ -0,0 +1,236 @@
|
||||
package org.isoron.uhabits.views;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
public class HabitHistoryView extends View
|
||||
{
|
||||
|
||||
private Habit habit;
|
||||
private int reps[];
|
||||
|
||||
private Context context;
|
||||
private Paint pSquareBg, pSquareFg, pTextHeader;
|
||||
|
||||
private int width, height;
|
||||
private int squareSize, squareSpacing;
|
||||
private int nColumns, offsetWeeks;
|
||||
|
||||
private int colorPrimary, colorPrimaryBrighter, grey;
|
||||
|
||||
public HabitHistoryView(Context context, Habit habit, int squareSize)
|
||||
{
|
||||
super(context);
|
||||
this.habit = habit;
|
||||
this.context = context;
|
||||
this.squareSize = squareSize;
|
||||
|
||||
Typeface fontawesome = Typeface.createFromAsset(context.getAssets(),
|
||||
"fontawesome-webfont.ttf");
|
||||
|
||||
colorPrimary = habit.color;
|
||||
colorPrimaryBrighter = ColorHelper.mixColors(colorPrimary, Color.WHITE, 0.5f);
|
||||
grey = Color.rgb(230, 230, 230);
|
||||
squareSpacing = 2;
|
||||
|
||||
pTextHeader = new Paint();
|
||||
pTextHeader.setColor(Color.LTGRAY);
|
||||
pTextHeader.setTextAlign(Align.LEFT);
|
||||
pTextHeader.setTextSize(squareSize * 0.5f);
|
||||
pTextHeader.setAntiAlias(true);
|
||||
|
||||
pSquareBg = new Paint();
|
||||
pSquareBg.setColor(habit.color);
|
||||
|
||||
pSquareFg = new Paint();
|
||||
pSquareFg.setColor(Color.WHITE);
|
||||
pSquareFg.setAntiAlias(true);
|
||||
// pSquareFg.setTypeface(fontawesome);
|
||||
pSquareFg.setTextSize(squareSize * 0.5f);
|
||||
pSquareFg.setTextAlign(Align.CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
setMeasuredDimension(getMeasuredWidth(), 8 * squareSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
nColumns = (w / squareSize) - 1;
|
||||
fetchReps();
|
||||
}
|
||||
|
||||
private void fetchReps()
|
||||
{
|
||||
Calendar currentDate = new GregorianCalendar();
|
||||
currentDate.add(Calendar.DAY_OF_YEAR, -offsetWeeks * 7);
|
||||
int dayOfWeek = currentDate.get(Calendar.DAY_OF_WEEK) % 7;
|
||||
|
||||
long dateTo = DateHelper.getStartOfToday();
|
||||
for (int i = 0; i < 7 - dayOfWeek; i++)
|
||||
dateTo += DateHelper.millisecondsInOneDay;
|
||||
|
||||
for (int i = 0; i < offsetWeeks * 7; i++)
|
||||
dateTo -= DateHelper.millisecondsInOneDay;
|
||||
|
||||
long dateFrom = dateTo;
|
||||
for (int i = 0; i < nColumns * 7; i++)
|
||||
dateFrom -= DateHelper.millisecondsInOneDay;
|
||||
|
||||
reps = habit.getReps(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
{
|
||||
super.onDraw(canvas);
|
||||
|
||||
Rect square = new Rect(0, 0, squareSize - squareSpacing, squareSize - squareSpacing);
|
||||
|
||||
Calendar currentDate = new GregorianCalendar();
|
||||
currentDate.add(Calendar.DAY_OF_YEAR, -(offsetWeeks-1) * 7);
|
||||
|
||||
int nDays = nColumns * 7;
|
||||
int todayWeekday = new GregorianCalendar().get(Calendar.DAY_OF_WEEK) % 7;
|
||||
|
||||
currentDate.add(Calendar.DAY_OF_YEAR, -nDays);
|
||||
|
||||
SimpleDateFormat dfMonth = new SimpleDateFormat("MMM");
|
||||
SimpleDateFormat dfYear = new SimpleDateFormat("yyyy");
|
||||
|
||||
String previousMonth = "";
|
||||
String previousYear = "";
|
||||
|
||||
int colors[] = { grey, colorPrimaryBrighter, colorPrimary };
|
||||
String markers[] = { context.getString(R.string.fa_times),
|
||||
context.getString(R.string.fa_check), context.getString(R.string.fa_check) };
|
||||
|
||||
float squareTextOffset = pSquareFg.getFontSpacing() * 0.4f;
|
||||
float headerTextOffset = pTextHeader.getFontSpacing() * 0.3f;
|
||||
boolean justPrintedYear = false;
|
||||
|
||||
int k = nDays;
|
||||
for (int i = 0; i < nColumns; i++)
|
||||
{
|
||||
String month = dfMonth.format(currentDate.getTime());
|
||||
String year = dfYear.format(currentDate.getTime());
|
||||
|
||||
if(!month.equals(previousMonth))
|
||||
{
|
||||
int offset = 0;
|
||||
if(justPrintedYear)
|
||||
offset += squareSize;
|
||||
|
||||
canvas.drawText(month, square.left + offset, square.bottom - headerTextOffset,
|
||||
pTextHeader);
|
||||
previousMonth = month;
|
||||
justPrintedYear = false;
|
||||
}
|
||||
else if(!year.equals(previousYear))
|
||||
{
|
||||
canvas.drawText(year, square.left, square.bottom - headerTextOffset, pTextHeader);
|
||||
previousYear = year;
|
||||
justPrintedYear = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
justPrintedYear = false;
|
||||
}
|
||||
|
||||
|
||||
square.offset(0, squareSize);
|
||||
|
||||
for (int j = 0; j < 7; j++)
|
||||
{
|
||||
if(!(i == nColumns - 1 && offsetWeeks == 0 && j > todayWeekday))
|
||||
{
|
||||
pSquareBg.setColor(colors[reps[k]]);
|
||||
canvas.drawRect(square, pSquareBg);
|
||||
// canvas.drawText(markers[reps[k]], square.centerX(), square.centerY()
|
||||
// + squareTextOffset, pSquareFg);
|
||||
canvas.drawText(Integer.toString(currentDate.get(Calendar.DAY_OF_MONTH)),
|
||||
square.centerX(), square.centerY() + squareTextOffset, pSquareFg);
|
||||
}
|
||||
|
||||
currentDate.add(Calendar.DAY_OF_MONTH, 1);
|
||||
square.offset(0, squareSize);
|
||||
k--;
|
||||
}
|
||||
|
||||
square.offset(squareSize, -8 * squareSize);
|
||||
}
|
||||
|
||||
String wdays[] = { "Sat", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri" };
|
||||
|
||||
for (int i = 0; i < 7; i++)
|
||||
{
|
||||
square.offset(0, squareSize);
|
||||
canvas.drawText(wdays[i], square.left + headerTextOffset, square.bottom
|
||||
- headerTextOffset, pTextHeader);
|
||||
}
|
||||
}
|
||||
|
||||
private Float prevX, prevY;
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event)
|
||||
{
|
||||
int action = event.getAction();
|
||||
|
||||
int pointerIndex = MotionEventCompat.getActionIndex(event);
|
||||
final float x = MotionEventCompat.getX(event, pointerIndex);
|
||||
final float y = MotionEventCompat.getY(event, pointerIndex);
|
||||
|
||||
if(action == MotionEvent.ACTION_DOWN)
|
||||
{
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
}
|
||||
|
||||
if(action == MotionEvent.ACTION_MOVE)
|
||||
{
|
||||
float dx = x - prevX;
|
||||
float dy = y - prevY;
|
||||
|
||||
int newOffsetWeeks = offsetWeeks + (int) (dx / squareSize);
|
||||
newOffsetWeeks = Math.max(0, newOffsetWeeks);
|
||||
|
||||
if(newOffsetWeeks != offsetWeeks)
|
||||
{
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
offsetWeeks = newOffsetWeeks;
|
||||
|
||||
fetchReps();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue