반응형

https://github.com/phonegap/phonegap/wiki/App-Splash-Screen-Sizes

반응형

'android' 카테고리의 다른 글

Android Asynchronous Http Client library  (0) 2017.07.21
image downloading and caching library  (0) 2017.07.20
storage library  (0) 2017.07.20
multipicker library  (0) 2017.07.19
http multipart library  (0) 2017.07.19
반응형

http://loopj.com/android-async-http/



반응형

'android' 카테고리의 다른 글

App-Splash-Screen-Sizes  (0) 2018.05.31
image downloading and caching library  (0) 2017.07.20
storage library  (0) 2017.07.20
multipicker library  (0) 2017.07.19
http multipart library  (0) 2017.07.19
반응형

http://square.github.io/picasso/

반응형

'android' 카테고리의 다른 글

App-Splash-Screen-Sizes  (0) 2018.05.31
Android Asynchronous Http Client library  (0) 2017.07.21
storage library  (0) 2017.07.20
multipicker library  (0) 2017.07.19
http multipart library  (0) 2017.07.19
반응형

https://github.com/snatik/android-storage#copy

반응형

'android' 카테고리의 다른 글

Android Asynchronous Http Client library  (0) 2017.07.21
image downloading and caching library  (0) 2017.07.20
multipicker library  (0) 2017.07.19
http multipart library  (0) 2017.07.19
aquery library  (0) 2017.07.19
반응형

https://github.com/coomar2841/android-multipicker-library

반응형

'android' 카테고리의 다른 글

image downloading and caching library  (0) 2017.07.20
storage library  (0) 2017.07.20
http multipart library  (0) 2017.07.19
aquery library  (0) 2017.07.19
Android Thread example.  (0) 2017.03.08
반응형

https://github.com/javierugarte/multipart-android

반응형

'android' 카테고리의 다른 글

storage library  (0) 2017.07.20
multipicker library  (0) 2017.07.19
aquery library  (0) 2017.07.19
Android Thread example.  (0) 2017.03.08
Android SSL HTTPS 안드로이드 SSL HTTPS 통신 적용  (1) 2013.02.14
반응형

https://code.google.com/archive/p/android-query/

반응형

'android' 카테고리의 다른 글

multipicker library  (0) 2017.07.19
http multipart library  (0) 2017.07.19
Android Thread example.  (0) 2017.03.08
Android SSL HTTPS 안드로이드 SSL HTTPS 통신 적용  (1) 2013.02.14
안드로이드 모든 액티비티 종료  (1) 2013.01.15
반응형
thread를 pause/resume하려고 하지말고

그냥 onResume()할때마다 새로 생성해서 쓰는것이 편함.


반응형

'android' 카테고리의 다른 글

http multipart library  (0) 2017.07.19
aquery library  (0) 2017.07.19
Android SSL HTTPS 안드로이드 SSL HTTPS 통신 적용  (1) 2013.02.14
안드로이드 모든 액티비티 종료  (1) 2013.01.15
안드로이드 URL 이미지 캐싱  (0) 2013.01.11
반응형

Android SSL HTTPS 안드로이드 SSL HTTPS 통신 적용


Connect over secure rest web service for mobile application on android


In the last article, we developed application for android to get the data from rest web service (geo-names). Previous approach works fine for http rest web service but it doesn’t work over SSL secure connection. We were developing android application for a client whose rest web services are running over secure connection. Initially we thought it would be much simple to connect to secure rest web service because we already have the framework to connect to http connection. When we use it and there was exception “javax.net.ssl.SSLException: Not trusted server certificate” all over the application.
We didn’t loose our patience and asked our truly friends google and stackoverflow. We found various solution to intercept the connection and use self certificate but we wanted a solution which just by pass the authorization of the certificates. After checking various sites and reading the article, we found a solution which fit our requirements.


Create Easy SSL Socket Factory and create httpclient instance

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.http.conn.ssl.SSLSocketFactory;
public class EasySSLSocketFactory extends SSLSocketFactory {
        SSLContext sslContext = SSLContext.getInstance("TLS");

        public EasySSLSocketFactory(KeyStore truststore)
                        throws NoSuchAlgorithmException, KeyManagementException,
                        KeyStoreException, UnrecoverableKeyException {
                super(truststore);

                TrustManager tm = new X509TrustManager() {
                        public void checkClientTrusted(X509Certificate[] chain,
                                        String authType) throws CertificateException {
                        }

                        public void checkServerTrusted(X509Certificate[] chain,
                                        String authType) throws CertificateException {
                        }

                        public X509Certificate[] getAcceptedIssuers() {
                                return null;
                        }
                };

                sslContext.init(null, new TrustManager[] { tm }, null);
        }

