Skip to content

Commit ddc9f35

Browse files
committed
Android Studio formatting pass
Changed spacing from 4 spaces to 2 organized imports remove commented out section from SaveGame.java Change-Id: I24537e7d2da9f3f63537cd342ed970cb7e2f0bfb
1 parent d9e7b9d commit ddc9f35

File tree

11 files changed

+3205
-3235
lines changed

11 files changed

+3205
-3235
lines changed

BasicSamples/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java

Lines changed: 881 additions & 881 deletions
Large diffs are not rendered by default.

BasicSamples/CollectAllTheStars2/src/main/java/com/google/example/games/catt2/MainActivity.java

Lines changed: 857 additions & 857 deletions
Large diffs are not rendered by default.

BasicSamples/CollectAllTheStars2/src/main/java/com/google/example/games/catt2/SaveGame.java

Lines changed: 203 additions & 232 deletions
Large diffs are not rendered by default.

BasicSamples/CollectAllTheStars2/src/main/java/com/google/example/games/catt2/SelectSnapshotActivity.java

Lines changed: 131 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
*/
1515
package com.google.example.games.catt2;
1616

17-
import com.google.android.gms.common.images.ImageManager;
18-
import com.google.android.gms.games.snapshot.Snapshot;
19-
import com.google.android.gms.games.snapshot.SnapshotMetadata;
20-
2117
import android.app.Activity;
2218
import android.content.Context;
2319
import android.content.Intent;
@@ -32,162 +28,166 @@
3228
import android.widget.ListView;
3329
import android.widget.TextView;
3430

31+
import com.google.android.gms.common.images.ImageManager;
32+
import com.google.android.gms.games.snapshot.Snapshot;
33+
import com.google.android.gms.games.snapshot.SnapshotMetadata;
34+
3535
import java.util.ArrayList;
3636

