Android xml string-array 값 가져오기

<string-array name=”language”>
???????? ?<item>JAVA</item>
????????? <item>C</item>
????????? <item>C++</item>
????????? <item>C#</item>
????????? <item>SCRIPT</item>
</string-array>

String []?language = getResources().getStringArray(R.array.nation_number);
for(int i = 0 ; i < language.length ; i++){
????? Log.i(“language [ " + i + " ] = ” +?language[i] );
}

Android animation 효과들

애니메이션 효과들

<이동>
<?xml version=”1.0″ encoding=”utf-8″?>
<set xmlns:android=”http://schemas.android.com/apk/res/android
??? android:interpolator=”@android:anim/overshoot_interpolator”
??? >
?? <translate android:fromXDelta=”-100%”
????? android:toXDelta=”0″
????? android:duration=”1000″
????/>
</set>

<회전>
<?xml version=”1.0″ encoding=”utf-8″?>
<set xmlns:android=”http://schemas.android.com/apk/res/android
??? android:interpolator=”@android:anim/overshoot_interpolator”
??? >
?? <rotate android:fromDegress=”0.0″
????? android:toDegress=”360″
????? android:pivotX=”0%”
????? android:pivotY=”50%”
?? />
</set>

<크기>
<?xml version=”1.0″ encoding=”utf-8″?>
<set xmlns:android=”http://schemas.android.com/apk/res/android
??? android:interpolator=”@android:anim/overshoot_interpolator”
??? >
?? <scale android:fromXScale=”1″
????? android:toXScale=”1″
????? android:fromYScale=”0.1″
????? android:toYScale=”1.0″
????? android:duration=”500″
????? android:pivotX=”50%”
????? android:pivotY=”50%”
?? />
</set>

<알파>
<?xml version=”1.0″ encoding=”utf-8″?>
<set xmlns:android=”http://schemas.android.com/apk/res/android
??? android:interpolator=”@android:anim/overshoot_interpolator”
??? >
?? <alpha android:fromAlpha=”0.0″
????? android:toAlpha=”1.0″
????? android:duration=”1000″
?? />
</set>

<혼합>
<?xml version=”1.0″ encoding=”utf-8″?>
<set xmlns:android=”http://schemas.android.com/apk/res/android
??? android:interpolator=”@android:anim/overshoot_interpolator”
??? >
??? <translate
??????? android:fromYDelta=”0″
??????? android:toYDelta=”100%”
??????? android:duration=”1000″
??????? />
??? <alpha
??????? android:fromAlpha=”1.0″
??????? android:toAlpha=”0.0″
??????? android:duration=”1000″
??????? />
</set>

Android GPS 로 좌표 가져오기

LocationManager locationM;
LocationListener locationL;

locationM = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location loc = locationM.getLsatKnownLocation(LocationManager.GPS_PROVIDER);

if(loc == null){
?? return null;
}

locationL = new LocationListener(){
?? @Override
??
public void onStatusChanged(String provider, int status, Bundle extras) {

?? }
???@Override
?? public void onProviderEnabled(String provider) {
?
?? }
?? @Override
?? public void onProviderDisabled(String provider) {
?
?? }
?? //위치 정보가 변경 됐을 때 위치 정보를 가져온다.
?? @Override
?? public void onLocationChanged(Location location) {
????? Log.i("HONEYMAP","Lat:"+location.getLatitude()+
????????????????? "Lng:"+location.getLongitude());
????? myLat = location.getLatitude()*1E6;
????? myLng = location.getLongitude()*1E6;
?? }
};
?
//gps로부터 위치 변경이 올 경우 업데이트 하도록 설정
locationM.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationL);
?
//가장 최근 위치를 저장
myLat = locationM.getLastKnownLocation(LocationManager.GPS_PROVIDER).
??????????? getLatitude()*1E6;
myLng = locationM.getLastKnownLocation(LocationManager.GPS_PROVIDER).
??????????? getLongitude()*1E6;
?
?

Android txt 파일 읽어 오기

public void onCreate(Bundle savedInstanceState){
?? super.onCreate(savedInstanceState);
???setContentView(R.layout.text_test);

?? EditText txt_test = (EditText)findViewById(R.id.et_1);

?? String?test_file = getStringFromAsset2(safe_join_provision.this, “test.txt”);
}

public static String getStringFromAsset2(Activity activity, String file){
?? String result =”";
?? AssetManager assetManager = activity.getAssets();
? ?InputStream is = null;
? ?try {
????? is = assetManager.open(file);
????? result = convertStreamToString2(is);
? ?} catch (Exception e) {
????? // TODO: handle exception
? ?} finally{
????? try {
???????? is.close();
????? } catch (Exception e2) {
???????? // TODO: handle exception
???? ?}
?? }
?? return result;
}

 

?public static String convertStreamToString2(InputStream is) {
?? ByteArrayOutputStream baos = new ByteArrayOutputStream();
?? BufferedReader br = null;
?? String temp = “”;
?? try {
???br = new BufferedReader(new InputStreamReader(is));
?? } catch (Exception e1) {
???? ?// TODO Auto-generated catch block
????? e1.printStackTrace();
?? }
?? try {
????? String tmp = “”;
???
????? while((tmp = br.readLine()) != null){
??????? ?temp += tmp+”\n”;
???? ?}
?? } catch (Exception e) {
???? ?// TODO: handle exception
? ?} finally{
???? ?try {
??????? ?if(br != null)
??????? ?br.close();
????? } catch (IOException e) {
????????? // TODO Auto-generated catch block
???????? e.printStackTrace();
????? }
?? }

?? return temp;
}

Android 설치된 어플 목록 PackageInfo를 통해 가져오기 및 다른 어플 실행

1. 설치된 어플 목록 PackageInfo 를 통해 가져오기
List appinfo = getPackageManager().getInstalledPackages(PackageManager.GET_ACTIVITIES);
for(int i = 0 ; i < appinfo.size() ; i ++){
PackageInfo pi = appinfo.get(i);
String appname = pi.packageName
}

2. 다른 어플 실행 시키기 (1)
ComponentName compname = new ComponentName(“패키지명”, “클래스명”);
Intent actintent = new Intent(Intent.ACTION_MAIN);
actintent.ADDcategory(Intent.CATEGORY_LAUNCHER);
actintent.setComponent(compname);
act.startActivity(actintent);

다른 어플 실행 시키기 (2)
Intent toLaunch = Util.getLaunchIntentForPackage(CommonDefine.packageName);
toLaunch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent intentBack = PendingIntent.getActivity(aContext, 0, toLaunch, 0);

다른 어플 실행 시키기 (3)
PackageManager packagemanager = getPackageManager();
String packagename = (String)v.getTag();
try{
Intent intent = packagemanager.getLaunchIntentForPackage(packagename);
if(intent != null){
startActivity(intent);
}
}catch(ActivityNotFoundException e){
e.printStackTrace();
}

Andorid button에 selector 적용하기

drawable 폴더에 “btn_on.png”,”btn_off.png”,”icon_on_off.xml” 을 생성한다.

icon_on_off.xml 을 열어 아래 코드를 삽입한다.


android:drawable="@drawable/btn_on" />

android:drawable="@drawable/btn_on" />

android:drawable="@drawable/btn_on" />


※ 여기서 주의할 점 default 이미지 값은 맨 하단에 명시해야 정상적으로 작동된다는 점!!!!

3. ImageButton 을 사용하는 레이아웃 XML 파일을 열어서 아래와 같이 속성을 지정한다.

android:id="@+id/menu1"
android:background="#000000"
android:src="@drawable/menu_n1"
... >

※ 여기서 또 주의할 점 background에 #00000000을 넣어주지 않으면 안드로이드 기본 버튼 위에 이미지를 올린다는 점!!!!