'안드로이드'에 해당되는 글 48건

  1. 2013.09.11 [Android] - 안드로이드 화면 전환 슬라이드, Activity Slide
  2. 2013.08.29 [Android] - 안드로이드 Notification, 상태바 알림 사용예제
  3. 2013.07.23 [Android] - Service 구현시 메모리 정리시 서비스 죽을때 대처법
  4. 2013.07.15 [Android] - 안드로이드 현재 설정된 언어 가져오기
  5. 2013.07.05 [Android] - 안드로이드 ImageView 리사이징 함수
  6. 2013.07.02 [Android] - 안드로이드 AsyncTask 리턴값 받기 예제
  7. 2013.07.01 [Android] - 안드로이드 블루투스 헤드셋 브로드캐스트 리시버
  8. 2013.06.28 [Android] - 안드로이드 뒤로 두번 종료 소스

[Android] - 안드로이드 화면 전환 슬라이드, Activity Slide

Android Java 2013. 9. 11. 16:07
반응형

왼쪽에서 오른쪽으로 움직일때


startActivity(intent);

overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);


오른쪽에서 왼쪽으로 움직일때


overridePendingTransition(R.anim.left_in, R.anim.left_out);


res 폴더 아래 anim 폴더 생성후

left_in.xml

left_out.xml


*. left_in.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">

 <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>

 <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />

</set>


*. left_out.xml


<set xmlns:android="http://schemas.android.com/apk/res/android">

 <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="300"/>

 <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />

</set>

반응형
:

[Android] - 안드로이드 Notification, 상태바 알림 사용예제

Android Java 2013. 8. 29. 17:30
반응형

private static Notification noti;

private static final int notiId = 1;


noti = new NotificationCompat.Builder(ncontext)

.setSmallIcon(R.drawable.btn_star)

.setContentTitle(title)

.setContentText(content)

.setTicker("알람이 동작되었습니다.")

.setContentIntent(pintent)

.setAutoCancel(false)

.build();


noti.flags |= Notification.FLAG_NO_CLEAR; // 지우기 버튼 눌렀을때 지워지지 않게

nm.notify(notiId, noti); // 알림 동작

nm.cancel(notiId); // 알림 제거

반응형
:

[Android] - Service 구현시 메모리 정리시 서비스 죽을때 대처법

Android Java 2013. 7. 23. 17:00
반응형

<service android:process=":remote">

반응형
:

[Android] - 안드로이드 현재 설정된 언어 가져오기

Android Java 2013. 7. 15. 12:45
반응형

Locale locale = getResources().getConfiguration().locale;

String displayCountry =  locale.getDisplayCountry();

String country =  locale.getCountry();

String language =  locale.getLanguage();

Log.e(Gv.TAG, "Country = " + displayCountry  );

Log.e(Gv.TAG, "country = " + country  );

Log.e(Gv.TAG, "Language = " + language  );


반응형
:

[Android] - 안드로이드 ImageView 리사이징 함수

Android Java 2013. 7. 5. 11:23
반응형

public static Context context;

public static ImageView bg_mic;

public static final int ratioWidth  = 768;   // 이미지 제작시 작업한 가로 사이즈 (px)

public static final int ratioHeight = 1024; // 이미지 제작시 작업한 세로 사이즈 (px)


@Override

protected void onCreate(Bundle savedInstanceState) 

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main); 


context = this;


bg_mic = (ImageView) findViewById(R.id.bg_mic);

}


@Override

public void onWindowFocusChanged(boolean hasFocus) 

{

super.onWindowFocusChanged(hasFocus);

if (hasFocus == true) 

{

resizeImg(btn_mic, R.drawable.btn_mic_off_press, 0 , 1112);

}

}


public static void resizeImg(ImageView imgView, int id, int X, int Y)

{

BitmapFactory.Options options = new BitmapFactory.Options();

options.inJustDecodeBounds = true;

BitmapFactory.decodeResource(context.getResources(), id, options);

double imgWidth  = options.outWidth;

double imgHeight = options.outHeight;

double widthRat = (double) ratioWidth / imgWidth;

double HeightRat = (double) ratioWidth / imgHeight;

double XRate = (double) ratioWidth / X;

double YRate = (double) ratioWidth / Y;

int newX = (int) Math.ceil(DeviceWidth / XRate);

int newY = (int) Math.ceil(DeviceWidth / YRate);

int newImgWidth  = (int) Math.ceil(DeviceWidth / widthRat);

int newImgHeight = (int) Math.ceil(DeviceWidth / HeightRat);

if( ( newImgHeight + newY ) > DeviceHeight )

{

newY = DeviceHeight - newImgHeight;

}

if( ( newImgWidth + newX ) > DeviceWidth )

{

newX = DeviceWidth - newImgWidth;

}

Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), id);

Bitmap bm  = Bitmap.createScaledBitmap(bmp, newImgWidth, newImgHeight, true);


