From 9339ce3fea33f201580d79d258e5491c1a428d0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Rzepecki?= Date: Thu, 2 Jul 2009 21:05:32 +0200 Subject: [PATCH] My avatar gets shown. --- lib/jblip | 2 +- src/pl/blip/divide/bliper/Blip.java | 24 +++++++++++++++++++++--- src/pl/blip/divide/bliper/Dashboard.java | 24 +++++++++++++++++++++++- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/lib/jblip b/lib/jblip index 1cf9819..cc68ac9 160000 --- a/lib/jblip +++ b/lib/jblip @@ -1 +1 @@ -Subproject commit 1cf98192d65e475bf2184c07e102d70972ed9d84 +Subproject commit cc68ac9fd90b06d985d181bba665e6f8831ddb77 diff --git a/src/pl/blip/divide/bliper/Blip.java b/src/pl/blip/divide/bliper/Blip.java index 1ec0e40..cb2a304 100644 --- a/src/pl/blip/divide/bliper/Blip.java +++ b/src/pl/blip/divide/bliper/Blip.java @@ -2,6 +2,8 @@ package pl.blip.divide.bliper; import jblip.BlipClient; import jblip.ErrorMessage; +import jblip.resources.UserPicture; +import jblip.resources.UserPicture.PictureSize; import android.content.ContentProvider; import android.content.ContentValues; import android.content.Context; @@ -36,6 +38,8 @@ public class Blip extends ContentProvider { } public static final String CONNECTION_STATE = "connection_state"; + public static final String MY_AVATAR = "my_avatar"; + public static final String MY_USERNAME = "my_username"; private class BlipCursor extends AbstractCursor { @Override @@ -96,6 +100,11 @@ public class Blip extends ContentProvider { public Bundle getExtras() { Bundle b = new Bundle(); b.putInt(CONNECTION_STATE, state); + if (state == STATE_OK) { + b.putString(MY_USERNAME, username); + UserPicture avatar = client.getAvatar(username); + b.putString(MY_AVATAR, client.getUrl(avatar.getPath(PictureSize.PICO)).toString()); + } return b; } } @@ -107,6 +116,8 @@ public class Blip extends ContentProvider { public static final int STATE_OK = 0; public static final int STATE_NO_CREDENTIALS = -1; private int state; + private String username; + private BlipClient client; @Override public int delete(Uri uri, String selection, String[] selectionArgs) { @@ -129,15 +140,22 @@ public class Blip extends ContentProvider { @Override public boolean onCreate() { login(); + if (state != STATE_OK) + return true; + return true; } private void login() { - SharedPreferences account_info = getContext().getSharedPreferences(CREDENTIALS, Context.MODE_PRIVATE); - if (!account_info.contains(PASSWORD_KEY)) + SharedPreferences credentials = getContext().getSharedPreferences(CREDENTIALS, Context.MODE_PRIVATE); + if (!credentials.contains(PASSWORD_KEY)) state = STATE_NO_CREDENTIALS; - else + else { state = STATE_OK; + username = credentials.getString(USERNAME_KEY, null); + final String password = credentials.getString(PASSWORD_KEY, null); + client = new jblip.base.HttpClient(username, password); + } } @Override diff --git a/src/pl/blip/divide/bliper/Dashboard.java b/src/pl/blip/divide/bliper/Dashboard.java index 880e8fb..361a5ec 100644 --- a/src/pl/blip/divide/bliper/Dashboard.java +++ b/src/pl/blip/divide/bliper/Dashboard.java @@ -1,9 +1,16 @@ package pl.blip.divide.bliper; +import java.net.URL; +import java.net.URLConnection; + import android.app.Activity; import android.content.Intent; import android.database.Cursor; +import android.graphics.BitmapFactory; import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageView; public class Dashboard extends Activity { /** Called when the activity is first created. */ @@ -11,13 +18,28 @@ public class Dashboard extends Activity { public void onCreate(Bundle icicle) { super.onCreate(icicle); - setContentView(R.layout.main); + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.main, null); + setContentView(view); + + ImageView avatar = (ImageView) view.findViewById(R.id.avatar); Cursor c = managedQuery(Blip.CONTENT_URI, new String[]{}, null, null, null); Bundle b = c.getExtras(); if (b.getInt(Blip.CONNECTION_STATE) == Blip.STATE_NO_CREDENTIALS) { finish(); // no point in staying around if we're not logged in, the login activity will call us login(); + } else { + try { + final URL avatarUrl = new URL(b.getString(Blip.MY_AVATAR)); + final URLConnection connection = avatarUrl.openConnection(); + connection.setDoInput(true); + connection.connect(); + avatar.setImageBitmap(BitmapFactory.decodeStream(connection.getInputStream())); + } catch (Exception e) { + e.printStackTrace(); + // ah, well. TODO? + } } } -- 2.11.4.GIT