Allow views to be rendered by the layout editor

pull/171/head
Alinson S. Xavier 9 years ago
parent 4b04966617
commit 66c3136fad

@ -39,6 +39,7 @@ public class CheckmarkPanelView extends LinearLayout implements Preferences.List
private static final int CHECKMARK_RIGHT_TO_LEFT = 1;
@Nullable
private Preferences prefs;
private int checkmarkValues[];
@ -130,18 +131,20 @@ public class CheckmarkPanelView extends LinearLayout implements Preferences.List
private int getCheckmarkOrder()
{
if (isInEditMode()) return CHECKMARK_LEFT_TO_RIGHT;
if (prefs == null) return CHECKMARK_LEFT_TO_RIGHT;
return prefs.shouldReverseCheckmarks() ? CHECKMARK_RIGHT_TO_LEFT :
CHECKMARK_LEFT_TO_RIGHT;
}
private void init()
{
if (isInEditMode()) return;
Context appContext = getContext().getApplicationContext();
if(appContext instanceof HabitsApplication)
{
HabitsApplication app = (HabitsApplication) appContext;
prefs = app.getComponent().getPreferences();
}
HabitsApplication app =
(HabitsApplication) getContext().getApplicationContext();
prefs = app.getComponent().getPreferences();
setWillNotDraw(false);
}
@ -182,13 +185,13 @@ public class CheckmarkPanelView extends LinearLayout implements Preferences.List
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
prefs.addListener(this);
if(prefs != null) prefs.addListener(this);
}
@Override
protected void onDetachedFromWindow()
{
prefs.removeListener(this);
if(prefs != null) prefs.removeListener(this);
super.onDetachedFromWindow();
}

@ -21,6 +21,7 @@ package org.isoron.uhabits.activities.habits.list.views;
import android.content.*;
import android.graphics.*;
import android.support.annotation.*;
import android.util.*;
import android.view.*;
import android.widget.*;
@ -37,6 +38,7 @@ public class HeaderView extends LinearLayout
private int buttonCount;
@Nullable
private Preferences prefs;
public HeaderView(Context context, AttributeSet attrs)
@ -49,9 +51,12 @@ public class HeaderView extends LinearLayout
setButtonCount(5);
}
HabitsApplication app =
(HabitsApplication) context.getApplicationContext();
prefs = app.getComponent().getPreferences();
Context appContext = context.getApplicationContext();
if(appContext instanceof HabitsApplication)
{
HabitsApplication app = (HabitsApplication) appContext;
prefs = app.getComponent().getPreferences();
}
}
public void setButtonCount(int buttonCount)
@ -90,7 +95,7 @@ public class HeaderView extends LinearLayout
private boolean shouldReverseCheckmarks()
{
if (isInEditMode()) return false;
if(prefs == null) return false;
return prefs.shouldReverseCheckmarks();
}
}

Loading…
Cancel
Save