Math.ceil(DeviceWidth / YRate));

imgView.setImageBitmap(bm);

if(X > 0)

imgView.setX( newX );

if(Y > 0)

imgView.setY( newY );

}


* 이미지 제작시 기준잡았던 사이즈를 기준으로 X, Y 픽셀을 입력하시면됩니다.

직접 만든거라서 오류가 발생할수도 있습니다. ( 참고로 안드로이드 한지 한달째 입니다... )


반응형
:

[Android] - 안드로이드 AsyncTask 리턴값 받기 예제

Android Java 2013. 7. 2. 19:51
반응형

데이터 수신요청 쪽 ----------------------------------------------------


ArrayList<String> param = new ArrayList<String>();

param.add("url=" + MusicGlobalsClass.HTTP_HOST + "/Login.php");

String url = MusicGlobalsClass.HTTP_HOST + "/Login.php";

String parm = "mode=login";

   parm   += "&";

   parm   += "id=" + id;

   parm   += "&";

   parm   += "pw=" + pw;


HttpResponse result = null;

try {

result = new NetworkClass().execute(url, parm).get();

processEntity(result);

} catch (InterruptedException e) {

e.printStackTrace();

} catch (ExecutionException e) {

e.printStackTrace();

}


private void processEntity(HttpResponse rtnResult)

{

HttpEntity entity = rtnResult.getEntity();

BufferedReader br;

String line, result = "";

try 

{

br = new BufferedReader(new InputStreamReader(entity.getContent(), "UTF-8"));

while((line = br.readLine()) != null) 

{

result += line;

}

Log.i(MusicGlobalsClass.TAG, " 결과 == " + result);

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IllegalStateException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}


데이터 AsyncTask 처리 ----------------------------------------------------

NetworkClass.java


public class NetworkClass extends AsyncTask<String, Void, HttpResponse>

{

@Override 

protected void onPreExecute() {

      super.onPreExecute(); 

}

@Override

protected HttpResponse doInBackground(String... param) 

{

String httpHost = param[0];

String[] pm = param[1].split("&");

List postParam = new ArrayList();

UrlEncodedFormEntity entity = null;

HttpResponse response = null;

HttpClient client = new DefaultHttpClient();

HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000);

HttpPost httpPost = new HttpPost(httpHost);

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

{

String[] newPm = pm[i].split("=");

postParam.add(new BasicNameValuePair(newPm[0], newPm[1]));

}

try 

{

entity = new UrlEncodedFormEntity(postParam, "UTF-8");

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

}


httpPost.setEntity(entity);

try 

{

response = client.execute(httpPost);

}

catch(ClientProtocolException e)

{

e.printStackTrace();

}

catch(IOException e)

{

e.printStackTrace();

}


return response;

}

@Override

protected void onPostExecute(HttpResponse result) {

super.onPostExecute(result);

}

}



반응형
:

[Android] - 안드로이드 블루투스 헤드셋 브로드캐스트 리시버

Android Java 2013. 7. 1. 11:51
반응형

@Override

public void onReceive(Context context, Intent intent) 

{

String action = intent.getAction();

Log.i(TAG, " ================== " + action);

if(action.equals(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED))

{

int status = intent.getIntExtra(BluetoothHeadset.EXTRA_STATE, AudioManager.SCO_AUDIO_STATE_ERROR);

// status = 0 : Disconnected

// status = 1 : Connecting

// status = 2 : Connected

if(status == 0)

{

Log.e(TAG, " ================== 헤드셋 연결해제");

}else if(status == 1)

{

Log.e(TAG, " ================== 헤드셋 연결중");

}else if(status == 2)

{

Log.e(TAG, " ================== 헤드셋 연결됨");

}

}

}

반응형
:

[Android] - 안드로이드 뒤로 두번 종료 소스

Android Java 2013. 6. 28. 15:13
반응형

public class TransferActivity extends Activity 

{

private boolean m_bFlag = false;

private Handler m_hHandler;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.transferactivity);

m_hHandler = new Handler() {

@Override

public void handleMessage(Message msg) {

if(msg.what == 0) {

m_bFlag = false;

}

}

};

}

public boolean onKeyDown(int KeyCode, KeyEvent event)

{

super.onKeyDown(KeyCode, event);


if(event.getAction() == KeyEvent.ACTION_DOWN) {

switch(KeyCode) {

case KeyEvent.KEYCODE_BACK: // `뒤로` 키와 같은 기능을 한다.

if(!m_bFlag) {

Toast.makeText(getApplicationContext(), "뒤로 버튼을 한번 더 누르시면 종료됩니다",     Toast.LENGTH_SHORT).show();

m_bFlag = true;

m_hHandler.sendEmptyMessageDelayed(0, 2000);


return false;

}

else {

moveTaskToBack(true);

finish();

android.os.Process.killProcess(android.os.Process.myPid() ); 

}

return true;

}

}


return false;

}

}

반응형
: