2014. 4. 16. 12:07 안드로이드

cygwin 설치



빨간색 칠해진 DEVEL과 CURL을 체크해서 설치 

(혹시 설치했는데 또 설치하고싶으면 setup.exe파일 다시 실행해서 설치 하고 싶은 것만 체크해서 다시 설치 하면된다)


그러고 나서는 안드로이드에 나와있는 순서대로 하면 된다 

검색해서 나온 블로그에 나와있는 방법대로 하면 안되던데 홈페이지 들어가서 하면 바로 된다.

http://source.android.com/source/downloading.html


cygwin에서의 폴더 이동은 

cd /cygdrive/d/project/a/b  요렇게 넣어주면 폴더 이동이 된다



posted by 욱이다
2014. 4. 8. 14:40 안드로이드

안드로이드 50메가가 넘어가는 파일 다운로드 


생각 없이 쭉 따라 하면 됩니다.

확장 파일은 안드로이드 콘솔에다 업로드 하는데 .. 누구는 압축을 안한 압축파일을 하라고해서 그렇게 하니 됐습니다. 

알집에 보니 압축률 없이 압축하는 방법이 있습니다.

안드로이드에서 샘플이 제공되고 있습니다. 

D:\adt-bundle-windows-x86_64\sdk\extras\google\play_apk_expansion\downloader_sample

파일이 저장되면 아래의 경로에 저장 됩니다.

 Environment.getExternalStorageDirectory() + "/Android/obb/" + thePackageName + "/main."

+ Def.EXTENSION_FILE_VERSION + "." + thePackageName + ".obb";



시작합니다.

아래의 두개의 프로젝트를 import한다 

D:\adt-bundle-windows-x86_64\sdk\extras\google\play_apk_expansion\downloader_library

D:\adt-bundle-windows-x86_64\sdk\extras\google\play_apk_expansion\zip_file

downloader_library여기서 에러 나는데 library라이센스를 다시 정해 주면된다 


라이센스는 D:\adt-bundle-windows-x86_64\sdk\extras\google\play_licensing 여기 있습니다.


downloader_library,zip_file 둘을 작업 중인 프로젝트에서 프로젝트>안드로이드>library에 add한다 



AndroidManifest.xml

         <service

            android:name="com.home.test.s1.ExpansionFile.ExpansionFileDownloaderService"/>

        <receiver

            android:name="com.home.test.s1.ExpansionFile.ExpansionFileAlarmReceiver" />


이건 그냥 내가 쓴건데 이중에 뭐가 필요한건지 모르겠네 ...

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />




두개의 파일


ExpansionFileAlarmReceiver.java

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageManager.NameNotFoundException;

import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller;

public class ExpansionFileAlarmReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

// TODO Auto-generated method stub

try {

DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent,

ExpansionFileDownloaderService.class);

} catch (NameNotFoundException e) {


}

}

}


ExpansionFileDownloaderService.java
import com.google.android.vending.expansion.downloader.impl.DownloaderService;
public class ExpansionFileDownloaderService extends DownloaderService {
//렌덤 숫자 20개 (byte) 아무렇게나 바이트 숫자 넣으세요
private static final byte[] SALT = new byte[]{
0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9};
@Override
public String getAlarmReceiverClassName() {
// TODO Auto-generated method stub
return ExpansionFileDownloaderService.class.getName();
}
@Override
public String getPublicKey() {
// TODO Auto-generated method stub
    //이건 MIIBIjANBgkq...... 요래 시작하는 긴거 알지요 ? 안드로이드 콘솔에서 해당 앱눌러서 publickey
return getResources().getString(R.string.base64EncodedPublicKey);
}
@Override
public byte[] getSALT() {
// TODO Auto-generated method stub
return SALT;
}
}


요건 activity에서 기록하는것 
 Def.EXTENSION_FILE_VERSION 이건 확장 파일을 콘솔에 올렸을때의 앱버젼이다


public class IntroLogoActivity extends SActivity implements IDownloaderClient {
.
.
.
.

String mainFileName = Helpers.getExpansionAPKFileName(this, true, Def.EXTENSION_FILE_VERSION);
Log.e(Constants.TAG, "CRC does not match for entry: ");

if (!Helpers.doesFileExist(this, mainFileName,
Integer.parseInt(getResources().getString(R.string.extendfilesize)), false)) {

mExtensionFrame.setVisibility(View.VISIBLE);
Intent launcher = getIntent();
Intent fromNotification = new Intent(this, getClass());
fromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
fromNotification.setAction(launcher.getAction());
if (launcher.getCategories() != null) {
for (String cat : launcher.getCategories()) {
fromNotification.addCategory(cat);
}
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 279912, fromNotification,
PendingIntent.FLAG_UPDATE_CURRENT);
try {
// Start the download
int result = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent,
ExpansionFileDownloaderService.class);
Log.i("AA", "DownloaderClientMarshaller result => " + result);
if (DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED != result) {
// implement Downloading UI.
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,
ExpansionFileDownloaderService.class);
ToastS.makeText(mToast, this, "파일을 다운로드 중입니다.");
}
} catch (NameNotFoundException e) {
Log.e("apk-expansion-files", "NameNotFoundException occurred. " + e.getMessage(), e);
}
} else {
CallNext();
}

.
.
.
.

@Override
protected void onResume() {
if (null != mDownloaderClientStub) {
mDownloaderClientStub.connect(this);
}
super.onResume();
}
@Override
protected void onStop() {
if (null != mDownloaderClientStub) {
mDownloaderClientStub.disconnect(this);
}
super.onStop();
}



@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
// TODO Auto-generated method stub
//다운로드 진행 상황 보여줄려고 하는 ui입니다 입맞에 맞게 작성하시면됩니다 .
//일단 값들은 찍어 보세요 
progress.mOverallTotal = progress.mOverallTotal;
mExtenstionProgress.setMax((int) (progress.mOverallTotal >> 8));
mExtenstionProgress.setProgress((int) (progress.mOverallProgress >> 8));
mExtensionCur.setText(Long.toString(progress.mOverallProgress * 100 / progress.mOverallTotal) + "%");
mExtensionMax.setText(Helpers.getDownloadProgressString(progress.mOverallProgress, progress.mOverallTotal));
}

@Override
public void onDownloadStateChanged(int newState) {
// TODO Auto-generated method stub
Log.i("AA", "in onDownloadStateChanged, newState=" + newState);
boolean showDashboard = true;

boolean fAppFinish = false;
//상황에 맞게 작업들을 넣어줘야합니다.
switch (newState) {
case STATE_COMPLETED:// The download was finished
showDashboard = false;
CallNext();
break;
case STATE_IDLE:
Log.i("AA", "in onDownloadStateChanged, STATE_IDLE");
break;
case STATE_FETCHING_URL:
showDashboard = true;
Log.i("AA", "in onDownloadStateChanged, STATE_FETCHING_URL");
break;
case STATE_CONNECTING:
showDashboard = true;
Log.i("AA", "in onDownloadStateChanged, STATE_CONNECTING");
break;
case STATE_DOWNLOADING:
showDashboard = true;
Log.i("AA", "in onDownloadStateChanged, STATE_DOWNLOADING");
break;
case STATE_PAUSED_NETWORK_UNAVAILABLE:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_NETWORK_UNAVAILABLE");
break;
case STATE_PAUSED_BY_REQUEST:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_BY_REQUEST");
break;
case STATE_PAUSED_WIFI_DISABLED_NEED_CELLULAR_PERMISSION:
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_WIFI_DISABLED_NEED_CELLULAR_PERMISSION");
break;
case STATE_PAUSED_NEED_CELLULAR_PERMISSION:
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_NEED_CELLULAR_PERMISSION");
break;
case STATE_PAUSED_WIFI_DISABLED:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_WIFI_DISABLED");
break;
case STATE_PAUSED_NEED_WIFI:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_NEED_WIFI");
break;
case STATE_PAUSED_ROAMING:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_ROAMING");
break;
case STATE_PAUSED_NETWORK_SETUP_FAILURE:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_NETWORK_SETUP_FAILURE");
break;
case STATE_PAUSED_SDCARD_UNAVAILABLE:
Log.i("AA", "in onDownloadStateChanged, STATE_PAUSED_SDCARD_UNAVAILABLE");
break;
case STATE_FAILED_UNLICENSED:
ToastS.makeText(mToast, this, "라이센스 검사에 실패 했습니다.\n앱을 종료합니다.");
fAppFinish = true;
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_FAILED_UNLICENSED");
break;
case STATE_FAILED_FETCHING_URL:
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_FAILED_FETCHING_URL");
break;
case STATE_FAILED_SDCARD_FULL:
ToastS.makeText(mToast, this, "저장 공간이 부족합니다.");
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_FAILED_SDCARD_FULL");
break;
case STATE_FAILED_CANCELED:
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_FAILED_CANCELED");
break;
case STATE_FAILED:
showDashboard = false;
Log.i("AA", "in onDownloadStateChanged, STATE_FAILED");
break;
}
int newDashboardVisibility = showDashboard ? View.VISIBLE : View.GONE;
if (mExtensionFrame.getVisibility() != newDashboardVisibility) {
mExtensionFrame.setVisibility(newDashboardVisibility);
}

if (fAppFinish) {
finish();
}

}

@Override
public void onServiceConnected(Messenger m) {
// TODO Auto-generated method stub
Log.i("AA", "Download started...");
mRemoteService = DownloaderServiceMarshaller.CreateProxy(m);

mRemoteService.onClientUpdated(mDownloaderClientStub.getMessenger());

}


.
.
.
요건 파일 가져오는거 2가지 방법
public AssetFileDescriptor getAssetFileDescriptor(String filePath) {
PackageManager manager = this.getPackageManager();
PackageInfo info;
try {
info = manager.getPackageInfo(this.getPackageName(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
return null;
}
String thePackageName = this.getPackageName();
// int thePackageVer = info.versionCode;

String zipFilePath = Environment.getExternalStorageDirectory() + "/Android/obb/" + thePackageName + "/main."
+ Def.EXTENSION_FILE_VERSION + "." + thePackageName + ".obb";
ZipResourceFile expansionFile = null;
AssetFileDescriptor afd = null;
try {
expansionFile = new ZipResourceFile(zipFilePath);

afd = expansionFile.getAssetFileDescriptor(filePath);
} catch (IOException e) {
e.printStackTrace();
}
return afd;
}

public InputStream getAssetFileInputStream(String filePath) {

PackageManager manager = this.getPackageManager();
PackageInfo info;
try {
info = manager.getPackageInfo(this.getPackageName(), 0);
} catch (NameNotFoundException e) {
e.printStackTrace();
return null;
}
String thePackageName = this.getPackageName();
// int thePackageVer = info.versionCode;

String zipFilePath = Environment.getExternalStorageDirectory() + "/Android/obb/" + thePackageName + "/main."
+ Def.EXTENSION_FILE_VERSION + "." + thePackageName + ".obb";
ZipResourceFile expansionFile = null;
InputStream is = null;
try {
expansionFile = new ZipResourceFile(zipFilePath);
is = expansionFile.getInputStream(filePath);

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



라이센스 에러 나고 페치 url 실패 나고 하는데요 
확장 파일 버젼 잘 맞추고 사이닝된 apk파일과 콘솔에 올린 버젼이 같으면 됩니다.

일단은 저는 알파테스트로 apk를 올리고 거기다 확장 파일 올리고 
다음 부터는 싸이닝된 apk파일 만들어서 폰에 넣고 설치하고를 반복 하면서 테스트 했습니다.

그런데 확장 파일콘솔에 올리고 난뒤에 디버깅으로 앱 설치해도 확장 파일 다운로드가 되네요 디버깅이 더 쉬워 졌어요


처음에 콘솔에 올리고 언제 업데이트 되서 테스트 하나 막막했음 ....


'안드로이드' 카테고리의 다른 글

cardslib  (0) 2014.04.30
안드로이드 소스 다운로드  (0) 2014.04.16
안드로이드 화학기호 수학기호의 승 표시  (0) 2014.02.27
구글 영수증 코드 확인 하는 방법  (0) 2014.02.12
ANDROID LISTVIEW GET HEIGHT  (0) 2014.01.15
posted by 욱이다
2014. 2. 27. 13:43 안드로이드


TextView tvInfo;

tvInfo.setText(Html.fromHtml("SO<sub><small>4</small></sub><sup><small>2</small></sup>    SO<sub>4</sub><sup>2</sup>"));


아 .. 씸플하다 




posted by 욱이다
2014. 2. 12. 17:39 안드로이드

구글 영수증 확인 코드 서버용이네


안드로이드 sdk에 위치해있다

D:\adt-bundle-windows-x86_64\sdk\sources\android-19\java\security\Security.java


/*

 *  Licensed to the Apache Software Foundation (ASF) under one or more

 *  contributor license agreements.  See the NOTICE file distributed with

 *  this work for additional information regarding copyright ownership.

 *  The ASF licenses this file to You under the Apache License, Version 2.0

 *  (the "License"); you may not use this file except in compliance with

 *  the License.  You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 *  Unless required by applicable law or agreed to in writing, software

 *  distributed under the License is distributed on an "AS IS" BASIS,

 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 *  See the License for the specific language governing permissions and

 *  limitations under the License.

 */


package java.security;


import java.io.BufferedInputStream;

import java.io.InputStream;

import java.util.Enumeration;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import java.util.Map.Entry;

import java.util.Properties;

import java.util.Set;

import org.apache.harmony.security.fortress.Engine;

import org.apache.harmony.security.fortress.SecurityAccess;

import org.apache.harmony.security.fortress.Services;


/**

 * {@code Security} is the central class in the Java Security API. It manages

 * the list of security {@code Provider} that have been installed into this

 * runtime environment.

 */

public final class Security {


    // Security properties

    private static final Properties secprops = new Properties();


    // static initialization

    // - load security properties files

    // - load statically registered providers

    // - if no provider description file found then load default providers

    static {

        boolean loaded = false;

        try {

            InputStream configStream = Security.class.getResourceAsStream("security.properties");

            InputStream input = new BufferedInputStream(configStream);

            secprops.load(input);

            loaded = true;

            configStream.close();

        } catch (Exception ex) {

            System.logE("Could not load 'security.properties'", ex);

        }

        if (!loaded) {

            registerDefaultProviders();

        }

        Engine.door = new SecurityDoor();

    }


    /**

     * This class can't be instantiated.

     */

    private Security() {

    }


    // Register default providers

    private static void registerDefaultProviders() {

        secprops.put("security.provider.1", "com.android.org.conscrypt.OpenSSLProvider");

        secprops.put("security.provider.2", "org.apache.harmony.security.provider.cert.DRLCertFactory");

        secprops.put("security.provider.3", "com.android.org.bouncycastle.jce.provider.BouncyCastleProvider");

        secprops.put("security.provider.4", "org.apache.harmony.security.provider.crypto.CryptoProvider");

        secprops.put("security.provider.5", "com.android.org.conscrypt.JSSEProvider");

    }


    /**

     * Returns value for the specified algorithm with the specified name.

     *

     * @param algName

     *            the name of the algorithm.

     * @param propName

     *            the name of the property.

     * @return value of the property.

     * @deprecated Use {@link AlgorithmParameters} and {@link KeyFactory} instead.

     */

    @Deprecated

    public static String getAlgorithmProperty(String algName, String propName) {

        if (algName == null || propName == null) {

            return null;

        }

        String prop = "Alg." + propName + "." + algName;

        Provider[] providers = getProviders();

        for (Provider provider : providers) {

            for (Enumeration e = provider.propertyNames(); e.hasMoreElements(); ) {

                String propertyName = (String) e.nextElement();

                if (propertyName.equalsIgnoreCase(prop)) {

                    return provider.getProperty(propertyName);

                }

            }

        }

        return null;

    }


    /**

     * Insert the given {@code Provider} at the specified {@code position}. The

     * positions define the preference order in which providers are searched for

     * requested algorithms.

     *

     * @param provider

     *            the provider to insert.

     * @param position

     *            the position (starting from 1).

     * @return the actual position or {@code -1} if the given {@code provider}

     *         was already in the list. The actual position may be different

     *         from the desired position.

     */

    public static synchronized int insertProviderAt(Provider provider, int position) {

        // check that provider is not already

        // installed, else return -1; if (position <1) or (position > max

        // position) position = max position + 1; insert provider, shift up

        // one position for next providers; Note: The position is 1-based

        if (getProvider(provider.getName()) != null) {

            return -1;

        }

        int result = Services.insertProviderAt(provider, position);

        renumProviders();

        return result;

    }


    /**

     * Adds the given {@code provider} to the collection of providers at the

     * next available position.

     *

     * @param provider

     *            the provider to be added.

     * @return the actual position or {@code -1} if the given {@code provider}

     *         was already in the list.

     */

    public static int addProvider(Provider provider) {

        return insertProviderAt(provider, 0);

    }


    /**

     * Removes the {@code Provider} with the specified name form the collection

     * of providers. If the the {@code Provider} with the specified name is

     * removed, all provider at a greater position are shifted down one

     * position.

     *

     * <p>Returns silently if {@code name} is {@code null} or no provider with the

     * specified name is installed.

     *

     * @param name

     *            the name of the provider to remove.

     */

    public static synchronized void removeProvider(String name) {

        // It is not clear from spec.:

        // 1. if name is null, should we checkSecurityAccess or not?

        //    throw SecurityException or not?

        // 2. as 1 but provider is not installed

        // 3. behavior if name is empty string?


        Provider p;

        if ((name == null) || (name.length() == 0)) {

            return;

        }

        p = getProvider(name);

        if (p == null) {

            return;

        }

        Services.removeProvider(p.getProviderNumber());

        renumProviders();

        p.setProviderNumber(-1);

    }


    /**

     * Returns an array containing all installed providers. The providers are

     * ordered according their preference order.

     *

     * @return an array containing all installed providers.

     */

    public static synchronized Provider[] getProviders() {

        return Services.getProviders();

    }


    /**

     * Returns the {@code Provider} with the specified name. Returns {@code

     * null} if name is {@code null} or no provider with the specified name is

     * installed.

     *

     * @param name

     *            the name of the requested provider.

     * @return the provider with the specified name, maybe {@code null}.

     */

    public static synchronized Provider getProvider(String name) {

        return Services.getProvider(name);

    }


    /**

     * Returns the array of providers which meet the user supplied string

     * filter. The specified filter must be supplied in one of two formats:

     * <nl>

     * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE

     * <p>

     * (for example: "MessageDigest.SHA")

     * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE

     * ATTR_NAME:ATTR_VALUE

     * <p>

     * (for example: "Signature.MD2withRSA KeySize:512")

     * </nl>

     *

     * @param filter

     *            case-insensitive filter.

     * @return the providers which meet the user supplied string filter {@code

     *         filter}. A {@code null} value signifies that none of the

     *         installed providers meets the filter specification.

     * @throws InvalidParameterException

     *             if an unusable filter is supplied.

     * @throws NullPointerException

     *             if {@code filter} is {@code null}.

     */

    public static Provider[] getProviders(String filter) {

        if (filter == null) {

            throw new NullPointerException("filter == null");

        }

        if (filter.length() == 0) {

            throw new InvalidParameterException();

        }

        HashMap<String, String> hm = new HashMap<String, String>();

        int i = filter.indexOf(':');

        if ((i == filter.length() - 1) || (i == 0)) {

            throw new InvalidParameterException();

        }

        if (i < 1) {

            hm.put(filter, "");

        } else {

            hm.put(filter.substring(0, i), filter.substring(i + 1));

        }

        return getProviders(hm);

    }


    /**

     * Returns the array of providers which meet the user supplied set of

     * filters. The filter must be supplied in one of two formats:

     * <nl>

     * <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE

     * <p>

     * for example: "MessageDigest.SHA" The value associated with the key must

     * be an empty string. <li> CRYPTO_SERVICE_NAME.ALGORITHM_OR_TYPE

     * ATTR_NAME:ATTR_VALUE

     * <p>

     * for example: "Signature.MD2withRSA KeySize:512" where "KeySize:512" is

     * the value of the filter map entry.

     * </nl>

     *

     * @param filter

     *            case-insensitive filter.

     * @return the providers which meet the user supplied string filter {@code

     *         filter}. A {@code null} value signifies that none of the

     *         installed providers meets the filter specification.

     * @throws InvalidParameterException

     *             if an unusable filter is supplied.

     * @throws NullPointerException

     *             if {@code filter} is {@code null}.

     */

    public static synchronized Provider[] getProviders(Map<String,String> filter) {

        if (filter == null) {

            throw new NullPointerException("filter == null");

        }

        if (filter.isEmpty()) {

            return null;

        }

        java.util.List<Provider> result = Services.getProvidersList();

        Set<Entry<String, String>> keys = filter.entrySet();

        Map.Entry<String, String> entry;

        for (Iterator<Entry<String, String>> it = keys.iterator(); it.hasNext();) {

            entry = it.next();

            String key = entry.getKey();

            String val = entry.getValue();

            String attribute = null;

            int i = key.indexOf(' ');

            int j = key.indexOf('.');

            if (j == -1) {

                throw new InvalidParameterException();

            }

            if (i == -1) { // <crypto_service>.<algorithm_or_type>

                if (val.length() != 0) {

                    throw new InvalidParameterException();

                }

            } else { // <crypto_service>.<algorithm_or_type> <attribute_name>

                if (val.length() == 0) {

                    throw new InvalidParameterException();

                }

                attribute = key.substring(i + 1);

                if (attribute.trim().length() == 0) {

                    throw new InvalidParameterException();

                }

                key = key.substring(0, i);

            }

            String serv = key.substring(0, j);

            String alg = key.substring(j + 1);

            if (serv.length() == 0 || alg.length() == 0) {

                throw new InvalidParameterException();

            }

            Provider p;

            for (int k = 0; k < result.size(); k++) {

                try {

                    p = result.get(k);

                } catch (IndexOutOfBoundsException e) {

                    break;

                }

                if (!p.implementsAlg(serv, alg, attribute, val)) {

                    result.remove(p);

                    k--;

                }

            }

        }

        if (result.size() > 0) {

            return result.toArray(new Provider[result.size()]);

        }

        return null;

    }


    /**

     * Returns the value of the security property named by the argument.

     *

     * @param key

     *            the name of the requested security property.

     * @return the value of the security property.

     */

    public static String getProperty(String key) {

        if (key == null) {

            throw new NullPointerException("key == null");

        }

        String property = secprops.getProperty(key);

        if (property != null) {

            property = property.trim();

        }

        return property;

    }


    /**

     * Sets the value of the specified security property.

     */

    public static void setProperty(String key, String value) {

        secprops.put(key, value);

    }


    /**

     * Returns a {@code Set} of all registered algorithms for the specified

     * cryptographic service. {@code "Signature"}, {@code "Cipher"} and {@code

     * "KeyStore"} are examples for such kind of services.

     *

     * @param serviceName

     *            the case-insensitive name of the service.

     * @return a {@code Set} of all registered algorithms for the specified

     *         cryptographic service, or an empty {@code Set} if {@code

     *         serviceName} is {@code null} or if no registered provider

     *         provides the requested service.

     */

    public static Set<String> getAlgorithms(String serviceName) {

        Set<String> result = new HashSet<String>();

        // compatibility with RI

        if (serviceName == null) {

            return result;

        }

        for (Provider provider : getProviders()) {

            for (Provider.Service service: provider.getServices()) {

                if (service.getType().equalsIgnoreCase(serviceName)) {

                    result.add(service.getAlgorithm());

                }

            }

        }

        return result;

    }


    /**

     *

     * Update sequence numbers of all providers.

     *

     */

    private static void renumProviders() {

        Provider[] p = Services.getProviders();

        for (int i = 0; i < p.length; i++) {

            p[i].setProviderNumber(i + 1);

        }

    }


    private static class SecurityDoor implements SecurityAccess {

        // Access to Security.renumProviders()

        public void renumProviders() {

            Security.renumProviders();

        }


        //  Access to Security.getAliases()

        public List<String> getAliases(Provider.Service s) {

            return s.getAliases();

        }


        // Access to Provider.getService()

        public Provider.Service getService(Provider p, String type) {

            return p.getService(type);

        }

    }

}



posted by 욱이다
2014. 1. 15. 16:50 안드로이드

안드로이드 가변적인 LISTVIEW의 높이에 맞게 레이아웃을 잡을려고 할때 쓰나 



private int getListViewHeight(ListView list) {

 ListAdapter adapter = list.getAdapter();

 int listviewHeight = 0;

 list.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

 listviewHeight = list.getMeasuredHeight() * adapter.getCount() + (adapter.getCount() * list.getDividerHeight());

 return listviewHeight;

 }




mListView_ExamUnitList.invalidate();


int listHeight = getListViewHeight(mListView_ExamUnitList);

RelativeLayout.LayoutParams params2 =  new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,listHeight);

params2.addRule(RelativeLayout.BELOW,R.id.usersetting_spinner);

params2.setMargins(Util.dpToPx(getResources(), 10), Util.dpToPx(getResources(), 10), Util.dpToPx(getResources(), 10), 0);

mListView_ExamUnitList.setLayoutParams(params2);






요건 DP를 픽셀로 바꾸는 것

public static int dpToPx(Resources res, int dp) {

return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, res.getDisplayMetrics());

}

posted by 욱이다
2014. 1. 11. 10:19 안드로이드

 translateAnimation후 click이벤트 먹게 하는 방법


package com.paran.animation.demo.app.animation;


import android.app.Activity;

import android.content.Context;

import android.graphics.Rect;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.animation.Animation;

import android.view.animation.Animation.AnimationListener;

import android.view.animation.AnimationSet;

import android.view.animation.AnimationUtils;

import android.view.animation.RotateAnimation;

import android.view.animation.TranslateAnimation;

import android.widget.Button;

import android.widget.FrameLayout;

import android.widget.FrameLayout.LayoutParams;

import android.widget.Toast;


public class ShotButton extends Activity

{


FrameLayout Root;

Button ShotBtn, BulletBtn[];



@Override

protected void onCreate(Bundle savedInstanceState)

{

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

Root = new FrameLayout(this);


BulletBtn = new Button[5];

for (int i = 0; i < 5; i++)

{

BulletBtn[i] = new Button(this);

BulletBtn[i].setText("" + i);

final int index = i;

BulletBtn[i].setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

// TODO Auto-generated method stub

Toast.makeText(ShotButton.this, BulletBtn[index].getText(), Toast.LENGTH_SHORT).show();

}

});

Root.addView(BulletBtn[i], new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT));

}


