Android Open Source - amanaje Message 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;
/*w  w w . jav a 2s .  co  m*/
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.concurrent.ExecutionException;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
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 android.widget.TextView;

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

public class MessageActivity extends Activity {

  private String body = null;
  private String address = null;
  private Activity thisActivity = null;
  private AsyncTaskManager aTaskMan = null;
  private SmsEntity smsEntity = null;

  private long extraEpoch = -0l;
  private String extraPubKey = null;
  private String extraSeed = null;

  TextView msgTv = null;
  EditText replyEt = null;
  Button decryptBt = null;
  Button replyBt = null;
  Button delBt = null;
  EditText privKeyPasswd = null;



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

    thisActivity = this;

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      body = extras.getString("body");
      address = extras.getString("address");

      extraPubKey  = extras.getString("pubKey");
      extraSeed  = extras.getString("seed");
      extraEpoch = extras.getLong("epoch");

      smsEntity = new SmsEntity();
      smsEntity.setAddress(address);
      smsEntity.setDate(extraEpoch);
      smsEntity.setBody(body);
      smsEntity.setPubKey(extraPubKey);
      smsEntity.setSeed(extraSeed);

      ConfigEntity cfgContactEntity = null;
      try {
        String hexNumber = Utils.getInstance().byteArrayToHexString(address.getBytes());
        String fileName = Constants.PUB_KEY_FILE_LOCATION+"."+hexNumber;
        File contactFile = new File(getFilesDir(), fileName);
        cfgContactEntity = null;
        cfgContactEntity = (Utils.getInstance().configFileToConfigEntity(contactFile));
        cfgContactEntity.setConfigFileName(fileName);
        smsEntity.setPubKey(cfgContactEntity.getPublicKey());
        smsEntity.setSeed(cfgContactEntity.getSeed());
      } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
      } catch (AppException e) {
        e.printStackTrace();
      }


    }

    msgTv = (TextView) findViewById(R.id.messageTv);
    replyBt = (Button) findViewById(R.id.replyMsgBt);
    replyBt.setEnabled(false);
    replyEt = (EditText) findViewById(R.id.replyEt);
    replyEt.setEnabled(false);
    decryptBt = (Button) findViewById(R.id.decBt);
    delBt = (Button) findViewById(R.id.delMsgBt);
    privKeyPasswd = (EditText) findViewById(R.id.privKeyPasswdEd);


    privKeyPasswd.requestFocus();

    replyBt.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {

        smsEntity.setBody(replyEt.getText().toString());
        aTaskMan = new AsyncTaskManager(thisActivity, Constants.SEND_SMS_TYPE, smsEntity);
        aTaskMan.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);

      }
    });


    
    
    decryptBt.setOnClickListener(new OnClickListener() {



      String dec = null;

      @Override
      public void onClick(View v) {

        smsEntity.setPrivKeyPasswd(privKeyPasswd.getText().toString());
        privKeyPasswd.setText("");
        privKeyPasswd.setEnabled(false);
        decryptBt.setEnabled(false);


        aTaskMan = new AsyncTaskManager(thisActivity, Constants.DEC_SMS_TYPE, smsEntity);
        aTaskMan.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, null);

        try {
          dec = aTaskMan.get();
        } catch (InterruptedException e) {
          e.printStackTrace();
        } catch (ExecutionException e) {
          e.printStackTrace();
        }

        msgTv.setText(address+": "+dec);
        if(null != dec){
          replyEt.setEnabled(true);
          replyEt.requestFocus();
          replyBt.setEnabled(true);
        }
      }
    });

    
    
  }

  @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