        @Override
        public Socket createSocket(Socket socket, String host, int port,
                        boolean autoClose) throws IOException, UnknownHostException {
                return sslContext.getSocketFactory().createSocket(socket, host, port,
                                autoClose);
        }

        @Override
        public Socket createSocket() throws IOException {
                return sslContext.getSocketFactory().createSocket();
        }

}

We shall be using this ssl socket factory to access the secure connection to rest web service.


import java.security.KeyStore;


import org.apache.http.HttpVersion;

import org.apache.http.client.HttpClient;

import org.apache.http.conn.ClientConnectionManager;

import org.apache.http.conn.scheme.PlainSocketFactory;

import org.apache.http.conn.scheme.Scheme;

import org.apache.http.conn.scheme.SchemeRegistry;

import org.apache.http.conn.ssl.SSLSocketFactory;

import org.apache.http.impl.client.DefaultHttpClient;

import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;

import org.apache.http.params.BasicHttpParams;

import org.apache.http.params.HttpParams;

import org.apache.http.params.HttpProtocolParams;

import org.apache.http.protocol.HTTP;


public class HttpUtils {

        public static HttpClient getNewHttpClient() {

            try {

                KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());

                trustStore.load(null, null);


                SSLSocketFactory sf = new EasySSLSocketFactory(trustStore);

                sf.setHostnameVerifier(

                       SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);


                HttpParams params = new BasicHttpParams();

                HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

                HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);


                SchemeRegistry registry = new SchemeRegistry();

                registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

                registry.register(new Scheme("https", sf, 443));


                ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);


                return new DefaultHttpClient(ccm, params);

            } catch (Exception e) {

                return new DefaultHttpClient();

            }

        }

}


Back to our original rest client code


// Create a new RestTemplate instance

RestTemplate restTemplate = new RestTemplate();


// The HttpComponentsClientHttpRequestFactory uses the

// org.apache.http package to make network requests

restTemplate

.setRequestFactory(new HttpComponentsClientHttpRequestFactory(

HttpUtils.getNewHttpClient()));


// The URL for making the GET request

final String url = "https://xxx.xxx.xxx.xxx";

                                // Initiate the HTTP GET request, expecting an array of

// objects in response

Object result = restTemplate.getForObject(url, Object.class);



Finally we were able to make connection over secure rest web service android application.

Feel free to comment or ask questions.


원문: http://www.makeurownrules.com/secure-rest-web-service-mobile-application-android.html



반응형

'android' 카테고리의 다른 글

aquery library  (0) 2017.07.19
Android Thread example.  (0) 2017.03.08
안드로이드 모든 액티비티 종료  (1) 2013.01.15
안드로이드 URL 이미지 캐싱  (0) 2013.01.11
안드로이드 Bitmap 비교 방법  (0) 2013.01.11
반응형

안드로이드 모든 액티비티 종료



구글링 해보니 모든 액티비티를 종료하는 방법에 여러가지가 있었다.


이것 저것 해보니 귀차니즘 발동...


먼저 ActivityManager 클래스를 작성한다.

이 클래스에서 모든 액티비티를 ArrayList에 담아서 가지고 있도록 한다.

ActivityManager클래스는 singleton으로 구현.

package com.example.activitytest.manager;


import java.util.ArrayList;


import android.app.Activity;


public class ActivityManager {


private static ActivityManager activityMananger = null;

private ArrayList<activity> activityList = null;

private ActivityManager() {

activityList = new ArrayList<activity>();

}

public static ActivityManager getInstance() {

if( ActivityManager.activityMananger == null ) {

activityMananger = new ActivityManager();

}

return activityMananger;

}

/**

* 액티비티 리스트 getter.

* @return activityList

*/

public ArrayList<activity> getActivityList() {

return activityList;

}


/**

* 액티비티 리스트에 추가.

* @param activity

*/

public void addActivity(Activity activity) {

activityList.add(activity);

}

/**

* 액티비티 리스트에서 삭제.

* @param activity

* @return boolean

*/

public boolean removeActivity(Activity activity) {

return activityList.remove(activity);

}

/**

* 모든 액티비티 종료.

*/

public void finishAllActivity() {

for (Activity activity : activityList) {

activity.finish();

}

}

}



다음으로 Activity를 상속받은 ParentActivity 클래스를 하나 작성하고 ParentActivity 상속 받아서

새로운 Activity를 작성한다.

ParentActivity 클래스에서는 onCreate()메소드가 호출(새로운 Activity가 생성)될 때 마다 생성된 Activity를 

ActivityManager 클래스를 통해 ArrayList<Activity>에 add시킨다.


package com.example.activitytest.manager;


