Android Open Source - MakeWithMotoSampleApp Utils






From Project

Back to project page MakeWithMotoSampleApp.

License

The source code is released under:

GNU General Public License

If you think the Android project MakeWithMotoSampleApp 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.makewithmoto.fragments;
/**//  ww  w  . j  a  v a 2s . c o m
 * Class containing some useful functions when working with graphics 
 * 
 * taken from Processing.org source code 
 * 
 */


import java.io.OutputStream;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

import android.graphics.Bitmap;
import android.view.View;

public class Utils {

  static public int getAge(int _year, int _month, int _day) {

    GregorianCalendar cal = new GregorianCalendar();
    int y, m, d, a;

    y = cal.get(Calendar.YEAR);
    m = cal.get(Calendar.MONTH);
    d = cal.get(Calendar.DAY_OF_MONTH);
    cal.set(_year, _month, _day);
    a = y - cal.get(Calendar.YEAR);
    if ((m < cal.get(Calendar.MONTH))
        || ((m == cal.get(Calendar.MONTH)) && (d < cal.get(Calendar.DAY_OF_MONTH)))) {
      --a;
    }
    if (a < 0)
      throw new IllegalArgumentException("Age < 0");
    return a;
  }

  //TODO: activar el jpeg provider
  public void handleConnection(Socket socket /* ,JpegProvider jpegProvider */) throws Exception {
    // byte[] data = jpegProvider.getJpeg();
    OutputStream outputStream = socket.getOutputStream();
    outputStream
        .write(("HTTP/1.0 200 OK\r\n" + "Server: YourServerName\r\n"
            + "Connection: close\r\n" + "Max-Age: 0\r\n" + "Expires: 0\r\n"
            + "Cache-Control: no-cache, private\r\n" + "Pragma: no-cache\r\n"
            + "Content-Type: multipart/x-mixed-replace; "
            + "boundary=--BoundaryString\r\n\r\n").getBytes());
    while (true) {
      // data = jpegProvider.getJpeg();
      outputStream.write(("--BoundaryString\r\n" + "Content-type: image/jpg\r\n"
          + "Content-Length: " +
          // data.length +
          "\r\n\r\n").getBytes());
      // outputStream.write(data);
      outputStream.write("\r\n\r\n".getBytes());
      outputStream.flush();
    }
  } 

  static public void rescale(View view) {
    Bitmap originalImage = null;

    originalImage = Bitmap.createScaledBitmap(originalImage, view.getWidth(), view.getHeight(),
        true);

  }

  static public String getCurrentTime() {

    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); 
    return sdf.format(cal.getTime());

  } 
  
  
  public static String bytetostring(byte[] b) {
    int j = 0, in = 0;
    String[] hex = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E",
        "F" };
    String out = "";

    for (int i = 0; i < b.length; ++i) {
      in = (int) b[i] & 0x0f;
      j = (in >> 4) & 0x0f;
      out += hex[j];
      j = in & 0xf;
      out += hex[j];

    }

    return out;
  } 



}




Java Source Code List

android_serialport_api.SerialPort.java
com.makewithmoto.boards.MAKr.java
com.makewithmoto.boards.MIOIOListener.java
com.makewithmoto.bt.BluetoothSerialService.java
com.makewithmoto.bt.BluetoothViewer.java
com.makewithmoto.bt.DeviceListActivity.java
com.makewithmoto.bt.SimpleBT.java
com.makewithmoto.example.ActivityBT.java
com.makewithmoto.example.ActivityMAKr.java
com.makewithmoto.example.ActivityMOIO.java
com.makewithmoto.example.Application.java
com.makewithmoto.example.LauncherActivity.java
com.makewithmoto.extras.AccelerometerManager.java
com.makewithmoto.extras.CustomSensorListener.java
com.makewithmoto.extras.CustomSensorManager.java
com.makewithmoto.extras.WhatIsRunningInterface.java
com.makewithmoto.extras.WhatIsRunning.java
com.makewithmoto.fragments.CameraFragment.java
com.makewithmoto.fragments.DebugFragment.java
com.makewithmoto.fragments.EmptyFragment.java
com.makewithmoto.fragments.GraphFragment.java
com.makewithmoto.fragments.ImageFragment.java
com.makewithmoto.fragments.Utils.java
com.makewithmoto.fragments.VideoPlayerFragment.java
com.makewithmoto.fragments.VideoTextureFragment.java
com.makewithmoto.views.CanvasUtils.java
com.makewithmoto.views.PlotView.java