EMMA Coverage Report (generated Thu May 14 14:26:10 CEST 2015)
[all classes][net.mandaria.tippytipper.preferences]

COVERAGE SUMMARY FOR SOURCE FILE [DecimalPreference.java]

nameclass, %method, %block, %line, %
DecimalPreference.java100% (1/1)100% (6/6)95%  (277/293)90%  (64,2/71)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class DecimalPreference100% (1/1)100% (6/6)95%  (277/293)90%  (64,2/71)
onSetInitialValue (boolean, Object): void 100% (1/1)60%  (18/30)52%  (4,2/8)
bindData (): void 100% (1/1)89%  (34/38)70%  (7/10)
DecimalPreference (Context, AttributeSet): void 100% (1/1)100% (34/34)100% (8/8)
onBindDialogView (View): void 100% (1/1)100% (6/6)100% (3/3)
onCreateDialogView (): View 100% (1/1)100% (142/142)100% (33/33)
onDialogClosed (boolean): void 100% (1/1)100% (43/43)100% (9/9)

1package net.mandaria.tippytipper.preferences;
2 
3import net.mandaria.tippytipper.widgets.*;
4import android.content.Context;
5import android.util.AttributeSet;
6import android.view.Gravity;
7import android.view.View;
8import android.preference.DialogPreference;
9import android.widget.TableLayout;
10import android.widget.TableRow;
11import android.widget.TextView;
12 
13public class DecimalPreference extends DialogPreference
14{
15        private static final String androidns = "http://schemas.android.com/apk/res/android";
16        private static final String appns = "http://schemas.android.com/apk/res/net.mandaria.tippytipper";
17 
18        private NumberPicker mPickInteger, mPickDecimal;
19        private TextView mSplashText, mValueText;
20        private Context mContext;
21 
22        private String mDialogMessage, mSuffix;
23        private float mDefault, mValue = 0;
24        private int mInteger, mDecimal = 0;
25 
26        public DecimalPreference(Context context, AttributeSet attrs)
27        {
28                super(context, attrs);
29                mContext = context;
30 
31                mDialogMessage = attrs.getAttributeValue(androidns, "dialogMessage");
32                mSuffix = attrs.getAttributeValue(androidns, "text");
33                mDefault = attrs.getAttributeIntValue(androidns, "defaultValue", 0);
34        }
35 
36        @Override
37        protected View onCreateDialogView()
38        {
39                TableLayout.LayoutParams params;
40                // LinearLayout layout = new LinearLayout(mContext);
41                TableLayout layout = new TableLayout(mContext);
42                // layout.setOrientation(LinearLayout.VERTICAL);
43                layout.setPadding(6, 6, 6, 6);
44 
45                mSplashText = new TextView(mContext);
46                if (mDialogMessage != null)
47                        mSplashText.setText(mDialogMessage);
48 
49                TableRow row_header = new TableRow(mContext);
50                row_header.addView(mSplashText);
51 
52                mPickInteger = new NumberPicker(mContext);
53                mPickDecimal = new NumberPicker(mContext);
54                mPickDecimal.setFormatter(NumberPicker.THREE_DIGIT_FORMATTER);
55 
56                TextView dot = new TextView(mContext);
57                dot.setText(".");
58                dot.setTextSize(32);
59 
60                TextView percent = new TextView(mContext);
61                percent.setText("%");
62                percent.setTextSize(32);
63 
64                TableRow row_one = new TableRow(mContext);
65                row_one.setGravity(Gravity.CENTER);
66                row_one.addView(mPickInteger);
67                row_one.addView(dot);
68                row_one.addView(mPickDecimal);
69                row_one.addView(percent);
70 
71                layout.addView(row_header);
72 
73                TableLayout table_main = new TableLayout(mContext);
74                table_main.addView(row_one);
75 
76                TableRow row_main = new TableRow(mContext);
77                row_main.setGravity(Gravity.CENTER_HORIZONTAL);
78                row_main.addView(table_main);
79 
80                layout.addView(row_main);
81 
82                if (shouldPersist())
83                        mValue = getPersistedFloat(mDefault);
84 
85                bindData();
86 
87                return layout;
88        }
89 
90        private void bindData()
91        {
92                mInteger = (int) Math.floor(mValue);
93                float decimal = (mValue * 1000) - (mInteger * 1000);
94                mDecimal = (int) decimal;
95                try
96                {
97                        mPickInteger.setCurrent(mInteger);
98                        mPickDecimal.setCurrent(mDecimal);
99                }
100                catch (Exception ex)
101                {
102                        int test = 0;
103                        test++;
104                }
105        }
106 
107        @Override
108        protected void onBindDialogView(View v)
109        {
110                super.onBindDialogView(v);
111                bindData();
112        }
113 
114        @Override
115        protected void onSetInitialValue(boolean restore, Object defaultValue)
116        {
117                super.onSetInitialValue(restore, defaultValue);
118                if (restore)
119                {
120                        try
121                        {
122                                mValue = shouldPersist() ? getPersistedFloat(mDefault) : 0;
123                        }
124                        catch (Exception ex)
125                        {
126                                mValue = mDefault;
127                        }
128                }
129                else
130                        mValue = (Float) defaultValue;
131        }
132 
133        @Override
134        protected void onDialogClosed(boolean positiveResult)
135        {
136                if (positiveResult == true)
137                {
138                        super.onDialogClosed(positiveResult);
139                        // HACK: "click" both picker inputs to validate inputs before closing the dialog
140                        // this is to fix a problem of closing the dialog not causing the onFocusChange of the picker
141                        // to be called
142                        mPickInteger.onClick(null);
143                        mPickDecimal.onClick(null);
144                        String value = mPickInteger.getCurrent() + "." + mPickDecimal.getCurrentFormatted();
145                        mValue = Float.valueOf(value);
146                        if (shouldPersist())
147                                persistFloat(mValue);
148                }
149        }
150}

[all classes][net.mandaria.tippytipper.preferences]
EMMA 2.0.5312 (C) Vladimir Roubtsov