public class AppsAdapter extends BaseAdapter {
public AppsAdapter() {
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i;
if (convertView == null) {
i = new ImageView(MyHome.this);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new GridView.LayoutParams(50, 50));
} else {
i = (ImageView) convertView;
}
ResolveInfo info = mApps.get(position);
i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));
return i;
}
public final int getCount() {
return mApps.size();
}
public final Object getItem(int position) {
return mApps.get(position);
}
public final long getItemId(int position) {
return position;
}
}
4) Add onItemClick for GridView
123456
private OnItemClickListener listener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
//TODO....
}
};
5) Launch app when click
1234567891011121314
public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
ResolveInfo info = mApps.get(position);
// Package Name
String pkg = info.activityInfo.packageName;
// Main activity of app
String cls = info.activityInfo.name;
ComponentName componet = new ComponentName(pkg, cls);
Intent i = new Intent();
i.setComponent(componet);
startActivity(i);
}
}
If you want to disable the home/menu/back/search keys or key layout in your apps. You can add some code response the key press event. But if you want to do this out of your apps, you can change the config of system key layout. Of course you have to root first.
You can find *.kl files in /system/usr/keylayout .
Here are some instructions for the files.
AVRCP.kl - Key layout used for Bluetooth AVRCP support.
Generic.kl - Generic key layout file for full alphabetic US English PC style external keyboards.
qwerty.kl - Emulator keyboard layout #1.
Vendor_045e_Product_028e.kl - XBox 360 USB Controller
Vendor_046d_Product_c216.kl - Logitech Dual Action Controller
Vendor_046d_Product_c294.kl - Logitech G25 Racing Wheel (in Compatibility Mode)
Vendor_046d_Product_c299.kl - Logitech G25 Racing Wheel (in Native Mode)
Vendor_046d_Product_c532.kl - Logitech Revue Wireless keyboard
Vendor_054c_Product_0268.kl - Sony Playstation(R)3 Controller
Vendor_05ac_Product_0239.kl - Apple Wireless Keyboard
Vendor_22b8_Product_093d.kl - Motorola Bluetooth Wireless Keyboard.
Edit one .kl file for example.
Here is one line of .kl file.
key 158 BACK WAKE_DROPPED
Explain:
158 - key code
BACK - key function
WAKE - wake up device with sending message to apps
WAKE_DROPPED - wake up device without sending message to apps
We can change BACK to MENU, save the file, restart. Than BACK key changed to MENU key.
So than we can disable any keys or key layout of your device.
#0 0x000000302b807abc in pthread_mutex_lock () from /lib64/tls/libpthread.so.0
#1 0x0000002a9bf58564 in AutoLock (this=0x7fbfff7d50, lock=@0x2a9d7a1af0) at ./util/Lock.h:36
#2 0x0000002a9bf5a91a in forum::HealthyStatus::getSelectRate (this=0x2a9d7a1a98, timeout=100, checkTime=3, minRate=0.10000000000000001)
at filter/HealthyFilter.cpp:80
#3 0x0000002a9bf5b29b in forum::HealthyFilter::doFilter (this=0x1dd88e0, request=0x7fbfff8610) at filter/HealthyFilter.cpp:239
#4 0x0000002a9bf55f9c in forum::ChainFilter::doFilter (this=0x1dd86c0, request=0x7fbfff8610) at filter/ChainFilter.cpp:19
#5 0x0000002a9bf537ba in forum::CamelSuperStrategy::fetchServer (this=0x1ddd850, req=0x7fbfff8f00) at strategy/CamelSuperStrategy.cpp:140
#6 0x0000002a9bf39753 in odp::CamelService::fetchServer (this=0x1dd7d00, req=0x7fbfff9420) at CamelService.cpp:480
#7 0x0000002a9bf47e2b in odp::WorkerManager::fetchServer (this=0x13c6210, serviceName=0x2aa017c088 "Redis_pic_counter", req=0x7fbfff9420) at WorkerManager.cpp:282
#8 0x0000002a9bee02a0 in camel_call (service=0x2aa017c088 "Redis_pic_counter", method=0x2aa01735a8 "INCR", request_value=0x2aa01735e8, return_value=0x2aa0179598,
extra=0x2aa0174720) at worker_proc.cpp:764
#9 0x0000002a9bed9474 in zif_ral (ht=4, return_value=0x2aa0179598, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at camel.cpp:331
#10 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfff9750, return_value_used=1)
at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#11 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfff9750)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
#12 0x000000000076739f in execute (op_array=0x2aa017a710) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#13 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa017a710) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#14 0x000000000073b37b in zend_call_function (fci=0x7fbfff9a20, fci_cache=Variable "fci_cache" is not available.
)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:1049
#15 0x000000000075b2cb in zend_call_method (object_pp=0x7fbfff9ae0, obj_ce=0x2aa0178bf0, fn_proxy=0x2aa0178dd0, function_name=0xc7c52f "__call", function_name_len=6,
retval_ptr_ptr=0x7fbfff9ae8, param_count=729840304, arg1=0x2aa016d948, arg2=0x2aa016c948)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_interfaces.c:88
#16 0x0000000000763389 in zend_std_call_user_call (ht=Variable "ht" is not available.
)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_object_handlers.c:673
#17 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfff9d00, return_value_used=1)
at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#18 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfff9d00)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
#19 0x000000000076739f in execute (op_array=0x2aa01729c8) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#20 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa01729c8) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#21 0x000000000076765c in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfff9fe0)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:234
#22 0x000000000076739f in execute (op_array=0x2aa0166b80) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#23 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa0166b80) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#24 0x000000000073b37b in zend_call_function (fci=0x7fbfffa250, fci_cache=Variable "fci_cache" is not available.
)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:1049
#25 0x000000000073c2b6 in call_user_function_ex (function_table=Variable "function_table" is not available.
)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:650
#26 0x0000000000696881 in zif_call_user_func_array (ht=Variable "ht" is not available.
)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/ext/standard/basic_functions.c:5217
#27 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfffa510, return_value_used=1)
at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#28 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffa510)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
---Type <return> to continue, or q <return> to quit---
#29 0x000000000076739f in execute (op_array=0x2aa016cc70) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#30 0x0000002a98bc0800 in xdebug_execute (op_array=0x2aa016cc70) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#31 0x000000000076765c in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffa7a0)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:234
#32 0x000000000076739f in execute (op_array=0x2a9ff05740) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#33 0x0000002a98bc0800 in xdebug_execute (op_array=0x2a9ff05740) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#34 0x000000000076765c in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffaa00)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:234
#35 0x000000000076739f in execute (op_array=0x2a9ff19428) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#36 0x0000002a98bc0800 in xdebug_execute (op_array=0x2a9ff19428) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#37 0x000000000073b37b in zend_call_function (fci=0x7fbfffacd0, fci_cache=Variable "fci_cache" is not available.
)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_execute_API.c:1049
#38 0x000000000075b2cb in zend_call_method (object_pp=0x7fbfffadc0, obj_ce=0x2a9ff05430, fn_proxy=0x0, function_name=0x2a98d14a27 "execute", function_name_len=7,
retval_ptr_ptr=0x7fbfffade0, param_count=729840304, arg1=0x0, arg2=0x0)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_interfaces.c:88
#39 0x0000002a98cfe3ae in ap_dispatcher_handle (dispatcher=0x2a95c36c40, request=0x2a95c3b2e0, response=0x2a95c3efd0, view=0x2a9fefd6d0)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php-ap_1-1-1-0_PD_BL/output/ap_dispatcher.c:683
#40 0x0000002a98cfea5c in ap_dispatcher_dispatch (dispatcher=0x2a95c36c40)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php-ap_1-1-1-0_PD_BL/output/ap_dispatcher.c:878
#41 0x0000002a98cfbb5d in zim_ap_application_run (ht=Variable "ht" is not available.
) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php-ap_1-1-1-0_PD_BL/output/ap_application.c:438
#42 0x0000002a98bc0b24 in xdebug_execute_internal (current_execute_data=0x7fbfffb0e0, return_value_used=0)
at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1339
#43 0x0000000000767d90 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fbfffb0e0)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:202
#44 0x000000000076739f in execute (op_array=0x2a95c34990) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
#45 0x0000002a98bc0800 in xdebug_execute (op_array=0x2a95c34990) at /home/st/zhangdongjin/php-libs/downloads/xdebug-2.1.0/xdebug.c:1272
#46 0x0000000000749128 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/Zend/zend.c:1134
#47 0x00000000007080c6 in php_execute_script (primary_file=0x7fbffffa80)
at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/main/main.c:2037
#48 0x00000000007d7494 in main (argc=4, argv=0x7fbffffbd8) at /home/work/opbin/install/basic-env_1-0-1_BL/output/tmp/php_5-2-17_PD_BL/output/sapi/cgi/cgi_main.c:2120
5、Using command f could select and print a stack frame.
1
(gdb) f 30
12
#30 0x00000000007672df in execute (op_array=0x2aa00101f8) at /home/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h:92
92 in /home/output/tmp/php_5-2-17_PD_BL/output/Zend/zend_vm_execute.h
I updated my Mac OS X to 10.8GM today. Everything was fine. And then update Xcode to 4.4GM for 4.3 doesn’t support 10.8. I made a mistake that I run Xcode.app in dmg file. Then a setup wizard showed up. I press next next next… Suddenly I remind I should move the app to Application folder first. But the setup wizard can’t show up again. And the path of xcode had be set to /Volumes/Xcode.app/…
How to change it to the right path? I googled it there is a command named xcode-select.
$ xcode-select
xcode-select: Error: no command option given.
xcode-select: Report or change the path to the active
Xcode installation for this machine.
Usage: xcode-select –print-path
Prints the path of the active Xcode folder
or: xcode-select –switch
Sets the path for the active Xcode folder
or: xcode-select –version
Prints the version of xcode-select
HTML5 is very popular now. Lots of apps in mobile using HTML5 framework like PhoneGap, Sencha, Trigger, jQueryMobile…
If you want to develop Mac apps, you have to learn Objective-C and cocoa. But it is difficult for a beginner or web designer. So how about using HTML5? We can add a WebView on the app and display local html in it.
Let’s start!
1. Create a Mac OS X Cocoa Application
Find it in XCode -> File -> New -> Project -> Mac OS X Application -> Cocoa Application
2. Add [WebKit.framework] in your [Link Binary With Libraries].
3. Copy your web files like .html, .js, images to your project. If you can’t see them in your XCode, you should drop them from Finder to XCode.
I did some tests. These web files should be used like in the same path. I think it’s because the files in [Copy Bundle Resources] of [Build Phases] are in the same level.
4. Open your MainMenu.xib and drop a WebView in the interface. Make the size suit your app.
5. Link the WebView to your AppDelegate.h. The code in AppDelegate.h:
As we all know, it’s cost $99 to become a apple developer. But sometimes we have to make sure the app is ready. So how to deploy app before we have a certificate private key? Here we go!
My test environment is:
1、Macbook Air 2011 13'' + Mac OS X Lion 10.7.4 + XCode 4.3.2 + iOS SDK 5.1
2、iPad 1 + iOS 5.0.1
First, modify your SDK setting
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/
sudo vi SDKSettings.plist
Find the key named CODE_SIGNING_REQUIRED and change its value to NO
Second, modify your project setting
1、Select your project in the left [Project navigator]
2、Select the [PROJECT] or [TARGETS]
3、Select [Build Setting]
4、Change the [Code Signing Identity]'s children to [Don't Code Sign]
Third, connect your iOS device to your Mac. The version of iOS between my iPad(5.0) and SDK(5.1) is different, so your device will not show up. If then, you should change the [iOS Deployment Target] in [Build Setting] to your device’s version(mine is 5.0).
Finally, Select your device instead of the simulator and RUN.