|
15 | 15 |
|
16 | 16 | package com.google.example.games.bg; |
17 | 17 |
|
| 18 | +import java.io.IOException; |
| 19 | +import java.io.InputStream; |
| 20 | +import java.net.URL; |
18 | 21 | import java.util.ArrayList; |
19 | 22 | import java.util.HashMap; |
20 | 23 |
|
|
24 | 27 | import android.content.Intent; |
25 | 28 | import android.graphics.Bitmap; |
26 | 29 | import android.graphics.BitmapFactory; |
| 30 | +import android.os.AsyncTask; |
27 | 31 | import android.os.Bundle; |
28 | 32 | import android.util.Log; |
29 | 33 | import android.view.View; |
| 34 | +import android.widget.ImageView; |
30 | 35 | import android.widget.TextView; |
31 | 36 | import android.widget.Toast; |
32 | 37 |
|
|
37 | 42 | import com.google.android.gms.games.Game; |
38 | 43 | import com.google.android.gms.games.Games; |
39 | 44 | import com.google.android.gms.games.GamesActivityResultCodes; |
| 45 | +import com.google.android.gms.games.Player; |
40 | 46 | import com.google.android.gms.games.request.GameRequest; |
41 | 47 | import com.google.android.gms.games.request.GameRequestBuffer; |
42 | 48 | import com.google.android.gms.games.request.OnRequestReceivedListener; |
@@ -116,12 +122,62 @@ protected void onCreate(Bundle savedInstanceState) { |
116 | 122 | private void showSignInBar() { |
117 | 123 | findViewById(R.id.sign_in_bar).setVisibility(View.VISIBLE); |
118 | 124 | 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 | + |
119 | 132 | } |
120 | 133 |
|
121 | 134 | // Shows the "sign out" bar (explanation and button). |
122 | 135 | private void showSignOutBar() { |
123 | 136 | findViewById(R.id.sign_in_bar).setVisibility(View.GONE); |
124 | 137 | 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 | + } |
125 | 181 | } |
126 | 182 |
|
127 | 183 | // Count GameRequests in a GameRequestBuffer that have not yet expired |
@@ -450,8 +506,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { |
450 | 506 | if (resultCode == RESULT_OK) { |
451 | 507 | mGoogleApiClient.connect(); |
452 | 508 | } 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); |
455 | 510 | } |
456 | 511 | break; |
457 | 512 | } |
|
0 commit comments