Skip to content

Commit

Permalink
Merge branch 'hotfix/1.7.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed May 21, 2017
2 parents 692fe32 + 8b835b9 commit fa416ad
Show file tree
Hide file tree
Showing 31 changed files with 585 additions and 119 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

### 1.7.1 (May 21, 2017)

* Fix crash (BadParcelableException)
* Fix layout for RTL languages such as Arabic
* Automatically detect and reject invalid database files
* Add Hebrew translation

### 1.7.0 (Mar 31, 2017)

* Sort habits automatically
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
testCoverageEnabled = true
testCoverageEnabled = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public class CheckmarkButtonViewTest extends BaseViewTest
public void setUp()
{
super.setUp();
setSimilarityCutoff(0.03f);
setSimilarityCutoff(0.015f);

latch = new CountDownLatch(1);
view = new CheckmarkButtonView(targetContext);
view.setValue(Checkmark.UNCHECKED);
view.setColor(ColorUtils.getAndroidTestColor(7));
view.setColor(ColorUtils.getAndroidTestColor(5));

measureView(view, dpToPixels(40), dpToPixels(40));
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<manifest
package="org.isoron.uhabits"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="27"
android:versionName="1.7.0">
android:versionCode="28"
android:versionName="1.7.1">

<uses-permission android:name="android.permission.VIBRATE"/>

Expand Down
13 changes: 11 additions & 2 deletions app/src/main/java/org/isoron/uhabits/HabitsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

import android.app.*;
import android.content.*;
import android.support.annotation.*;

import com.activeandroid.*;

import org.isoron.uhabits.models.sqlite.*;
import org.isoron.uhabits.notifications.*;
import org.isoron.uhabits.preferences.*;
import org.isoron.uhabits.tasks.*;
Expand Down Expand Up @@ -88,7 +88,16 @@ public void onCreate()
if (db.exists()) db.delete();
}

DatabaseUtils.initializeActiveAndroid(context);
try
{
DatabaseUtils.initializeActiveAndroid(context);
}
catch (InvalidDatabaseVersionException e)
{
File db = DatabaseUtils.getDatabaseFile(context);
db.renameTo(new File(db.getAbsolutePath() + ".invalid"));
DatabaseUtils.initializeActiveAndroid(context);
}

widgetUpdater = component.getWidgetUpdater();
widgetUpdater.startListening();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
package org.isoron.uhabits.activities.common.views;

import android.os.*;
import android.view.*;