ShotBtn = new Button(this);

ShotBtn.setText("START");

ShotBtn.setOnClickListener(new OnClickListener()

{

@Override

public void onClick(View v)

{

// TODO Auto-generated method stub

for (int i = 0; i < 5; i++)

{

final int index = i;

final int finalx = 100 * i + 50, finaly = 500;

AnimationSet animation = new AnimationSet(false);

RotateAnimation AniRotation = new RotateAnimation(0, 720);

AniRotation.setDuration(400);

TranslateAnimation AniTrans = new TranslateAnimation(0, finalx, 0, finaly);

AniTrans.setDuration(400);

AniTrans.setInterpolator(AnimationUtils.loadInterpolator(ShotButton.this,

android.R.anim.overshoot_interpolator));

AniTrans.setStartOffset(20 * i);


// animation.addAnimation(AniRotation);

animation.addAnimation(AniTrans);

animation.setFillAfter(true);//이거 하면 위치에 가던데 아래의 리스너로 setmargins하면 더 아래로 내려 가버리더라

// animation.setFillEnabled(true);


BulletBtn[i].startAnimation(animation);


animation.setAnimationListener(new AnimationListener()

{

@Override

public void onAnimationStart(Animation animation)

{

// TODO Auto-generated method stub

//처음의 버튼 위치 

FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(BulletBtn[index]

.getLayoutParams());

lp.setMargins(0, 0, 0, 0);

BulletBtn[index].setLayoutParams(lp);

BulletBtn[index].requestLayout();

fAniEnd = false;

}


@Override

public void onAnimationRepeat(Animation animation)

{

// TODO Auto-generated method stub


}


@Override

public void onAnimationEnd(Animation animation)

{

// TODO Auto-generated method stub

// if (animation.equals(BulletBtn[index].getAnimation()))

{

//애니가 끝났을때 버튼의 위치 

// FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(BulletBtn[index]

// .getLayoutParams());

// Log.i("aa","Margin "+lp.leftMargin+" "+lp.rightMargin+ " "+lp.topMargin+" "+lp.bottomMargin);

// lp.setMargins(finalx, finaly, 0, 0);

// BulletBtn[index].setLayoutParams(lp);

// BulletBtn[index].requestLayout();


BulletBtn[index].postDelayed(new Runnable()

{

@Override

public void run()

{

// TODO Auto-generated method stub



FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(BulletBtn[index]

.getLayoutParams());


lp.setMargins(finalx, finaly, 0, 0);

BulletBtn[index].setLayoutParams(lp);

BulletBtn[index].requestLayout();


BulletBtn[index].clearAnimation();

}

}, 0);

}


}

});

}

}

});

