웹에 있는 이미지를 읽어서 ImageView에 출력

[code java]
package yell.exam01;

import java.io.FileOutputStream;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import yell.exam01.R;

public class test_network extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_network);
}

public void mOnClick(View v) {

EditText et = (EditText) findViewById(R.id.textURL);
ImageView iv = (ImageView) findViewById(R.id.imageview1);

if (et.getText().toString() != null) {
try {
HttpGet httpget = new HttpGet(et.getText().toString());
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(httpget);
InputStream is = new BufferedHttpEntity(response.getEntity()).getContent();

Bitmap bit = BitmapFactory.decodeStream(is);
iv.setImageBitmap(bit);

String path = Environment.getDataDirectory().getAbsolutePath();
path += “/data/yell.exam01/files/test.png”;

Log.d(“YELL”, path);
FileOutputStream fos = new FileOutputStream(path);
bit.compress(Bitmap.CompressFormat.PNG, 100, fos);
}
catch (Exception e) {
// TODO: handle exception
Log.d(“YELL”, e.getMessage());
}
}
}
}
[/code]

쓰레드를 사용해서 웹페이지 소스 가져오기

[code java]
package yell.exam01;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import yell.exam01.R;

public class test_network extends Activity {

downloadThread mThread;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_network);
}

public void mOnClick(View v) {

EditText et = (EditText) findViewById(R.id.textURL);
ImageView iv = (ImageView) findViewById(R.id.imageview1);

if (et.getText().toString() != null) {
mThread = new downloadThread(et.getText().toString());
mThread.start();
}
}

class downloadThread extends Thread {
String mAddr;

public downloadThread(String addr) {
// TODO Auto-generated constructor stub
mAddr = addr;
}

@Override
public void run() {
// TODO Auto-generated method stub
HttpGet httpget = new HttpGet(mAddr);
DefaultHttpClient client = new DefaultHttpClient();
try {
client.execute(httpget, mResHandler);
}
catch (Exception e) {
// TODO: handle exception
}
}

ResponseHandler mResHandler = new ResponseHandler() {
public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
// TODO Auto-generated method stub

Log.d(“YELL”, “읽기 스트림 시작”);

StringBuilder html = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while ((line = br.readLine()) != null) {
html.append(line + “\n”);
}
br.close();

Log.d(“YELL”, “끗~ 메시지 보냄”);
Log.d(“YELL”, html.substring(0, 1000).toString());

Message message = mAfterDown.obtainMessage();
Bundle bundle = new Bundle();
bundle.putString(“result”, html.toString());
message.setData(bundle);
mAfterDown.sendMessage(message);
}
catch (Exception e) {
// TODO: handle exception
}

return html.toString();
}
};

Handler mAfterDown = new Handler() {
public void handleMessage(android.os.Message msg) {
String sResult = msg.getData().getString(“result”);
TextView tv = (TextView) findViewById(R.id.textview_result);
tv.setText(sResult);
};
};
}
}
[/code]

탭(TabHost, TabWidget)

[code java]




[/code]
[code java]
public class TabTest extends TabActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_test);

TabHost mTab = getTabHost();
Intent intent;

intent = new Intent().setClass(this, Tab01.class);
mTab.addTab(mTab.newTabSpec(“tag1”).setIndicator(“TAB1”).setContent(intent));

intent = new Intent().setClass(this, Tab02.class);
mTab.addTab(mTab.newTabSpec(“tag2”).setIndicator(“TAB2”).setContent(intent));

intent = new Intent().setClass(this, Tab03.class);
mTab.addTab(mTab.newTabSpec(“tag3”).setIndicator(“TAB3”).setContent(intent));

mTab.setCurrentTab(0);
}
}
[/code]

암시적 인텐트

[code java]
public void mOnClick(View v) {
Intent intent;
switch (v.getId()) {
case R.id.btnWeb:
intent = new Intent(Intent.ACTION_VIEW, Uri.parse(“http://www.yell.co.kr”));
startActivity(intent);
break;

case R.id.btnCall:
intent = new Intent(Intent.ACTION_DIAL, Uri.parse(“tel:010-1234-5678”));
startActivity(intent);
break;

case R.id.btnPhoto:
intent = new Intent(Intent.ACTION_VIEW);
String sd = Environment.getExternalStorageDirectory().getAbsolutePath();
Uri uri = Uri.fromFile(new File(sd + “/devil.jpg”));
intent.setDataAndType(uri, “image/jpeg”);
startActivity(intent);
break;

default:
break;
}
}
[/code]

액티비티간의 통신

[Codejava]
package yell.exam01;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Exam01Activity extends Activity {

TextView mText;
final static int ACT_EDIT = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);

mText = (TextView) findViewById(R.id.textView1);
}

public void modifyText(View v) {
switch (v.getId()) {
case R.id.btnModify:
Intent intent = new Intent(this, Exam01_modifyText.class);
intent.putExtra(“TextIn”, mText.getText().toString());
startActivityForResult(intent, ACT_EDIT);
break;

default:
break;
}
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACT_EDIT:
if (resultCode == RESULT_OK) {
mText.setText(data.getStringExtra(“TextOut”));
}
break;

default:
break;
}
}

public void showSubActivity(View v) {
Intent intent = new Intent(this, Exam01SubActivity.class);
startActivity(intent);
}
}
[/code]

