EMMA Coverage Report (generated Thu Mar 30 17:28:05 CEST 2017)
[all classes][net.mandaria.tippytipper.preferences]

COVERAGE SUMMARY FOR SOURCE FILE [NumberPickerPreference.java]

nameclass, %method, %block, %line, %
NumberPickerPreference.java100% (1/1)100% (6/6)94%  (223/236)92%  (54.2/59)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class NumberPickerPreference100% (1/1)100% (6/6)94%  (223/236)92%  (54.2/59)
onSetInitialValue (boolean, Object): void 100% (1/1)60%  (18/30)52%  (4.2/8)
bindData (): void 100% (1/1)88%  (7/8)75%  (3/4)
NumberPickerPreference (Context, AttributeSet): void 100% (1/1)100% (48/48)100% (10/10)
onBindDialogView (View): void 100% (1/1)100% (6/6)100% (3/3)
onCreateDialogView (): View 100% (1/1)100% (120/120)100% (27/27)
onDialogClosed (boolean): void 100% (1/1)100% (24/24)100% (7/7)

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

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