2010/09/29

C++ 키보드 상태 알아내기2




bool bLCtrl = (GetKeyState(VK_LCONTROL) & 0x8000) != 0;
bool bLShift = (GetKeyState(VK_LSHIFT) & 0x8000) != 0;
bool bLMenu = (GetKeyState(VK_LMENU) & 0x8000) != 0;

bool bCapsLock = GetKeyState( VK_CAPITAL ) != 0;
bool bNumLock = GetKeyState( VK_NUMLOCK ) != 0;
bool bScrollLock = GetKeyState( VK_SCROLL ) != 0;

TRACE("Caps Lock : %s, Num Lock : %s, Scroll Lock : %s \n"
, ( bCapsLock )? "ON": "OFF"
, ( bNumLock )? "ON": "OFF"
, ( bScrollLock )? "ON": "OFF"
);
<

Original Post : http://neodreamer-dev.tistory.com/461

2010/09/18

[Android Tips] 화면 상태 확인 하기

현재 화면이 가로인지 새로인지 확인하는 방법은 화면 해상도를 확인하는 방법도 있겠지만 API 에서 제공하는 함수로도 확인 할 수 있다. 가로 혹은 세로 해상도가 같은 경우에는 API 함수를 이용하는 것이 보다 정확할 것이다.





Android 2.1 이하에서는 getOrientation() 만 동작하며 Android 2.2 이상에서는 getOrientation() 과 getRotation() 이 동작을 한다.






Android 2.1 이하


WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();

int orientation = disp.getOrientation(); // Android 2.1
Log.i( "Orientation", "orientation : " + orientation );






Android 2.2 이상


WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();

int rotation = disp.getRotation(); // Android 2.2
Log.i( "Rotation", "rotation : " + rotation );

switch ( rotation )
{
case Surface.ROTATION_0:
Log.i( "Roation", "Portrait : 0" );
break;

case Surface.ROTATION_90:
Log.i( "Roation", "Landscape : 90" );
break;

case Surface.ROTATION_180:
Log.i( "Roation", "Portrait : 180" );
break;

case Surface.ROTATION_270:
Log.i( "Roation", "Landscape : 270" );
break;
}
<

Original Post : http://neodreamer-dev.tistory.com/460

[Android Tips] 화면 해상도 알아내기


방법 #1


DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

int ScreenWidth = metrics.widthPixels
int ScreenHeight = metrics.heightPixels






방법 #2


WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
Display dsp = wm.getDefaultDisplay();

int height = dsp.getHeight();
int width = dsp.getWidth();
<

Original Post : http://neodreamer-dev.tistory.com/459

2010/09/15

[Android Dev.] 화면 회전에 대응하는 UI 구성하기

안드로이드 기기를 보통 사용하는 세로(portrait) 방향 화면에서 가로(landscape) 방향 화면으로 전환하는 것에 대응 하기 위해 서는 서로 다른 Layout 을 구성하는 리소스(xml)를 만들어야 한다.





아주 단순한 layout 구성으로 기본적인 TextView 와 버튼 두개로 구성된 UI 이다. 파일 이름은 main.xml 이다.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
/>
</LinearLayout>






위의 layout 구성은 아래와 같은 화면이다.






이 화면을 가로(Landscape)로 변경(에뮬레이터에서 Ctrl+F11)을 하면 아래와 같은 화면이 된다. UI 구성이 변하지 않은 화면이 나온다.






세로 방향 구성과는 다르게 가로 방향의 UI 구성을 새로 하기 위해서는 res 폴더에 layout-land 폴더를 만들고 layout 폴더에 있는 구성 파일과 동일한 UI 구성 파일(xml)을 만들어 작성을 하면 화면의 회전에 따라 각각의 UI 구성이 출력 된다.






아래는 layout-land 폴더에 작성한 main.xml 파일 이다.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
/>
</LinearLayout>
</LinearLayout>






이 소스를 실행 시켜서 화면 전환을 해 보면 아래와 같은 변화된 UI 의 화면을 볼 수 있다.