Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ public class BeaconFenceActivity extends AppCompatActivity {
private static final int BEACON_ZONE_IN = 0;
private static final int BEACON_ZONE_OUT = 1;

@BindView(R.id.layout_root)
RelativeLayout mLayoutHeadphoneFence;
@BindView(R.id.text_headphone_state)
TextView mHeadphoneText;
@BindView(R.id.layout_root) RelativeLayout mLayoutBeaconFence;
@BindView(R.id.text_headphone_state) TextView mBeaconText;

private GoogleApiClient mGoogleApiClient;
private PendingIntent mPendingIntent;
Expand Down Expand Up @@ -115,11 +113,11 @@ private void setupGoogleApiClient() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutBeaconFence,
"Fence Registered",
Snackbar.LENGTH_LONG).show();
} else {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutBeaconFence,
"Fence Not Registered",
Snackbar.LENGTH_LONG).show();
}
Expand All @@ -135,14 +133,14 @@ private void unregisterFences() {
.build()).setResultCallback(new ResultCallbacks<Status>() {
@Override
public void onSuccess(@NonNull Status status) {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutBeaconFence,
"Fence Removed",
Snackbar.LENGTH_LONG).show();
}

@Override
public void onFailure(@NonNull Status status) {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutBeaconFence,
"Fence Not Removed",
Snackbar.LENGTH_LONG).show();
}
Expand All @@ -151,10 +149,10 @@ public void onFailure(@NonNull Status status) {

private void setBeaconState(int beaconState) {
if (beaconState == BEACON_ZONE_IN) {
mHeadphoneText.setText(R.string.text_in_beacon_zone);
mBeaconText.setText(R.string.text_in_beacon_zone);

} else {
mHeadphoneText.setText(R.string.text_not_in_beacon_zone);
mBeaconText.setText(R.string.text_not_in_beacon_zone);
}
}

Expand All @@ -176,8 +174,8 @@ public void onReceive(Context context, Intent intent) {
setBeaconState(BEACON_ZONE_OUT);
break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutHeadphoneFence,
"Oops, your headphone status is unknown!",
Snackbar.make(mLayoutBeaconFence,
"Oops, your beacon status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class LocationFenceActivity extends AppCompatActivity {
public static final int STATUS_EXITING = 3;

@BindView(R.id.layout_location_fence) RelativeLayout mLayoutLocationFence;
@BindView(R.id.text_headphone_state) TextView mHeadphoneText;
@BindView(R.id.text_location_state) TextView mLocationText;

private static final int PERMISSION_REQUEST_ACCESS_FINE_LOCATION = 940;

Expand Down Expand Up @@ -162,19 +162,19 @@ public void onFailure(@NonNull Status status) {
});
}

private void setHeadphoneState(int status) {
private void setLocationState(int status) {
switch (status) {
case STATUS_IN:
mHeadphoneText.setText(R.string.text_at_home);
mLocationText.setText(R.string.text_at_home);
break;
case STATUS_OUT:
mHeadphoneText.setText(R.string.text_not_at_home);
mLocationText.setText(R.string.text_not_at_home);
break;
case STATUS_ENTERING:
mHeadphoneText.setText(R.string.text_entering_home);
mLocationText.setText(R.string.text_entering_home);
break;
case STATUS_EXITING:
mHeadphoneText.setText(R.string.text_exiting_home);
mLocationText.setText(R.string.text_exiting_home);
break;
}
}
Expand All @@ -191,42 +191,42 @@ public void onReceive(Context context, Intent intent) {
if (TextUtils.equals(fenceState.getFenceKey(), IN_LOCATION_FENCE_KEY)) {
switch (fenceState.getCurrentState()) {
case FenceState.TRUE:
setHeadphoneState(STATUS_IN);
setLocationState(STATUS_IN);
break;
case FenceState.FALSE:
setHeadphoneState(STATUS_OUT);
setLocationState(STATUS_OUT);
break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutLocationFence,
"Oops, your headphone status is unknown!",
"Oops, your location status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
} else if (TextUtils.equals(fenceState.getFenceKey(), EXITING_LOCATION_FENCE_KEY)) {
switch (fenceState.getCurrentState()) {
case FenceState.TRUE:
setHeadphoneState(STATUS_EXITING);
setLocationState(STATUS_EXITING);
break;
case FenceState.FALSE:

break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutLocationFence,
"Oops, your headphone status is unknown!",
"Oops, your location status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
} else if (TextUtils.equals(fenceState.getFenceKey(), ENTERING_LOCATION_FENCE_KEY)) {
switch (fenceState.getCurrentState()) {
case FenceState.TRUE:
setHeadphoneState(STATUS_ENTERING);
setLocationState(STATUS_ENTERING);
break;
case FenceState.FALSE:

break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutLocationFence,
"Oops, your headphone status is unknown!",
"Oops, your location status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public class TimeFenceActivity extends AppCompatActivity {
private static final int TIME_WITHIN = 0;
private static final int TIME_NOT_IN = 1;

@BindView(R.id.layout_root) RelativeLayout mLayoutHeadphoneFence;
@BindView(R.id.text_headphone_state) TextView mHeadphoneText;
@BindView(R.id.layout_root) RelativeLayout mLayoutTimeFence;
@BindView(R.id.text_headphone_state) TextView mTimeText;

private GoogleApiClient mGoogleApiClient;
private PendingIntent mPendingIntent;
Expand Down Expand Up @@ -79,22 +79,22 @@ protected void onStop() {
}

private void setupFence() {
AwarenessFence headphoneFence = TimeFence.inDailyInterval(TimeZone.getDefault(),
AwarenessFence timeFence = TimeFence.inDailyInterval(TimeZone.getDefault(),
0L, 24L * 60L * 60L * 1000L);
Awareness.FenceApi.updateFences(
mGoogleApiClient,
new FenceUpdateRequest.Builder()
.addFence(TIME_FENCE_KEY, headphoneFence, mPendingIntent)
.addFence(TIME_FENCE_KEY, timeFence, mPendingIntent)
.build())
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutTimeFence,
"Fence Registered",
Snackbar.LENGTH_LONG).show();
} else {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutTimeFence,
"Fence Not Registered",
Snackbar.LENGTH_LONG).show();
}
Expand All @@ -110,14 +110,14 @@ private void unregisterFence() {
.build()).setResultCallback(new ResultCallbacks<Status>() {
@Override
public void onSuccess(@NonNull Status status) {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutTimeFence,
"Fence Removed",
Snackbar.LENGTH_LONG).show();
}

@Override
public void onFailure(@NonNull Status status) {
Snackbar.make(mLayoutHeadphoneFence,
Snackbar.make(mLayoutTimeFence,
"Fence Not Removed",
Snackbar.LENGTH_LONG).show();
}
Expand All @@ -126,9 +126,9 @@ public void onFailure(@NonNull Status status) {

private void setTimeState(int timeState) {
if (timeState == TIME_WITHIN) {
mHeadphoneText.setText(R.string.text_that_time);
mTimeText.setText(R.string.text_that_time);
} else {
mHeadphoneText.setText(R.string.text_not_that_time);
mTimeText.setText(R.string.text_not_that_time);
}
}

Expand All @@ -150,8 +150,8 @@ public void onReceive(Context context, Intent intent) {
setTimeState(TIME_NOT_IN);
break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutHeadphoneFence,
"Oops, your headphone status is unknown!",
Snackbar.make(mLayoutTimeFence,
"Oops, your time status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ protected void onStop() {
}

private void registerFences() {
AwarenessFence headphoneFence = DetectedActivityFence.during(DetectedActivity.WALKING);
AwarenessFence startWalking = DetectedActivityFence.starting(DetectedActivity.WALKING);
AwarenessFence duringWalkingFence = DetectedActivityFence.during(DetectedActivity.WALKING);
AwarenessFence startWalkingFence = DetectedActivityFence.starting(DetectedActivity.WALKING);
AwarenessFence stopWalkingFence = DetectedActivityFence.stopping(DetectedActivity.WALKING);

Awareness.FenceApi.updateFences(
mGoogleApiClient,
new FenceUpdateRequest.Builder()
.addFence(DURING_FENCE_KEY, headphoneFence, mPendingIntent)
.addFence(STARTING_FENCE_KEY, startWalking, mPendingIntent)
.addFence(DURING_FENCE_KEY, duringWalkingFence, mPendingIntent)
.addFence(STARTING_FENCE_KEY, startWalkingFence, mPendingIntent)
.addFence(STOPPING_FENCE_KEY, stopWalkingFence, mPendingIntent)
.build())
.setResultCallback(new ResultCallback<Status>() {
Expand Down Expand Up @@ -135,8 +135,8 @@ public void onFailure(@NonNull Status status) {
});
}

private void setHeadphoneState(int headphoneState) {
switch (headphoneState) {
private void setUserState(int userState) {
switch (userState) {
case STATUS_DEFAULT:
mDetectedActivityText.setText(R.string.text_still);

Expand Down Expand Up @@ -191,40 +191,40 @@ public void onReceive(Context context, Intent intent) {
if (TextUtils.equals(fenceState.getFenceKey(), DURING_FENCE_KEY)) {
switch(fenceState.getCurrentState()) {
case FenceState.TRUE:
setHeadphoneState(STATUS_DURING);
setUserState(STATUS_DURING);
break;
case FenceState.FALSE:
setHeadphoneState(STATUS_DEFAULT);
setUserState(STATUS_DEFAULT);
break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutDetectedActivityFence,
"Oops, your headphone status is unknown!",
"Oops, your user status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
} else if (TextUtils.equals(fenceState.getFenceKey(), STARTING_FENCE_KEY)) {
switch(fenceState.getCurrentState()) {
case FenceState.TRUE:
setHeadphoneState(STATUS_STARTING);
setUserState(STATUS_STARTING);
break;
case FenceState.FALSE:
break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutDetectedActivityFence,
"Oops, your headphone status is unknown!",
"Oops, your user status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
} else if (TextUtils.equals(fenceState.getFenceKey(), STOPPING_FENCE_KEY)) {
switch(fenceState.getCurrentState()) {
case FenceState.TRUE:
setHeadphoneState(STATUS_STOPPING);
setUserState(STATUS_STOPPING);
break;
case FenceState.FALSE:
break;
case FenceState.UNKNOWN:
Snackbar.make(mLayoutDetectedActivityFence,
"Oops, your headphone status is unknown!",
"Oops, your user status is unknown!",
Snackbar.LENGTH_LONG).show();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_location_fence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
android:orientation="vertical">

<TextView
android:id="@+id/text_headphone_state"
android:id="@+id/text_location_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
Expand Down