Root.addView(ShotBtn, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));


setContentView(Root);

}


boolean fAniEnd = false;

}



posted by 욱이다
2013. 10. 22. 09:59 안드로이드

how to check started service in android ?

영어로는 이렇게 나와있드라고요 ...


<uses-permission android:name="android.permission.GET_TASKS" />


private boolean isServiceRunning(String serviceName)

{

ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);

List<ActivityManager.RunningServiceInfo> l = am.getRunningServices(Integer.MAX_VALUE);

Iterator<ActivityManager.RunningServiceInfo> i = l.iterator();

while (i.hasNext())

{

ActivityManager.RunningServiceInfo runningServiceInfo = (ActivityManager.RunningServiceInfo) i

.next();

if (runningServiceInfo.service.getClassName().equals(serviceName)) { return true; }

}

return false;

}





if(isServiceRunning("kr.my.test.MessageShowService"))

{

Intent ppp = new Intent(getActivity(), MessageShowService.class);

getActivity().stopService(ppp);

}



'안드로이드' 카테고리의 다른 글

ANDROID LISTVIEW GET HEIGHT  (0) 2014.01.15
TranslateAnimation click work  (0) 2014.01.11
안드로이드 커스텀 xml 사용  (0) 2013.08.30
무조건 status bar 보이기  (0) 2013.08.20
Android Asynchronous Http Client  (0) 2013.08.08
posted by 욱이다
2013. 8. 30. 23:53 안드로이드

