Android Open Source - D2D_Fountain_codes_cp Assist Activity






From Project

Back to project page D2D_Fountain_codes_cp.

License

The source code is released under:

GNU General Public License

If you think the Android project D2D_Fountain_codes_cp 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 sonic.xud.gwifisuperdownload;
/*w  ww .j av a2 s  .  c o  m*/
import java.io.File;
import java.io.FileWriter;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.LinkedHashMap;

import sonic.xud.assistclass.MobileIp;
import sonic.xud.assistclass.Signal;
import sonic.xud.assistclass.TransmitHandler;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public class AssistActivity extends Activity {

  private Context context;
  private Button beginButton;
  private ProgressBar downloadBar, transBar;
  private TextView downloadSpeedView, transSpeedView;

  private HashMap<Long, Long> speedMap = new LinkedHashMap<Long, Long>();
  private long priorTime = 0, currentTime = 0;

  // private static String TAG_LOG = "AssistActivity";

  private Handler handler = new Handler() {

    @Override
    public void handleMessage(Message msg) {
      currentTime = System.currentTimeMillis();
      Bundle data = (Bundle) msg.obj;
      long size = data.getLong("size");
      long speed = 1000*size/(currentTime-priorTime);
      speedMap.put(currentTime, speed);
      downloadSpeedView.setText(String.valueOf(speed));
      transSpeedView.setText(String.valueOf(speed));
      priorTime = currentTime;
    }
  };

  // ???????????
  private void write(HashMap<Long, Long> value) {
    try {
      File file = new File(Signal.speedPath + "assistspeed.txt");
      // ????????????
      FileWriter fileWriter = new FileWriter(file, false);
      fileWriter.write(value.toString());
      fileWriter.flush();
      fileWriter.close();
      value.clear();
    } catch (Exception e) {
      // TODO: handle exception
      e.printStackTrace();
    }
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.assist);
    init();
  }

  private void init() {
    context = AssistActivity.this;
    File file = new File(Signal.AssistPath);
    if (!file.exists()) {
      file.mkdirs();
    }
    File file2 = new File(Signal.speedPath);
    if (!file2.exists()) {
      file2.mkdirs();
    }
    downloadBar = (ProgressBar) findViewById(R.id.downloadbar);
    transBar = (ProgressBar) findViewById(R.id.transbar);
    downloadSpeedView = (TextView) findViewById(R.id.downloadspeed);
    transSpeedView = (TextView) findViewById(R.id.transmitspeed);

    beginButton = (Button) findViewById(R.id.beginBtn);
    beginButton.setOnClickListener(new OnClickListener() {

      public void onClick(View v) {
        // TODO Auto-generated method stub
        new Thread(new Runnable() {

          public void run() {
            // TODO Auto-generated method stub
            priorTime = System.currentTimeMillis();
            currentTime = System.currentTimeMillis();
            service();
          }
        }).start();
      }
    });
  }

  @Override
  protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop();
    write(speedMap);
  }

  // ???????????
  private void service() {
    try {
      InetSocketAddress inAddress = new InetSocketAddress(
          MobileIp.gprsIp(context), 8001);
      DatagramSocket insoSocket = new DatagramSocket(inAddress);
      System.err.println("????????udp?????????? " + insoSocket);
      InetSocketAddress outAddress = new InetSocketAddress(
          MobileIp.wifiIp(context), 8001);
      DatagramSocket outSocket = new DatagramSocket(outAddress);
      System.err.println("???????udp?????????? " + insoSocket);
      TransmitHandler transmitHandler = new TransmitHandler(insoSocket,
          outSocket, handler, context);
    } catch (Exception e) {
      // TODO: handle exception
    }

  }
}




Java Source Code List

cn.fudan.sonic.server.ServerFrame.java
cn.fudan.sonic.server.SingletonThreadPool.java
cn.fudan.sonic.util.SwingConsole.java
sonic.xud.assistclass.FinalDataSource.java
sonic.xud.assistclass.IPv4Util.java
sonic.xud.assistclass.MyHttpClient.java
sonic.xud.assistclass.SingletonThreadPool.java
sonic.xud.gwifisuperdownload.AssistActivity.java
sonic.xud.gwifisuperdownload.MainActivity.java
sonic.xud.gwifisuperdownload.SponsorActivity.java