import android.app.Activity;

import android.os.Bundle;

import android.widget.Toast;


public class ParentActivity extends Activity {


private ActivityManager am = ActivityManager.getInstance();

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

am.addActivity(this);

}

@Override

protected void onDestroy() {

// TODO Auto-generated method stub

super.onDestroy();

am.removeActivity(this);

}

@Override

public void onBackPressed() {

// TODO Auto-generated method stub

super.onBackPressed();

// 뒤로가기 버튼 클릭시

Toast.makeText(getBaseContext(), "모든 액티비티 종료.", Toast.LENGTH_SHORT).show();

am.finishAllActivity();

}

}


그림으로 정리하면.








결론은 ParentActivity 클래스를 상속받아서 Activity를 구현해서 개발하면 된다.


모든 액티비티를 종료하려면 ActivityManager 클래스의 finishAllActivity() 메소드를 호출해서 종료시키면 된다.




ActivityManager클래스와 ParentActivity클래스에 필요한 메소드 잘 구현해서 써먹도록 하자.


// 프로젝트 파일 첨부.

AndroidAllActivityTest.zip






반응형
반응형
안드로이드 URL 이미지 캐싱

캐싱은 아니고 URL에서 가져온 이미지를 스토리지에 저장하고 ImageView에 보여주는거.
캐싱이라고 볼수도 있겠지. 생각하기 나름.

URL에서 이미지를 가져와서 리스트뷰에 넣을때 사용하기 위해서 만듬.
한번만 보여질 이미지라면 URL에서 Bitmap형태로 가져와 ImageView에 setImageBitmap() 하는것이 더 낳은듯.

하지만 xxx톡 같은 메신져의 경우, 친구목록에 사진은 바뀌어진 이미지만 다시 그려주고 
같은 이미지인 경우 storage에서 가져와서 보여주는거 같다. 
그래서 만들어봄.

먼저, 
- cache경로에 이미지 파일이 있는 경우.
1. cache경로에서 이미지를 가져와 ImageView에 그린다.
2. url에서 이미지를 가져와 임시파일로 저장하고, cache경로에 이미지와 비교한다.
3.1. 두 파일이 같으면 임시파일을 삭제한다. 그리고 끝.
3.2. 두 파일이 다르면 url에서 가져온 이미지를 cache경로에 새로 저장하고, 
       ImageView에 새로운 이미지로 set해준다. 그리고 끝.


- cache경로에 이미지 파일이 없는 경우.
1. URL에서 이미지 가져와서 cache위치에 저장하고 ImageView에 그린다.
2. 끝.

간략하게. 
저장되어있는 파일 먼저 화면에 보여주고, URL에서 가져온 이미지랑 비교해서 
다르면 새로 저장하고 새로 화면에 보여줌. 

리스트뷰에 적용해보니 리스트가 스크롤 될때 약간 버벅거리는듯하다.
아마도 이미지 크기를 줄이거나 임시파일을 쓰지않고 비교할수 있는 방법으로 
고치면 좀 개선이 될거 같기도하다.

AndroidManifest.xml 에 권한을 줘야한다.


import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.nio.ByteBuffer;

import java.util.Arrays;


import org.apache.http.HttpEntity;

import org.apache.http.HttpResponse;

import org.apache.http.HttpStatus;

import org.apache.http.client.ClientProtocolException;

import org.apache.http.client.HttpClient;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.impl.client.DefaultHttpClient;


import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.os.AsyncTask;

import android.util.Log;

import android.widget.ImageView;


public class ImageCacheDownloader extends AsyncTask<String, Integer, Bitmap> {

private Context context = null;

private ImageView imageview = null;

private String imageURL = null;


/**

* ImageCacheDownloader(Context _context, ImageView _imageView, String _url)

* @param _context

* @param _imageView

* @param _url

*/

public ImageCacheDownloader(Context _context, ImageView _imageView, String _url) {

this.context = _context;

this.imageview = _imageView;

this.imageURL = _url;

}


private String urlToFileFullPath(String _url) {

return context.getCacheDir().getAbsolutePath() + _url.substring(_url.lastIndexOf("/"), _url.length());

}

@Override

protected void onPreExecute() {

// TODO Auto-generated method stub

super.onPreExecute();

String fileFullPath = urlToFileFullPath(imageURL);

if( new File(fileFullPath).exists() ) {

//파일이 있으면. 저장되어있는 이미지 화면에 표시.

Bitmap myBitmap = BitmapFactory.decodeFile(fileFullPath);

imageview.setImageBitmap(myBitmap);

}

}


//@Override

protected void onPostExecute(Bitmap result) {

super.onPostExecute(result);


String fileFullPath = urlToFileFullPath(imageURL);

String tempFilePath = fileFullPath+"_temp";

writeFile(result, new File(tempFilePath)); // 다운로드한 파일 임시로 생성..

File downTempFile = new File(tempFilePath);

File newFile = new File(fileFullPath);

if( new File(fileFullPath).exists() ) {

//파일이 있으면.

Bitmap prevBitmap = BitmapFactory.decodeFile(fileFullPath);

Bitmap downBitmap = BitmapFactory.decodeFile(downTempFile.getAbsolutePath());


// 파일이 같다.

if( sameAs(prevBitmap,downBitmap) ) {

//Log.i("egg", "같은사진이다.");

} else {

//Log.i("egg", "다른 사진이라서 새로 설정한다");

imageview.setImageBitmap(result);

writeFile(result, newFile);

}

} else {

writeFile(result, newFile);

imageview.setImageBitmap(result);

}

downTempFile.delete();

}

/**

* Bitmap을 비교. 

* @param bitmap1

* @param bitmap2

* @return boolean

*/

private boolean sameAs(Bitmap bitmap1, Bitmap bitmap2) {

ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes());

