'Interesting/ANDROID'에 해당되는 글 50

  1. 2008.01.29 android.graphics.Path class
  2. 2008.01.09 [안드로이드]투명바탕 만들기
  3. 2007.12.14 안드로이드 : 노트패드 연습 2
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/ANDROID | Posted by hyena0 2008. 1. 9. 00:58

[안드로이드]투명바탕 만들기

투명바탕만들기

투명바탕의 APP를 만들려면 다음의 절차를 거치면 된다.

1. AndroidMenifest.xml 파일을 녹색부분과 같이 수정한다.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.android.transp">
    <application android:icon="@drawable/icon" android:theme="@android:style/Theme.Dark">
        <activity class=".transp" android:label="@string/app_name" android:theme="@style/Theme.Transparent">
            <intent-filter>
                <action android:value="android.intent.action.MAIN" />
                <category android:value="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

2. style 을 추가하고, 투명한 값의 정의를 내린다.
 개발하는 안드로이드 폴더중 values 내에 styles.xml , colors.xml 파일을 아래와 같이 추가한다.

styles.xml
<?xml version="1.0" encoding="utf-8" ?>
 <resources>
  <style name="app_name" />

 <style name="app_name.Transparent">
  <item name="android:windowBackground">@drawable/draw_background</item>
  <item name="android:windowNoTitle">true</item>
  <item name="android:foregroundColor">#fff</item>
  </style>
  </resources>

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
     <drawable name="transparent_background">#a0000000</drawable>
</resources>

3. 메인함수에서 해당  xml을 호출한다.

  setContentView(R.layout.xml_name);

Interesting/ANDROID | Posted by hyena0 2007. 12. 14. 00:13

안드로이드 : 노트패드 연습 2

노트패드 연습 2

 노트패드에 사용자 생성, 편집, 삭제 기능을 추가해 보는 것이 연습 2의 목표이다.

 . 새로운 activity를 생성하고 android manifest를 추가한다.
 . StartSubActivity()를 이용해서 다른 activity를 비동기로 일으킨다.
 . activity들 사이에 데이터 통과
 . 좀더 진보한 화면 레이아웃을 어떻게 사용하나

Step 1
 볼 것들 : String.xml , rows 에 대한 멤버변수, fillData(), onListItemClick() 와 onActivityResult(
 
Step 2
 OnCreate() 메소드를 확인한다. 연습1과 변화없다.

Step 3
 onCreateOptionMenu()에서 파란색 부분을 추가한다.

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        menu.add(0, INSERT_ID, R.string.menu_insert);
        menu.add(0, DELETE_ID, R.string.menu_delete);
        return true;
    }

Step 4
 onMenuItemSelected()에서 DELETE_ID에 대한 새로운 경우를 추가한다.

@Override
    public boolean onMenuItemSelected(int featureId, Item item) {
        super.onMenuItemSelected(featureId, item);
        switch(item.getId()) {
        case INSERT_ID:
            createNote();
            fillData();
            break;
        case DELETE_ID:
            dbHelper.deleteRow(rows.get(getSelection()).rowId);
            fillData();
            break;
        }
      
        return true;
    }

Step 5
 createNote() 메소드를 채운다. NoteEdit 클래스를 이용해서 노트(ACTIVITY_CREATE)를 생성하기 위해 새 intent를 생성한다.

Intent i = new Intent(this, NoteEdit.class);
startSubActivity(i, ACTIVITY_CREATE);


하지만 아직 NoteEdit는 생성하지 않았다. 뒤에서 보자.

Step 6
 onListItemClick()를 채우자.
사용자가 리스트로부터 아이템을 선택하므로onListItemClick()은 override 된 메소드이다.
이 메소드는 NoteEdit 클래스를 이용해서 노트를 편집하기 위해 intent를 생성한다.

        super.onListItemClick(l, v, position, id);
        Intent i = new Intent(this, NoteEdit.class);   // intent 를 생성
        i.putExtra(KEY_ROW_ID, rows.get(position).rowId); // row id 값을 가져옴
        i.putExtra(KEY_BODY, rows.get(position).body);  // body 값을 가져옴
        i.putExtra(KEY_TITLE, rows.get(position).title); // title 값을 가져옴
        startSubActivity(i, ACTIVITY_EDIT);

putExtra(String name, Object name) 은 intent에 확장된 데이터를 넣는 것이다.

Step 7
 onActivityResult를 다음과 같이 변경한다.

protected void onActivityResult(int requestCode, int resultCode, String data, Bundle extras) {
        super.onActivityResult(requestCode, resultCode, data, extras);
       
        // TODO: fill in rest of method
        switch(requestCode) {
        case ACTIVITY_CREATE:
            String title = extras.getString(KEY_TITLE);
            String body = extras.getString(KEY_BODY);
            dbHelper.createRow(title, body);
            fillData();
            break;
        case ACTIVITY_EDIT:
            Long rowId = extras.getLong(KEY_ROW_ID);
            if (rowId != null) {
                String editTitle = extras.getString(KEY_TITLE);
                String editBody = extras.getString(KEY_BODY);
                dbHelper.updateRow(rowId, editTitle, editBody);
            }
            fillData();
            break;
        }
       
    }

Step 8
 note_edit.xml 을 보라.

Step 9
android.app.Activity를 확장해서 NoteEdit 클래스를 생성한다.

Step 10, Step 11
onClick()과 onCreate() 를 채운다.

protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.note_edit);
      
        titleText = (EditText) findViewById(R.id.title);
        bodyText = (EditText) findViewById(R.id.body);
     
        Button confirmButton = (Button) findViewById(R.id.confirm);
      
        rowId = null;
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            String title = extras.getString(Notepadv2.KEY_TITLE);
            String body = extras.getString(Notepadv2.KEY_BODY);
            rowId = extras.getLong(Notepadv2.KEY_ROW_ID);
         
            if (title != null) {
                titleText.setText(title);
            }
            if (body != null) {
                bodyText.setText(body);
            }
        }
      
        confirmButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                Bundle bundle = new Bundle();
              
                bundle.putString(Notepadv2.KEY_TITLE, titleText.getText().toString());
                bundle.putString(Notepadv2.KEY_BODY, bodyText.getText().toString());
                if (rowId != null) {
                    bundle.putLong(Notepadv2.KEY_ROW_ID, rowId);
                }
              
                setResult(RESULT_OK, null, bundle);
                finish();
            }
         
        });
    }


Step 12
manifest 파일에 새로운 activity를 채운다.

<activity class=".NoteEdit"/>

Step 13

.