mikebai.com

  • Home
  • dev
  • DotNET
  • M365
  • 搞笑
  • 杂七杂八
  • FocusDict
dev
dev

onTouchEvent 中onTouch的返回值的意义

今天想捕获Gallery的Touch事件做自己想要的处理,但你添加完setOnTouchListener监听完之后eclipse自动会生成一个 onTouch方法,就可以在这里面做你想要做的处理了,若你小心地看它会增加return false这行。我在处理完Event.ACTION_MOVE时将其改为return true。当我运行我的程序的时候发现Gallery不能左右滚动了。我就觉得很纳闷了,怎么不能滚动了呢?然后一个朋友提示我应该return false.我改完运行后,果真可以滚动了,并且我在move的时候也实现了我的处理。当时我就在想:return false和return true有何区别呢? 下面就是我在别的文章学习总结来的结论: 1,return false说明你还没消费onTouch事件,在执行完你onTouch里面的代码之后,onTouch事件并没有结束。就是会自动地执行Gallery 这个view里onTouch代码(这个为默认).所以这就是为什么没增加你的处理的时候就只自动地调用Gallery的onTouch,若你在 onTouch里面增加你的代码并且return false就会执行你的处理和默认的处理。 2,return true说明你已经消费完了onTouch事件,在执行完你的onTouch里面的代码之后,这个onTouch事件就结束了。也就是说不会再调用默认的 onTouch事件了。在onTouch里面有很多种的处理比如move,down,up....,若你在move里面return false,那么接着的fling,up等后面的事件也不会处理的。 Java代码  mGallery.setOnTouchListener(new OnTouchListener(){                  //@Override               public boolean onTouch(View v, MotionEvent event) {                   // TODO Auto-generated method stub                   System.out.println("Gallery onTouch");                   if(event.getAction()==MotionEvent.ACTION_MOVE){                       mDismiss.removeMessages(1);                       System.out.println("ACTION_MOVE ");                                          }else if(event.getAction()==MotionEvent.ACTION_UP){                       mDismiss.sendEmptyMessageDelayed(1,10000);                       System.out.println("ACTION_UP ");                   }                   return false;               }                          }); 

2011-09-02 0comments 102hotness 0likes mikebai Read all
dev

eclipse使用的几个技巧

1.快捷键设置在eclipse中无法导入既存配置,可以通过保存以下路径的文件,达到导入配置的目的 .metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.workbench.prefs 2.ctrl+鼠标左键可以跳转到定义,但是ctrl左键我一般都是用来选择字符串进行拷贝使用,所以有冲突 可以通过更改以下配置 General → Editors → Text Editors → Hyperlinking 页面 将Default modifier key:设置从默认的CTRL更改为Alt即可.   3.android中xml格式化为每个属性占一行的格式 XML→ XML Files→ Editor页面 选中 Split multiple attributes each on a new line  

2011-08-15 0comments 103hotness 0likes mikebai Read all
dev

屏幕横纵切换导致onDestroy

引述以下2篇文章 横竖屏切换时候activity的生命周期 android:configChanges .http://blog.csdn.net/kepoon/article/details/6258070 1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次 2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次 3、设置Activity的android:configChanges="orientation|keyboardHidden"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法   Android android:configChangeshttp://www.cnmsdn.com/html/201003/1269552382ID2711.html  这是hipak那边测试反馈回来的一个问题,说来惭愧,一直没注意到这个问题的存在。以为Power键就是onPause处理就完了,结果不是。   这里边google的设计或许也有点问题,在竖屏情况下也许是一样处理的,不过当你的app是横屏,那就要注意了。   每次Power键的时候,app是会强制回到竖屏状态的,并且会重新调用Activity的onCreate(),当然很多时候这不是我们想要的。所以就需要用到android:configChanges了,在配置文件里设置 android:configChanges="keyboardHidden|orientation",这样在屏幕方向改变的时候就不会重新调用 Activity的onCreate(),而是调用onConfigurationChanged(),然后在Activity里重载下   01.@Override   02.public void onConfigurationChanged(Configuration newConfig){   03. super.onConfigurationChanged(newConfig);   04. if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){   05. //横向   06. }else{   07. //竖向   08. }   09.}   一般就这么处理下就可以了,要命的是用到了SurfaceView,而SurfaceView和Thread的生命周期是不一样的,唉,这里要说一下Google提供的sample了,里边有bug!!   由于每次Power键的时候会调用SurfaceView的surfaceDestroyed(SurfaceHolder holder),但是回到app的时候又没有执行surfaceCreated(SurfaceHolder holder),于是就咯屁了~~   目前想到一个能解决的方案是在onConfigurationChanged(Configuration newConfig)里手动处理,surfaceDestroyed(SurfaceHolder holder)+urfaceCreated(SurfaceHolder holder)+pause()处理。。。   唉,希望可以找到一个比较好的解决方案吧。

2011-08-06 0comments 106hotness 0likes mikebai Read all
dev

loading进度条

By Jay Liang Here is another thing in android that kept me scratching my head for a day before i finally figure out how to do it properly because of the lack of documentations and books for Android development at this time. The android app that I am currently working on has a search feature which will fire a http request and shows the result in a list view. The search can be slow depending on the network speed so I wanted to put a loading dialog on the screen to indicate that the app is processing. There's a ProgressDialog class in Android's SDK, so the idea is to just first build and show a progress dialog before the search starts, and then cancel the dialog on search completion:   ProgressDialog pd = ProgressDialog.show(this,"Title","Message",true, false); makeHttpRequest();pd.dismiss(); The above snippet will not work because the makeHttpRequest() method is being executed on the UI thread (Android has a similar threading model as Swing) therefore the dialog will not show on the screen until makeHttpRequest() returns. That's understandable, so how about putting the method in a background thread like this: final ProgressDialog pd = ProgressDialog.show(this,"Title","Message",true, false); new Thread(new Runnable(){public void run(){makeHttpRequest();pd.dimiss();}}).start();This works as we would expect, the progress dialog is shown and then it will disappear when makeHttpRequest() is finished. However, here's the difficult bit. The above code will cause your application to crash if the user change the phone's orientation while the progress dialog is not yet dismissed. W/dalvikvm( 292): threadid=3: thread exiting with uncaught exception(group=0x40010e28)E/AndroidRuntime( 292): Uncaught handler: thread main exiting…

2011-08-06 0comments 114hotness 0likes mikebai Read all
dev

Android基础教程(二)之五大布局对象---FrameLayout,LinearLayout ,AbsoluteLayout,RelativeLayout,TableLayout

大家好,我们这一节讲一下Android对用五大布局对象,它们分别是FrameLayout(框架布局:不知道是不是这么翻译的),LinearLayout (线性布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局),TableLayout(表格布局).   FrameLayout:   FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象 — 比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后一个子元素是透明的)。   我们看一下效果图:     其中Main.xml 代码如下:   <?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"    android:layout_height="fill_parent"    >  <!-- 我们在这里加了一个Button按钮 --> <Button     android:text="button"     android:layout_width="fill_parent"    android:layout_height="wrap_content"/> <TextView     android:text="textview"    android:textColor="#0000ff"     android:layout_width="wrap_content"    android:layout_height="wrap_content"/> </FrameLayout>   LinearLayout:   LinearLayout以你为它设置的垂直或水平的属性值,来排列所有的子元素。所有的子元素都被堆放在其它元素之后,因此一个垂直列表的每一行只会有一个元素,而不管他们有多宽,而一个水平列表将会只有一个行高(高度为最高子元素的高度加上边框高度)。LinearLayout保持子元素之间的间隔以及互相对齐(相对一个元素的右对齐、中间对齐或者左对齐)。   LinearLayout还支持为单独的子元素指定weight 。好处就是允许子元素可以填充屏幕上的剩余空间。这也避免了在一个大屏幕中,一串小对象挤成一堆的情况,而是允许他们放大填充空白。子元素指定一个weight 值,剩余的空间就会按这些子元素指定的weight 比例分配给这些子元素。默认的 weight 值为0。例如,如果有三个文本框,其中两个指定了weight 值为1,那么,这两个文本框将等比例地放大,并填满剩余的空间,而第三个文本框不会放大。   我们看一下效果图:     其中Main.xm l代码如下:   <?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">   <LinearLayout     android:orientation="vertical"     android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:layout_weight="2">     <TextView        android:text="Welcome to Mr Wei's blog"         android:textSize="15pt"        android:layout_width="fill_parent"        android:layout_height="wrap_content"     />     </LinearLayout>     <LinearLayout     android:orientation="horizontal"     android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:layout_weight="1">         <TextView         android:text="red"         android:gravity="center_horizontal" //这里字水平居

2011-08-03 0comments 110hotness 0likes mikebai Read all
dev

wav压缩制式一览表

位于wav文件中的第21和22个字节所代表的code值 00101 /* WAVE form wFormatTag IDs */ 00102 00103  #define  WAVE_FORMAT_UNKNOWN 0x0000 /* Microsoft Corporation */ 00104  #define  WAVE_FORMAT_ADPCM 0x0002 /* Microsoft Corporation */ 00105  #define  WAVE_FORMAT_IEEE_FLOAT 0x0003 /* Microsoft Corporation */ 00106  #define  WAVE_FORMAT_VSELP 0x0004 /* Compaq Computer Corp. */ 00107  #define  WAVE_FORMAT_IBM_CVSD 0x0005 /* IBM Corporation */ 00108  #define  WAVE_FORMAT_ALAW 0x0006 /* Microsoft Corporation */ 00109  #define  WAVE_FORMAT_MULAW 0x0007 /* Microsoft Corporation */ 00110  #define  WAVE_FORMAT_DTS 0x0008 /* Microsoft Corporation */ 00111  #define  WAVE_FORMAT_OKI_ADPCM 0x0010 /* OKI */ 00112  #define  WAVE_FORMAT_DVI_ADPCM 0x0011 /* Intel Corporation */ 00113  #define  WAVE_FORMAT_IMA_ADPCM (WAVE_FORMAT_DVI_ADPCM) /* Intel Corporation */ 00114  #define  WAVE_FORMAT_MEDIASPACE_ADPCM 0x0012 /* Videologic */ 00115  #define  WAVE_FORMAT_SIERRA_ADPCM 0x0013 /* Sierra Semiconductor Corp */ 00116  #define  WAVE_FORMAT_G723_ADPCM 0x0014 /* Antex Electronics Corporation */ 00117  #define  WAVE_FORMAT_DIGISTD 0x0015 /* DSP Solutions, Inc. */ 00118  #define  WAVE_FORMAT_DIGIFIX 0x0016 /* DSP Solutions, Inc. */ 00119  #define  WAVE_FORMAT_DIALOGIC_OKI_ADPCM 0x0017 /* Dialogic Corporation */ 00120  #define  WAVE_FORMAT_MEDIAVISION_ADPCM 0x0018 /* Media Vision, Inc. */ 00121  #define  WAVE_FORMAT_CU_CODEC 0x0019 /* Hewlett-Packard Company */ 00122  #define  WAVE_FORMAT_YAMAHA_ADPCM 0x0020 /* Yamaha Corporation of America */ 00123  #define  WAVE_FORMAT_SONARC 0x0021 /* Speech Compression */ 00124  #define  WAVE_FORMAT_DSPGROUP_TRUESPEECH 0x0022 /* DSP Group, Inc */ 00125  #define  WAVE_FORMAT_ECHOSC1 0x0023 /* Echo Speech Corporation */ 00126  #define  WAVE_FORMAT_AUDIOFILE_AF36 0x0024 /* Virtual Music, Inc. */ 00127  #define  WAVE_FORMAT_APTX 0x0025 /* Audio Processing Technology */ 00128  #define  WAVE_FORMAT_AUDIOFILE_AF10 0x0026 /* Virtual Music, Inc. */ 00129  #define  WAVE_FORMAT_PROSODY_1612 0x0027 /* Aculab plc */ 00130  #define  WAVE_FORMAT_LRC 0x0028 /* Merging Technologies S.A. */ 00131  #define  WAVE_FORMAT_DOLBY_AC2 0x0030 /* Dolby Laboratories */ 00132  #define  WAVE_FORMAT_GSM610 0x0031 /* Microsoft Corporation */ 00133  #define  WAVE_FORMAT_MSNAUDIO 0x0032 /* Microsoft Corporation */ 00134  #define&nbs

2011-07-26 0comments 114hotness 0likes mikebai Read all
dev

Wave File Format

Table of Contents•Overview •Data Formats •File Structure   Wave File Header   Wave File Chunks     Format Chunk - "fmt "     Data Chunk - "data"     Fact Chunk - "fact"     Cue Chunk - "cue "     Playlist Chunk - "plst"     Associated Data List Chunk - "list"     Label Chunk - "labl"     Labeled Text Chunk - "ltxt"     Note Chunk - "note"     Sample Chunk - "smpl"     Instrument Chunk - "inst" •Format Variations  OverviewThe Wave file format is Windows' native file format for storing digital audio data. It has become one of the most widely supported digital audio file formats on the PC due to the popularity of Windows and the huge number of programs written for the platform. Almost every modern program that can open and/or save digital audio supports this file format, making it both extremely useful and a virtual requirement for software developers to understand. The following specification gives a detailed description of the structure and inner workings of this format. Data FormatsSince the Wave file format is native to Windows and therefor Intel processors, all data values are stored in Little-Endian (least significant byte first) order. StringsWave files may contain strings of text for specifying cue point labels, notes, etc. Strings are stored in a format where the first byte specifies the number of following ASCII text bytes in the string. The following bytes are of course the ASCII character bytes that make up the text string. Pascal programmers will notice that this is the same format used for Pascal strings. 7…

2011-07-25 0comments 115hotness 0likes mikebai Read all
dev

av文件格式分析详解

wav文件格式分析详解一、综述    WAVE文件作为多媒体中使用的声波文件格式之一,它是以RIFF格式为标准的。    RIFF是英文Resource Interchange File Format的缩写,每个WAVE文件的头四个字节便是“RIFF”。    WAVE文件是由若干个Chunk组成的。按照在文件中的出现位置包括:RIFF WAVE Chunk, Format Chunk, Fact Chunk(可选), Data Chunk。具体见下图:------------------------------------------------|             RIFF WAVE Chunk                  ||             ID  = 'RIFF'                     ||             RiffType = 'WAVE'                |------------------------------------------------|             Format Chunk                     ||             ID = 'fmt '                      |------------------------------------------------|             Fact Chunk(optional)             ||             ID = 'fact'                      |------------------------------------------------|             Data Chunk                       ||             ID = 'data'                      |------------------------------------------------            图1   Wav格式包含Chunk示例    其中除了Fact Chunk外,其他三个Chunk是必须的。每个Chunk有各自的ID,位于Chunk最开始位置,作为标示,而且均为4个字节。并且紧跟在ID后面的是Chunk大小(去除ID和Size所占的字节数后剩下的其他字节数目),4个字节表示,低字节表示数值低位,高字节表示数值高位。下面具体介绍各个 Chunk内容。PS:所有数值表示均为低字节表示低位,高字节表示高位。二、具体介绍RIFF WAVE Chunk    ==================================    |       |所占字节数|  具体内容   |    ==================================    | ID    |  4 Bytes |   'RIFF'    |    ----------------------------------    | Size  |  4 Bytes |             |    ----------------------------------    | Type  |  4 Bytes |   'WAVE'    |    ----------------------------------            图2  RIFF WAVE Chunk    以'FIFF'作为标示,然后紧跟着为size字段,该size是整个wav文件大小减去ID和Size所占用的字节数,即FileLen - 8 = Size。然后是Type字段,为'WAVE',表示是wav文件。    结构定义如下: struct RIFF_HEADER {  char szRiffID[4];  // 'R','I','F','F'  DWORD dwRiffSize;  char szRiffFormat[4]; // 'W','A','V','E' };Format Chunk    ===================================

2011-07-25 0comments 113hotness 0likes mikebai Read all
dev

WAVE PCM soundfile format

The WAVE file format is a subset of Microsoft's RIFF specification for the storage of multimedia files. A RIFF file starts out with a file header followed by a sequence of data chunks. A WAVE file is often just a RIFF file with a single "WAVE" chunk which consists of two sub-chunks -- a "fmt " chunk specifying the data format and a "data" chunk containing the actual sample data. Call this form the "Canonical form". Who knows how it really all works. I use the standard WAVE format as created by the sox program: Offset Size Name Description The canonical WAVE format starts with the RIFF header: 0 4 ChunkID Contains the letters "RIFF" in ASCII form (0x52494646 big-endian form). 4 4 ChunkSize 36 + SubChunk2Size, or more precisely: 4 + (8 + SubChunk1Size) + (8 + SubChunk2Size) This is the size of the rest of the chunk following this number. This is the size of the entire file in bytes minus 8 bytes for the two fields not included in this count: ChunkID and ChunkSize. 8 4 Format Contains the letters "WAVE" (0x57415645 big-endian form). The "WAVE" format consists of two subchunks: "fmt " and "data": The "fmt " subchunk describes the sound data's format: 12 4 Subchunk1ID Contains the letters "fmt " (0x666d7420 big-endian form). 16 4 Subchunk1Size 16 for PCM. This is the size of the rest of the Subchunk which follows this number. 20 2 AudioFormat PCM = 1 (i.e. Linear quantization) Values other than 1 indicate some form of compression. 22 2 NumChannels Mono…

2011-07-25 0comments 102hotness 0likes mikebai Read all
dev

java datetime操作

java.lang.Object....|__java.util.Date..........|__java.sql.Date/java.sql.Timestamp /java.sql.Time【父类】java.util.Date日期格式为:年月日时分秒【子类】java.sql.Date日期格式为:年月日[只存储日期数据不存储时间数据]【子类】java.sql.Time日期格式为:时分秒【子类】java.sql.Timestamp日期格式为:年月日时分秒纳秒(毫微秒)针对不同的数据库选用不同的日期类型·Oracle的Date类型,只需要年月日,选择使用java.sql.Date类型·MS Sqlserver数据库的DateTime类型,需要年月日时分秒,选择java.sql.Timestamp类型------------------------------------------四种对象内部均使用系统时间作为标准数据·系统时间:自 1970 年 1 月 1 日 00:00:00 GMT 以来的毫秒数,即格林尼治标准时间(GMT)·本地时间:根据时区不同打印出来的时间[当时区为GMT+0时,系统时间与本地时间相同]我们使用的是以本地时间为参考标准的------------------------------------------生成日期对象方法一:除了父类,三个子类均可通过给其发送valueOf()消息,生成所需格式的对象。java.sql.Date sqlDate = java.sql.Date.valueOf("2010-08-20");java.sql.Time time = java.sql.Time.valueOf("13:44:53");java.sql.Timestamp time = java.sql.Timestamp.valueOf("2010-08-20 14:06:27.186");方法二:·java.util.Date——>java.sql.Datenew java.sql.Date(new java.util.Date().getTime());new java.util.Date(new java.sql.Date().getTime());//此处IDE报错·java.util.Date——>java.sql.Timestampnew java.sql.Timestamp(new java.util.Date().getTime());//此处IDE报错·java.util.Date——>java.sql.Timenew java.sql.Time(new java.util.Date().getTime());·Timestamp timestamp  = new Timestamp(System.currentTimeMillis());------------------------------------------我们可以使用DateFormat处理字符串来定义时间日期的格式注:String都是先转换为java.util.Date,然后再转换成所需的格式CalendarCalendar calendar=Calendar.getInstance();//获得当前时间,声明时间变量int year = calendar.get(Calendar.YEAR);int month = calendar.get(Calendar.MONTH);month = month+1; //[0,11]int date = calendar.get(Calendar.DATE);String today = ""+year+"-"+month+"-"+date+"";..................................String to Date[java.sql.Date]String to Time[java.sql.Timestamp]..................................DateFormat dateFormat;dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);//dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.SSS", Locale.ENGLISH);//设定格式dateFormat.setLenient(false);java.util.Date timeDate = dateFormat.parse(dateString);//util类型java.sql.Date dateTime = new java.sql.Date(timeDate.getTime());//sql类型// java.sql.Timestamp dateTime = new java.sql.Timestamp(timeDate.getTime());//Timestamp类型 Java代码  public class DateTest  {        public static void main(String[] args) throws ParseException{            try{                 String dateString = "2010-08-20 12:00:00.125";                 DateFormat dateFo

2011-07-21 0comments 105hotness 0likes mikebai Read all
1…1718192021…25

Recent Posts

  • c# winform适配高dpi
  • com.microsoft.sqlserver.jdbc.SQLServerException “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server建立安全连接
  • java -cp 用法介绍
  • HTML 容器元素
  • MVC的cshtml的介绍

Recent Comments

No comments to show.

COPYRIGHT © 2025 mikebai.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang