2121import android .widget .Spinner ;
2222import android .widget .TimePicker ;
2323
24+ import com .microsoft .azure .mobile .CustomProperties ;
2425import com .microsoft .azure .mobile .MobileCenter ;
2526import com .microsoft .azure .mobile .sasquatch .R ;
2627
27- import java .lang .reflect .Method ;
2828import java .text .DateFormat ;
2929import java .util .ArrayList ;
3030import java .util .Calendar ;
@@ -69,18 +69,11 @@ private void addProperty() {
6969
7070 @ SuppressWarnings ({"unused" , "unchecked" })
7171 public void send (@ SuppressWarnings ("UnusedParameters" ) View view ) {
72- try {
73- Class classCustomProperties = Class .forName ("com.microsoft.azure.mobile.CustomProperties" );
74- Object customProperties = classCustomProperties .getConstructor ().newInstance ();
75- for (CustomPropertyFragment property : mProperties ) {
76- property .set (customProperties );
77- }
78- Method method = MobileCenter .class .getDeclaredMethod ("setCustomProperties" ,classCustomProperties );
79- method .setAccessible (true );
80- method .invoke (null , customProperties );
81- } catch (Throwable throwable ) {
82- throwable .printStackTrace ();
72+ CustomProperties customProperties = new CustomProperties ();
73+ for (CustomPropertyFragment property : mProperties ) {
74+ property .set (customProperties );
8375 }
76+ MobileCenter .setCustomProperties (customProperties );
8477 }
8578
8679 public static class CustomPropertyFragment extends Fragment
@@ -108,13 +101,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
108101 Bundle savedInstanceState ) {
109102 View view = inflater .inflate (R .layout .custom_property , container , false );
110103
111- mEditKey = ( EditText ) view .findViewById (R .id .key );
112- mEditType = ( Spinner ) view .findViewById (R .id .type );
113- mEditString = ( EditText ) view .findViewById (R .id .string );
114- mEditNumber = ( EditText ) view .findViewById (R .id .number );
115- mEditDate = ( EditText ) view .findViewById (R .id .date );
116- mEditTime = ( EditText ) view .findViewById (R .id .time );
117- mEditBool = ( CheckBox ) view .findViewById (R .id .bool );
104+ mEditKey = view .findViewById (R .id .key );
105+ mEditType = view .findViewById (R .id .type );
106+ mEditString = view .findViewById (R .id .string );
107+ mEditNumber = view .findViewById (R .id .number );
108+ mEditDate = view .findViewById (R .id .date );
109+ mEditTime = view .findViewById (R .id .time );
110+ mEditBool = view .findViewById (R .id .bool );
118111 mDateTime = view .findViewById (R .id .datetime );
119112
120113 mEditType .setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
@@ -193,15 +186,15 @@ public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
193186 setDate (calendar .getTime ());
194187 }
195188
196- public void set (Object customProperties ) throws Throwable {
189+ public void set (CustomProperties customProperties ) {
197190 int type = mEditType .getSelectedItemPosition ();
198191 String key = mEditKey .getText ().toString ();
199192 switch (type ) {
200193 case TYPE_CLEAR :
201- customProperties .getClass (). getMethod ( " clear" , String . class ). invoke ( customProperties , key );
194+ customProperties .clear ( key );
202195 break ;
203196 case TYPE_BOOLEAN :
204- customProperties .getClass (). getMethod ( " set" , String . class , boolean . class ). invoke ( customProperties , key , mEditBool .isChecked ());
197+ customProperties .set ( key , mEditBool .isChecked ());
205198 break ;
206199 case TYPE_NUMBER :
207200 String stringValue = mEditNumber .getText ().toString ();
@@ -211,13 +204,13 @@ public void set(Object customProperties) throws Throwable {
211204 } catch (NumberFormatException ignored ) {
212205 value = Double .parseDouble (stringValue );
213206 }
214- customProperties .getClass (). getMethod ( " set" , String . class , Number . class ). invoke ( customProperties , key , value );
207+ customProperties .set ( key , value );
215208 break ;
216209 case TYPE_DATETIME :
217- customProperties .getClass (). getMethod ( " set" , String . class , Date . class ). invoke ( customProperties , key , mDate );
210+ customProperties .set ( key , mDate );
218211 break ;
219212 case TYPE_STRING :
220- customProperties .getClass (). getMethod ( " set" , String . class , String . class ). invoke ( customProperties , key , mEditString .getText ().toString ());
213+ customProperties .set ( key , mEditString .getText ().toString ());
221214 break ;
222215 }
223216 }
0 commit comments