Android Open Source - singly-android Authenticated Services Activity






From Project

Back to project page singly-android.

License

The source code is released under:

MIT License

If you think the Android project singly-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.singly.android.component;
//from w  w w  .  ja  v a  2 s.  c o m
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.LinearLayout;

import com.singly.android.sdk.R;

/**
 * An activity class that uses the AuthenticatedServicesFragment to display a 
 * list of services a use can authenticate with along with the services they 
 * are already authenticated against.
 * 
 * Intent values can be passed in as intent extra information to change the
 * behavior of the AuthenticatedServicesActivity component.  They are:
 * 
 * <ol>
 *   <li>scopes - A bundle of service name to oauth scope parameter.</li>
 *   <li>flags - A bundle of service name to oauth flag parameter.</li>
 *   <li>includes - An array of the service names to include.  Only those
 *   services specified will be displayed.  If not set all services Singly 
 *   provides authentication for are displayed.</li>
 *   <li>useNative - True|False should we use native authentication if and when
 *   it is available.</li>
 * </ol>   
 * 
 * When using the AuthenticatedServicesActivity the activity must be registered 
 * in the AndroidManifest.xml file as follows.
 * 
 * <pre>
 * <activity android:name="com.singly.android.component.AuthenticatedServicesActivity" />
 * </pre>
 */
public class AuthenticatedServicesActivity
  extends FragmentActivity {

  protected Context context;
  protected LinearLayout singlyAuthServicesLayout;
  protected AuthenticatedServicesFragment authServices;

  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.singly_auth_services_activity);

    // set the context and any scopes specified
    this.context = this;
    Intent intent = getIntent();

    // the id and layouts for the fragments
    int authServicesId = R.id.singlyAuthServicesLayout;
    singlyAuthServicesLayout = (LinearLayout)findViewById(authServicesId);

    FragmentManager fragmentManager = getSupportFragmentManager();

    // setup the friends list fragment
    Fragment authServicesFrag = fragmentManager
      .findFragmentById(authServicesId);
    if (authServicesFrag != null) {
      authServices = (AuthenticatedServicesFragment)authServicesFrag;
    }
    else if (singlyAuthServicesLayout != null) {

      authServices = new AuthenticatedServicesFragment();

      // service specific scopes
      Bundle oauthScopes = intent.getBundleExtra("scopes");
      if (oauthScopes != null) {
        Map<String, String> scopes = new HashMap<String, String>();
        for (String key : oauthScopes.keySet()) {
          scopes.put(key, oauthScopes.getString(key));
        }
        if (!scopes.isEmpty()) {
          authServices.setScopes(scopes);
        }
      }

      // service specific flags
      Bundle oauthFlags = intent.getBundleExtra("flags");
      if (oauthFlags != null) {
        Map<String, String> flags = new HashMap<String, String>();
        for (String key : oauthFlags.keySet()) {
          flags.put(key, oauthFlags.getString(key));
        }
        if (!flags.isEmpty()) {
          authServices.setFlags(flags);
        }
      }

      // native authentication if available
      boolean useNativeAuth = intent.getBooleanExtra("useNativeAuth", false);
      authServices.setUseNativeAuth(useNativeAuth);

      // setup a service inclusion list
      String[] includesAr = intent.getStringArrayExtra("includes");
      if (includesAr != null && includesAr.length > 0) {
        Set<String> includedSet = new HashSet<String>(Arrays.asList(includesAr));
        authServices.setIncludedServices(includedSet);
      }

      // add the fragment
      FragmentTransaction authServicesTrans = fragmentManager.beginTransaction();
      authServicesTrans.add(authServicesId, authServices);
      authServicesTrans.commit();
    }
  }

}




Java Source Code List

com.singly.android.client.AsyncApiResponseHandler.java
com.singly.android.client.AuthenticationActivity.java
com.singly.android.client.AuthenticationWebViewListener.java
com.singly.android.client.BaseAuthenticationWebViewClient.java
com.singly.android.client.FacebookAuthenticationActivity.java
com.singly.android.client.SinglyClient.java
com.singly.android.component.AbstractCachingBlockLoadedListAdapter.java
com.singly.android.component.AuthenticatedServicesActivity.java
com.singly.android.component.AuthenticatedServicesAdapter.java
com.singly.android.component.AuthenticatedServicesFragment.java
com.singly.android.component.DeviceOwnerActivity.java
com.singly.android.component.Friend.java
com.singly.android.component.FriendsListActivity.java
com.singly.android.component.FriendsListAdapter.java
com.singly.android.component.FriendsListFragment.java
com.singly.android.component.FriendsListRowClickListener.java
com.singly.android.component.SinglyService.java
com.singly.android.component.TableOfContentsFragment.java
com.singly.android.component.TableOfContentsTouchListener.java
com.singly.android.examples.MainActivity.java
com.singly.android.util.BitmapUtils.java
com.singly.android.util.ImageCacheListener.java
com.singly.android.util.ImageInfo.java
com.singly.android.util.JSON.java
com.singly.android.util.RemoteImageCache.java
com.singly.android.util.SinglyUtils.java
com.singly.android.util.URLUtils.java