Android Open Source - android_smsoverxmpp Main Activity






From Project

Back to project page android_smsoverxmpp.

License

The source code is released under:

GNU General Public License

If you think the Android project android_smsoverxmpp 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.smorra.smsoverxmpp;
//from  w ww  .  j  av  a2 s.c  o m
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.security.cert.Certificate;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Calendar;
import java.util.Enumeration;

import org.spongycastle.asn1.ASN1InputStream;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.x500.X500Name;
import org.spongycastle.asn1.x509.SubjectPublicKeyInfo;
import org.spongycastle.cert.X509CertificateHolder;
import org.spongycastle.cert.X509v3CertificateBuilder;
import org.spongycastle.cert.jcajce.JcaX509CertificateConverter;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.spongycastle.operator.ContentSigner;
import org.spongycastle.operator.jcajce.JcaContentSignerBuilder;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class MainActivity extends ActionBarActivity implements OnClickListener
{

  public static MainActivity singleton;
  public static IpReceiver ipReceiver;
  


  @Override
  protected void onDestroy()
  {
    singleton = null;
    unregisterReceiver(ipReceiver);
    ipReceiver = null;
    super.onDestroy();
  }

  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    System.out.println("PW IS " + Util.getPw(this));
    System.out.println("Creating socket");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



    LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
    AdView mAdView = new AdView(this);
    mAdView.setAdUnitId("ca-app-pub-5240245808933327/7911141092");
    mAdView.setAdSize(AdSize.BANNER);
    layout.addView(mAdView, 0);
    mAdView.loadAd(new AdRequest.Builder().build());

    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(this);

    b = (Button) findViewById(R.id.button2);
    b.setOnClickListener(this);
    singleton = this;

    updateIp();

    final EditText ed = (EditText) findViewById(R.id.editText1);
    ed.setFocusableInTouchMode(true);

    

    // Password
    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    if (!sharedPref.contains("pw"))
    {
      Editor e = sharedPref.edit();
      e.putString("pw", Util.generateHex(6));
      e.commit();
    }
    ed.setText(sharedPref.getString("pw", ""));
    ed.addTextChangedListener(new TextWatcher()
    {

      @Override
      public void afterTextChanged(Editable arg0)
      {
        Editor e = sharedPref.edit();
        e.putString("pw", ed.getText().toString());
        e.commit();
      }

      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after)
      {
        // TODO Auto-generated method stub

      }

      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count)
      {
        // TODO Auto-generated method stub

      }

    });

    ipReceiver = new IpReceiver();
    registerReceiver(ipReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

  }

  void updateIp()
  {
    TextView tv1 = (TextView) findViewById(R.id.textView2);
    String ip = null;
    try
    {
      ip = ip();
    }
    catch (SocketException e)
    {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    if (ip == null)
      tv1.setText("Not connected");
    else
      tv1.setText(ip);
  }

  static String ip() throws SocketException
  {
    Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
    NetworkInterface ni;
    while (nis.hasMoreElements())
    {
      ni = nis.nextElement();
      if (!ni.isLoopback()/* not loopback */&& ni.isUp()/* it works now */)
      {
        for (InterfaceAddress ia : ni.getInterfaceAddresses())
        {
          // filter for ipv4/ipv6
          if (ia.getAddress().getAddress().length == 4)
          {
            // 4 for ipv4, 16 for ipv6
            return ia.getAddress().getHostAddress();
          }
        }
      }
    }
    return null;
  }

  @Override
  public void onClick(View arg0)
  {
    if (arg0 == findViewById(R.id.button1))
    {
      startService(new Intent(this, Service_.class));
    }
    else if (arg0 == findViewById(R.id.button2))
    {
      System.out.println("stopping.....");
      stopService(new Intent(this, Service_.class));

    }
  }
}




Java Source Code List

com.smorra.smsoverxmpp.BootReceiver.java
com.smorra.smsoverxmpp.Client.java
com.smorra.smsoverxmpp.Contact.java
com.smorra.smsoverxmpp.IpReceiver.java
com.smorra.smsoverxmpp.MainActivity.java
com.smorra.smsoverxmpp.PhoneNumber.java
com.smorra.smsoverxmpp.Server.java
com.smorra.smsoverxmpp.Service_.java
com.smorra.smsoverxmpp.SmsReceiver.java
com.smorra.smsoverxmpp.Util.java