    bitmap1.copyPixelsToBuffer(buffer1);


    ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes());

    bitmap2.copyPixelsToBuffer(buffer2);

    return Arrays.equals(buffer1.array(), buffer2.array());

}

@Override

protected Bitmap doInBackground(String... params) {

return downloadBitmap(imageURL);

}

/**

* httpclient 이미지 파일 다운로드.

* @param imageUrl

* @return Bitmap

*/

private Bitmap downloadBitmap(String imageUrl) {

    Bitmap bm = null;

HttpClient httpclient = new DefaultHttpClient();

HttpGet getRequest = new HttpGet(imageUrl);

HttpResponse response;

try {

response = httpclient.execute(getRequest);

int statusCode = response.getStatusLine().getStatusCode();

if (statusCode != HttpStatus.SC_OK) { 

            Log.w("egg", "Error " + statusCode + " while retrieving bitmap from " + imageUrl); 

            return null;

        }

HttpEntity entity = response.getEntity();

        if (entity != null) {

            InputStream inputStream = null;

            try {

                inputStream = entity.getContent(); 

                final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

                bm = bitmap;

                //eturn bitmap;

            } finally {

                if (inputStream != null) {

                    inputStream.close();  

                }

                entity.consumeContent();

            }

        }

} catch (ClientProtocolException e) { e.printStackTrace(); } 

catch (IOException e) { e.printStackTrace(); }

return bm;

    }


/**

* 새로운 파일을 쓴다. 

* @param Bimap bmp

* @param File f

*/

private void writeFile(Bitmap bmp, File f) {

FileOutputStream out = null;

try {

out = new FileOutputStream(f);

bmp.compress(Bitmap.CompressFormat.PNG, 50, out); // PNG type, 50

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (out != null)

out.close();

} catch (Exception ex) {

}

}

}

}



반응형
반응형

안드로이드 Bitmap 비교 하기


Bitmap 클래스에 sameAs(Bitmap other) 메소드로 비교할 수 있다.

이 메소드는 API Level 12버전부터 추가되어 이하 API버전에서는 사용할 수 가 없다는거...

( http://developer.android.com/reference/android/graphics/Bitmap.html#sameAs%28android.graphics.Bitmap%29 )



구글링해서 답을 찾았다. 

(주소: http://stackoverflow.com/questions/6120439/comparing-bitmap-images-in-android )


/**

* Bitmap을 비교. 

* @param bitmap1

* @param bitmap2

* @return boolean

*/

private boolean sameAs(Bitmap bitmap1, Bitmap bitmap2) {

ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes());

    bitmap1.copyPixelsToBuffer(buffer1);


    ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes());

    bitmap2.copyPixelsToBuffer(buffer2);

    return Arrays.equals(buffer1.array(), buffer2.array());

}



반응형
반응형

액션바 라이브러리.

데모 돌려보니 쓸만한거 같다.

안드로이드 2.2.x 버전부터 동일하게 사용가능하다니 쓸만한듯 ㅎ


http://actionbarsherlock.com/index.html


ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.

반응형
반응형

C:\Users\Kim\.android>"C:\Program Files\Java\jdk1.6.0_23\bin\keytool" -list -ali
as androiddebugkey -keystore debug.keystore -storepass android -keypass android
androiddebugkey, 2011. 2. 5, PrivateKeyEntry,
인증서 지문(MD5): ??????????????????????????

C:\Users\Kim\.android>

http://code.google.com/intl/ko-KR/android/maps-api-signup.html

Google Map v1 일떄.. 

반응형

+ Recent posts