Skip to content

Commit c1cec16

Browse files
committed
Merge conflict
2 parents ce6aeba + 1e1b68c commit c1cec16

20 files changed

Lines changed: 108 additions & 37 deletions

File tree

BasicSamples/BeGenerous/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
android:minSdkVersion="9"
3535
android:targetSdkVersion="19" />
3636

37+
<!-- used to download the player's image. If you don't need the user's image,
38+
this permission can be removed.
39+
-->
40+
<uses-permission android:name="android.permission.INTERNET" />
41+
42+
<!-- used to get the player's email address (aka accountName). If you don't need the
43+
the user's email, this permission can be removed.
44+
-->
45+
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
46+
3747
<application
3848
android:allowBackup="true"
3949
android:icon="@drawable/ic_launcher"

BasicSamples/BeGenerous/src/main/java/com/google/example/games/bg/BeGenerousActivity.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
package com.google.example.games.bg;
1717

18+
import java.io.IOException;
19+
import java.io.InputStream;
20+
import java.net.URL;
1821
import java.util.ArrayList;
1922
import java.util.HashMap;
2023

@@ -24,9 +27,11 @@
2427
import android.content.Intent;
2528
import android.graphics.Bitmap;
2629
import android.graphics.BitmapFactory;
30+
import android.os.AsyncTask;
2731
import android.os.Bundle;
2832
import android.util.Log;
2933
import android.view.View;
34+
import android.widget.ImageView;
3035
import android.widget.TextView;
3136
import android.widget.Toast;
3237

@@ -37,6 +42,7 @@
3742
import com.google.android.gms.games.Game;
3843
import com.google.android.gms.games.Games;
3944
import com.google.android.gms.games.GamesActivityResultCodes;
45+
import com.google.android.gms.games.Player;
4046
import com.google.android.gms.games.request.GameRequest;
4147
import com.google.android.gms.games.request.GameRequestBuffer;
4248
import com.google.android.gms.games.request.OnRequestReceivedListener;
@@ -116,12 +122,62 @@ protected void onCreate(Bundle savedInstanceState) {
116122
private void showSignInBar() {
117123
findViewById(R.id.sign_in_bar).setVisibility(View.VISIBLE);
118124
findViewById(R.id.sign_out_bar).setVisibility(View.GONE);
125+
ImageView vw = (ImageView) findViewById(R.id.avatar);
126+
vw.setImageBitmap(null);
127+
TextView name = (TextView)findViewById(R.id.playerName);
128+
name.setText("");
129+
TextView email = (TextView)findViewById((R.id.playerEmail));
130+
email.setText("");
131+
119132
}
120133

121134
// Shows the "sign out" bar (explanation and button).
122135
private void showSignOutBar() {
123136
findViewById(R.id.sign_in_bar).setVisibility(View.GONE);
124137
findViewById(R.id.sign_out_bar).setVisibility(View.VISIBLE);
138+
139+
Player player = Games.Players.getCurrentPlayer(mGoogleApiClient);
140+
String url = player.getIconImageUrl();
141+
TextView name = (TextView)findViewById(R.id.playerName);
142+
name.setText(player.getDisplayName());
143+
if (url != null) {
144+
ImageView vw = (ImageView) findViewById(R.id.avatar);
145+
146+
// load the image in the background.
147+
new DownloadImageTask(vw).execute(url);
148+
}
149+
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
150+
TextView emailView = (TextView)findViewById((R.id.playerEmail));
151+
emailView.setText(email);
152+
}
153+
154+
/**
155+
* AsyncTask to download an image from a URL and set the image to the
156+
* ImageView that is passed in on the constructor.
157+
*/
158+
class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
159+
ImageView bmImage;
160+
161+
public DownloadImageTask(ImageView bmImage) {
162+
this.bmImage = bmImage;
163+
}
164+
165+
@Override
166+
protected Bitmap doInBackground(String... strings) {
167+
Bitmap mIcon11 = null;
168+
String url = strings[0];
169+
try {
170+
InputStream in = new URL(url).openStream();
171+
mIcon11 = BitmapFactory.decodeStream(in);
172+
} catch (IOException e) {
173+
Log.e(TAG, e.getMessage());
174+
}
175+
return mIcon11;
176+
}
177+
protected void onPostExecute(Bitmap result) {
178+
bmImage.setImageBitmap(result);
179+
bmImage.setVisibility(View.VISIBLE);
180+
}
125181
}
126182

127183
// Count GameRequests in a GameRequestBuffer that have not yet expired
@@ -450,8 +506,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
450506
if (resultCode == RESULT_OK) {
451507
mGoogleApiClient.connect();
452508
} else {
453-
BaseGameUtils.showActivityResultError(this, requestCode, resultCode,
454-
R.string.signin_failure, R.string.signin_other_error);
509+
BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_other_error);
455510
}
456511
break;
457512
}

BasicSamples/BeGenerous/src/main/res/layout/activity_main.xml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,33 @@
6666
android:src="@drawable/ic_send_gift" />
6767

