2011년 3월 30일 수요일
Failed to install user.apk on device 'Mxxxxxxx': timeout
2011년 3월 13일 일요일
Couldn't get connection factory client
2. cmd창의 경로를 아래와 같이 이동합니다.(전 윈7이며 제컴퓨터 기준으로 한거랍니다.)
C:\Users\mycomputer\.android
3. 아래 명령어를 입력한다.
keytool -list -alias androiddebugkey -keystore debug.keystore -storepass android -keypass android
4. 나온 인증서지문(MD5)를 복사한다.
5. http://code.google.com/intl/ko-KR/android/maps-api-signup.html 페이지에 가서 동의를 클릭하고 복사한 인증서 지문을 붙여넣어 오케이 한다.
2010년 5월 22일 토요일
Spinner : Changing Header Text Color
1) main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Spinner android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"/>
</LinearLayout>
2) SpinnerDemo.java
package com.commonsware.android.selection;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class SpinnerDemo extends Activity
implements AdapterView.OnItemSelectedListener {
TextView selection;
String[] items={"a", "b", "c", "d", "e",
"e", "f", "g", "h", "i",
"j", "k", "l", "james", "m"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection=(TextView)findViewById(R.id.selector);
Spinner spin=(Spinner)findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter<String> aa=new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
items);
aa.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
public void onItemSelected(AdapterView<?> parent,
View v, int position, long id) {
selection.setText(items[position]);
((TextView)parent.getChildAt(0)).setTextColor(Color.RED);
// Of cause, This source is abailable for index number more than 0.
}
public void onNothingSelected(AdapterView<?> parent) {
selection.setText("");
}
}
Reference source : http://apress.com
2010년 4월 26일 월요일
Access SDCard
C:\>mksdcard 256M c:\sd.img
C:\>dir c:\sd.img
C 드라이브의 볼륨에는 이름이 없습니다.
볼륨 일련 번호: D88A-40A9
c:\ 디렉터리
2010-04-27 오전 09:49 268,435,456 sd.img
1개 파일 268,435,456 바이트
0개 디렉터리 68,453,728,256 바이트 남음
2010년 4월 14일 수요일
Weather Program
1) Class Diagram
2) Widget Images
3) Google Weather API example
http://www.google.co.uk/ig/api?weather=london
<?xml version="1.0" ?>
2010년 4월 13일 화요일
Use SurfaceView
1) /MyGraphics2D02/src/my/MyGraphics2D02/MyGraphics2D02.java
package my.MyGraphics2D02;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
public class MyGraphics2D02 extends Activity {
class GraphicIcon { // 새로운 비트맵 아이콘들을 생성하기 위한 클래스를 추가
private Bitmap bm;
private Coordinates co; // 좌표처리
public GraphicIcon(Bitmap bitmap) {
bm = bitmap;
co = new Coordinates();
}
public Bitmap getGraphic() {
return bm;
}
public Coordinates getCoordinates() {
return co;
}
public class Coordinates {
private int x = 0;
private int y = 0;
public int getX() {
return x;
}
public void setX(int value) {
x = value - bm.getWidth() / 2;
}
public int getY() {
return y;
}
public void setY(int value) {
y = value - bm.getHeight() / 2;
}
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Enable extended window features. This is a convenience for calling getWindow().requestFeature().
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(new CustomView(this));
}
class CustomView extends SurfaceView implements SurfaceHolder.Callback {
private CustomViewThread CVThread;
// ArrayList Graphics는 GraphicIcon클래스를 사용해 생성한 객체들을 저장
private ArrayList<GraphicIcon> graphics = new ArrayList<GraphicIcon>();
private int x = 70;
private int y = 70;
public CustomView(Context context) {
super(context);
getHolder().addCallback(this);
CVThread = new CustomViewThread(getHolder(), this);
setFocusable(true); // 해당 View가 touch mode에서 Focus가 가도록 지정합니다.
}
@Override
public void onDraw(Canvas canvas) {
Bitmap bm;
canvas.drawColor(Color.parseColor("#dedede"));
GraphicIcon.Coordinates co;
// For문 : ArrayList graphics에 들어 있는 객체들을 하나씩 꺼내어 graphic변수에 저장하여 그림을 그림.
for (GraphicIcon graphic : graphics) {
bm = graphic.getGraphic();
co = graphic.getCoordinates();
canvas.drawBitmap(bm, co.getX(), co.getY(), null);
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
CVThread.setRunning(true);
CVThread.start();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
CVThread.setRunning(false);
while (retry) {
try {
CVThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
}
public boolean onTouchEvent(MotionEvent event) {
synchronized (CVThread.getSurfaceHolder()) { // ConcurrentModificationException 처리
if(event.getAction()==MotionEvent.ACTION_DOWN){ //드레그해도 연속으로 생성되지 않게 함.
GraphicIcon graphic = new GraphicIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
graphic.getCoordinates().setX((int) event.getX());
graphic.getCoordinates().setY((int) event.getY());
graphics.add(graphic);
}
return true;
}
}
}
class CustomViewThread extends Thread {
private SurfaceHolder surfaceholder;
private CustomView customview;
private boolean running = false;
public SurfaceHolder getSurfaceHolder() {
return surfaceholder;
}
public CustomViewThread(SurfaceHolder surfaceHolder, CustomView CustomView) {
surfaceholder = surfaceHolder;
customview = CustomView;
}
public void setRunning(boolean run) {
running = run;
}
@Override
public void run() {
Canvas c;
while (running) {
c = null;
try {
c = surfaceholder.lockCanvas(null);
synchronized (surfaceholder) {
customview.onDraw(c);
}
} finally {
if (c != null) {
surfaceholder.unlockCanvasAndPost(c);
}
}
}
}
}
}
2) Result image
Reference http://www.androidside.com
2010년 4월 12일 월요일
Google MapView in Android
1) System confirm path
내컴퓨터 > 고급 > 환경변수 > path >
Add this path :
C:\android\tools;C:\Program Files\Java\jdk1.6.0_17\bin
2) Get the API Key
C:\>cd C:\Documents and Settings\%username%\.android\
C:\Documents and Settings\jp\.android>keytool -list -alias androiddebugkey -keys
tore debug.keystore -storepass android -keypass android
androiddebugkey, 2010. 4. 12, PrivateKeyEntry,
인증서 지문(MD5): B1:B9:5F:01??????????????????:27:BF:29:FA:67:5C:26
http://code.google.com/intl/ko/android/maps-api-signup.html
Sign Up for the Android Maps API
3) Create AVD
over level Google APIs Level 6
4) Create project
5) /HelloMyMap/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.HelloMyMap"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".HelloMyMap"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="6" />
</manifest>
6) /HelloMyMap/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="00Q8dPkiSL???????????????v-PfctrXmOFA"
/>
</RelativeLayout>
7) /HelloMyMap/src/my/HelloMyMap/HelloItemizedOverlay.java
package my.HelloMyMap;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
public class HelloItemizedOverlay extends ItemizedOverlay {
private Context mContext;
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
// TODO Auto-generated constructor stub
mContext = context;
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mOverlays.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return mOverlays.size();
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
8) /HelloMyMap/src/my/HelloMyMap/HelloMyMap.java
package my.HelloMyMap;
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ZoomControls;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class HelloMyMap extends MapActivity {
List<Overlay> mapOverlays;
Drawable drawable;
HelloItemizedOverlay itemizedOverlay;
LinearLayout linearLayout;
MapView mapView;
ZoomControls mZoom;
@Override
protected boolean isRouteDisplayed() {
return false;
}
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.setSatellite(false);
GeoPoint p=new GeoPoint(53458671,-2267346);
MapController mc=mapView.getController();
mc.animateTo(p);
mc.setZoom(5);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.androidmarker);
itemizedOverlay = new HelloItemizedOverlay(drawable,this);
OverlayItem overlayitem = new OverlayItem(p, "Hello", "Man Utd.");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
}
}
9) Result Images
Reference http://www.androidside.com
TabWidget
1) /HelloTabWidget/res/values/attr.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>
2) /HelloTabWidget/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is another tab">
<TextView
android:id="@+textview2/dateDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""/>
<Button
android:id="@+textview2/pickDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change the date"/>
</LinearLayout>
<TextView
android:id="@+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
</FrameLayout>
</LinearLayout>
</TabHost>
3) /HelloTabWidget/src/my/HelloTabWidget/HelloTabWidget.java
package my.HelloTabWidget;
import java.util.Calendar;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class HelloTabWidget extends TabActivity {
TabHost mTabHost = null;
private TextView mDateDisplay;
private Button mPickDate;
private int mYear;
private int mMonth;
private int mDay;
static final int DATE_DIALOG_ID = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1", getResources().getDrawable(R.drawable.icon1)).setContent(R.id.gallery));
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2", getResources().getDrawable(R.drawable.icon2)).setContent(R.id.textview2));
mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3", getResources().getDrawable(R.drawable.icon3)).setContent(R.id.textview3));
mTabHost.setCurrentTab(0);
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position, long id) {
Toast.makeText(HelloTabWidget.this, "" + (position+1), Toast.LENGTH_SHORT).show();
}
});
// capture our View elements
mDateDisplay = (TextView) findViewById(R.textview2.dateDisplay);
mPickDate = (Button) findViewById(R.textview2.pickDate);
// add a click listener to the button
mPickDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
// get the current date
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
// display the current date
updateDisplay();
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
}
return null;
}
private void updateDisplay() {
mDateDisplay.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(mYear).append("-")
.append(mMonth + 1).append("-")
.append(mDay).append(" "));
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
}
};
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Context mContext;
private Integer[] mImageIds = {
R.drawable.f1,
R.drawable.f2,
R.drawable.f3,
R.drawable.f4,
R.drawable.f5,
R.drawable.f6
};
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(
R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);
return i;
}
}
}
4) Relsult Images
Form configuration components
Linear Layout Example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:text="red"
android:gravity="center_horizontal"
android:background="#aa0000"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="green"
android:gravity="center_horizontal"
android:background="#00aa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="blue"
android:gravity="center_horizontal"
android:background="#0000aa"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<TextView
android:text="yellow"
android:gravity="center_horizontal"
android:background="#aaaa00"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<Button
android:text="row one"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="row two"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="row three"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:text="row four"
android:textSize="15pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Reference http://www.androidside.com