기술참고자료/Android | 2011. 10. 18. 10:02
리스트뷰 등에 커스텀 레이아웃을 생성하여,
이미지와 텍스트 등의 데이터를 출력하고자 할때에 어느정도의 갯수를 보여주기 위해서는
엄청난 버벅거림과 짜증남을 감수해야 하고, 이것은 사용자에게 예외발생의 주 원인을 제공하기도 한다.
이러한 상황에 멀티쓰레딩을 사용한다면, 좀 더 유연하고 동적인 프로그램을 제공할 수 있다.
테스트를 해 보았는데, 매우 유용하게 사용이 가능할 것으로 보인다.
본문에도 나와있지만,
원문은 http://android-developers.blogspot.com/2010/07/multithreading-for-performance.html 이다.
static Bitmap downloadBitmap(String url) { final AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); final HttpGet getRequest = new HttpGet(url); try { HttpResponse response = client.execute(getRequest); final int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url); return null; } final HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = null; try { inputStream = entity.getContent(); final Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } finally { if (inputStream != null) { inputStream.close(); } entity.consumeContent(); } } } catch (Exception e) { // Could provide a more explicit error message for IOException or IllegalStateException getRequest.abort(); Log.w("ImageDownloader", "Error while retrieving bitmap from " + url, e.toString()); } finally { if (client != null) { client.close(); } } return null; } |
static class FlushedInputStream extends FilterInputStream { public FlushedInputStream(InputStream inputStream) { super(inputStream); } @Override public long skip(long n) throws IOException { long totalBytesSkipped = 0L; while (totalBytesSkipped < n) { long bytesSkipped = in.skip(n - totalBytesSkipped); if (bytesSkipped == 0L) { int byte = read(); if (byte < 0) { break; // we reached EOF } else { bytesSkipped = 1; // we read one byte } } totalBytesSkipped += bytesSkipped; } return totalBytesSkipped; } } |
public class ImageDownloader { public void download(String url, ImageView imageView) { BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); task.execute(url); } } /* class BitmapDownloaderTask, see below */ } |
class BitmapDownloaderTask extends AsyncTask<String, Void, Bitmap> { private String url; private final WeakReference<ImageView> imageViewReference; public BitmapDownloaderTask(ImageView imageView) { imageViewReference = new WeakReference<ImageView>(imageView); } @Override // Actual download method, run in the task thread protected Bitmap doInBackground(String... params) { // params comes from the execute() call: params[0] is the url. return downloadBitmap(params[0]); } @Override // Once the image is downloaded, associates it to the imageView protected void onPostExecute(Bitmap bitmap) { if (isCancelled()) { bitmap = null; } if (imageViewReference != null) { ImageView imageView = imageViewReference.get(); if (imageView != null) { imageView.setImageBitmap(bitmap); } } } } |
static class DownloadedDrawable extends ColorDrawable { private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference; public DownloadedDrawable(BitmapDownloaderTask bitmapDownloaderTask) { super(Color.BLACK); bitmapDownloaderTaskReference = new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask); } public BitmapDownloaderTask getBitmapDownloaderTask() { return bitmapDownloaderTaskReference.get(); } } |
public void download(String url, ImageView imageView) { if (cancelPotentialDownload(url, imageView)) { BitmapDownloaderTask task = new BitmapDownloaderTask(imageView); DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task); imageView.setImageDrawable(downloadedDrawable); task.execute(url, cookie); } } |
private static boolean cancelPotentialDownload(String url, ImageView imageView) { BitmapDownloaderTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView); if (bitmapDownloaderTask != null) { String bitmapUrl = bitmapDownloaderTask.url; if ((bitmapUrl == null) || (!bitmapUrl.equals(url))) { bitmapDownloaderTask.cancel(true); } else { // The same URL is already being downloaded. return false; } } return true; } |
private static BitmapDownloaderTask getBitmapDownloaderTask(ImageView imageView) { if (imageView != null) { Drawable drawable = imageView.getDrawable(); if (drawable instanceof DownloadedDrawable) { DownloadedDrawable downloadedDrawable = (DownloadedDrawable)drawable; return downloadedDrawable.getBitmapDownloaderTask(); } } return null; } |
if (imageViewReference != null) { ImageView imageView = imageViewReference.get(); BitmapDownloaderTask bitmapDownloaderTask = getBitmapDownloaderTask(imageView); // Change bitmap only if this process is still associated with it if (this == bitmapDownloaderTask) { imageView.setImageBitmap(bitmap); } } |
[Android] TableView 모서리 둥글게 처리하기 (0) | 2011.10.18 |
---|---|
[Android] TextView에서의 줄간격 설정 (0) | 2011.10.18 |
[Android] ListView, transcriptMode (0) | 2011.09.20 |
[Android] TextView에서 볼드체 쓰기 (0) | 2011.06.21 |
[Android] 단말기 전화번호 및 상태정보 얻는 방법 (0) | 2011.05.06 |
서버운영일지 | 2011. 10. 8. 11:04
주소는 http://www.ubuntu.com/download/ubuntu/download 입니다.
|
sudo su -비밀번호입력apt-get update (패키지 소스리스트 업데이트 명령어 - 금방되더군요)apt-get diet-upgrade (각 패키지에 대한 의존성검사를 수행하면서 업그레이드 명령어 - 좀 오래걸립니다)
그놈에 대한 정보 : http://ko.wikipedia.org/wiki/GNOME
apt-get install xorg gdm
/etc/init.d/gdm start
apt-get install gnome-session gnome-menus gnome-panel metacity nautilus'apt-get auto remove' 어쩌구 하는 문자열이 출력되면서 끝났습니다.
권장되는 패키지들(apt-get install 뒤에 설치할 패키지들의 이름을 써서 설치함)
- gnome-applets
- gnome-control-center
- gnome-volume-manager
- libsmbclient
- gnome-screensaver
- menu
- network-manager-gnome
- gnome-utils
- gnome-system-tools
- gnome-netstatus-applet
- gnome-nettool
- libgnomevfs2-extra
선택적으로 설치한 유용한 패키지들
- gnome-terminal
- gedit
- firefox
데스크탑 테마설치함
- ubuntu-artwork
- ubuntu-sounds
- human-theme
- usplash-theme-ubuntu
패키지 관리자 설치함
- apt-get install gnome-app-install update-manager restricted-manager
/etc/init.d/gdm start
sudo apt-get install ttf-unfonts
[Ubuntu Diary] 시스템 환경 확인하기 (0) | 2012.02.10 |
---|---|
[Ubuntu Diary] OS설치하기 - sexyubuntu 시작하기 (2) | 2012.02.10 |
[Ubuntu Diary] 다시 시작! (0) | 2012.02.10 |
[Ubuntu Diary] JDK 설치 및 환경변수 등록 (1) | 2011.11.15 |
[Ubuntu Diary] 시작하며... (0) | 2011.10.08 |
서버운영일지 | 2011. 10. 8. 10:49
[Ubuntu Diary] 시스템 환경 확인하기 (0) | 2012.02.10 |
---|---|
[Ubuntu Diary] OS설치하기 - sexyubuntu 시작하기 (2) | 2012.02.10 |
[Ubuntu Diary] 다시 시작! (0) | 2012.02.10 |
[Ubuntu Diary] JDK 설치 및 환경변수 등록 (1) | 2011.11.15 |
[Ubuntu Diary] OS 다운로드 및 설치 (2) | 2011.10.08 |
기술참고자료/Android | 2011. 9. 20. 20:35
android:transcriptMode에 대해서 알아보자.
android:transcriptMode
Sets the transcript mode for the list. In transcript mode, the list scrolls to the bottom to make new items visible when they are added.
Must be one of the following constant values.
Constant Value Description
disabled 0 Disables transcript mode. This is the default value.
normal 1 The list will automatically scroll to the bottom when a data set change
notification is received and only if the last item is already visible on screen.
alwaysScroll 2 The list will automatically scroll to the bottom,
no matter what items are currently visible.
위에 자료는 안드로이드 API에 있는 내용이다. 간단하게 설명을하자면
transcriptMode 속성은 3가지의 값을 정의해줄수 있고 각각의 설명은 아래와 같다.
1. disabled : 스크롤이 되지 않음
2. nomal : 현재의 포커스에서 추가된만큼의 포커스가 이동
3. alwaysScroll : 마지막에 추가된곳으로 포커스 이동
제가 만들프로그램은 마지막에 추가된곳으로 포커스가 이동을 해야하기 때문에 alwaysScroll을 줘야한다.
위와같이 Java단에서 설정을 해줘도 되고 xml에서 설정을 해줘도 된다.getListView().setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
[Android] TextView에서의 줄간격 설정 (0) | 2011.10.18 |
---|---|
[Android] Multithreading For Performance (성능 향상을 위한 멀티쓰레딩 기법) (0) | 2011.10.18 |
[Android] TextView에서 볼드체 쓰기 (0) | 2011.06.21 |
[Android] 단말기 전화번호 및 상태정보 얻는 방법 (0) | 2011.05.06 |
[Android] Wi-Fi 상태와 3G 상태를 구분하자. (0) | 2011.05.06 |
기술참고자료/PHP | 2011. 8. 30. 20:26
오늘은 무슨 바람이 들었는지, PHP 환경설정을 해보기로 했습니다.
이클립스 공식 사이트에 가보니, PHP 개발용 IDE 지원이 종료되었나봅니다.
저렴한 영어실력으로 본 내용이니 실력좋으신 분들은 가서 직접 보고 오시면 좀 더 좋을 것 같네요.
기본 이클립스에 PDT를 설치하면, PHP 개발이 가능하다고 들었습니다.
그래서 PDT를 찾아다니다가 검색을 통해 zend-eclipse-php-helios-win32-x86.zip 파일을 다운로드 받았습니다.
해당 파일은 검색하면 많이 나옵니다. 예를들면...
http://downloads.zend.com/pdt/all-in-one/helios/
자료를 찾으면서 RSE에 대해서 알 수 있었습니다.
Remote System Explorer 라는 녀석이였는데, 플러그인 형태로 제공됩니다.
공식 사이트는 아래의 경로이구요.
http://www.eclipse.org/tm/.
제가 살펴본 바로는 이클립스를 사용하면서 FTP / Linux / SSH / Telnet / Unix / Windows 등과 연동하여 사용할 수 있도록 돕는 플러그인으로 확인했습니다. (눈으로만)
일단 설치방법에 대한 조언을 얻기 위해 아래의 블로그를 찾아가 보았는데요. 정말 도움이 많이 되었습니다.
http://byeonely.tistory.com/147
위 블로그의 도움을 얻어 환경설정하는 순서와 방법에 대한 내용을 간추려 적어보도록 하겠습니다.
1. http://www.eclipse.org/dsdp/tm/ 여기에 접속
2. Latest Release 라는 텍스트 옆의 Download 클릭
3. All-in-one (includes runtime and documentation for dstore, ftp, local, ssh, and telnet) 이라는 타이틀을 가진 항목에서 RSE-runtime-3.3.zip (Recommended for most users)를 선택하여 다운로드
4. 압축 해제 후, 설치된 이클립스의 각 폴더에 복사해 넣기(경로 그대로 해당 위치에 넣으시면 됩니다.)
5. 이클립스 구동
6. 이클립스의 퍼스펙티브에 Remote System Explorer 라든지, View에 동일항목이 추가되었는지 확인
오늘은 환경설정만 해보았고, 실제 사용하는 방법등에 대해서는 다음 포스트에 적어보도록 하겠습니다.
아참, PHP 무료 호스팅을 찾으시는 분들은 아래 사이트에 한번 가보세요.
저도 오늘 처음 가입해서 사용해 보았는데, 사용하기 편리하고 좋더군요.
http://www.zymic.com/
[PHP] Flickr API를 이용한 갤러리 구현 (0) | 2012.04.18 |
---|