Skip to content

Commit e7ec001

Browse files
authored
Merge pull request #467 from Microsoft/release/demo_v0.10.0
Use public custom properties API in sasquatch
2 parents 865e8fc + 313a104 commit e7ec001

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

apps/sasquatch/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ android {
2222
}
2323

2424
dependencies {
25-
def version = "0.9.0"
25+
def version = "0.10.0"
2626
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
2727
projectDependencyCompile project(':sdk:mobile-center-analytics')
2828
projectDependencyCompile project(':sdk:mobile-center-crashes')

apps/sasquatch/src/main/java/com/microsoft/azure/mobile/sasquatch/activities/CustomPropertiesActivity.java

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import android.widget.Spinner;
2222
import android.widget.TimePicker;
2323

24+
import com.microsoft.azure.mobile.CustomProperties;
2425
import com.microsoft.azure.mobile.MobileCenter;
2526
import com.microsoft.azure.mobile.sasquatch.R;
2627

27-
import java.lang.reflect.Method;
2828
import java.text.DateFormat;
2929
import java.util.ArrayList;
3030
import 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

Comments
 (0)