android custum layout xml
// CustomView.java

public class CustomView extends LinearLayout {

    public CustomView(Context context) {
        super(context);
        init(context);
    }

    public CustomView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public CustomView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context ctx) {
        LayoutInflater.from(ctx).inflate(R.layout.view_custom, this, true);
            // extra init
    }

}



// view_custom.xml

    <!-- Views -->
</merge>

'안드로이드' 카테고리의 다른 글

TranslateAnimation click work  (0) 2014.01.11
안드로이드 서비스 돌고있는지 체크  (0) 2013.10.22
무조건 status bar 보이기  (0) 2013.08.20
Android Asynchronous Http Client  (0) 2013.08.08
Eclipse Attach Source  (0) 2013.02.26
posted by 욱이다
2013. 8. 20. 17:05 안드로이드

android status bar 갑자기 hidden 

view above status bar

camera after activity view 

구글에 검색좀 되라고 .. 영어로 


WindowManager.LayoutParams attrs = getWindow().getAttributes();

{

attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;

}

getWindow().setAttributes(attrs);

posted by 욱이다
2013. 8. 8. 16:42 안드로이드

한글로 잘 설명된 블로그 

http://edoli.tistory.com/91


대표 블로그

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



한번 써봐야겠다 



document


http://loopj.com/android-async-http/doc/com/loopj/android/http/RequestParams.html





