mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Allow views to be rendered by the layout editor
This commit is contained in:
@@ -39,6 +39,7 @@ public class CheckmarkPanelView extends LinearLayout implements Preferences.List
|
|||||||
|
|
||||||
private static final int CHECKMARK_RIGHT_TO_LEFT = 1;
|
private static final int CHECKMARK_RIGHT_TO_LEFT = 1;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Preferences prefs;
|
private Preferences prefs;
|
||||||
|
|
||||||
private int checkmarkValues[];
|
private int checkmarkValues[];
|
||||||
@@ -130,18 +131,20 @@ public class CheckmarkPanelView extends LinearLayout implements Preferences.List
|
|||||||
|
|
||||||
private int getCheckmarkOrder()
|
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 :
|
return prefs.shouldReverseCheckmarks() ? CHECKMARK_RIGHT_TO_LEFT :
|
||||||
CHECKMARK_LEFT_TO_RIGHT;
|
CHECKMARK_LEFT_TO_RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
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);
|
setWillNotDraw(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,13 +185,13 @@ public class CheckmarkPanelView extends LinearLayout implements Preferences.List
|
|||||||
protected void onAttachedToWindow()
|
protected void onAttachedToWindow()
|
||||||
{
|
{
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
prefs.addListener(this);
|
if(prefs != null) prefs.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow()
|
protected void onDetachedFromWindow()
|
||||||
{
|
{
|
||||||
prefs.removeListener(this);
|
if(prefs != null) prefs.removeListener(this);
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.activities.habits.list.views;
|
|||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.graphics.*;
|
import android.graphics.*;
|
||||||
|
import android.support.annotation.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
@@ -37,6 +38,7 @@ public class HeaderView extends LinearLayout
|
|||||||
|
|
||||||
private int buttonCount;
|
private int buttonCount;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Preferences prefs;
|
private Preferences prefs;
|
||||||
|
|
||||||
public HeaderView(Context context, AttributeSet attrs)
|
public HeaderView(Context context, AttributeSet attrs)
|
||||||
@@ -49,9 +51,12 @@ public class HeaderView extends LinearLayout
|
|||||||
setButtonCount(5);
|
setButtonCount(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
HabitsApplication app =
|
Context appContext = context.getApplicationContext();
|
||||||
(HabitsApplication) context.getApplicationContext();
|
if(appContext instanceof HabitsApplication)
|
||||||
prefs = app.getComponent().getPreferences();
|
{
|
||||||
|
HabitsApplication app = (HabitsApplication) appContext;
|
||||||
|
prefs = app.getComponent().getPreferences();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setButtonCount(int buttonCount)
|
public void setButtonCount(int buttonCount)
|
||||||
@@ -90,7 +95,7 @@ public class HeaderView extends LinearLayout
|
|||||||
|
|
||||||
private boolean shouldReverseCheckmarks()
|
private boolean shouldReverseCheckmarks()
|
||||||
{
|
{
|
||||||
if (isInEditMode()) return false;
|
if(prefs == null) return false;
|
||||||
return prefs.shouldReverseCheckmarks();
|
return prefs.shouldReverseCheckmarks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user