Skip to content

Commit

Permalink
Add javadoc, refactor code and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Protino committed Feb 28, 2017
1 parent f747769 commit f388a37
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 146 deletions.
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@
</service>

<!-- Wearable Google Wearable Api Data Service -->
<service
android:name=".wearable.WearableDataService">
</service>
<service android:name=".wearable.WearableDataService"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,21 @@ public class WearableDataService extends Service
@Override
public void onCreate() {
super.onCreate();
Log.d(LOG_TAG, "onCreate: ");
googleApiClient = new GoogleApiClient.Builder(WearableDataService.this)
.addApi(Wearable.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
googleApiClient.connect();
}

@Override
public void onDestroy() {
super.onDestroy();
Log.d(LOG_TAG, "onDestroy: destroyed");
}
//Lifecycle end

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (googleApiClient != null && !googleApiClient.isConnected()) {
googleApiClient.connect();
}
/** Keep the service alive until data_items are sent*/
return Service.START_STICKY;
}

Expand All @@ -75,7 +69,7 @@ public void onConnected(@Nullable Bundle bundle) {

@Override
public void onConnectionSuspended(int i) {
Log.d(LOG_TAG, "onConnectionSuspended: wearable api suspended");
//ignore
}

@Override
Expand All @@ -84,6 +78,11 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}


/**
* Gracefully disconnects the client
*
* @param googleApiClient client that needs to be disconnected
*/
private void disconnect(GoogleApiClient googleApiClient) {
if (googleApiClient != null && (googleApiClient.isConnected() || googleApiClient.isConnecting())) {
googleApiClient.disconnect();
Expand Down Expand Up @@ -120,7 +119,6 @@ private SendUpdates(String location) {
public void run() {
try {
dataMap = fetchData();
Log.d(LOG_TAG, "run: fetched data - " + dataMap.toString());
sendData(PATH, dataMap);
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -166,6 +164,7 @@ private void sendData(String path, DataMap dataMap) {
if (result.getStatus().isSuccess()) {
Log.d(LOG_TAG, "sendData: " + dataMap + " successfully sent");
} else {
// TODO: 28-Feb-17 Add a mechanism to start the service again with exponential backoff
Log.e(LOG_TAG, "sendData: Failed to send data item");
}
disconnect(googleApiClient);
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/detail_today_grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
android:background="@android:color/white"
app:columnCount="2">

<android.support.v7.widget.Space
<android.support.v4.widget.Space
android:layout_height="@dimen/detail_view_padding_vertical"
app:layout_columnSpan="2"
app:layout_columnWeight="1"
Expand Down Expand Up @@ -69,7 +69,7 @@
app:layout_columnWeight="1"
tools:text="10"/>

<android.support.v7.widget.Space
<android.support.v4.widget.Space
android:layout_height="@dimen/detail_view_padding_vertical"
app:layout_columnSpan="2"
app:layout_columnWeight="1"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_detail_wide.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
android:paddingRight="@dimen/abc_list_item_padding_horizontal_material"
>

<android.support.v7.widget.Space
<android.support.v4.widget.Space
app:layout_columnSpan="2"
app:layout_rowWeight="1" />

Expand Down Expand Up @@ -120,7 +120,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Title"
/>

<android.support.v7.widget.Space
<android.support.v4.widget.Space
app:layout_columnSpan="2"
app:layout_rowWeight="1" />

Expand Down
12 changes: 4 additions & 8 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@
android:resource="@xml/watch_face"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview"
android:resource="@drawable/art_light_clouds"/>

<!-- <meta-data -->
<!-- android:name="com.google.android.wearable.watchface.preview" -->
<!-- android:resource="@drawable/preview_analog"/> -->
<!-- <meta-data -->
<!-- android:name="com.google.android.wearable.watchface.preview_circular" -->
<!-- android:resource="@drawable/preview_analog_circular"/> -->
android:resource="@drawable/preview_square"/>
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
android:resource="@drawable/preview_circular"/>

<!-- wearable configuration activity -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import com.google.android.gms.wearable.DataMapItem;
import com.google.android.gms.wearable.WearableListenerService;


/**
* Created by Gurupad Mamadapur on 27-Feb-17.
* Listens for data layer changes. Saves new data in {@link SharedPreferences}.
*/

public class DataLayerListenerService extends WearableListenerService {
private static final String LOG_TAG = DataLayerListenerService.class.getSimpleName();
private SharedPreferences sharedPreferences;
Expand Down
Loading

0 comments on commit f388a37

Please sign in to comment.