@Override public void onResume() { super.onResume(); Intent intent = getIntent(); String scheme = intent.getScheme(); OAuth savedToken = getOAuthToken(); if (CALLBACK_SCHEME.equals(scheme) && (savedToken == null || savedToken.getUser() == null)) { Uri uri = intent.getData(); String query = uri.getQuery(); logger.debug("Returned Query: {}", query); // $NON-NLS-1$ String[] data = query.split("&"); // $NON-NLS-1$ if (data != null && data.length == 2) { String oauthToken = data[0].substring(data[0].indexOf("=") + 1); // $NON-NLS-1$ String oauthVerifier = data[1].substring(data[1].indexOf("=") + 1); // $NON-NLS-1$ logger.debug( "OAuth Token: {}; OAuth Verifier: {}", oauthToken, oauthVerifier); // $NON-NLS-1$ OAuth oauth = getOAuthToken(); if (oauth != null && oauth.getToken() != null && oauth.getToken().getOauthTokenSecret() != null) { GetOAuthTokenTask task = new GetOAuthTokenTask(this); task.execute(oauthToken, oauth.getToken().getOauthTokenSecret(), oauthVerifier); } } } }
@Override protected List<Photo> doInBackground(OAuth... params) { OAuth oauth = params[0]; if (oauth != null) { OAuthToken token = oauth.getToken(); Flickr f = FlickrHelper.getInstance() .getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret()); if (BuildConfig.DEBUG) Log.d(TAG, "Fetching page " + mPage); try { return f.getPoolsInterface() .getPhotos(mGroup.getId(), null, Constants.EXTRAS, Constants.FETCH_PER_PAGE, mPage); } catch (Exception e) { e.printStackTrace(); mException = e; } } else { if (BuildConfig.DEBUG) Log.d(TAG, "Making unauthenticated call"); if (BuildConfig.DEBUG) Log.d(TAG, "Fetching page " + mPage); try { return FlickrHelper.getInstance() .getPoolsInterface() .getPhotos(mGroup.getId(), null, Constants.EXTRAS, Constants.FETCH_PER_PAGE, mPage); } catch (Exception e) { e.printStackTrace(); mException = e; } } return null; }
public OAuth getOAuthToken() { // Restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String oauthTokenString = settings.getString(KEY_OAUTH_TOKEN, null); String tokenSecret = settings.getString(KEY_TOKEN_SECRET, null); if (oauthTokenString == null && tokenSecret == null) { logger.warn("No oauth token retrieved"); // $NON-NLS-1$ return null; } OAuth oauth = new OAuth(); String userName = settings.getString(KEY_USER_NAME, null); String userId = settings.getString(KEY_USER_ID, null); if (userId != null) { User user = new User(); user.setUsername(userName); user.setId(userId); oauth.setUser(user); } OAuthToken oauthToken = new OAuthToken(); oauth.setToken(oauthToken); oauthToken.setOauthToken(oauthTokenString); oauthToken.setOauthTokenSecret(tokenSecret); logger.debug( "Retrieved token from preference store: oauth token={}, and token secret={}", oauthTokenString, tokenSecret); //$NON-NLS-1$ return oauth; }
@Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); /* Load the users oauth token */ mOAuth = OAuthUtils.loadAccessToken(this); if (mOAuth != null) { mUser = mOAuth.getUser(); } mTextUtils = new TextUtils(getAssets()); /* Set custom title on action bar (it will be null for dialog * activities */ mActionBar = getActionBar(); if (mActionBar != null) { if (!getResources().getBoolean(R.bool.sw600dp)) { new GlimmrAbCustomTitle(this).init(mActionBar); } else { mActionBar.setTitle(""); } } setProgressBarIndeterminateVisibility(Boolean.FALSE); /* Load default preferences */ PreferenceManager.setDefaultValues(this, R.xml.preferences, false); if (isTaskRoot()) { startTapeQueues(); } }
private List<Photo> getUserPhotos() throws Exception { OAuthToken token = mOAuth.getToken(); Flickr f = FlickrHelper.getInstance() .getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret()); return f.getPeopleInterface() .getPhotos(mUser.getId(), Constants.EXTRAS, Constants.FETCH_PER_PAGE, PAGE); }
@Override protected List<Photoset> doInBackground(Void... arg0) { OAuth oAuth = authentication.getOAuth(); if (oAuth == null) return null; FlickrHelper.setOAuth(oAuth); List<Photoset> result = new ArrayList<Photoset>(); PhotosetsInterface intf = FlickrHelper.getFlickr().getPhotosetsInterface(); try { Collection<Photoset> photosets; int page = 1; final int perPage = 10; do { try { photosets = intf.getList(oAuth.getUser().getId(), perPage, page).getPhotosets(); } catch (FlickrException e) { if (e.getErrorCode().compareTo("1") == 0) // empty page break; throw e; } for (Photoset p : photosets) result.add(p); page += 1; } while (photosets.size() >= perPage); return result; } catch (IOException e) { Log.w(TAG, e); error = e; return null; } catch (FlickrException e) { Log.w(TAG, e); error = e; return null; } catch (JSONException e) { Log.w(TAG, e); error = e; return null; } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.refreshButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { load(getOAuthToken()); } }); OAuth oauth = getOAuthToken(); if (oauth == null || oauth.getUser() == null) { OAuthTask task = new OAuthTask(this); task.execute(); } else { load(oauth); } }
/** * In onCreate() you setup any connections / cursors to your data source. Heavy lifting, for * example downloading or creating content etc, should be deferred to onDataSetChanged() or * getViewAt(). Taking more than 20 seconds in this call will result in an ANR. */ public void onCreate() { if (Constants.DEBUG) Log.d(TAG, "onCreate"); mOAuth = OAuthUtils.loadAccessToken(mContext); mUser = null; if (OAuthUtils.isLoggedIn(mContext)) { mUser = mOAuth.getUser(); } mPhotos = new ArrayList<Photo>(); mWidgetType = StackViewWidgetConfigure.loadWidgetType(mContext); }
public static OAuth getOAuthToken() { String oauthTokenString = CacheManager.getStringCacheData(KEY_OAUTH_TOKEN); String tokenSecret = CacheManager.getStringCacheData(KEY_TOKEN_SECRET); if (StringUtils.isNull(oauthTokenString) && StringUtils.isNull(tokenSecret)) { return null; } OAuth oauth = new OAuth(); String userName = CacheManager.getStringCacheData(KEY_USER_NAME); String userId = CacheManager.getStringCacheData(KEY_USER_ID); if (StringUtils.isNotNull(userId)) { User user = new User(); user.setUsername(userName); user.setId(userId); oauth.setUser(user); } OAuthToken oauthToken = new OAuthToken(); oauth.setToken(oauthToken); oauthToken.setOauthToken(oauthTokenString); oauthToken.setOauthTokenSecret(tokenSecret); return oauth; }
public void onOAuthDone(OAuth result) { if (result == null) { Toast.makeText( this, "Authorization failed", //$NON-NLS-1$ Toast.LENGTH_LONG) .show(); } else { User user = result.getUser(); OAuthToken token = result.getToken(); if (user == null || user.getId() == null || token == null || token.getOauthToken() == null || token.getOauthTokenSecret() == null) { Toast.makeText( this, "Authorization failed", //$NON-NLS-1$ Toast.LENGTH_LONG) .show(); return; } String message = String.format( Locale.US, "Authorization Succeed: user=%s, userId=%s, oauthToken=%s, tokenSecret=%s", //$NON-NLS-1$ user.getUsername(), user.getId(), token.getOauthToken(), token.getOauthTokenSecret()); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); saveOAuthToken( user.getUsername(), user.getId(), token.getOauthToken(), token.getOauthTokenSecret()); load(result); } }
private List<Photo> getFavoritePhotos() throws Exception { OAuthToken token = mOAuth.getToken(); Flickr f = FlickrHelper.getInstance() .getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret()); Date minFavDate = null; Date maxFavDate = null; return f.getFavoritesInterface() .getList( mUser.getId(), minFavDate, maxFavDate, Constants.FETCH_PER_PAGE, PAGE, Constants.EXTRAS); }
private List<Photo> getContactsPhotos() throws Exception { OAuthToken token = mOAuth.getToken(); Flickr f = FlickrHelper.getInstance() .getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret()); boolean justFriends = false; boolean singlePhoto = false; boolean includeSelf = false; return f.getPhotosInterface() .getContactsPhotos( Constants.FETCH_PER_PAGE, Constants.EXTRAS, justFriends, singlePhoto, includeSelf, PAGE, Constants.FETCH_PER_PAGE); }
public static boolean hasLogin() { OAuth oauth = getOAuthToken(); if (oauth == null || oauth.getUser() == null) return false; return true; }