ListView에 버튼을 넣으려면 커스터마이징을 해야한다. BaseAdapter를 상속받아 Adapter를 커스텀하고

아래와 같이 이벤트 리스너를 등록을하면 버튼은 작동을 하지만 리스트가 클릭이 되지 않는 문제가 생긴다.


ListView.setOnItemClickListener()

ListView.setOnItemLongClickListener()


구글링 결과 커스텀 리스트에 버튼이 들어있을경우 모든 이벤트를 버튼이 흡수해버린다.
ImageButton으로 되어있는걸 ImageView로 변경하고 ImageView에 android:clickable="true" 옵션을 주니
이벤트 리스너가 정상작동한다.








커스텀 리스트뷰를 만들어 적용 후 데이터를 넣고 스크롤을 했더니 아이템 위치가 변경되는 현상이 발견.

생성한 Adapter의 getView에 홀더를 추가하여 데이터 변형을 방지 하였다.


@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final int pos = position;
		
		CustomViewHolder holder;

		if ( convertView == null ) {
			.. 생략
			final TextView textview = (TextView)convertView.findViewById(R.id.custom_word_text);
			textview.setText( m_List.get(pos).getWord() );

			ImageButton btn = (ImageButton) convertView.findViewById(R.id.custom_word_listen);

			holder = new CustomViewHolder();
			holder.m_TextView	= textview;
			holder.m_ImgBtn		= btn;
			
			convertView.setTag(holder);
		}
		else {
			holder = (CustomViewHolder) convertView.getTag();
		}

		if ( m_List.get(pos).isVisibleWord() ) {
			holder.m_TextView.setText(m_List.get(pos).getWord());
		}
		else
			holder.m_TextView.setText(m_List.get(pos).getMeaning());
			
		return convertView;
	}
	
	public class CustomViewHolder {
		public TextView		m_TextView;
		public ImageButton	m_ImgBtn;
	}







Jni를 사용할때 Java를 거치지 않고 Asset파일에 접근 할 수 있다.

먼저 Java에서 Context.getAssets();을 사용하여 AssetManager를 보내준다.

	private static native void nativeCreated(AssetManager asset);

jni.c

#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
AAssetManager	*mgr;

void Java_pe_berabue_ex_GLView_nativeCreated(JNIEnv * env, jclass cls, jobject assetManager)
{
	char *buf;
	int fileSize;

	mgr = AAssetManager_fromJava(GetEnv(), assetManager);

	AAsset* asset = AAssetManager_open(mgr, "tmp.txt", AASSET_MODE_UNKNOWN);	// Asset 폴더안에 tmp.txt가 존재하면

	if ( asset == NULL )
		return;
	
	fileSize = AAsset_getLength(asset);
	
	if ( fileSize == 0 )
		return;
	
	buf = (char *)malloc(sizeof(char)*fileSize);
	AAsset_read(asset, buf, fileSize);
	
	AAsset_close(asset);
}

최소한의 소스만 적어보자면 위와 같다.

헤더파일을 포함시키고 Java에서 받아온 assetManager를 사용하면 된다.


android:minSdkVersion 9 이상 사용가능







C 사용시

void Java_com_berabue_test_GLView_nativeDrawFrame()
{
	LOGI("onDrawFrame");
}


C++ 사용시  


extern "C"
{
	JNIEXPORT void JNICALL Java_com_berabue_test_GLView_nativeDrawFrame()
	{
		LOGI("onDrawFrame");
	}
}








NDK 개발 시 앱이 종료되면서 위와같은 에러가 출력 될 때가 있다.

이때는 함수까지만 확인이 가능하고 정확한 라인을 알 수 없으므로 오류가 나는 라인을 알아 볼 수 있는 방법을 알아본다.


1. cygwin을 사용해서 cygwin이 설치 된 폴더에 bin으로 들어간다.


2. bin폴더에 오류가 발생한 라이브러리를 붙여넣기 한다. (lib라이브러리.so)


3. addr2line.exe -f -e 라이브러리명.so 00041f40

 위와 같은 형식의 명령어를 입력한다.

 00041f40은 위 이미지에 #06 pc 우측에 있는 16진수이다. 16진수를 입력하면 해당 함수의 몇번째 라인에서 오류가 났는지 출력 된다.


명령어 입력시 아래와같이 출력된다.


getJClass

C:/Develop/Android/workspace/프로젝트명/jni/jni-ndk.c:32


