D:\appengine-java-sdk-1.7.5\bin\appcfg.cmd update war -A szpureweb
星期一, 二月 25, 2013
delopy web app to Google appengine
D:\appengine-java-sdk-1.7.5\bin\appcfg.cmd update war -A szpureweb
星期日, 一月 27, 2013
如何在Eclipse 中实现Build number的功能
如图
1.首先输入当前Project的ant build.xml文件,和一个保存编译计数器的properties文件。
加入新的target用name 来指定:
2.给项目加入Ant Builder ,项目属性里寻找Builder 然后加入Ant Builder,然后将其用
up按钮移动到最顶部,让其第一个被调用.
3.要加入refresh的功能和默认的target,这个参考如上和如下两个图就知道了.
星期二, 一月 22, 2013
星期三, 一月 16, 2013
abap 执行本地SQL Native SQL
insert into test(code) valeus(
:pl_wa-Entity_Code,
);
endexec.
if sy-subrc ne 0.
write:/,'fail!'.
endif.
commit work.
星期一, 一月 14, 2013
Dynamic load properties file by Absolulated directory way.
通过getResourceAsStream方式载入的文件被Cache.
public InputStream getpro()
{
String propersetupfile="com/resources/controlSetup.properties";
String dir=this.getServlet().getServletContext().getRealPath("/");
System.out.println("real directory:"+dir);
String pdir=dir+"WEB-INF/classes/"+propersetupfile;
System.out.println("properties file in:"+pdir);
InputStream fi=null;
try
{
fi=new FileInputStream(pdir);
}catch(Exception e)
{
e.printStackTrace();
fi= this.getClass()
.getClassLoader()
.getResourceAsStream(propersetupfile);
}
return fi;
// return this.getClass()
// .getClassLoader()
// .getResourceAsStream(propersetupfile);
}
Java读取某个目录下的制定properteis tips
ResourceBundle rb = ResourceBundle.getBundle(fileName, new java.util.Locale(""));
在test目录下有2个文件 app.properties和app_en.properties
如果想读取 app.properties 则只要给一个空的Locale("")即可。
同样,想读取app_en.properties需要用 Locale("en")
Java计算tips,如何从一个数字字符串中得到字符整数转换。
int x = (character – '0') * 20;
星期四, 一月 10, 2013
abap 如何获得Internal table的定义字段,用RTTS
*& Report Z_GET_TABLE_COLUMNNAME
*& get component structure by RTTS.(Runtime Type Servcies)
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_GET_TABLE_COLUMNNAME.
TYPES: BEGIN OF typ_itab,
sex(20) TYPE c,
tigh TYPE i,
salary TYPE p LENGTH 12 DECIMALS 3,
name type string,
END OF typ_itab.
DATA: i_itab TYPE TABLE OF typ_itab , "if has with header line,exceptin happend
l_tabledescr_ref TYPE REF TO cl_abap_tabledescr,
l_descr_ref TYPE REF TO cl_abap_structdescr,
wa_table TYPE abap_compdescr.
l_tabledescr_ref ?= cl_abap_typedescr=>describe_by_data( i_itab ).
l_descr_ref ?= l_tabledescr_ref->get_table_line_type( ).
LOOP AT l_descr_ref->components INTO wa_table .
WRITE: / wa_table-name,wa_table-type_kind,
wa_table-length,wa_table-decimals.
ENDLOOP.
cl_salv_table 获得 所有internal table 定义field name
USING alv_table TYPE REF TO cl_salv_table.
DATA: lo_columns TYPE REF TO cl_salv_columns.
DATA: lo_column TYPE REF TO cl_salv_column.
"add field authority check
DATA: alv_fieldcat TYPE slis_fieldcat_alv.
DATA: cx_exc_ref TYPE REF TO cx_root.
DATA error_text TYPE c.
DATA:
lta_column_ref TYPE salv_t_column_ref
.
FIELD-SYMBOLS:
<lfs_column> LIKE LINE OF lta_column_ref
lo_columns = alv_table->get_columns( ).
lta_column_ref = lo_columns->get( ).
LOOP AT lta_column_ref ASSIGNING <lfs_column> .
lo_column = <lfs_column>-r_column.
write <lfs_column>-columnname.
ENDLOOP.
星期三, 一月 02, 2013
Volatile: why prevent compiler reorder code
解释链接:
http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#volatile
星期三, 十一月 28, 2012
Android,不再为线程烦恼
不再为线程烦恼
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
Bitmap b = loadImageFromNetwork();
mImageView.setImageBitmap(b);
}
}).start();
}new Thread(new Runnable() {
public void run() {
final Bitmap b = loadImageFromNetwork();
mImageView.post(new Runnable() {
public void run() {
mImageView.setImageBitmap(b);
}
});
}
}).start();
}
new DownloadImageTask().execute("http://example.com/image.png");
}
private class DownloadImageTask extends AsyncTask {
protected Bitmap doInBackground(String... urls) {
return loadImageFromNetwork(urls[0]);
}
protected void onPostExecute(Bitmap result) {
mImageView.setImageBitmap(result);
}
}
- 你可以用类型,泛型或这参数化参数制定处理的值或任务最后的值
- 方法 doInBackground() 自动在工人线程中执行
- onPreExecute(), onPostExecute() 和 onProgressUpdate() 被UI线程调用
- doInBackground() 返回的值被送往方法 onPostExecute()
- 你可以在UI 线程内任何时间调用 publishProgress() 来执行 onProgressUpdate()
- 你可以在任何线程内任何时间放弃任务
Fwd: 如何在Android 4 使用optins menu
Google is happy to bid farewell to the Menu button, and they don’t even want you calling that funny little three-dot button the “menu.”
Rather, Google wants us to think of the menu at an “action overflow.”
When there isn’t enough space in the Action Bar for all the icons you might need in an app, the action overflow handles it.
编写兼容的程序从2.x-4.x ,在Eclipse ADT 里编译的时候就必须要选择高版本LEVEL API,
但在发布的时候,AndroidManifest.xml,要删除掉 android:targetSdkVersion="16" ,而只保留 android:minSdkVersion="10"
android 2.3.3 level api,则在Android 4.X 系统下,options menu出现在了系统导航条上的三点菜单里。
注意,options menu->action bar ->system navigation bar -> overflow menu 几个概念的演化。
如图

