Android Open Source - singly-android Device Owner 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;
//ww w  .  j a  v  a2s. c o  m
import org.apache.commons.lang.StringUtils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.singly.android.client.SinglyClient;
import com.singly.android.sdk.R;

/**
 * An activity that prompts the user for their name, phone number, and email 
 * address.  The only reliable way to gather this type of information across 
 * phones and network providers is to ask for it.
 * 
 * The information input is then stored in shared preferences.
 */
public class DeviceOwnerActivity
  extends Activity {

  // android OK result code is -1, so we use -50 and less
  public static final int RESULT_DONT_SYNC = -50;

  @Override
  protected void onCreate(Bundle savedInstanceState) {

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

    final SharedPreferences prefs = getSharedPreferences("singly",
      Context.MODE_PRIVATE);
    String ownerName = prefs.getString(SinglyClient.OWNER_NAME, null);
    String ownerPhone = prefs.getString(SinglyClient.OWNER_PHONE_NUMBER, null);
    String ownerEmail = prefs.getString(SinglyClient.OWNER_EMAIL_ADDRESS, null);

    // populate the fields if they exist
    final EditText ownerNameEdit = (EditText)findViewById(R.id.ownerNameEdit);
    if (StringUtils.isNotBlank(ownerName)) {
      ownerNameEdit.setText(ownerName);
    }
    final EditText ownerPhoneEdit = (EditText)findViewById(R.id.ownerPhoneEdit);
    if (StringUtils.isNotBlank(ownerPhone)) {
      ownerPhoneEdit.setText(ownerPhone);
    }
    final EditText ownerEmailEdit = (EditText)findViewById(R.id.ownerEmailEdit);
    if (StringUtils.isNotBlank(ownerEmail)) {
      ownerEmailEdit.setText(ownerEmail);
    }

    // submit button saves inputs to shared preferences if they exists and then
    // closes the activity
    Button submitButton = (Button)findViewById(R.id.ownerButtonSubmit);
    submitButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        SharedPreferences.Editor editor = prefs.edit();

        String nameInput = ownerNameEdit.getText().toString();
        if (StringUtils.isNotBlank(nameInput)) {
          editor.putString(SinglyClient.OWNER_NAME, nameInput);
        }
        String phoneInput = ownerPhoneEdit.getText().toString();
        if (StringUtils.isNotBlank(phoneInput)) {
          editor.putString(SinglyClient.OWNER_PHONE_NUMBER, phoneInput);
        }
        String emailInput = ownerEmailEdit.getText().toString();
        if (StringUtils.isNotBlank(emailInput)) {
          editor.putString(SinglyClient.OWNER_EMAIL_ADDRESS, emailInput);
        }
        editor.commit();

        setResult(0);
        DeviceOwnerActivity.this.finish();
      }
    });

    // cancel button just closes activity
    Button cancelButton = (Button)findViewById(R.id.ownerButtonCancel);
    cancelButton.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        setResult(RESULT_DONT_SYNC);
        DeviceOwnerActivity.this.finish();
      }
    });

  }
}




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