해당 프로젝트 jni-ndk.c 소스의 32번 라인에서 오류가 발생한걸 확인 할 수 있다.





ndk-build 시 'note: the mangling of 'va_list' has changed in GCC 4.4' 해당 문구가 뜨면


Android.mk 파일에 아래 문구를 추가한다.


LOCAL_CFLAGS :=  -Wno-psabi






이 전 글에서 제작한 정적 라이브러리를 원하는 프로젝트에 포함시키는 방법입니다.


1. 먼저 준비된 라이브러리 파일(.a)과 헤더파일(.h)을 jni 폴더에 복사합니다.


2. Android.mk 파일을 열어 아래와 같이 수정합니다.



LOCAL_PATH := $(call my-dir)

# 미리 준비한 라이브러리 파일 관련
include $(CLEAR_VARS)
LOCAL_MODULE := static_berabue			# 대충 적으시면 됩니다.
LOCAL_SRC_FILES = ./libberabue.a		# 준비된 라이브러리 파일명
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)

# 현재 프로젝트 관련
# 제작될 so 파일명
LOCAL_MODULE := curlib

# 현재 프로젝트에 사용중인 소스파일명
LOCAL_SRC_FILES := jni-ndk.c\
				GLGameRenderer.c\

# 사용하는 라이브러리가 있다면.. 없으면 제거
LOCAL_LDLIBS := -lGLESv1_CM\
				-llog\
				-ljnigraphics\

# 위에서 적은 모듈명
LOCAL_STATIC_LIBRARIES := static_berabue

include $(BUILD_SHARED_LIBRARY)

작성이 완료되었으면 ndk-build를 해봅니다.


오류가 없다면 so 파일이 생성되어있습니다.





'Android > Etc.' 카테고리의 다른 글

NDK 개발 시 디버깅하기  (0) 2013.05.31
note: the mangling of 'va_list' has changed in GCC 4.4  (0) 2013.03.20
정적 라이브러리 만들기  (0) 2012.09.25
Max OS에서 NDK 개발하기  (1) 2012.07.04
넥서스S USB 드라이버 다운  (0) 2011.04.18



NDK로 개발중 자주 사용하는 부분만 따로 라이브러리화 시키기 위해서 정적 라이브러리 파일 .a를 만드는 방법입니다.


라이브러리화 시킬 소스파일이 있는 폴더에 android.mk 파일을 아래와 같이 작성합니다.

LOCAL_PATH := $(call my-dir)

# 제작될 라이브러리(.a) 소스
include $(CLEAR_VARS)

# 라이브러리 이름
LOCAL_MODULE    := berabue

# 라이브러리에 포함될 소스 파일명
LOCAL_SRC_FILES := main.c\
				math.c\
				struct.c\

include $(BUILD_STATIC_LIBRARY)


# 쓰레기 .so 파일로 필수로 작성되어야 합니다
include $(CLEAR_VARS)

# 아무것이나 적습니다
LOCAL_MODULE    := garbege

# 위에 작성한 정적 라이브러리 이름
LOCAL_STATIC_LIBRARIES := berabue
include $(BUILD_SHARED_LIBRARY)

android.mk 파일을 위와같이 작성한 뒤 해당 폴더를 빌드(ndk-build)하


obj -> local -> armeabi 폴더에 berabue.a 파일이 생성됩니다.


해당 라이브러리파일과 소스에 사용되는 헤더파일(.h)을 같이 사용할 프로젝트에 넣으면 됩니다.









1. 구글 개발자 사이트에서 맥os용 NDK를 다운받아 원하는곳에 압축을 풀어 놓는다.


2. 터미널을 켜고 ls -al을 입력하여 .bash_profile 파일이 있는지 확인한다. (없을경우로 설명, 있으면 지우고(?))


3. vi .bash_profile을 입력하고 i 를 입력하여 입력모드로 변경


4. export PATH=${PATH}:/Users/ChangKeun/Program/Android/android-ndk/ (ndk폴더가 있는 경로 입력)


5. esc를 눌러서 입력모드 종료 후 : 를 입력시키고 wq 입력 후 ls -al 생성되어있음.


6. source .bash_profile 입력을 통하여 path설정


7. ndk-build 테스트 ~ 성공 ~ !



'Android > Etc.' 카테고리의 다른 글

프로젝트에 정적 라이브러리 추가하기  (0) 2012.09.25
정적 라이브러리 만들기  (0) 2012.09.25
넥서스S USB 드라이버 다운  (0) 2011.04.18
Orientation 고정, 키보드 숨기기  (0) 2011.04.17
멀티터치 구현하기  (0) 2011.03.16