星期四, 十一月 22, 2012
Fwd: git Cannot pull into a repository with state: MERGING 解决
编辑后,使用add to index ,然后再commit,即可解决这个问题
星期四, 十一月 15, 2012
Android 4.2 root 后adb shell ,su 发现read-only file system.如何解决
mount 发现/system / 两个文件卷的路径,一般是第一列为物理路径,
第二列为系统卷,重新remount为可读写,
1.mount -o remount,rw rootfs
2.mount -o remount,rw /dev/block/platform/omap/omap_hsmmc.0/by-name/system
3.现在可以复制东西到/etc/了
原因是Android要在/ 卷和/system卷之间做很多的配置文件同步的比如,/etc/hosts,就会在/system/etc 下同步的。
正则表达式发现不包含某个特定字符串的表达
而以下pattern则无法处理包含ExcludeString的独立行
^(.(?!stringToExclude))*$
星期四, 十一月 08, 2012
正则表达式的例子
更加精简的pattern.
grep -P "\d{7}.(\d\d).{7}"
用来搜索同一个文本内的如下格式的数据:
2012083:04-09-14-15-26-33-04
2012084:02-10-20-26-28-29-14
2012103 11 14 32 33 02 09 04 14 11 33 32 364812438 452814888
Re: 正则表达一点例子.
更加精简的pattern.
grep -P "\d{7}.(\d\d).{7}"
用来搜索同一个文本内的如下格式的数据:
2012083:04-09-14-15-26-33-04
2012084:02-10-20-26-28-29-14
2012103 11 14 32 33 02 09 04 14 11 33 32 364812438 452814888
grep -P "\d{7}(\s+|:)(\d\d[\s+-]?){7}"
用来搜索同一个文本内的如下格式的数据:
2012083:04-09-14-15-26-33-04
2012084:02-10-20-26-28-29-14
2012103 11 14 32 33 02 09 04 14 11 33 32 364812438 452814888
正则表达一点例子.
用来搜索同一个文本内的如下格式的数据:
2012083:04-09-14-15-26-33-04
2012084:02-10-20-26-28-29-14
2012103 11 14 32 33 02 09 04 14 11 33 32 364812438 452814888
星期三, 十一月 07, 2012
规则表达一些概念
贪婪(greedy)
一般默认情况下,正则的量词是贪婪的,也就是“尽可能多地匹配”,符号通常是:* + ? {num,num}
举个例子说,比如"a+"这个正则,对于"aaaaaab"这个字符串,它就会匹配到6个a,这是最常见的情况
勉强(reluctant)[也叫懒惰(lazy)]
勉强与贪婪正好是相对的,它“尽可能少地匹配”,它会用最小的努力,去完成(应付)正则的匹配要求,所以很懒。符号是贪婪量词后面加上问号:*? +? ?? {num,num}?
回到前面的那个例子,如果正则换成了“勉强”的,"a+?",对于目标字符串还是"aaaaaab",那么这个正则就只会匹配一个a,因为"+"量词的意思是“一个或一个以上”,匹配一个a就能满足要求,它就不再去尝试了(不像贪婪的"a+"那样,不遗余力将所有符合要求的都匹配了)
“勉强”的量词在实际的使用中也是比较常见的,例如引号配对之类的问题,例如有这么一个字符串,"A says, 'bb'.",想要用正则将单引号里面的bb匹配出来,可以用正则'.*',这种情况下默认的贪婪量词也是能适用的,但如果这个字符串变成了 "A says, 'bb', and C says, 'ddddd'.",如果还是用'.*',由于贪婪,它匹配到的并不是你想要的'bb', and C says, 'ddddd',中间的.(点元字符)代表任何字符,当然也包括单引号,所以'.*'会将两个单引号中间的所有内容都匹配,不管是不是含有单引号。显然这不是我们想要的结果。如果用“勉强”的量词,'.*?',加一个问号,那么它就会尽最小的能力去完成,只要下一个字符是单引号,.*?就停止尝试,结果它就只会匹配'bb',不会将后面的, and ....那些都纳进来。
侵占(possessive)
这个用得很少,侵占量词在很多语言的正则中都没有被支持,它的符号是在贪婪量词后面加上一个加号:*+ ++ ?+ {num,num}+
侵占量词有个特点,它前面的子表达式作为一个整体,不记录回溯点(关于回溯方面的问题,建议你去看一看《精通正则表达式》这本书,讲得比较详细),通常是可以利用这个特点,对正则的匹配效率进行优化。其实它是和固化分组等价的,不支持侵占量词的语言中可以用固化分组的形式来代替。固化分组的写法:(?>)
有个例子可以帮助理解侵占量词的特点,但这个例子并不实用:
对于字符串"abbbbbbc",如果用普通的(贪婪)正则"a.*c"来匹配的话,它可以匹配整个字符串,因为.*可以匹配任何数量的任何字符,它是可以匹配bbbbbbc的,但它会发现正则后面还有一个c需要匹配,否则不能匹配成功,所以.*就“退回”一个字符c,使得整个正则能够成功匹配(回溯),所以贪婪即使是“贪”,它还是会顾全大局,退回一些必要的字符。
换侵占量词就不同了,"a.*+c"是一个侵占式的,它并不能成功匹配,因为.*+太霸道,占着最后的那个c不肯放回(不回溯),所以a.*+前面就已经匹配了整个字符串abbbbbbc,a.*+正则后面的c发现没有字符可以匹配了,前面的又不肯吐出一个来,所以整个正则以匹配失败结束。(这个"a.*+c"可以用固化分组改写成:"a(?>.*)c")
星期二, 十一月 06, 2012
Android 2.3.3 以上通用Notification 生成 代码.使用NotificationCompat.Builder
//The IDs must be unique only within the namespace of your .apk's package nam
//这个ID只需要在你自己的app 空间里唯一即可,不是整个系统唯一
public void setupNotification(Context ctx)
{
Intent notificationIntent = new Intent(ctx, StartGateActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx,
0, notificationIntent,
0);
NotificationManager nm = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(100);
Resources res = ctx.getResources();
CharSequence text = res.getString(R.string.nf_text);
CharSequence contentTitle = res.getString(R.string.nf_title);
CharSequence ticket = res.getString(R.string.nf_ticket);
NotificationCompat.Builder builder= new NotificationCompat.Builder(ctx);
builder.setContentTitle(contentTitle)
.setContentText(text)
.setSmallIcon(R.drawable.ic_launcher)
.setOngoing(true) //this flag notification record can't be clear
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setTicker(ticket)
.setContentIntent(contentIntent);
Notification nf = builder.build();
nm.notify(100, nf);
}
星期一, 十一月 05, 2012
如何在app中3.0 API LEVEL 11后加入notification.
{
Intent notificationIntent = new Intent(ctx, LifeDemo.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx,
0, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager nm = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = ctx.getResources();
Notification.Builder builder = new Notification.Builder(ctx);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.ic_launcher))
.setTicker("Demo Show")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setContentTitle("Demo Show 1")
.setContentText("Demo Show2");
Notification n = builder.build();
nm.notify(1, n);
}
星期四, 十一月 01, 2012
如何给手机刷CMW Mod
fastboot boot recovery-clockwork-touch-6.0.1.4-maguro.img
#永久刷新
fastboot flash recovery recovery-clockwork-touch-6.0.1.4-maguro.img
adb reboot
发布一个apk的准备工作.
1.keytool -genkey -v -keystore debug.keystore -alias wxkdebugkey -keyalg RSA-validity 14000
跟随提示回答问题.
2.Jarsigner -verbose -keystore debug.keystore yourapk.apk wxkdebugkey
3.jarsigner -verify yourapk.apk
4.zipalign -v 4 yourapk.apk lastname.apk
5.start a avd
tools\android.bat list avd
Available Android Virtual Devices:
Name: AVD233
Path: d:\temp\.android\avd\AVD233.avd
Target: Android 2.3.3 (API level 10)
ABI: armeabi
Skin: WVGA800
---------
Name: avd411
Path: d:\temp\.android\avd\avd411.avd
Target: Android 4.1 (API level 16)
ABI: armeabi-v7a
Skin: WVGA800
Sdcard: 512M
Snapshot: true
emulator -avd AVD233 启动
5.adb devices
adb -e install lastname.apk
Android 产生key
JDK 7.0 Display MD5 key
keytool -v -list -alias wxkdebugkey -keystore my-release-key.keystore
星期二, 十月 23, 2012
比如屏幕旋转90度,Configuration Changes
Configuration Changes
If the configuration of the device (as defined by the Resources.Configuration class) changes, then anything displaying a user interface will need to update to match that configuration. Because Activity is the primary mechanism for interacting with the user, it includes special support for handling configuration changes.
Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from onSaveInstanceState(Bundle).
This is done because any application resource, including layout files, can change based on any configuration value. Thus the only safe way to handle a configuration change is to re-retrieve all resources, including layouts, drawables, and strings. Because activities must already know how to save their state and re-create themselves from that state, this is a convenient way to have an activity restart itself with a new configuration.
In some special cases, you may want to bypass restarting of your activity based on one or more types of configuration changes. This is done with the android:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted and onConfigurationChanged(Configuration) will not be called.
| 1 2 3 4 5 6 7 | <activity android:name=".SomeActivity" android:label="@string/app_name" android:configChanges="orientation"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter></activity> |
The "configChanges" attribute tells Android Platform that, some of the config changes will be handled by the activity by themselves. Platform does not need to do any special handling for these.
Android Configuration change.
In Android, a configuration change causes the current activity to go away and be recreated.
The application itself keeps on running, but it has the opportunity to change
how the activity is displayed in response to the configuration change.
use onSaveInstanceState(Bundle) to keep state or other runtime data.
root Jelly Bean 4.1.2
首先必须安装了Android sdk和对应手机的USB驱动。
android sdk: http://developer.android.com/sdk/index.html
需要一些工具
1.download cmw(ClockworkMod) recover 工具.
http://www.clockworkmod.com/rommanager
查找对应的设备后面的文件。
Galaxy Nexus 就要下载:
http://download2.clockworkmod.com/recoveries/recovery-clockwork-touch-6.0.1.0-maguro.img
2. download superuser packagae
http://androidsu.com/superuser/
下载 Superuser-3.1.3-arm-signed.zip
3.连接手机USB,设置为debug模式
用adb push Superuser-3.1.3-arm-signed.zip /sdcard/Superuser-3.1.3-arm-
传送到手机上
4.临时进入cmw recover 并安装superuser 包
进入window 命令行状态 cmd,进入android sdk安装目录下的android-sdk-windows\platform-tools目录.
adb reboot bootloader
fastboot boot recovery-clockwork-touch-6.0.1.0-maguro.img
等待3秒出现,安装CMW 安装界面,如果是touch版本,则用手势滚动屏幕,选择安装
select install zip from sdcard.
否则用音量上下键移动,电源键确认来选择。
安装完成后,用adb reboot 启动手机即可。
星期四, 九月 20, 2012
Fwd: OSWORKFLOW on JBOSS 4.22 Config.
http://java.net/downloads/osworkflow/
2.将osworkflow-2.8.0-example.war展开到jboss 422/server/default/deploy/osworkflow-2.8.0-example.war 目录下。
3.在MYSQL 上建立一个osworkflow的database,并运行osworkflow-2.8.0\src\etc\deployment\jdbc
\mysql.sql,建立其需要使用的表格.
4.配置JBOSS 数据源
在jboss 422/server/default/deploy/mysql-ds.xml里加入数据源:
<!-- add for osworkflow datasorce -->
<local-tx-datasource>
<jndi-name>osworkflow</jndi-name>
<connection-url>jdbc:mysql://192.1.1.100:3306/osworkflow?autoReconnect=true&useUnicode=TRUE&characterEncoding=utf-8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password></password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<min-pool-size>5</min-pool-size>
<max-pool-size>10</max-pool-size>
<idle-timeout-minutes>1</idle-timeout-minutes>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
5.进入jboss 422/server/default/deploy/osworkflow-2.8.0-example.war/WEB-INF/classes下修改配置,加入数据源说明.
注意Linux table name 有大小写的问题。
osuser.xml:
<opensymphony-user>
<provider class="com.opensymphony.user.provider.jdbc.JDBCAccessProvider">
<property name="user.table">OS_USER</property>
<property name="group.table">OS_GROUP</property>
<property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
<property name="user.password">passwordhash</property>
<property name="group.name">groupname</property>
<property name="membership.userName" >username</property>
<property name="membership.groupName">groupname</property>
<property name="datasource">java:/osworkflow</property>
</provider>
<provider class="com.opensymphony.user.provider.jdbc.JDBCCredentialsProvider">
<property name="user.table">OS_USER</property>
<property name="group.table">OS_GROUP</property>
<property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
<property name="user.password">passwordhash</property>
<property name="group.name">groupname</property>
<property name="membership.userName" >username</property>
<property name="membership.groupName">groupname</property>
<property name="datasource">java:/osworkflow</property>
</provider>
<provider class="com.opensymphony.user.provider.jdbc.JDBCProfileProvider">
<property name="user.table">OS_USER</property>
<property name="group.table">OS_GROUP</property>
<property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
<property name="user.password">passwordhash</property>
<property name="group.name">groupname</property>
<property name="membership.userName" >username</property>
<property name="membership.groupName">groupname</property>
<property name="datasource">java:/osworkflow</property>
</provider>
<authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />
</opensymphony-user>
osworkflow.xml:
<osworkflow>
<!--persistence class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore"/-->
<persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore">
<property key="datasource" value="java:/osworkflow"/>
<property key="entry.sequence"
value="SELECT max(id)+1 FROM OS_WFENTRY"/>
<property key="entry.table" value="OS_WFENTRY"/>
<property key="entry.id" value="ID"/>
<property key="entry.name" value="NAME"/>
<property key="entry.state" value="STATE"/>
<property key="step.sequence" value="SELECT max(ID)+1 FROM OS_STEPIDS"/>
<property key="step.sequence.increment" value="INSERT INTO OS_STEPIDS (ID) values (null)"/>
<property key="step.sequence.retrieve" value="SELECT max(ID) FROM OS_STEPIDS"/>
<property key="entry.sequence.increment" value="INSERT INTO OS_ENTRYIDS (ID) values (null)"/>
<property key="entry.sequence.retrieve" value="SELECT max(ID) FROM OS_ENTRYIDS"/>
<property key="history.table" value="OS_HISTORYSTEP"/>
<property key="current.table" value="OS_CURRENTSTEP"/>
<property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/>
<property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/>
<property key="step.id" value="ID"/>
<property key="step.entryId" value="ENTRY_ID"/>
<property key="step.stepId" value="STEP_ID"/>
<property key="step.actionId" value="ACTION_ID"/>
<property key="step.owner" value="OWNER"/>
<property key="step.caller" value="CALLER"/>
<property key="step.startDate" value="START_DATE"/>
<property key="step.finishDate" value="FINISH_DATE"/>
<property key="step.dueDate" value="DUE_DATE"/>
<property key="step.status" value="STATUS"/>
<property key="step.previousId" value="PREVIOUS_ID"/>
</persistence>
<factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
<property key="resource" value="workflows.xml" />
</factory>
</osworkflow>
propertyset.xml:
<propertysets>
<propertyset name="jdbc" class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
<arg name="table.name" value="OS_PROPERTYENTRY"/>
<arg name="col.globalKey" value="GLOBAL_KEY"/>
<arg name="col.itemKey" value="ITEM_KEY"/>
<arg name="col.itemType" value="ITEM_TYPE"/>
<arg name="col.string" value="STRING_VALUE"/>
<arg name="col.date" value="DATE_VALUE"/>
<arg name="col.data" value="DATA_VALUE"/>
<arg name="col.float" value="FLOAT_VALUE"/>
<arg name="col.number" value="NUMBER_VALUE"/>
<arg name="datasource" value="java:/osworkflow"/>
<arg name="" value=""/>
</propertyset>
</propertysets>
至此配置完成,启动JBOSS,从浏览器输入:
http://192.168.1.1:8080/osworkflow-2.8.0-example/
即可查看.
星期二, 九月 18, 2012
Android如何确认一个Intent是否存在呢?
/**
* Indicates whether the specified action can be used as an intent. This
* method queries the package manager for installed packages that can
* respond to an intent with the specified action. If no suitable package is
* found, this method returns false.
*
* @param context The application's environment.
* @param action The Intent action to check for availability.
*
* @return True if an Intent with the specified action can be sent and
* responded to, false otherwise.
* Example:isIntentAvailable(getApplicationContext(),Intent.ACTION_WEB_SEARCH)
*/
public static boolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
星期四, 九月 13, 2012
Android动态改变语言并自动刷新菜单.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String languageToLoad = "zh";
locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, null);
//getBaseContext().getResources().getDisplayMetrics()
Log.v("log:","local is changed!");
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_main);
}
星期二, 九月 11, 2012
Andorid xml is binary format in .apk package
只有一个例外就是 res/raw下的文件是原始文件,没有做任何处理。
Activity的getString和Activity.getResource().getString的区别是什么呢?
localized string from the application's package's default string table
Resource的getString说明如下:
Returns the string value associated with a particular resource ID. It will be stripped of any styled text information
但是查看源代码,发现activity的getString如下:
public final String getString(int resId) {
return getResources().getString(resId);
}
其实是一回事。真不明白为什么说明差异如此之大。
Android classpath access external resource.
Resources.getSystem().getString(android.R.string.somecommonstuff)
星期一, 八月 27, 2012
如何禁止wxWidgets 2.9.x Debug信息
在wx/debug.h 里设置
wxDEBUG_LEVEL=0
然后从新编译所有的库文件,再编译应用代码。
REM 清除所有的库文件
mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=release MONOLITHIC=0 USE_STC=0 USE_PROPGRID=1 USE_GUI=1 clean
REM 重新编译所有库
mingw32-make -f makefile.gcc SHARED=0 UNICODE=1 BUILD=release MONOLITHIC=0 USE_STC=0 USE_PROPGRID=1 USE_GUI=1
禁止 wxWidgets 2.9 调试信息弹出
定义wxDEBUG_LEVEL=0 在 IMPLEMENT_APP() 代码前。
星期五, 八月 10, 2012
Dynamic load css definition file.
load: /*static*/ function (url_, /*optional*/ media_) {
// We are preventing loading a file already loaded
var _links = document.getElementsByTagName("link");
if (_links.length > 0 && _links["href"] == url_) return;
// Optional parameters check
var _media = media_ === undefined || media_ === null ? "all" : media_;
var _elstyle = document.createElement("link");
_elstyle.setAttribute("rel", "stylesheet");
_elstyle.setAttribute("type", "text/css");
_elstyle.setAttribute("media", _media);
_elstyle.setAttribute("href", url_);
var _head = document.getElementsByTagName("head")[0];
_head.element.appendChild(_elstyle);
}
};
星期三, 七月 25, 2012
如何用SVG显示汉字。只需要注意HTML需要用UTF-8格式保存即可.
<body>
<p><canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" +
"<foreignObject width='100%' height='100%'>" +
"<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px;color:red'>" +
"<em>I</em> like <span style='color:white; text-shadow:0 0 2px blue;'>网络的上面</span>" +
"</div>" +
"</foreignObject>" +
"</svg>";
var svg = new (self.BlobBuilder || self.MozBlobBuilder || self.WebKitBlobBuilder);
var DOMURL = self.URL || self.webkitURL || self;
var img = new Image();
svg.append(data);
var url = DOMURL.createObjectURL(svg.getBlob("image/svg+xml;charset=utf-8"));
img.onload = function() {
ctx.drawImage(img, 0, 0);
DOMURL.revokeObjectURL(url);
};
img.src = url;
</script>
</body>
</html>
星期一, 七月 16, 2012
tcpdump debug http traffic and dns query.
windump -i \Device\NPF_{CDF6DEBB-8C8E-49EF-91D5-CF6A69F1FE81} -n port 80 or port 443 or port 53
adb shell tcpdump -i wlan0 -n port 80 or port 443 or port 53
星期五, 六月 08, 2012
Android memory usage
App:Application
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)
星期二, 四月 03, 2012
POI 3.7如何实现cell的填充颜色。
必须在setCellValue之后,再调用setCellStyle的语句。
顺序不能错误,否则效果不如意。
style = wb.createCellStyle();
style.setFillForegroundColor(HSSFColor.YELLOW.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
cell = row.createCell((short) 2);
cell.setCellValue("X");
cell.setCellStyle(style);
如何在JSP里实现Streaming content,流失内容,让内容逐渐显示
2.在out.println一些之后使用out.flush().
这样在浏览器内就显示出来效果了,逐渐显示,而不是全部一下显示了。
星期二, 三月 06, 2012
如何制作Android显示百分比数字的状态条。
<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:padding="0dip"
>
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:indeterminateOnly="false"
android:layout_height="30dip" />
<TextView
android:id="@+id/perc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#ff0000"
android:textStyle="bold"
/>
</RelativeLayout>
代码:
package wxk.com;
import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
public class ThreadDemoActivity extends Activity {
ProgressBar bar;
TextView percent;
Handler handler=new Handler() {
@Override
public void handleMessage(Message msg) {
bar.incrementProgressBy(5);
percent.setText(String.format("%03d%%", bar.getProgress()));
}
};
boolean isRunning=false;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
bar=(ProgressBar)findViewById(R.id.progress);
percent=(TextView)findViewById(R.id.perc);
}
public void onStart() {
super.onStart();
bar.setProgress(0);
Thread background=new Thread(new Runnable() {
public void run() {
try {
for (int i=0;i<20 && isRunning;i++) {
Thread.sleep(1000);
handler.sendMessage(handler.obtainMessage());
}
}
catch (Throwable t) {
// just end the background thread
}
}
});
isRunning=true;
background.start();
}
public void onStop() {
super.onStop();
isRunning=false;
}
}
星期五, 二月 24, 2012
Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc)
Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc)
The default shell on most Linux operating systems is called Bash. There are a couple of important hotkeys that you should get familiar with if you plan to spend a lot of time at the command line. These shortcuts will save you a ton of time if you learn them.
| Ctrl + A | Go to the beginning of the line you are currently typing on |
| Ctrl + E | Go to the end of the line you are currently typing on |
| Ctrl + L | Clears the Screen, similar to the clear command |
| Ctrl + U | Clears the line before the cursor position. If you are at the end of the line, clears the entire line. |
| Ctrl + H | Same as backspace |
| Ctrl + R | Let's you search through previously used commands |
| Ctrl + C | Kill whatever you are running |
| Ctrl + D | Exit the current shell |
| Ctrl + Z | Puts whatever you are running into a suspended background process. fg restores it. |
| Ctrl + W | Delete the word before the cursor |
| Ctrl + K | Clear the line after the cursor |
| Ctrl + T | Swap the last two characters before the cursor |
| Esc + T | Swap the last two words before the cursor |
| Alt + F | Move cursor forward one word on the current line |
| Alt + B | Move cursor backward one word on the current line |
| Tab | Auto-complete files and folder names |
星期四, 十二月 22, 2011
html 模拟终端效果 style.
display: block;
width: 95%;
background: #222;
border-left: 6px solid #1664d9;
color: #0c0;
padding: 10px;
overflow:auto;
}
星期二, 十二月 13, 2011
Linux查询网络连接并搜索统计。
grep -E 选项可以同时搜索多个字符串,用符号 |隔开。
lsof -i4 只显示TCP IPV4的记录,也就是网络连接数目了。
星期二, 十一月 22, 2011
星期六, 十月 29, 2011
How to fix problem of incompatibility between GCC 4.6 and Android 2.3
http://buildall.wordpress.com/2011/05/27/how-to-fix-problem-of-incompatibility-between-gcc-4-6-and-android-2-3-gingerbread/
Hello everybody. Let's see how we can fix one problem that can happen when you try to compile the Android 2.3 after you already have installed GCC 4.6.
During Android compilation you can receive the following error message:
host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function 'void android::RefBase::weakref_type::trackMe(bool, bool)':
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing 'const android::RefBase::weakref_impl' as 'this' argument of 'void android::RefBase::weakref_impl::trackMe(bool, bool)' discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
make: *** Waiting for unfinished jobs....
To fix that, open a terminal and run (assuming you are in the folder android):
gedit frameworks/base/libs/utils/Android.mk
Change the line:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)
To:
LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive
After that, save the file and recompile the Android again.
That's it. See you next time.
星期二, 十月 25, 2011
如何安装Guest Addtions 在VirtualBox 和utunbu 11.10。
You can follow the steps below to install the guest additions program on your ubuntu 11.10:
1) Create a temp directory in your home directory
2) Copy the whole file into the temp directory from /media/VBo..
3) Sudo apt-get install linux-headers-3.0.0-12-generic-pae
*Actually you get to make sure what kernel version on your machine
*After that, make sure your get "linux-headers-3.0.0-12-generic-pae" tree in "usr/src"
4) Install the guest additions utility.
具体编译log可以查看/var/log/vboxadd-install.log
/usr/bin/VBoxClient× 系列软件,可以运行。
启动桌面后,即可粘帖了
星期一, 五月 23, 2011
星期五, 五月 06, 2011
Java WebStart和可执行jar文件如何读取外部jar文件包含的资源。
网络运行的Java Webstart的JNLP的写法里和可执行的jar文件里,都包含了对外部jar文件的依赖的语法
比如JNLP 语法:
<jar href="lib/hsqldb.jar"/>
可执行jar文件MANIFEST.MF里包含的语句:
Class-Path:
lib/appframework-1.0.3.jar
lib/swing-worker-1.1.jar
常见的是把图片等其他非class文件组织打包成一个jar文件,方便程序中使用。
在可执行的jar文件中,只需要一行代码就可以得到这些资源。
比如在lib/appframework-1.0.3.jar包含一个打印格式文件jrxml
都放在report/目录下,一个工作单打印文件WorkOrder.jrxml.
必须使用Thread.currentThread().getContextClassLoader()定制的ClassLoader来调用
或this.getClass().getClassLoader()
注意this的意思必须是个运行时的类实例,而不能是静态类的.class.getClass()的方法。
InputStream test=null;
try
{
test = Thread.currentThread().getContextClassLoader().getResourceAsStream("report/WorkOrder.jrxml");
或者:
test =new YouCurrentClassName().getClass().getClassLoader().getResourceAsStream("report/WorkOrder.jrxml");
if(test!=null)
{
InputStreamReader inr=new InputStreamReader(test,"UTF-8");
BufferedReader br=new BufferedReader(inr);
String line="";
while( (line=br.readLine())!=null)
{
System.out.println(line);
}
另外不在classpath里的jar包的资源调用。
可以使用java.net.URL("jar:file://d:/temp/test.jar!");的语法来读取。
public JarFile tJar = null;
public JarURLConnection uc = null;
String resourcepath="image/log.jpg";
URL u = new URL("jar:file:lib/ReportResource_jrxml.jar!/");
uc = (JarURLConnection)u.openConnection();
tJar = uc.getJarFile();
// Enumeration entries = tJar.entries();
// while (entries.hasMoreElements()) {
// ZipEntry entry = (ZipEntry) entries.nextElement();
// System.out.println(entry.getName());
//
// }
input = tJar.getInputStream(tJar.getEntry(resourcepath));
星期四, 五月 05, 2011
判断内部IP地址和外部IP地址(private IP address or public IP Address)
* Judge IP Address is private or public address
*/
public static boolean isInnerIP(String ipAddress){
boolean isInnerIp = false;
long ipNum = getIpNum(ipAddress);
/**
私有IP:A类 10.0.0.0-10.255.255.255
B类 172.16.0.0-172.31.255.255
C类 192.168.0.0-192.168.255.255
当然,还有127这个网段是环回地址
**/
long aBegin = getIpNum("10.0.0.0");
long aEnd = getIpNum("10.255.255.255");
long bBegin = getIpNum("172.16.0.0");
long bEnd = getIpNum("172.31.255.255");
long cBegin = getIpNum("192.168.0.0");
long cEnd = getIpNum("192.168.255.255");
isInnerIp = isInner(ipNum,aBegin,aEnd) || isInner(ipNum,bBegin,bEnd) || isInner(ipNum,cBegin,cEnd) || ipAddress.equals("127.0.0.1");
return isInnerIp;
}
private static long getIpNum(String ipAddress) {
String [] ip = ipAddress.split("\\.");
long a = Integer.parseInt(ip[0]);
long b = Integer.parseInt(ip[1]);
long c = Integer.parseInt(ip[2]);
long d = Integer.parseInt(ip[3]);
long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;
return ipNum;
}
private static boolean isInner(long userIp,long begin,long end){
return (userIp>=begin) && (userIp<=end);
}
星期五, 四月 15, 2011
改变JDE(julian)日期为标准ISO 格式(年-月-日)
WASTRT 是Order StartDate,都是6个长度的numberic 的字段。
通过下列表达式可以将其转换为标准的 yyyy-MM-dd格式。
TIMESTAMP(DATE(DIGITS(DEC(WATRDJ + 1900000,7,0))),TIME('00:00:00')) as t1 ,
char(DATE(CHAR(DEC(WASTRT + 1900000,7,0))),iso)
星期五, 三月 25, 2011
如何删除JDialog右上角的X 关闭按钮
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
public void buildGUI()
{
JDialog.setDefaultLookAndFeelDecorated(true);
JDialog d = new MyDialog();
d.setModal(true);
d.getRootPane().setDefaultButton(null);
JPanel p = new JPanel(new GridBagLayout());
JButton btn = new JButton("Exit");
p.add(btn,new GridBagConstraints());
d.getContentPane().add(p);
d.setSize(400,300);
d.setLocationRelativeTo(null);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.exit(0);
}
});
d.setVisible(true);
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run(){
new Testing().buildGUI();
}
});
}
}
class MyDialog extends JDialog
{
public MyDialog()
{
System.out.println("....");
removeX(this);
}
public void removeX(Component comp)
{
if (comp instanceof JButton)
{
System.out.println("..."+comp);
Icon i=((JButton)comp).getIcon();
System.out.println("..2."+i.getClass());
//System.out.println("...2"+(AbstractButton)comp.getDefaultIcon());
comp.getParent().remove(comp);
}
if (comp instanceof Container)
{
Component[] comps = ((Container)comp).getComponents();
for(int x = 0, y = comps.length; x < y; x++)
{
removeX(comps[x]);
}
}
}
}
</code>
星期三, 二月 16, 2011
星期一, 二月 07, 2011
VIM 大小写不敏感搜索.
:set ic (:set ignorecase) 忽略大小写
:set noic (:set noignorecase) 大小写敏感
或者使用:
/\cword.用前置模式来搜索,也可以
星期三, 一月 12, 2011
ECL 10.7.1 如何才能正确打印出汉字
foo.lsp文件内容
;foo.lsp
(ext::stream-external-format-set *standard-input* :CP936)
(ext::stream-external-format-set *standard-output* :CP936)
(print (length "好吧"))
(print "TEST" *standard-output*)
(princ "好吧" *standard-output*)
(format t "~%汉字来也")
这个代码只能在文件中执行,如果在ecl console里逐行敲入这些代码,反而出现错误:
ECL (Embeddable Common-Lisp) 10.7.1
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level in: #<process TOP-LEVEL>.
> (ext::stream-external-format-set *standard-input* :CP936)
> (ext::stream-external-format-set *standard-output* :CP936)
> (format t "汉字来也")
鹤酪
NIL
> (format t "汉字来也")
鹤酪
NIL
>
星期四, 一月 06, 2011
LISP在package如何访问TOPLEVEL定义的全局变量(Global Variable)?
如果在一个main.lisp中分别(load "*....lisp"),载入定义的package或者一些全局的数据.
往往会出现如下场景类似的问题:
CL-USER> (defvar foo 108) FOO CL-USER> foo 108 CL-USER>
CL-USER> (in-package :asdf) #<PACKAGE "ASDF"> ASDF>
The variable FOO is unbound. [Condition of type UNBOUND-VARIABLE]
避免这个情况,就是用如下引用方式:
ASDF> cl-user::foo 108 ASDF>