[code java]
package yell.exam01;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Exam01_modifyText extends Activity {

EditText mEdit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.modifytext);

mEdit = (EditText) findViewById(R.id.editText1);

Intent intent = getIntent();
String text = intent.getStringExtra(“TextIn”);
if (text != null) {
mEdit.setText(text);
}
}

public void mOnClick(View v) {
switch (v.getId()) {
case R.id.btnOk:
Intent intent = new Intent();
intent.putExtra(“TextOut”, mEdit.getText().toString());
setResult(RESULT_OK, intent);
finish();
break;

default:
setResult(RESULT_CANCELED);
finish();
break;
}
}
}
[/code]

이벤트 처리 > 익명 이너 클래스를 바로 사용

[code java]
package yell.exam01;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

public class Exam01Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout linear = new LinearLayout(this);
linear.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_DOWN ) {
Toast.makeText(Exam01Activity.this, “Touched!!!”, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
setContentView(linear);
}
}
[/code]

LinearLayout 객체를 생성한 뒤, 터치 리스너를 등록했다.

리스너에는 MotionEvent.ACTION_DOWN 즉, 화면 터치시 “Touched!!!”를 출력하도록 했다.

여러가지 이벤트 처리방법이 있는데 가장 간편한 방법이다.

jQuery UI Datepicker() / HTML Parsing Error – KB927917

사용자 삽입 이미지

HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917)

jQuery UI 에서 Datapicker 를 사용할 때 인터넷 익스플로러에서 위와 같은 오류가 나올 때가 있다.
항상 오류가 나타나는 것은 아니며,
몇몇 컴퓨터에서만 나타나는 현상이다

[소스]
<input type=”text” id=”sdate” name=”sdate” size=”12″ value=”” />
<script type=”text/javascript”>
<!–
    $(“#sdate”).datepicker({dateFormat: “yy-mm-dd”});
//–>
</script>

[해결방법]
<script type=”text/javascript”>
<!–
    $(function(){
        $(“#sdate”).datepicker({dateFormat: “yy-mm-dd”});
    });
//–>
</script>

Android SDK Tools Setup :: JDK not found

Java SE Development Kit (JDK) not found.

Android SDK relies on the Java SE Development Kit (JDK).
Go to http://java.sun.com > Downloads > Java SE > JDK to download adn install a JDK before continuing.

Note: A Java Runtime (JRE) is not enough to develop for Android.

Visit java.sun.com

==================================================================

안드로이드 SDK 설치시,
JDK가 설치되어 있음에도 Next 가 안되는 상황발생

해결방법(1)
http://codearetoy.wordpress.com/2010/12/23/jdk-not-found-on-installing-android-sdk/
위 링크로 이동해서 따라하면 된다
32bit로 설치하든지 zip 파일로 설치해 보길 권하고 있다.

해결방법(2)
Next > 버튼이 비활성화 되어 있다면 < Back 한번 눌렀다가 다시 와보면 Next >가 활성화 되어 있다.
설치를 진행하면 된다…. -_-;;;;;;;;;

사용자 삽입 이미지

퍼미션 변환

리눅스 설치후 보안을 위해서
퍼미션을 변경할 파일들

chmod 100 /usr/bin/top
chmod 660 /var/log/xferlog*
chmod 100 /usr/bin/w
chmod 660 /var/log/yum.log
chmod 100 /usr/bin/uptime
chmod 700 -R /etc/rc.d/
chmod 100 /usr/bin/last
chmod 700 -R /etc/cron.*
chmod 100 /usr/bin/free
chmod 640 /etc/fstab
chmod 100 /usr/bin/find
chmod 640 /etc/redhat-release
chmod 100 /bin/ping
chmod 640 /etc/proftpd.conf
chmod 100 /bin/netstat
chmod 640 /etc/crontab
chmod 100 /sbin/ifconfig
chmod 640 /etc/logrotate.conf
chmod 700 /proc/
chmod 640 -R /etc/xinetd.d/
chmod 700 /boot/
chmod 640 -R /etc/logrotate.d/
chmod 700 /usr/src/
chmod 640 /etc/lilo.conf
chmod 700 /usr/local/src/
chmod 640 -R /etc/snmp*
chmod 701 /www/
chmod 640 /etc/yum.conf
chmod 640 /var/log/dmesg
chmod 640 -R /etc/proftpd/
chmod 640 /var/log/ksyms*
chmod 640 /etc/snmpd.conf
chmod 640 /var/log/rpmpkgs*
chmod 640 /etc/rsyncd.conf
chmod 640 /var/log/snmpd.log*
chmod 640 /etc/xinetd.conf
chmod 660 /var/log/wtmp*
chmod 640 /etc/inetd.conf

ImageMagicK watermark(워터마크)

ImageMagicK 를 이용해서 이미지에 워터마크를 찍어보자

1. 설치
yum install imagemagick

2. 리사이즈
convert -resize 800×600 input.jpg output.jpg
convert -resize 800x input.jpg output.jpg
convert -reisze x600 input.jpg output.jpg
convert -resize 800×600! input.jpg output.jpg (느낌표(!) 사용시 강제로 사이즈 맞춤)

3. 워터마크
(투명도 30%, 이미지 가운데, watermark.png 이용)
composite -watermark 30% -gravity center watermark.png input.jpg output.jpg