FileDocCategorySizeDatePackage
GLSTester.javaAPI DocAndroid 1.5 API7793Wed May 06 22:41:08 BST 2009com.android.development

GLSTester

public class GLSTester extends android.app.Activity
Using a LogTextBox to display a scrollable text area to which text is appended.

Fields Summary
private static final String
TAG
private LogTextBox
mText
private com.google.android.googleapps.IGoogleLoginService
mGls
private android.content.ServiceConnection
mConnection
android.widget.CheckBox
mDoNotify
android.widget.CheckBox
mRunIntent
android.widget.Spinner
mService
android.widget.EditText
mUsernameEdit
Constructors Summary
Methods Summary
protected voidonActivityResult(int requestCode, int resultCode, android.content.Intent data)

        mText.append("resultCode: " + resultCode + "\n");
        if (data != null) {
            mText.append("account: " +
                         data.getStringExtra(GoogleLoginServiceConstants.AUTH_ACCOUNT_KEY) + "\n");
            mText.append("authtoken: " +
                         data.getStringExtra(GoogleLoginServiceConstants.AUTHTOKEN_KEY) + "\n");
        } else {
            mText.append("intent is null");
        }
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        // Open a connection to the Google Login Service.  Return the account.
        mConnection = new ServiceConnection() {
                public void onServiceConnected(ComponentName className, IBinder service) {
                    mGls = IGoogleLoginService.Stub.asInterface(service);
                }
                public void onServiceDisconnected(ComponentName className) {
                    mGls = null;
                }
            };

        bindService(GoogleLoginServiceConstants.SERVICE_INTENT,
                    mConnection, Context.BIND_AUTO_CREATE);

        setContentView(R.layout.gls_tester);

        mText = (LogTextBox) findViewById(R.id.text);
        mText.append("Hello, world!\n");
        Log.v(TAG, "hello, world!");

        mDoNotify = (CheckBox) findViewById(R.id.do_notification);
        mRunIntent = (CheckBox) findViewById(R.id.run_intent);
        mRunIntent.setChecked(true);

        mService = (Spinner) findViewById(R.id.service_spinner);

        mUsernameEdit = (EditText) findViewById(R.id.username_edit);

        Button b;
        b = (Button) findViewById(R.id.require_google);
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    String account = mGls.getAccount(GoogleLoginServiceConstants.REQUIRE_GOOGLE);
                    mText.append("REQUIRE_GOOGLE gave: " + account + "\n");
                    mUsernameEdit.setText(account == null ? "" : account);
                } catch (RemoteException e) {
                    mText.append("exception: " + e + "\n");
                }
            } });

        b = (Button) findViewById(R.id.prefer_hosted);
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    String account = mGls.getAccount(GoogleLoginServiceConstants.PREFER_HOSTED);
                    mText.append("PREFER_HOSTED gave: " + account + "\n");
                    mUsernameEdit.setText(account == null ? "" : account);
                } catch (RemoteException e) {
                    mText.append("exception: " + e + "\n");
                }
            } });


        b = (Button) findViewById(R.id.get_accounts);
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                try {
                    String[] accounts = mGls.getAccounts();
                    mText.append("account list: (" + accounts.length + " entries)\n");
                    for (String username: accounts) {
                        mText.append("  " + username + "\n");
                    }
                } catch (RemoteException e) {
                    mText.append("exception: " + e + "\n");
                }
            } });

        b = (Button) findViewById(R.id.clear);
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mText.setText("");
            } });

        b = (Button) findViewById(R.id.go);
        b.setOnClickListener(new Listener());

        b = (Button) findViewById(R.id.wipe_passwords);
        b.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                mText.setText("wiping passwords:\n");
                try {
                    String[] accounts = mGls.getAccounts();
                    LoginData ld = new LoginData();
                    for (String username: accounts) {
                        ld.mUsername = username;
                        mGls.updatePassword(ld);
                        mText.append("  " + username + "\n");
                    }
                    mText.append("done.\n");
                } catch (RemoteException e) {
                    mText.append("caught exception " + e + "\n");
                }
            } });

    
protected voidonDestroy()

        super.onDestroy();
        unbindService(mConnection);