'Android > Etc.' 카테고리의 다른 글

정적 라이브러리 만들기  (0) 2012.09.25
Max OS에서 NDK 개발하기  (1) 2012.07.04
Orientation 고정, 키보드 숨기기  (0) 2011.04.17
멀티터치 구현하기  (0) 2011.03.16
Permission  (0) 2011.01.26



타이틀바를 없애도 풀스크린 사용.
단말기를 기울였을때 화면을 바꾸고 싶지 않거나, 쿼티자판을 뺏을때 화면이 갱신되는 것을 막는다.

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="Test" 
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenorientation="landscape" android:configchanges="orientation|keyboardHidden">
</activity>
</application>



'Android > Etc.' 카테고리의 다른 글

Max OS에서 NDK 개발하기  (1) 2012.07.04
넥서스S USB 드라이버 다운  (0) 2011.04.18
멀티터치 구현하기  (0) 2011.03.16
Permission  (0) 2011.01.26
데이터 저장 (SharedPreferences)  (0) 2011.01.25

멀티터치는 2.1 이상의 버전에서 구현 가능하다.

	/* onTouch Event */
	public boolean onTouchEvent(MotionEvent e) {
		if ( e.getAction() == MotionEvent.ACTION_DOWN || e.getAction() == MotionEvent.ACTION_MOVE ) {
			int touchCount = e.getPointerCount();
						
			if ( touchCount > 1 ) {
				x1 = (int)e.getX(1);
				y1 = (int)e.getY(1);
			}
			else {
				x = (int)e.getX(0);
				y = (int)e.getY(0);
			}
		}
		return true;
	} // Touch Event 끝

간단한코드. e.getPointerCount()를 사용하여 몇개가 터치되고 있는지를 받아온다.
위 소스는 두개만을 받아왔다.
리스트를 사용하면 최대 지원가능한 수 까지 받아올 수 있을듯.

'Android > Etc.' 카테고리의 다른 글

