Skip to content

Instantly share code, notes, and snippets.

@hwrdprkns
Created January 4, 2012 19:38
Show Gist options
  • Save hwrdprkns/1561658 to your computer and use it in GitHub Desktop.
Save hwrdprkns/1561658 to your computer and use it in GitHub Desktop.
picasaProblems
mPicasaService = new PicasawebService("myAppName");
mPicasaService.setUserToken(PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("authtoken",""));
AsyncTask<Void,AlbumEntry,UserFeed> loadAlbumTask = new AsyncTask<Void,AlbumEntry,UserFeed>(){
@Override
protected UserFeed doInBackground(Void... params) {
try {
URL url = picasaURL("taylorhp?kind=album");
Log.e("Debug","Running the async task! "+url.toExternalForm());
UserFeed feed = mPicasaService.getFeed(url, UserFeed.class);
Log.e("Debug","The Feed for"+feed.getUsername()+": "+feed.getXmlBlob().getFullText());
for(AlbumEntry a : feed.getAlbumEntries()){publishProgress(a);}
return feed;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(AlbumEntry... values) {
((ArrayAdapter<String>)getListAdapter()).add(values[0].getTitle().getPlainText());
Log.e("Debug","Added: "+values[0].getTitle().getPlainText());
((ArrayAdapter<String>)getListAdapter()).notifyDataSetChanged();
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(UserFeed result) {
if(result != null)mAlbumFeed = result;
super.onPostExecute(result);
}
};
loadAlbumTask.execute();
private void commenceGoogleAuthentication(final AccountManager manager,final Account account){
manager.getAuthToken(account,"lh2", null, this, new AccountManagerCallback<Bundle>(){
@Override
public void run(AccountManagerFuture<Bundle> future) {
Bundle bundle;
try {
bundle = future.getResult();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putString("authtoken", bundle.getString(AccountManager.KEY_AUTHTOKEN)).commit();
prefs.edit().putString("authAccount", bundle.getString(AccountManager.KEY_ACCOUNT_NAME)).commit();
Log.d("Success",bundle.getString(AccountManager.KEY_ACCOUNT_NAME)+":"+bundle.getString(AccountManager.KEY_AUTHTOKEN));
} catch (OperationCanceledException e) {
runOnUiThread(new Runnable(){public void run(){manipulateCheckbox(((CheckBox)findViewById(R.id.gplusCheckbox)),false);}});
e.printStackTrace();
} catch (AuthenticatorException e) {
runOnUiThread(new Runnable(){public void run(){manipulateCheckbox(((CheckBox)findViewById(R.id.gplusCheckbox)),false);}});
e.printStackTrace();
} catch (IOException e) {
runOnUiThread(new Runnable(){public void run(){manipulateCheckbox(((CheckBox)findViewById(R.id.gplusCheckbox)),false);}});
e.printStackTrace();
}
}
private void manipulateCheckbox(CheckBox box, boolean set){
box.setChecked(set);
}
}, null);
manager.invalidateAuthToken("com.google", PreferenceManager.getDefaultSharedPreferences(mContext).getString("authtoken", null));
manager.getAuthToken(account,"lh2", null, this, new AccountManagerCallback<Bundle>(){
@Override
public void run(AccountManagerFuture<Bundle> future) {
Bundle bundle;
try {
bundle = future.getResult();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
prefs.edit().putString("authtoken", bundle.getString(AccountManager.KEY_AUTHTOKEN)).commit();
prefs.edit().putString("authAccount", bundle.getString(AccountManager.KEY_ACCOUNT_NAME)).commit();
Log.d("Success",bundle.getString(AccountManager.KEY_ACCOUNT_NAME)+":"+bundle.getString(AccountManager.KEY_AUTHTOKEN));
checkPreferences();
} catch (OperationCanceledException e) {
runOnUiThread(new Runnable(){public void run(){manipulateCheckbox(((CheckBox)findViewById(R.id.gplusCheckbox)),false);}});
e.printStackTrace();
} catch (AuthenticatorException e) {
runOnUiThread(new Runnable(){public void run(){manipulateCheckbox(((CheckBox)findViewById(R.id.gplusCheckbox)),false);}});
e.printStackTrace();
} catch (IOException e) {
runOnUiThread(new Runnable(){public void run(){manipulateCheckbox(((CheckBox)findViewById(R.id.gplusCheckbox)),false);}});
e.printStackTrace();
}
}
private void manipulateCheckbox(CheckBox box, boolean set){
box.setChecked(set);
}
}, null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment