'Interesting'에 해당되는 글 192

  1. 2008.01.31 [펌] 안드로이드 UDP 내용
  2. 2008.01.29 android.graphics.Path class
  3. 2008.01.16 [Macbook Air] 맥북 에어, 놀랍다...
Interesting/ANDROID | Posted by hyena0 2008. 1. 31. 00:43

[펌] 안드로이드 UDP 내용

아래는 참조용으로 사용합니다.
내용을 참조하시려면 www.anddev.org 를 보세요..
자세한 위치는 이곳 입니다.

----------------------------------------------------------------------------------------------------
 
UDP-Networking - within the Emulator


What you will learn: You will learn how to setup a UDP-Connection within the Emulator.

Question Problems/Questions: Write it right below...

Difficulty: 2 of 5 Smile

What it will look like:
"S:" stands for server, "C:" stands for Client:
Java:
D/UDP(1515): S: Connecting...
D/UDP(1515): S: Receiving...
D/UDP(1515): C: Connecting...
D/UDP(1515): C: Sending: 'Hello from Client'
D/UDP(1515): S: Received: 'Hello from Client'
D/UDP(1515): S: Done.
D/UDP(1515): C: Sent.
D/UDP(1515): C: Done.


Description:
0.) The MainActivity will do nothing, except to start 2 Threads. The first will be the Server waiting for a packet, that will be sent by the second Thread, the Client, 500ms later.
This is the simple MainActivity:
Java:
package org.anddev.android.udpconnection;

import android.app.Activity;
import android.os.Bundle;

public class UDPConnection extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
       
        /* Kickoff the Server, it will
         * be 'listening' for one client packet */

        new Thread(new Server()).start();
        /* GIve the Server some time for startup */
        try {
               Thread.sleep(500);
          } catch (InterruptedException e) { }
          
        // Kickoff the Client
        new Thread(new Client()).start();
    }
}

1.) The Server waiting for one packet.
Java:
package org.anddev.android.udpconnection;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import android.util.Log;

public class Server implements Runnable {

     public static final String SERVERIP = "127.0.0.1"; // 'Within' the emulator!
     public static final int SERVERPORT = 4444;

     @Override
     public void run() {
          try {
               /* Retrieve the ServerName */
               InetAddress serverAddr = InetAddress.getByName(SERVERIP);

               Log.d("UDP", "S: Connecting...");
               /* Create new UDP-Socket */
               DatagramSocket socket = new DatagramSocket(SERVERPORT, serverAddr);

               /* By magic we know, how much data will be waiting for us */
               byte[] buf = new byte[17];
               /* Prepare a UDP-Packet that can
                * contain the data we want to receive */

               DatagramPacket packet = new DatagramPacket(buf, buf.length);
               Log.d("UDP", "S: Receiving...");

               /* Receive the UDP-Packet */
               socket.receive(packet);
               Log.d("UDP", "S: Received: '" + new String(packet.getData()) + "'");
               Log.d("UDP", "S: Done.");
          } catch (Exception e) {
               Log.e("UDP", "S: Error", e);
          }
     }
}


2.) The Client that sends just one packet to the Server.
Java:
package org.anddev.android.udpconnection;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

import android.util.Log;

public class Client implements Runnable {
     @Override
     public void run() {
          try {
               // Retrieve the ServerName
               InetAddress serverAddr = InetAddress.getByName(Server.SERVERIP);
               
               Log.d("UDP", "C: Connecting...");
               /* Create new UDP-Socket */
               DatagramSocket socket = new DatagramSocket();
               
               /* Prepare some data to be sent. */
               byte[] buf = ("Hello from Client").getBytes();
               
               /* Create UDP-packet with
                * data & destination(url+port) */

               DatagramPacket packet = new DatagramPacket(buf, buf.length, serverAddr, Server.SERVERPORT);
               Log.d("UDP", "C: Sending: '" + new String(buf) + "'");
               
               /* Send out the packet */
               socket.send(packet);
               Log.d("UDP", "C: Sent.");
               Log.d("UDP", "C: Done.");
          } catch (Exception e) {
               Log.e("UDP", "C: Error", e);
          }
     }
}


Regards,
plusminus

_________________
| Android Development Community / Tutorials

----------------------------------------------------------------------------------------------------
Interesting/ANDROID | Posted by hyena0 2008. 1. 29. 00:20

android.graphics.Path class

android.graphics
public class

android.graphics.Path

java.lang.Object
android.graphics.Path

The Path class encapsulates compound (multiple contour) geometric paths consisting of straight line segments, quadratic curves, and cubic curves.

Nested Classes
Path.Direction Specifies how closed shapes (e.g.
Path.FillType Enum for the ways a path may be filled  

Summary

Public Constructors

          Path()
          Path(Path src)

Public Methods

        void addArc(RectF oval, float startAngle, float sweepAngle)
Add the specified arc to the path as a new contour.
        void addCircle(float x, float y, float radius, Direction dir)
Add a closed circle contour to the path
        void addOval(RectF oval, Direction dir)
Add a closed oval contour to the path
        void addPath(Path src, Matrix matrix)
Add a copy of src to the path, transformed by matrix
        void addPath(Path src)
Add a copy of src to the path
        void addPath(Path src, float dx, float dy)
Add a copy of src to the path, offset by (dx,dy)
        void addRect(RectF rect, Direction dir)
Add a closed rectangle contour to the path
        void addRect(float left, float top, float right, float bottom, Direction dir)
Add a closed rectangle contour to the path
        void addRoundRect(RectF rect, float rx, float ry, Direction dir)
Add a closed round-rectangle contour to the path
        void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)
Append the specified arc to the path as a new contour.
        void close()
Close the current contour.
        void computeBounds(RectF bounds, boolean exact)
Compute the bounds of the path, and write the answer into bounds.
        void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3).
        FillType  getFillType()
Return the path's fill type.
        void incReserve(int extraPtCount)
Hint to the path to prepare for adding more points.
        boolean isEmpty()
Returns true if the path is empty (contains no lines or curves)
        boolean isRect(RectF rect)
Returns true if the path specifies a rectangle.
        void lineTo(float x, float y)
Add a line from the last point to the specified point (x,y).
        void moveTo(float x, float y)
Set the beginning of the next contour to the point (x,y).
        boolean offset(float dx, float dy)
Offset the path by (dx,dy), returning true on success
        boolean offset(float dx, float dy, Path dst)
Offset the path by (dx,dy), returning true on success
        void quadTo(float x1, float y1, float x2, float y2)
Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2).
        void rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3)
Same as cubicTo, but the coordinates are considered relative to the current point on this contour.
        void rLineTo(float dx, float dy)
Same as lineTo, but the coordinates are considered relative to the last point on this contour.
        void rMoveTo(float dx, float dy)
Set the beginning of the next contour relative to the last point on the previous contour.
        void rQuadTo(float dx1, float dy1, float dx2, float dy2)
Same as quadTo, but the coordinates are considered relative to the last point on this contour.
        void reset()
Clear any lines and curves from the path, making it empty.
        void set(Path src)
Replace the contents of this with the contents of src.
        void setFillType(FillType ft)
Set the path's fill type.
        boolean transform(Matrix matrix)
Transform the points in this path by matrix, and write the answer into dst.
        boolean transform(Matrix matrix, Path dst)
Transform the points in this path by matrix, and write the answer into dst.

Protected Methods

        void finalize()
Called by the virtual machine when there are no longer any (non-weak) references to the receiver.
Methods inherited from class java.lang.Object

Details

Public Constructors

public Path()

public Path(Path src)

Public Methods

public void addArc(RectF oval, float startAngle, float sweepAngle)

Add the specified arc to the path as a new contour.

Parameters

oval The bounds of oval used to define the shape and size of the arc
startAngle Starting angle (in degrees) where the arc begins
sweepAngle Sweep angle (in degrees) measured clockwise

public void addCircle(float x, float y, float radius, Direction dir)

Add a closed circle contour to the path

Parameters

x The x-coordinate of the center of a circle to add as a closed contour to the path
y The y-coordinate of the center of a circle to add as a closed contour to the path
radius The radius of a circle to add as a closed contour to the path
dir The direction to wind the circle's contour

public void addOval(RectF oval, Direction dir)

Add a closed oval contour to the path

Parameters

oval The bounds of the oval to add as a closed contour to the path
dir The direction to wind the oval's contour

public void addPath(Path src, Matrix matrix)

Add a copy of src to the path, transformed by matrix

Parameters

src The path to add as a new contour

public void addPath(Path src)

Add a copy of src to the path

public void addPath(Path src, float dx, float dy)

Add a copy of src to the path, offset by (dx,dy)

Parameters

src The path to add as a new contour
dx The amount to translate the path in X as it is added

public void addRect(RectF rect, Direction dir)

Add a closed rectangle contour to the path

Parameters

rect The rectangle to add as a closed contour to the path
dir The direction to wind the rectangle's contour

public void addRect(float left, float top, float right, float bottom, Direction dir)

Add a closed rectangle contour to the path

Parameters

left The left side of a rectangle to add as a closed contour to the path
top The top of a rectangle to add as a closed contour to the path
right The right side of a rectangle to add as a closed contour to the path
bottom The bottom of a rectangle to add as a closed contour to the path
dir The direction to wind the rectangle's contour

public void addRoundRect(RectF rect, float rx, float ry, Direction dir)

Add a closed round-rectangle contour to the path

Parameters

rect The bounds of a round-rectangle to add as a closed contour to the path
rx The x-radius of the rounded corners on the round-rectangle
ry The y-radius of the rounded corners on the round-rectangle
dir The direction to wind the round-rectangle's contour

public void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo)

Append the specified arc to the path as a new contour. If the start of the path is different from the path's current last point, then an automatic lineTo() is added to connect the current contour to the start of the arc. However, if the path is empty, then we call moveTo() with the first point of the arc.

Parameters

oval The bounds of oval used to define the shape and size of the arc
startAngle Starting angle (in degrees) where the arc begins
sweepAngle Sweep angle (in degrees) measured clockwise
forceMoveTo If true, always begin a new contour with the arc

public void close()

Close the current contour. If the current point is not equal to the first point of the contour, a line segment is automatically added.

public void computeBounds(RectF bounds, boolean exact)

Compute the bounds of the path, and write the answer into bounds. If the path contains 0 or 1 points, the bounds is set to (0,0,0,0)

Parameters

bounds Returns the computed bounds of the path
exact If true, return the exact (but slower) bounds, else return just the bounds of all control points

public void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters

x1 The x-coordinate of the 1st control point on a cubic curve
y1 The y-coordinate of the 1st control point on a cubic curve
x2 The x-coordinate of the 2nd control point on a cubic curve
y2 The y-coordinate of the 2nd control point on a cubic curve
x3 The x-coordinate of the end point on a cubic curve
y3 The y-coordinate of the end point on a cubic curve

public FillType getFillType()

Return the path's fill type. This is used to define how "inside" is computed. The default value is WINDING.

Returns

  • the path's fill type

public void incReserve(int extraPtCount)

Hint to the path to prepare for adding more points. This can allow the path to more efficiently grow its storage.

Parameters

extraPtCount The number of extra points that may be added to this path

public boolean isEmpty()

Returns true if the path is empty (contains no lines or curves)

Returns

  • true if the path is empty (contains no lines or curves)

public boolean isRect(RectF rect)

Returns true if the path specifies a rectangle. If so, and if rect is not null, set rect to the bounds of the path. If the path does not specify a rectangle, return false and ignore rect.

Parameters

rect If not null, returns the bounds of the path if it specifies a rectangle

Returns

  • true if the path specifies a rectangle

public void lineTo(float x, float y)

Add a line from the last point to the specified point (x,y). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters

x The x-coordinate of the end of a line
y The y-coordinate of the end of a line

public void moveTo(float x, float y)

Set the beginning of the next contour to the point (x,y).

Parameters

x The x-coordinate of the start of a new contour
y The y-coordinate of the start of a new contour

public boolean offset(float dx, float dy)

Offset the path by (dx,dy), returning true on success

Parameters

dx The amount in the X direction to offset the entire path
dy The amount in the Y direction to offset the entire path

Returns

  • true

public boolean offset(float dx, float dy, Path dst)

Offset the path by (dx,dy), returning true on success

Parameters

dx The amount in the X direction to offset the entire path
dy The amount in the Y direction to offset the entire path
dst The translated path is written here. Pass null to overwrite this path

Returns

  • true

public void quadTo(float x1, float y1, float x2, float y2)

Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for this contour, the first point is automatically set to (0,0).

Parameters

x1 The x-coordinate of the control point on a quadratic curve
y1 The y-coordinate of the control point on a quadratic curve
x2 The x-coordinate of the end point on a quadratic curve
y2 The y-coordinate of the end point on a quadratic curve

public void rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3)

Same as cubicTo, but the coordinates are considered relative to the current point on this contour. If there is no previous point, then a moveTo(0,0) is inserted automatically.

public void rLineTo(float dx, float dy)

Same as lineTo, but the coordinates are considered relative to the last point on this contour. If there is no previous point, then a moveTo(0,0) is inserted automatically.

Parameters

dx The amount to add to the x-coordinate of the previous point on this contour, to specify a line
dy The amount to add to the y-coordinate of the previous point on this contour, to specify a line

public void rMoveTo(float dx, float dy)

Set the beginning of the next contour relative to the last point on the previous contour. If there is no previous contour, this is treated the same as moveTo().

Parameters

dx The amount to add to the x-coordinate of the end of the previous contour, to specify the start of a new contour
dy The amount to add to the y-coordinate of the end of the previous contour, to specify the start of a new contour

public void rQuadTo(float dx1, float dy1, float dx2, float dy2)

Same as quadTo, but the coordinates are considered relative to the last point on this contour. If there is no previous point, then a moveTo(0,0) is inserted automatically.

Parameters

dx1 The amount to add to the x-coordinate of the last point on this contour, to specify the control point of a quadratic curve
dy1 The amount to add to the y-coordinate of the last point on this contour, to specify the control point of a quadratic curve
dx2 The amount to add to the x-coordinate of the last point on this contour, to specify the end point of a quadratic curve
dy2 The amount to add to the y-coordinate of the last point on this contour, to specify the end point of a quadratic curve

public void reset()

Clear any lines and curves from the path, making it empty. This does NOT change the fill-type setting.

public void set(Path src)

Replace the contents of this with the contents of src.

public void setFillType(FillType ft)

Set the path's fill type. This is used to define how "inside" is computed.

Parameters

ft The new fill type for this path

public boolean transform(Matrix matrix)

Transform the points in this path by matrix, and write the answer into dst.

Parameters

matrix The matrix to apply to the path

Returns

  • true

public boolean transform(Matrix matrix, Path dst)

Transform the points in this path by matrix, and write the answer into dst.

Parameters

matrix The matrix to apply to the path
dst The transformed path is written here. Pass null to overwrite this path

Returns

  • true

Protected Methods

protected void finalize()

Called by the virtual machine when there are no longer any (non-weak) references to the receiver. Subclasses can use this facility to guarantee that any associated resources are cleaned up before the receiver is garbage collected. Uncaught exceptions which are thrown during the running of the method cause it to terminate immediately, but are otherwise ignored.

Note: The virtual machine assumes that the implementation in class Object is empty.

Throws

Throwable java.lang.Throwable
Interesting/Apple | Posted by hyena0 2008. 1. 16. 23:00

[Macbook Air] 맥북 에어, 놀랍다...

Macbook Air

 Macworld 2008에서 스티브 잡스가 소개한 Macbook Air는 말그대로 충격 그 자체였다.

사용자 삽입 이미지

 서류봉투에서 꺼내진 노트북의 얇기는 정말 서류 뭉치를 방불케 했고, 디자인과 성능또한 현재 다른 노트북과 비교가 되지 않을 정도였다.

사용자 삽입 이미지

 게다가 멀티터치를 지원하는 터치패드는 아이폰에서 보여주었던 기능을 그대로 가지고 있었다.

 인텔과 협력하여 훨씬 작아진  Core2Duo CPU 를 탑재한 맥북 에어는 그야말로 탄성이 절로 나오는 제품이다.
사용자 삽입 이미지

 Display 역시 LCD가 아니라 smart LED로 되어 있어서 얇은 본체를 유지할 수 있고, 파격적으로 단순화 시킨 외부입출력장치는 USB 와 mini DVI 만을 제공한다.

 그럼 인터넷은 어떻게 하냐고? 당연히 무선랜으로 이용하게 된다. 철저히 휴대성을 강조하고 단순함을 극대화 시키기 위해 디자인 했다는 느낌을 받게 만든다.

 아래의 가이드 투어를 보면 제품의 사용법과 프로그램 설치방법 등이 자세히 설명된다.