Max OS에서 NDK 개발하기  (1) 2012.07.04
넥서스S USB 드라이버 다운  (0) 2011.04.18
Orientation 고정, 키보드 숨기기  (0) 2011.04.17
Permission  (0) 2011.01.26
데이터 저장 (SharedPreferences)  (0) 2011.01.25
Constants
String ACCESS_CHECKIN_PROPERTIES Allows read/write access to the "properties" table in the checkin database, to change values that get uploaded.
String ACCESS_COARSE_LOCATION Allows an application to access coarse (e.g., Cell-ID, WiFi) location
String ACCESS_FINE_LOCATION Allows an application to access fine (e.g., GPS) location
String ACCESS_LOCATION_EXTRA_COMMANDS Allows an application to access extra location provider commands
String ACCESS_MOCK_LOCATION Allows an application to create mock location providers for testing
String ACCESS_NETWORK_STATE Allows applications to access information about networks
String ACCESS_SURFACE_FLINGER Allows an application to use SurfaceFlinger's low level features
String ACCESS_WIFI_STATE Allows applications to access information about Wi-Fi networks
String ACCOUNT_MANAGER Allows applications to call into AccountAuthenticators.
String AUTHENTICATE_ACCOUNTS Allows an application to act as an AccountAuthenticator for the AccountManager
String BATTERY_STATS Allows an application to collect battery statistics
String BIND_APPWIDGET Allows an application to tell the AppWidget service which application can access AppWidget's data.
String BIND_DEVICE_ADMIN Must be required by device administration receiver, to ensure that only the system can interact with it.
String BIND_INPUT_METHOD Must be required by an InputMethodService, to ensure that only the system can bind to it.
String BIND_REMOTEVIEWS Must be required by a RemoteViewsService, to ensure that only the system can bind to it.
String BIND_WALLPAPER Must be required by a WallpaperService, to ensure that only the system can bind to it.
String BLUETOOTH Allows applications to connect to paired bluetooth devices
String BLUETOOTH_ADMIN Allows applications to discover and pair bluetooth devices
String BRICK Required to be able to disable the device (very dangerous!).
String BROADCAST_PACKAGE_REMOVED Allows an application to broadcast a notification that an application package has been removed.
String BROADCAST_SMS Allows an application to broadcast an SMS receipt notification
String BROADCAST_STICKY Allows an application to broadcast sticky intents.
String BROADCAST_WAP_PUSH Allows an application to broadcast a WAP PUSH receipt notification
String CALL_PHONE Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.
String CALL_PRIVILEGED Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed.
String CAMERA Required to be able to access the camera device.
String CHANGE_COMPONENT_ENABLED_STATE Allows an application to change whether an application component (other than its own) is enabled or not.
String CHANGE_CONFIGURATION Allows an application to modify the current configuration, such as locale.
String CHANGE_NETWORK_STATE Allows applications to change network connectivity state
String CHANGE_WIFI_MULTICAST_STATE Allows applications to enter Wi-Fi Multicast mode
String CHANGE_WIFI_STATE Allows applications to change Wi-Fi connectivity state
String CLEAR_APP_CACHE Allows an application to clear the caches of all installed applications on the device.
String CLEAR_APP_USER_DATA Allows an application to clear user data
String CONTROL_LOCATION_UPDATES Allows enabling/disabling location update notifications from the radio.
String DELETE_CACHE_FILES Allows an application to delete cache files.
String DELETE_PACKAGES Allows an application to delete packages.
String DEVICE_POWER Allows low-level access to power management
String DIAGNOSTIC Allows applications to RW to diagnostic resources.
String DISABLE_KEYGUARD Allows applications to disable the keyguard
String DUMP Allows an application to retrieve state dump information from system services.
String EXPAND_STATUS_BAR Allows an application to expand or collapse the status bar.
String FACTORY_TEST Run as a manufacturer test application, running as the root user.
String FLASHLIGHT Allows access to the flashlight
String FORCE_BACK Allows an application to force a BACK operation on whatever is the top activity.
String GET_ACCOUNTS Allows access to the list of accounts in the Accounts Service
String GET_PACKAGE_SIZE Allows an application to find out the space used by any package.
String GET_TASKS Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.
String GLOBAL_SEARCH This permission can be used on content providers to allow the global search system to access their data.
String HARDWARE_TEST Allows access to hardware peripherals.
String INJECT_EVENTS Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.
String INSTALL_LOCATION_PROVIDER Allows an application to install a location provider into the Location Manager
String INSTALL_PACKAGES Allows an application to install packages.
String INTERNAL_SYSTEM_WINDOW Allows an application to open windows that are for use by parts of the system user interface.
String INTERNET Allows applications to open network sockets.
String KILL_BACKGROUND_PROCESSES Allows an application to call killBackgroundProcesses(String).
String MANAGE_ACCOUNTS Allows an application to manage the list of accounts in the AccountManager
String MANAGE_APP_TOKENS Allows an application to manage (create, destroy, Z-order) application tokens in the window manager.
String MASTER_CLEAR
String MODIFY_AUDIO_SETTINGS Allows an application to modify global audio settings
String MODIFY_PHONE_STATE Allows modification of the telephony state - power on, mmi, etc.
String MOUNT_FORMAT_FILESYSTEMS Allows formatting file systems for removable storage.
String MOUNT_UNMOUNT_FILESYSTEMS Allows mounting and unmounting file systems for removable storage.
String NFC Allows applications to perform I/O operations over NFC
String PERSISTENT_ACTIVITY This constant is deprecated. This functionality will be removed in the future; please do not use. Allow an application to make its activities persistent.
String PROCESS_OUTGOING_CALLS Allows an application to monitor, modify, or abort outgoing calls.
String READ_CALENDAR Allows an application to read the user's calendar data.
String READ_CONTACTS Allows an application to read the user's contacts data.
String READ_FRAME_BUFFER Allows an application to take screen shots and more generally get access to the frame buffer data
String READ_HISTORY_BOOKMARKS Allows an application to read (but not write) the user's browsing history and bookmarks.
String READ_INPUT_STATE Allows an application to retrieve the current state of keys and switches.
String READ_LOGS Allows an application to read the low-level system log files.
String READ_PHONE_STATE Allows read only access to phone state.
String READ_SMS Allows an application to read SMS messages.
String READ_SYNC_SETTINGS Allows applications to read the sync settings
String READ_SYNC_STATS Allows applications to read the sync stats
String REBOOT Required to be able to reboot the device.
String RECEIVE_BOOT_COMPLETED Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting.
String RECEIVE_MMS Allows an application to monitor incoming MMS messages, to record or perform processing on them.
String RECEIVE_SMS Allows an application to monitor incoming SMS messages, to record or perform processing on them.
String RECEIVE_WAP_PUSH Allows an application to monitor incoming WAP push messages.
String RECORD_AUDIO Allows an application to record audio
String REORDER_TASKS Allows an application to change the Z-order of tasks
String RESTART_PACKAGES This constant is deprecated. The restartPackage(String) API is no longer supported.
String SEND_SMS Allows an application to send SMS messages.
String SET_ACTIVITY_WATCHER Allows an application to watch and control how activities are started globally in the system.
String SET_ALARM Allows an application to broadcast an Intent to set an alarm for the user.
String SET_ALWAYS_FINISH Allows an application to control whether activities are immediately finished when put in the background.
String SET_ANIMATION_SCALE Modify the global animation scaling factor.
String SET_DEBUG_APP Configure an application for debugging.
String SET_ORIENTATION Allows low-level access to setting the orientation (actually rotation) of the screen.
String SET_PREFERRED_APPLICATIONS This constant is deprecated. No longer useful, seeaddPackageToPreferred(String) for details.
String SET_PROCESS_LIMIT Allows an application to set the maximum number of (not needed) application processes that can be running.
String SET_TIME Allows applications to set the system time
String SET_TIME_ZONE Allows applications to set the system time zone
String SET_WALLPAPER Allows applications to set the wallpaper
String SET_WALLPAPER_HINTS Allows applications to set the wallpaper hints
String SIGNAL_PERSISTENT_PROCESSES Allow an application to request that a signal be sent to all persistent processes
String STATUS_BAR Allows an application to open, close, or disable the status bar and its icons.
String SUBSCRIBED_FEEDS_READ Allows an application to allow access the subscribed feeds ContentProvider.
String SUBSCRIBED_FEEDS_WRITE
String SYSTEM_ALERT_WINDOW Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications.
String UPDATE_DEVICE_STATS Allows an application to update device statistics.
String USE_CREDENTIALS Allows an application to request authtokens from the AccountManager
String USE_SIP Allows an application to use SIP service
String VIBRATE Allows access to the vibrator
String WAKE_LOCK Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming
String WRITE_APN_SETTINGS Allows applications to write the apn settings
String WRITE_CALENDAR Allows an application to write (but not read) the user's calendar data.
String WRITE_CONTACTS Allows an application to write (but not read) the user's contacts data.
String WRITE_EXTERNAL_STORAGE Allows an application to write to external storage
String WRITE_GSERVICES Allows an application to modify the Google service map.
String WRITE_HISTORY_BOOKMARKS Allows an application to write (but not read) the user's browsing history and bookmarks.
String WRITE_SECURE_SETTINGS Allows an application to read or write the secure system settings.
String WRITE_SETTINGS Allows an application to read or write the system settings.
String WRITE_SMS Allows an application to write SMS messages.
String WRITE_SYNC_SETTINGS Allows applications to write the sync settings