6868
</RelativeLayout>
69-
69+
70+
<ImageView
71+
android:layout_width="100dp"
72+
android:layout_height="100dp"
73+
android:id="@+id/avatar"
74+
android:layout_gravity="center_horizontal"/>
75+
76+
77+
<TextView
78+
android:layout_width="wrap_content"
79+
android:layout_height="wrap_content"
80+
android:textAppearance="?android:attr/textAppearanceMedium"
81+
android:id="@+id/playerName"
82+
android:layout_gravity="center_horizontal"
83+
/>
84+
<TextView
85+
android:layout_width="wrap_content"
86+
android:layout_height="wrap_content"
87+
android:textAppearance="?android:attr/textAppearanceSmall"
88+
android:id="@+id/playerEmail"
89+
android:layout_gravity="center_horizontal"
90+
/>
91+
7092
<!-- MAIN DISPLAY -->
7193
<RelativeLayout style="@style/MainDisplay">
7294

95+
7396
<ImageButton
7497
android:id="@+id/button_send_gift"
7598
style="@style/Button"
@@ -89,7 +112,7 @@
89112
android:src="@drawable/ic_open_inbox"
90113
android:layout_toRightOf="@id/button_send_request" />
91114

92-
115+
93116
</RelativeLayout>
94117

95118
<!-- SIGN-IN BAR -->

BasicSamples/BeGenerous/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<string name="request_icon_description">Request Icon</string>
4040
<string name="gift_count">Incoming: %d</string>
4141
<string name="request_count">Incoming: %d</string>
42-
<string name="signin_failure">Unable to sign in. Check your internet connection and try again later.</string>
4342
<string name="signin_other_error">There was an issue with sign in. Please try again later.</string>
4443

4544
</resources>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ public void onActivityResult(int requestCode, int responseCode,
259259
if (responseCode == RESULT_OK) {
260260
mGoogleApiClient.connect();
261261
} else {
262-
BaseGameUtils.showActivityResultError(this,requestCode,responseCode,
263-
R.string.signin_failure, R.string.signin_other_error);
262+
BaseGameUtils.showActivityResultError(this,requestCode,responseCode, R.string.signin_other_error);
264263
}
265264
break;
266265
}

BasicSamples/ButtonClicker/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@
4040
<string name="game_problem">An error occurred while starting the game. Please try again.</string>
4141
<string name="click_me">Click me!</string>
4242
<string name="is_inviting_you">is challenging you to a game!</string>
43-
<string name="signin_failure">Unable to sign in. Check your internet connection and try again later.</string>
4443
<string name="signin_other_error">There was an issue with sign in. Please try again later.</string>
4544
</resources>

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
155155
if (resultCode == RESULT_OK) {
156156
mGoogleApiClient.connect();
157157
} else {
158-
BaseGameUtils.showActivityResultError(this, requestCode, resultCode,
159-
R.string.signin_failure, R.string.signin_other_error);
158+
BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_other_error);
160159
}
161160
}
162161
// the standard snapshot selection intent

BasicSamples/CollectAllTheStars2/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<string name="menu_sync">Load</string>
3636
<string name="menu_save">Save</string>
3737
<string name="menu_select">Select</string>
38-
<string name="signin_failure">Unable to sign in. Check your internet connection and try again later.</string>
3938
<string name="signin_other_error">There was an issue with sign in. Please try again later.</string>
4039
<string name="title_saved_games">"Saved Games"</string>
4140
<string name="title_load_game">Select saved game to load</string>

BasicSamples/SavedGames/src/main/java/com/google/example/games/savedgames/MainActivity.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.google.android.gms.games.snapshot.SnapshotMetadata;
4040
import com.google.android.gms.games.snapshot.SnapshotMetadataChange;
4141
import com.google.android.gms.games.snapshot.Snapshots;
42-
import com.google.android.gms.plus.Plus;
4342
import com.google.example.games.basegameutils.BaseGameUtils;
4443

4544
/**
@@ -143,8 +142,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
143142
// There was an error during sign-in, display a Dialog with the appropriate message
144143
// to the user.
145144
Log.d(TAG, "onActivityResult: RC_SIGN_IN (Error)");
146-
BaseGameUtils.showActivityResultError(this, requestCode, resultCode,
147-
R.string.signin_failure, R.string.signin_other_error);
145+
BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_other_error);
148146
}
149147
} else if (requestCode == RC_SELECT_SNAPSHOT) {
150148
Log.d(TAG, "onActivityResult: RC_SELECT_SNAPSHOT, resultCode = " + resultCode);

BasicSamples/SavedGames/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ limitations under the License.
1919
<string name="migrate">Migrate</string>
2020
<string name="select">Select</string>
2121
<string name="signin_other_error">There was an error during sign in.</string>
22-
<string name="signin_failure">Unable to sign in. Please check your connection and try again,</string>
2322
<string name="message_sign_in">Sign-in to begin.</string>
2423
<string name="message_signed_in">Signed in.</string>
2524
<string name="saved_games_load_success">Loaded from Saved Games.</string>

0 commit comments

Comments
 (0)