Android Open Source - amanaje Contact Detail Activity






From Project

Back to project page amanaje.

License

The source code is released under:

Apache License

If you think the Android project amanaje 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.amanaje.activities;
/* ww w.j  a v a2 s  .  c  o  m*/
import java.io.File;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.amanaje.R;
import com.amanaje.asynctasks.AsyncTaskManager;
import com.amanaje.commons.ActivityHelper;
import com.amanaje.commons.Constants;
import com.amanaje.entities.ConfigEntity;

public class ContactDetailActivity extends Activity {

  private AsyncTaskManager aTaskMan = null;
  private Button save = null;
  private Button send = null;
  private Button del = null;
  private EditText nick = null;
  private EditText number = null;
  private EditText aKey1 = null;
  private EditText aKey2 = null;
  private EditText pubKey = null;
  private Activity thisActivity = null;
  private String extraNick = null;
  private String extraNumber = null;
  private String extraPubKey = null;
  private String extraFileName = null;
  private String extraSeed = null;
  private String extraAkey1 = null;
  private String extraAkey2 = null;
  private String thisContactFileName = null;
  private File thisContact = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact_detail);

    save =     (Button)   findViewById(R.id.saveContactBt);
    send =     (Button)   findViewById(R.id.sendSmsBt);
    del =     (Button)   findViewById(R.id.delContactBt);
    nick =     (EditText)   findViewById(R.id.nickContactEt);
    number =   (EditText)   findViewById(R.id.numberContactEt);
    aKey1 =   (EditText)   findViewById(R.id.actKey1ContactEt);
    aKey2 =   (EditText)   findViewById(R.id.actKey2ContactEt);
    pubKey =   (EditText)   findViewById(R.id.pubKeyContactEt);
    del.setEnabled(false);
    send.setEnabled(false);

    thisActivity = this;

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      extraNick = extras.getString("nick");
      extraNumber = extras.getString("number");
      extraPubKey  = extras.getString("pubkey");
      
      extraAkey1 = extras.getString("aKey1"); 
      extraAkey2 = extras.getString("aKey2");
      
      extraSeed = extras.getString("seed");
      extraFileName = extras.getString("fileName");
      
      thisContactFileName = extras.getString("thisContactFileName");
      
      if(extraAkey1 != null && extraAkey2 != null){
        aKey1.setText(extraAkey1);
        aKey2.setText(extraAkey2);
      }

      if(extraPubKey != null) pubKey.setText(extraPubKey);

      if(extraNick != null && extraNumber != null){
        nick.setText(extraNick);
        nick.setEnabled(false);
        number.setText(extraNumber);
        number.setEnabled(false);
        del.setEnabled(true);
        send.setEnabled(true);
      }
    }
    
    send.setOnClickListener(new OnClickListener() {
      
      @Override
      public void onClick(View v) {
        Intent i = new Intent(getApplicationContext(), NewSmsActivity.class);
        i.putExtra("nick", extraNick);
        i.putExtra("number", extraNumber);
        i.putExtra("pubKey", extraPubKey);
        i.putExtra("seed", extraSeed);
        startActivity(i);
      }
    });

    if(!nick.isEnabled()) save.setText("Update");

    save.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        int err = 0;
        if(!number.getText().toString().contains("+")){
          err++;

          ActivityHelper.getInstance().showAlertDialog(thisActivity, "Error", "Invalid Phone Number. Try COUNTRY CODE, AREA CODE and PHONE NUMBER.");

        }

        if(number.getText().toString().length()< 5){
          err++;

          ActivityHelper.getInstance().showAlertDialog(thisActivity, "Error","Too small Phone Number. Try COUNTRY CODE, AREA CODE and PHONE NUMBER.");

        }

        if(nick.getText().toString().length() == 0){
          err++;

          ActivityHelper.getInstance().showAlertDialog(thisActivity, "Error","Invalid nick.");

        }

        if(pubKey.getText().toString().length() == 0){
          err++;

          ActivityHelper.getInstance().showAlertDialog(thisActivity, "Error","Invalid public key.");

        }

        if(aKey1.getText().toString().length() == 0 || aKey2.getText().toString().length() == 0 ){
          err++;

          ActivityHelper.getInstance().showAlertDialog(thisActivity, "Error","Invalid Activation Key.");

        }

        if(err == 0){
          
          String message = "User added.";
          
          if(!nick.isEnabled()){
            thisContact = new File(getFilesDir(), thisContactFileName);
            thisContact.delete();
            message = "User updated.";
          }
          ConfigEntity configEntity = new ConfigEntity(nick.getText().toString(), number.getText().toString(), null, pubKey.getText().toString(), aKey1.getText().toString(), aKey2.getText().toString());
          aTaskMan = new AsyncTaskManager(thisActivity, Constants.SAVE_CONTACT_TYPE, configEntity);
          aTaskMan.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);
          
          ActivityHelper.getInstance().showAlertDialog(thisActivity, "Success", message);
          
          Intent i = new Intent(getApplicationContext(), PrivContactsActivity.class);
          startActivity(i);
        }
      }
    });

    del.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
        if(!nick.isEnabled()){
          
          thisContact = new File(getFilesDir(), thisContactFileName);
          AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
          builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
              .setNegativeButton("No", dialogClickListener).show();
          
          
        }

      }
      
      DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              switch (which){
              case DialogInterface.BUTTON_POSITIVE:
                thisContact.delete();
                onBackPressed();
                
                  break;

              case DialogInterface.BUTTON_NEGATIVE:
                  //No button clicked
                  break;
              }
          }
      };

      
    });
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    return ActivityHelper.getInstance().onOptionsItemSelected(thisActivity, item);
  }
  
  @Override
  public void onBackPressed() {
    Intent intent = new Intent(this, MainActivity.class);
    this.startActivityForResult(intent, 0);
  }
}




Java Source Code List

com.amanaje.activities.ContactDetailActivity.java
com.amanaje.activities.MainActivity.java
com.amanaje.activities.MessageActivity.java
com.amanaje.activities.NewSmsActivity.java
com.amanaje.activities.PrivContactsActivity.java
com.amanaje.activities.SettingsActivity.java
com.amanaje.activities.package-info.java
com.amanaje.asynctasks.AsyncTaskManager.java
com.amanaje.asynctasks.package-info.java
com.amanaje.commons.ActivityHelper.java
com.amanaje.commons.AppException.java
com.amanaje.commons.AppMessages.java
com.amanaje.commons.Constants.java
com.amanaje.commons.StaticObj.java
com.amanaje.commons.Utils.java
com.amanaje.commons.package-info.java
com.amanaje.crypto.CryptoUtils.java
com.amanaje.crypto.TotpImpl.java
com.amanaje.crypto.package-info.java
com.amanaje.entities.ConfigEntity.java
com.amanaje.entities.CryptoAlgoEntity.java
com.amanaje.entities.OpenPgpEntity.java
com.amanaje.entities.SmsEntity.java
com.amanaje.entities.package-info.java
com.amanaje.view.adapters.RowContactAdapter.java
com.amanaje.view.adapters.StableArrayAdapter.java
com.amanaje.view.adapters.package-info.java
org.jdamico.bc.openpgp.utils.PgpHelper.java
org.jdamico.bc.openpgp.utils.RSAKeyPairGenerator.java
org.jdamico.bc.openpgp.utils.package-info.java