public class BundleSavedState extends View.BaseSavedState
public class BundleSavedState extends android.support.v4.view.AbsSavedState
{
public static final Parcelable.Creator<BundleSavedState> CREATOR =
new Parcelable.Creator<BundleSavedState>()
Expand Down Expand Up @@ -51,7 +50,7 @@ public BundleSavedState(Parcelable superState, Bundle bundle)
public BundleSavedState(Parcel source)
{
super(source);
this.bundle = source.readBundle();
this.bundle = source.readBundle(getClass().getClassLoader());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public abstract class BaseDialog extends AppCompatDialogFragment

private ColorPickerDialogFactory colorPickerDialogFactory;

@Override
public int getTheme()
{
return R.style.DialogWithTitle;
}

@Override
public void onActivityCreated(Bundle savedInstanceState)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,56 @@
package org.isoron.uhabits.activities.habits.list.views;

import android.content.*;
import android.content.res.*;
import android.graphics.*;
import android.support.annotation.*;
import android.text.*;
import android.util.*;
import android.view.*;
import android.widget.*;

import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.habits.list.controllers.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.utils.*;

public class CheckmarkButtonView extends TextView
import static android.view.View.MeasureSpec.*;
import static org.isoron.uhabits.models.Checkmark.*;
import static org.isoron.uhabits.utils.AttributeSetUtils.*;

public class CheckmarkButtonView extends View
{
private int color;

private int value;

private StyledResources res;
private StyledResources styledRes;

private TextPaint paint;

private int lowContrastColor;

private RectF rect;

public CheckmarkButtonView(Context context)
{
super(context);
init();
}

public CheckmarkButtonView(@Nullable Context ctx, @Nullable AttributeSet attrs)
{
super(ctx, attrs);
init();

if(ctx == null) throw new IllegalStateException();
if(attrs == null) throw new IllegalStateException();

int paletteColor = getIntAttribute(ctx, attrs, "color", 0);
setColor(ColorUtils.getAndroidTestColor(paletteColor));

int value = getIntAttribute(ctx, attrs, "value", 0);
setValue(value);
}

public void setColor(int color)
{
this.color = color;
Expand All @@ -57,54 +85,60 @@ public void setController(final CheckmarkButtonController controller)
public void setValue(int value)
{
this.value = value;
updateText();
postInvalidate();
}

public void toggle()
{
value = (value == Checkmark.CHECKED_EXPLICITLY ? Checkmark.UNCHECKED :
Checkmark.CHECKED_EXPLICITLY);

value = (value == CHECKED_EXPLICITLY ? UNCHECKED : CHECKED_EXPLICITLY);
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
updateText();
postInvalidate();
}

private void init()
@Override
protected void onDraw(Canvas canvas)
{
res = new StyledResources(getContext());
super.onDraw(canvas);
Resources resources = getResources();

paint.setColor(value == CHECKED_EXPLICITLY ? color : lowContrastColor);
int id = (value == UNCHECKED ? R.string.fa_times : R.string.fa_check);
String label = resources.getString(id);
float em = paint.measureText("m");

setWillNotDraw(false);
rect.set(0, 0, getWidth(), getHeight());
rect.offset(0, 0.4f * em);
canvas.drawText(label, rect.centerX(), rect.centerY(), paint);
}

setMinHeight(
getResources().getDimensionPixelSize(R.dimen.checkmarkHeight));
setMinWidth(
getResources().getDimensionPixelSize(R.dimen.checkmarkWidth));
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
Resources res = getResources();
int height = res.getDimensionPixelSize(R.dimen.checkmarkHeight);
int width = res.getDimensionPixelSize(R.dimen.checkmarkWidth);

setFocusable(false);
setGravity(Gravity.CENTER);
setTypeface(InterfaceUtils.getFontAwesome(getContext()));
widthMeasureSpec = makeMeasureSpec(width, EXACTLY);
heightMeasureSpec = makeMeasureSpec(height, EXACTLY);

super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

private void updateText()
private void init()
{
int lowContrastColor = res.getColor(R.attr.lowContrastTextColor);

if (value == Checkmark.CHECKED_EXPLICITLY)
{
setText(R.string.fa_check);
setTextColor(color);
}

if (value == Checkmark.CHECKED_IMPLICITLY)
{
setText(R.string.fa_check);
setTextColor(lowContrastColor);
}

if (value == Checkmark.UNCHECKED)
{
setText(R.string.fa_times);
setTextColor(lowContrastColor);
}
setFocusable(false);

Resources res = getResources();
styledRes = new StyledResources(getContext());

paint = new TextPaint();
paint.setTypeface(InterfaceUtils.getFontAwesome(getContext()));
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(res.getDimension(R.dimen.regularTextSize));

rect = new RectF();
color = ColorUtils.getAndroidTestColor(0);
lowContrastColor = styledRes.getColor(R.attr.lowContrastTextColor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ private void initEditMode()
scoreRing.setPercentage(rand.nextFloat());
checkmarkPanel.setColor(color);
checkmarkPanel.setCheckmarkValues(values);
checkmarkPanel.setButtonCount(5);
}

private void refresh()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class HeaderView extends ScrollableChart

private RectF rect;

private int maxDataOffset;

public HeaderView(Context context, AttributeSet attrs)
{
super(context, attrs);
Expand All @@ -76,7 +74,6 @@ public HeaderView(Context context, AttributeSet attrs)

Resources res = context.getResources();
setScrollerBucketSize((int) res.getDimension(R.dimen.checkmarkWidth));
setDirection(shouldReverseCheckmarks() ? 1 : -1);

StyledResources sr = new StyledResources(context);
paint = new TextPaint();
Expand All @@ -99,7 +96,7 @@ public void atMidnight()
@Override
public void onCheckmarkOrderChanged()
{
setDirection(shouldReverseCheckmarks() ? 1 : -1);
updateDirection();
postInvalidate();
}

Expand All @@ -112,11 +109,20 @@ public void setButtonCount(int buttonCount)
@Override
protected void onAttachedToWindow()
{
updateDirection();
super.onAttachedToWindow();
if (prefs != null) prefs.addListener(this);
if (midnightTimer != null) midnightTimer.addListener(this);
}

private void updateDirection()
{
int direction = -1;
if (shouldReverseCheckmarks()) direction *= -1;
if (InterfaceUtils.isLayoutRtl(this)) direction *= -1;
setDirection(direction);
}

@Override
protected void onDetachedFromWindow()
{
Expand Down Expand Up @@ -145,6 +151,7 @@ protected void onDraw(Canvas canvas)
float width = res.getDimension(R.dimen.checkmarkWidth);
float height = res.getDimension(R.dimen.checkmarkHeight);
boolean reverse = shouldReverseCheckmarks();
boolean isRtl = InterfaceUtils.isLayoutRtl(this);

day.add(GregorianCalendar.DAY_OF_MONTH, -getDataOffset());
float em = paint.measureText("m");
Expand All @@ -153,9 +160,13 @@ protected void onDraw(Canvas canvas)
{
rect.set(0, 0, width, height);
rect.offset(canvas.getWidth(), 0);

if(reverse) rect.offset(- (i + 1) * width, 0);
else rect.offset((i - buttonCount) * width, 0);

if (isRtl) rect.set(canvas.getWidth() - rect.right, rect.top,
canvas.getWidth() - rect.left, rect.bottom);

String text = DateUtils.formatHeaderDate(day).toUpperCase();
String[] lines = text.split("\n");

Expand Down
Loading

0 comments on commit fa416ad

Please sign in to comment.