RequestParams params = new RequestParams();

params.put("DEVICEID", WanjaApplication.GetDeviceIdObtain(this));

AsyncHttpClient client = new AsyncHttpClient();

// 포스트 방식일때

client.post("http://www.naver.com/", params,new ResponseHandler());

//겟 방식 일때 

client.get("http://www.naver.com/a?dfasd=1&dfas=2", new ResponseHandler());


class ResponseHandler extends AsyncHttpResponseHandler {
@Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
// TODO Auto-generated method stub
Log.i("AA", "onFailure " + arg0 + " " + arg2 + " " + arg3.toString());
for (int i = 0; i < arg1.length; i++) {
Log.i("AA", "onFailure " + arg1[i].getName() + " " + arg1[i].getValue() + " ");
}
super.onFailure(arg0, arg1, arg2, arg3);
}

@Override
public void onFinish() {
// TODO Auto-generated method stub
Log.i("AA", "onFinish ");
loading.dismiss();
super.onFinish();
}

@Override
public void onStart() {
// TODO Auto-generated method stub
Log.i("AA", "onStart ");
loading.show();
super.onStart();
}

@Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
// TODO Auto-generated method stub

Log.i("AA", "onSuccess " + arg0 + " " + arg2);
for (int i = 0; i < arg1.length; i++)
Log.i("AA", "onSuccess " + arg1[i].getName() + " " + arg1[i].getValue() + " ");
super.onSuccess(arg0, arg1, arg2);
}

@Override
protected void sendMessage(Message msg) {
// TODO Auto-generated method stub
Log.i("AA", "sendMessage " + msg);
super.sendMessage(msg);
}

@Override
public void sendResponseMessage(HttpResponse arg0) throws IOException {
// TODO Auto-generated method stub
Log.i("AA", "sendResponseMessage " + arg0.toString());
super.sendResponseMessage(arg0);
}

}


'안드로이드' 카테고리의 다른 글

안드로이드 커스텀 xml 사용  (0) 2013.08.30
무조건 status bar 보이기  (0) 2013.08.20
Eclipse Attach Source  (0) 2013.02.26
안드로이드 커스텀 폰트 사용 (android custom font)  (0) 2012.11.14
프로가드 제외하기  (0) 2012.08.09
posted by 욱이다
prev 1 2 3 4 5 next