3737
/**
3838
* Activity to select a snapshot from a list of snapshots or snapshot metadata. The intended
3939
* use of this activity is to present a choice of two conflicting snapshots to the user so
4040
* they can select the "best" snapshot.
41-
*
41+
* <p>
4242
* There is also a code path that loads all the saved games and presents this list, which is not
4343
* expected to be "production" code, but rather demonstrate how the Snapshots.load() method works.
4444
*
4545
* @author Clayton Wilkinson (Google)
4646
*/
4747
public class SelectSnapshotActivity extends Activity implements AdapterView.OnItemClickListener {
4848

49-
private static final String TAG = "SelSnapshotActivity";
50-
// intent data which is a snapshot metadata
51-
public static final String SNAPSHOT_METADATA = "snapshotmeta";
49+
private static final String TAG = "SelSnapshotActivity";
50+
// intent data which is a snapshot metadata
51+
public static final String SNAPSHOT_METADATA = "snapshotmeta";
5252

53-
// intent data that is a list of snapshot metadatas.
54-
public static final String SNAPSHOT_METADATA_LIST = "snapshotmetaList";
53+
// intent data that is a list of snapshot metadatas.
54+
public static final String SNAPSHOT_METADATA_LIST = "snapshotmetaList";
5555

56-
// intent data that is the conflict id. used when resolving a conflict.
57-
public static final String CONFLICT_ID = "conflictId";
56+
// intent data that is the conflict id. used when resolving a conflict.
57+
public static final String CONFLICT_ID = "conflictId";
5858

59-
// intent data that is the retry count for retrying the conflict resolution.
60-
public static final String RETRY_COUNT = "retrycount";
59+
// intent data that is the retry count for retrying the conflict resolution.
60+
public static final String RETRY_COUNT = "retrycount";
6161

62-
// keep these variables for the current activity and return them in the result.
63-
private String mConflictId;
62+
// keep these variables for the current activity and return them in the result.
63+
private String mConflictId;
6464

65-
private int mRetryCount;
65+
private int mRetryCount;
6666

67-
@Override
68-
protected void onCreate(Bundle savedInstanceState) {
69-
super.onCreate(savedInstanceState);
70-
setContentView(R.layout.activity_select_snapshot);
71-
72-
//expect the intent to include the list of snapshots or snapshot metadatas to display
73-
Intent intent = getIntent();
74-
if (intent != null) {
75-
ArrayList<SnapshotMetadata> snapshotMetadataList;
76-
ListView vw = (ListView) findViewById(R.id.snapshot_list);
77-
78-
snapshotMetadataList = intent.getParcelableArrayListExtra(SNAPSHOT_METADATA_LIST);
79-
// set a custom list adapter that can display the image and other
80-
// information about a snapshot.
81-
vw.setAdapter(
82-
new SnapshotListAdapter<SnapshotMetadata>(this, snapshotMetadataList));
83-
84-
mConflictId = intent.getStringExtra(CONFLICT_ID);
85-
mRetryCount = intent.getIntExtra(RETRY_COUNT, 0);
86-
87-
// register this class as the listener for when an item is selected
88-
vw.setOnItemClickListener(this);
89-
}
67+
@Override
68+
protected void onCreate(Bundle savedInstanceState) {
69+
super.onCreate(savedInstanceState);
70+
setContentView(R.layout.activity_select_snapshot);
71+
72+
//expect the intent to include the list of snapshots or snapshot metadatas to display
73+
Intent intent = getIntent();
74+
if (intent != null) {
75+
ArrayList<SnapshotMetadata> snapshotMetadataList;
76+
ListView vw = (ListView) findViewById(R.id.snapshot_list);
77+
78+
snapshotMetadataList = intent.getParcelableArrayListExtra(SNAPSHOT_METADATA_LIST);
79+
// set a custom list adapter that can display the image and other
80+
// information about a snapshot.
81+
vw.setAdapter(
82+
new SnapshotListAdapter<SnapshotMetadata>(this, snapshotMetadataList));
83+
84+
mConflictId = intent.getStringExtra(CONFLICT_ID);
85+
mRetryCount = intent.getIntExtra(RETRY_COUNT, 0);
86+
87+
// register this class as the listener for when an item is selected
88+
vw.setOnItemClickListener(this);
9089
}
90+
}
9191

9292

93-
@Override
94-
public void onItemClick(AdapterView<?> adapterView, View view, int position, long listId) {
93+
@Override
94+
public void onItemClick(AdapterView<?> adapterView, View view, int position, long listId) {
95+
96+
SnapshotMetadata selected = (SnapshotMetadata) adapterView.getItemAtPosition(position);
97+
Intent intent = new Intent(Intent.ACTION_DEFAULT);
9598

96-
SnapshotMetadata selected = (SnapshotMetadata) adapterView.getItemAtPosition(position);
97-
Intent intent = new Intent(Intent.ACTION_DEFAULT);
99+
intent.putExtra(SNAPSHOT_METADATA, selected.freeze());
100+
101+
if (mConflictId != null) {
102+
intent.putExtra(CONFLICT_ID, mConflictId);
103+
intent.putExtra(RETRY_COUNT, mRetryCount);
104+
}
98105

99-
intent.putExtra(SNAPSHOT_METADATA, selected.freeze());
106+
Log.d(TAG, "Finishing item at position " + position + " clicked");
107+
setResult(RESULT_OK, intent);
108+
finish();
109+
}
100110

101-
if (mConflictId != null) {
102-
intent.putExtra(CONFLICT_ID, mConflictId);
103-
intent.putExtra(RETRY_COUNT, mRetryCount);
104-
}
111+
/**
112+
* Custom mSnapshotMetadataArrayList adapter which holds the snapshot metadata. This is used
113+
* to
114+
* display the image and information for each snapshot.
115+
*/
116+
static class SnapshotListAdapter<T> extends ArrayAdapter<T> {
105117

106-
Log.d(TAG, "Finishing item at position " + position + " clicked");
107-
setResult(RESULT_OK, intent);
108-
finish();
118+
119+
public SnapshotListAdapter(Activity activity, ArrayList<T> data) {
120+
super(activity, R.layout.snapshotlayout, data);
109121
}
110122

123+
@Override
124+
public View getView(int position, View convertView, ViewGroup parent) {
125+
126+
// load the view used for each item in the mSnapshotMetadataArrayList
127+
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
128+
Context.LAYOUT_INFLATER_SERVICE);
129+
View rowView = inflater.inflate(R.layout.snapshotlayout, parent, false);
130+
131+
// get the elements of the view which display the specific data for the snapshot.
132+
TextView textView = (TextView) rowView.findViewById(R.id.label);
133+
TextView ageView = (TextView) rowView.findViewById(R.id.age);
134+
ImageView imageView = (ImageView) rowView.findViewById(R.id.snapshot_icon);
135+
136+
SnapshotMetadata snapshotMetadata;
137+
T item = getItem(position);
138+
if (item instanceof Snapshot) {
139+
snapshotMetadata = ((Snapshot) item).getMetadata();
140+
} else {
141+
snapshotMetadata = (SnapshotMetadata) item;
142+
}
143+
textView.setText(snapshotMetadata.getDescription());
144+
ageView.setText(getAge(snapshotMetadata.getLastModifiedTimestamp()));
145+
ImageManager.create(getContext())
146+
.loadImage(imageView, snapshotMetadata.getCoverImageUri());
147+
148+
return rowView;
149+
150+
}
151+
152+
153+
private static final long MILLIS_PER_MINUTE = 60 * 1000;
154+
155+
private static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
156+
157+
private static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR;
158+
111159
/**
112-
* Custom mSnapshotMetadataArrayList adapter which holds the snapshot metadata. This is used
113-
* to
114-
* display the image and information for each snapshot.
160+
* Helper function to convert the time difference into a string like "3 days ago"
161+
*
162+
* @param timestamp - the time to convert.
163+
* @return localized string, never null.
115164
*/
116-
static class SnapshotListAdapter<T> extends ArrayAdapter<T> {
117-
118-
119-
public SnapshotListAdapter(Activity activity, ArrayList<T> data) {
120-
super(activity, R.layout.snapshotlayout, data);
121-
}
122-
123-
@Override
124-
public View getView(int position, View convertView, ViewGroup parent) {
125-
126-
// load the view used for each item in the mSnapshotMetadataArrayList
127-
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(
128-
Context.LAYOUT_INFLATER_SERVICE);
129-
View rowView = inflater.inflate(R.layout.snapshotlayout, parent, false);
130-
131-
// get the elements of the view which display the specific data for the snapshot.
132-
TextView textView = (TextView) rowView.findViewById(R.id.label);
133-
TextView ageView = (TextView) rowView.findViewById(R.id.age);
134-
ImageView imageView = (ImageView) rowView.findViewById(R.id.snapshot_icon);
135-
136-
SnapshotMetadata snapshotMetadata;
137-
T item = getItem(position);
138-
if (item instanceof Snapshot) {
139-
snapshotMetadata = ((Snapshot) item).getMetadata();
140-
} else {
141-
snapshotMetadata = (SnapshotMetadata) item;
142-
}
143-
textView.setText(snapshotMetadata.getDescription());
144-
ageView.setText(getAge(snapshotMetadata.getLastModifiedTimestamp()));
145-
ImageManager.create(getContext())
146-
.loadImage(imageView, snapshotMetadata.getCoverImageUri());
147-
148-
return rowView;
149-
150-
}
151-
152-
153-
private static final long MILLIS_PER_MINUTE = 60 * 1000;
154-
155-
private static final long MILLIS_PER_HOUR = 60 * MILLIS_PER_MINUTE;
156-
157-
private static final long MILLIS_PER_DAY = 24 * MILLIS_PER_HOUR;
158-
159-
/**
160-
* Helper function to convert the time difference into a string like "3 days ago"
161-
*
162-
* @param timestamp - the time to convert.
163-
* @return localized string, never null.
164-
*/
165-
private String getAge(long timestamp) {
166-
long delta = System.currentTimeMillis() - timestamp;
167-
int days = (int) (delta / MILLIS_PER_DAY);
168-
169-
delta = delta % MILLIS_PER_DAY;
170-
int hours = (int) (delta / MILLIS_PER_HOUR);
171-
172-
delta = delta % MILLIS_PER_HOUR;
173-
int minutes = (int) (delta / MILLIS_PER_MINUTE);
174-
175-
delta = (int) (delta % MILLIS_PER_MINUTE);
176-
int seconds = (int) delta / 1000;
177-
178-
if (days > 0) {
179-
return getContext().getString(R.string.format_days_ago, days);
180-
}
181-
if (hours > 0) {
182-
return getContext().getString(R.string.format_hours_ago, hours);
183-
}
184-
if (minutes > 0) {
185-
return getContext().getString(R.string.format_minutes_ago, minutes);
186-
}
187-
if (seconds > 0) {
188-
return getContext().getString(R.string.format_seconds_ago, seconds);
189-
}
190-
return getContext().getString(R.string.moments_ago);
191-
}
165+
private String getAge(long timestamp) {
166+
long delta = System.currentTimeMillis() - timestamp;
167+
int days = (int) (delta / MILLIS_PER_DAY);
168+
169+
delta = delta % MILLIS_PER_DAY;
170+
int hours = (int) (delta / MILLIS_PER_HOUR);
171+
172+
delta = delta % MILLIS_PER_HOUR;
173+
int minutes = (int) (delta / MILLIS_PER_MINUTE);
174+
175+
delta = (int) (delta % MILLIS_PER_MINUTE);
176+
int seconds = (int) delta / 1000;
177+
178+
if (days > 0) {
179+
return getContext().getString(R.string.format_days_ago, days);
180+
}
181+
if (hours > 0) {
182+
return getContext().getString(R.string.format_hours_ago, hours);
183+
}
184+
if (minutes > 0) {
185+
return getContext().getString(R.string.format_minutes_ago, minutes);
186+
}
187+
if (seconds > 0) {
188+
return getContext().getString(R.string.format_seconds_ago, seconds);
189+
}
190+
return getContext().getString(R.string.moments_ago);
192191
}
192+
}
193193
}

0 commit comments

Comments
 (0)