'Android > Etc.' 카테고리의 다른 글

Max OS에서 NDK 개발하기  (1) 2012.07.04
넥서스S USB 드라이버 다운  (0) 2011.04.18
Orientation 고정, 키보드 숨기기  (0) 2011.04.17
멀티터치 구현하기  (0) 2011.03.16
데이터 저장 (SharedPreferences)  (0) 2011.01.25

private SharedPreferences pref;
  
    // 데이터 가져오기
    pref = context.getSharedPreferences("score"0)
    high_Score = pref .getInt("key_Score"0);
 
         ---------------------------------------------------------------
         context.getSharedPreferences("score"0)
     "score"는 단말기내의 공간에 score.xml을 참조한다.
     0은 권한을 뜻하는데 어떻게 score.xml이 생기는지 어떤 권한인지는 아직 모르겠다.
 
         high_Score 변수에 키 값이 "key_Score"라고 저장된 Int형 값을 가져온다.
         key_Score라는 키 값이 없으면 디폴트로 0을 가져온다.
 
      // 데이터 저장
      SharedPreferences.Editor ed = pref.edit()
      ed.putInt("key_Score", score)
      ed.commit();

             -------------------------------------------------------

             key_Score 라는 키 값을 갖는 Int형 저장소에 score를 저장한다.

             commit(); 을 완료해 주어야 값이 저장된다.

'Android > Etc.' 카테고리의 다른 글

Max OS에서 NDK 개발하기  (1) 2012.07.04
넥서스S USB 드라이버 다운  (0) 2011.04.18
Orientation 고정, 키보드 숨기기  (0) 2011.04.17
멀티터치 구현하기  (0) 2011.03.16
Permission  (0) 2011.01.26

+ Recent posts