清除Linux系统中/var/spool/clientmqueue目录

linux系统运行一段时间后会发现/var/spool/clientmqueue/目录很大,甚至占满了不大的磁盘空间,这些文件是如何产生的,能否清除,如何清除呢? 该目录下的文件是corntab操作产生的,这些文件一般要通过mail的形式发给对应的用户的,如果sendMail没有启动,这些文件就会长期保存在这里. 这些文件可以清除,但清除方法不能用一般的rm方法,会示显示参数列表过长(-bash: /bin/rm: Argument list too long)无法用rm直接删除. 正确的清除方法如下: 以root身份进入/var/spool/clientmqueue/,执行: ls|xargs rm -f 就能全部删除了 如何才能不产生这些文件呢?彻底的解决方法如下: 将crontab里面的命令后面加上 > /dev/null 2>&1。 如:ls -l / > /dev/null 2>&1 源自:http://blog.3gstdy.com

Java基础

1、序列化 Volatile transient http://www.blogjava.net/fhtdy2004/archive/2009/06/20/286112.html 2、Math API http://hunter090730.iteye.com/blog/485770 public static void main(String args[]) { System.out.println(“result:”+11+1); System.out.println(“result:”+”12345”.valueOf(54321)); double d = -4.4999999; System.out.println(Math.ceil(d));//不小于参数的最小整数值. System.out.println(Math.floor(d));//不大于参数的最大整数值. System.out.println(Math.round(d));//四舍五入法最接近参数的int/long值. } 输出为: result:111 result:54321 -4.0 -5.0 -4 3、Android的Message,MessageQueue,Looper,Handler详解+实例 http://blog.csdn.net/zhangren07/article/details/6400845 4、HashTable ,HashMap 5、Android 主要组件Activity, Service, ContextProvider, BroadcastReceiver 6、android:screenOrientation

MySQL 表损坏修复方法Table ‘%s’ is marked as crashed and last (automatic) repair failed

问题分析: 数据表损坏造成的。 解决方法: 1、通过论坛的 tool 工具进行修复 下载地址和使用说明见:http://www.discuz.net/thread-982699-1-1.html 2、myisamchk 修复 myisamchk 命令的格式如下: 1)myisamchk –recover tbl_name 2)myisamchk –recover /path/tbl_name 这种方法要指定数据表在磁盘上的位置。 3、使用 phpMyAdmin 修复数据的方法 进入论坛数据库,然后选择要修复的表,在页脚下拉框选择“修复”即可。 注意:如果需要修复数据库,修复前一定要做好备份。

SSH项目查找问题的一般方法

SSH开发项目是目前十分流行的一个趋势。对于从事JavaEE项目开发多年的朋友来说,开发时使用SSH确实能带来不少的便利。SSH帮你做了一个规划,让你将不同的程序代码放到不同的地方。使整个工程看起来,更加工整,大家都采用这种模式开发程序,相互更容易沟通。新的成员也更容易融入到项目中。但对于刚入行的朋友来说,有点力不从心。有些朋友会说我只是实现一个很小的功能,为什么要写那么多的代码,建立那么多的类,还有一大堆的配置文件。出现一些问题还要花上半天去找原因,真是麻烦。所以在这里我想结合自己的体会、经历,对于初涉及到SSH项目的朋友,说说如何快速定位问题。 1、直接根据错误日志找到出错位置。(这种方法比较容易,大家常用的,不多说) 对一些不明错误(所谓不明错误是指编译没有问题,运行过程也不报错,但就是得不到预期的结果)用第一种方法是找不到原因的。要查找此类问题要根据SSH框架的结构,我们都知道: SSH框架是由三个框架有机组合而成的,它们分工明确,流水作业。从前台到后台,从Http请求到数据库,依次为Stucts->Spring->Hibernate。所以当出现错误时,我们可采用两种方法: 2、顺藤摸瓜: 从Stucts开始,看看是否能接收到正确的请求数据。如果正确,接着往下看看Spring中的业务操作是否正确,如果没有问题就接着往下找,到Hibernate层看看,操作数据库是否有问题。对于一般的问题通过这三个步骤都能找出问题的原因。但这种找原因方法破费太大了一些。对于那些隐蔽较好的错误。或者,开发者,过于疲劳没有思路时才如此全面检查。另外:这种方法对初涉及SSH项目的朋友比较有好处,多如此查找几次你就明白了SSH框架的运行机制。 3、大胆猜测,定点检查: 如果你从事SSH项目有一年半载了,对SSH比较熟悉了,并且对所做项目比较了解。遇到不明错误就可根据经验猜测什么地方出现了问题,就在那打上一个断点,或者多猜测几个位置,用一组测试数据测试,当运行到断点时,看看数据是否有异常。 转载请标明出处:3G Study :http://blog.3gstdy.com/archives/594

iphone

http://bbs.weiphone.com/read-htm-tid-812586-page-1.html 本来想在cydia store上买一个的,可以国内怎么也连不上。后来找了找,在国外一个网站上找到了displayout程序。版本低了点,不过我测试了可以正常使用,特意给大家分享一下。 DEB格式的,DEB的安装见网上有关贴子。我用的是下面的方法: 1、首先用WinSCP或iPhone Exlplorer或者其它软件将Deb包拷贝到 /var/root/Media/Cydia/AutoInstall(如果没有这个文件夹,就创建一个,注意大小写) 2、重新启动 iPad 后就会自动安装, 之后再重启 iPad 就完成安装了。 displayout安装包 displayout.deb (20 K) 下载次数:5491 =================================== 分量5条线,三条是信号,2条是音频,分量最高可传输与支持1080P的视频,AV三条线,一条是信号,2条是音频,AV是576 i的信号传输 =================================== 复合视频 =================================== 苹果视频线有5头和3头之分,5头的统称为色差线用于大多数液晶电视 输出图像更清晰,红色和白色插头为音频输出 红蓝绿为视频输出.所以 画面清晰度方面要好于3头AV线的很多.3头的统称为 AV 线 一般用于老式的电视 红色和白色插头为音频输出.黄色插头为视频输出.输出图像清晰度相对于5头线较差 ====================== 只要用机子进入设置-通用-关于本机,就可以看到Apple Composite AV Cable的字样就绝对假不了色差视频 发挥电视极致 卡登仕Wii极品色差分量线 ============================== 头视频线 可用型号:IPAD iphone 一代、iphone 3G、iphone 3Gs、touch 一代、touch 2代、touch 3代NANO 4、NANO5 iphone 4 touch 4代 ============================== http://www.shangpinjia.com/show.php?catid=1006&id=15186 客户最关心的问题来了 很多客户问这视频线 可以同步界面或者游戏吗?答:是可以的 , 为了这个问题,店主自己测试了效果,前提是需要 越狱 你的IPAD iphone 4 3gs 等等需要越狱过 就可以同步游戏了 下面放上教程(越狱参考各大网站教程) 1:首先我们需要在手机上安装一个软件(TVOUT)有几个版本 都支持)可以自己到cydia下载 下面有cydia下载教程 自己也可以到各大网站下载 下面是在手机上cydia下载的 这个是越狱后的文件,我手机是中文版本的 因为我下了中文包, 自带是英文的 点最右边的搜索 输入 tvout 这时会弹出下面这个,我建议下载tvout 2 新版的嘛 比较好用 安装成功了 就是这个软件 我们的iphone 4 IPAD 有这个图标就OK乐 下面是这软件两种版本 但是都支持 接下来 是接线 接线问题 这个线是总长2米 客户总问的问题,还有带USB接口 可以边玩游戏边充电 本连接的视频线是五头的 所以直接按色在电视机上插上就可以了 电视机 后面插孔 是5个插头 不过我们这款是五头的 直接按色插上 绿色=绿色 蓝色=蓝牙 红色=红色 L和R 对应 视频线上的L线和R线 分别是红和白 已经成功插上 L和R 是下面两个 这时将苹果插头 插进iphone 或者 IPAD 然后电视选择 component输出 ,个人电视品牌不一样,请自己选择,图片仅供参考 电视自动转变为 你手机的界面 注意:旧版本的tvout 需要进入tvout 时才会帮你转变界面 我的电视是42寸的 ,个人电视尺寸不可以一样。可以自行到tvout里面设置尺寸,具体自己摸索 玩GT 赛车 系列 给力 斗地主 看优酷 大电视 弹琴 喷怒的小鸟 完成 注意问题: 1:玩大型游戏会出现卡屏时,直接拨掉线在插上 就可以恢复界面 2:看视频,玩游戏时,不横屏时,请将手机(横竖)摇晃几下就可以恢复横屏 http://bbs.weiphone.com/read-htm-tid-253530.html http://support.apple.com/kb/HT1454?viewlocale=zh_CN http://gogowiki.cn/?p=19807 Veency VNC Viewer http://www.happypda.com/read.php?107

提高Android应用程序的速度四大原则

我们之前曾向大家介绍了过《Android应用核心——Intent》。Intent可以算得上Android应用开发的重点之一,它负责对应用中各个组件之间的通讯与相互协调和调用。但是在Android开发中,对Android应用程序提速需要很多技巧和原则。首先, 我们要先明白“加快”是有两层意思的,第一层是代码执行所需要的时间,第二层意思是用户需要等待用户界面响应的时间。这两者有很大的不同,当然我们必须提高代码执行的效率,但是最重要的是用户所看到的东西。所以,如果不是必须的,就不要让用户等待。下面是提高Android应用程序运行速度的几条原则。 一、不要让UI线程等待 最基本的一个原则就是不要在用户界面线程中执行耗时的操作,如果这样做,用户界面将在操作完成前被锁定(界面卡死),这就给用户带来不好的使用体验。如果耗时超长,那么系统会删除该线程或提示用户是否中止该操作。 如果在UI线程中处理一些工作(业务操作),那么不管你的代码执行的是如何的流畅,其实都是一堆垃圾。 二、耗时操作 有哪些耗时的操作呢?最常见的是网络连接操作,网络状态随着环境的变化有很大差异,网络好的地方可能速度很快,但网络差的地方需要等待很长时间,所以一定不能在UI线程中执行网络操作。另外就是数据库操作和SD卡文件的读写操作,这些操作都尽量不要在UI线程中完成,对于数据库操作,我们可以建一些索引来提高程序运行速度。 三、模拟器和真实的设备 在模拟器和真实的设备上运行也有很大的差异,模拟器需要更好的CPU,如果你的电脑性能很差,你就会感觉到运行速度很慢,但如果在真实的设备上运行会很快,另外模拟器使用的是系统硬盘,访问速度会比真实的设备访问SD卡快很多。 四、通知用户 当需要用户等待时,一定要用进度条等告诉用户程序还在运行中,不要让用户界面卡死,使用一些正在载入的动画会让用户有更好的使用体验。

用Android程序打开和关闭输入法

一、打开输入法窗口:

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // 接受软键盘输入的编辑文本或其它视图 imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

二、关闭出入法窗口

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),

InputMethodManager.HIDE_NOT_ALWAYS);

//接受软键盘输入的编辑文本或其它视图

inputMethodManager

.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

三、如果输入法打开则关闭,如果没打开则打开 InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); 四、获取输入法打开的状态 InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); boolean isOpen=imm.isActive(); isOpen若返回true,则表示输入法打开

Android中ListView组件的Item拖动(Item改变顺序)

http://blog.csdn.net/mayingcai1987/archive/2011/04/25/6362325.aspx

  1. /*
    • Copyright (C) 2008 The Android Open Source Project
  2. *
    • Licensed under the Apache License, Version 2.0 (the “License”);
    • you may not use this file except in compliance with the License.
    • You may obtain a copy of the License at
  3. *
  4. *
    • Unless required by applicable law or agreed to in writing, software
    • distributed under the License is distributed on an “AS IS” BASIS,
    • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    • See the License for the specific language governing permissions and
    • limitations under the License.
  5. */
  6. package com.flora;
  7. import android.content.Context;
  8. import android.content.SharedPreferences;
  9. import android.content.res.Resources;
  10. import android.graphics.Bitmap;
  11. import android.graphics.PixelFormat;
  12. import android.graphics.Rect;
  13. import android.graphics.drawable.Drawable;
  14. import android.util.AttributeSet;
  15. import android.view.GestureDetector;
  16. import android.view.Gravity;
  17. import android.view.MotionEvent;
  18. import android.view.View;
  19. import android.view.ViewConfiguration;
  20. import android.view.ViewGroup;
  21. import android.view.WindowManager;
  22. import android.view.GestureDetector.SimpleOnGestureListener;
  23. import android.widget.AdapterView;
  24. import android.widget.ImageView;
  25. import android.widget.ListView;
  26. public class DragAndDropListView extends ListView {
  27. private ImageView mDragView;
  28. private WindowManager mWindowManager;
  29. private WindowManager.LayoutParams mWindowParams;
  30. /**
    • At which position is the item currently being dragged. Note that this
    • takes in to account header items.
  31. */
  32. private int mDragPos;
  33. /**
    • At which position was the item being dragged originally
  34. */
  35. private int mSrcDragPos;
  36. private int mDragPointX; // at what x offset inside the item did the user grab it
  37. private int mDragPointY; // at what y offset inside the item did the user grab it
  38. private int mXOffset; // the difference between screen coordinates and coordinates in this view
  39. private int mYOffset; // the difference between screen coordinates and coordinates in this view
  40. private DragListener mDragListener;
  41. private DropListener mDropListener;
  42. private RemoveListener mRemoveListener;
  43. private int mUpperBound;
  44. private int mLowerBound;
  45. private int mHeight;
  46. private GestureDetector mGestureDetector;
  47. private static final int FLING = 0;
  48. private static final int SLIDE = 1;
  49. private static final int TRASH = 2;
  50. private int mRemoveMode = -1;
  51. private Rect mTempRect = new Rect();
  52. private Bitmap mDragBitmap;
  53. private final int mTouchSlop;
  54. private int mItemHeightNormal;
  55. private int mItemHeightExpanded;
  56. private int mItemHeightHalf;
  57. private Drawable mTrashcan;
  58. public DragAndDropListView(Context context, AttributeSet attrs) {
  59. super(context, attrs);
  60. SharedPreferences pref = context.getSharedPreferences(“Music”, 3);
  61. mRemoveMode = pref.getInt(“deletemode”, -1);
  62. mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
  63. Resources res = getResources();
  64. mItemHeightNormal = res.getDimensionPixelSize(R.dimen.normal_height);
  65. mItemHeightHalf = mItemHeightNormal / 2;
  66. mItemHeightExpanded = res.getDimensionPixelSize(R.dimen.expanded_height);
  67. }
  68. @Override
  69. public boolean onInterceptTouchEvent(MotionEvent ev) {
  70. if (mRemoveListener != null && mGestureDetector == null) {
  71. if (mRemoveMode == FLING) {
  72. mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
  73. @Override
  74. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  75. float velocityY) {
  76. if (mDragView != null) {
  77. if (velocityX > 1000) {
  78. Rect r = mTempRect;
  79. mDragView.getDrawingRect(r);
  80. if ( e2.getX() > r.right * 2 / 3) {
  81. // fast fling right with release near the right edge of the screen
  82. stopDragging();
  83. mRemoveListener.remove(mSrcDragPos);
  84. unExpandViews(true);
  85. }
  86. }
  87. // flinging while dragging should have no effect
  88. return true;
  89. }
  90. return false;
  91. }
  92. });
  93. }
  94. }
  95. if (mDragListener != null || mDropListener != null) {
  96. switch (ev.getAction()) {
  97. case MotionEvent.ACTION_DOWN:
  98. int x = (int) ev.getX();
  99. int y = (int) ev.getY();

  100. int itemnum = pointToPosition(x, y);

  101. if (itemnum == AdapterView.INVALID_POSITION) {
  102. break;
  103. }
  104. ViewGroup item = (ViewGroup) getChildAt(itemnum - getFirstVisiblePosition());
  105. mDragPointX = x - item.getLeft();
  106. mDragPointY = y - item.getTop();
  107. mXOffset = ((int)ev.getRawX()) - x;
  108. mYOffset = ((int)ev.getRawY()) - y;
  109. // The left side of the item is the grabber for dragging the item
  110. if (x < 64) {
  111. item.setDrawingCacheEnabled(true);
  112. // Create a copy of the drawing cache so that it does not get recycled
  113. // by the framework when the list tries to clean up memory
  114. Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
  115. startDragging(bitmap, x, y);
  116. mDragPos = itemnum;
  117. mSrcDragPos = mDragPos;
  118. mHeight = getHeight();
  119. int touchSlop = mTouchSlop;
  120. mUpperBound = Math.min(y - touchSlop, mHeight / 3);
  121. mLowerBound = Math.max(y + touchSlop, mHeight * 2 /3);
  122. return false;
  123. }
  124. stopDragging();
  125. break;
  126. }
  127. }
  128. return super.onInterceptTouchEvent(ev);
  129. }
  130. /*
    • pointToPosition() doesn’t consider invisible views, but we
    • need to, so implement a slightly different version.
  131. */
  132. private int myPointToPosition(int x, int y) {
  133. if (y < 0) {
  134. // when dragging off the top of the screen, calculate position
  135. // by going back from a visible item
  136. int pos = myPointToPosition(x, y + mItemHeightNormal);
  137. if (pos > 0) {
  138. return pos - 1;
  139. }
  140. }
  141. Rect frame = mTempRect;
  142. final int count = getChildCount();
  143. for (int i = count - 1; i >= 0; i–) {
  144. final View child = getChildAt(i);
  145. child.getHitRect(frame);
  146. if (frame.contains(x, y)) {
  147. return getFirstVisiblePosition() + i;
  148. }
  149. }
  150. return INVALID_POSITION;
  151. }
  152. private int getItemForPosition(int y) {
  153. int adjustedy = y - mDragPointY - mItemHeightHalf;
  154. int pos = myPointToPosition(0, adjustedy);
  155. if (pos >= 0) {
  156. if (pos <= mSrcDragPos) {
  157. pos += 1;
  158. }
  159. } else if (adjustedy < 0) {
  160. // this shouldn’t happen anymore now that myPointToPosition deals
  161. // with this situation
  162. pos = 0;
  163. }
  164. return pos;
  165. }
  166. private void adjustScrollBounds(int y) {
  167. if (y >= mHeight / 3) {
  168. mUpperBound = mHeight / 3;
  169. }
  170. if (y <= mHeight * 2 / 3) {
  171. mLowerBound = mHeight * 2 / 3;
  172. }
  173. }
  174. /*
    • Restore size and visibility for all listitems
  175. */
  176. private void unExpandViews(boolean deletion) {
  177. for (int i = 0;; i++) {
  178. View v = getChildAt(i);
  179. if (v == null) {
  180. if (deletion) {
  181. // HACK force update of mItemCount
  182. int position = getFirstVisiblePosition();
  183. int y = getChildAt(0).getTop();
  184. setAdapter(getAdapter());
  185. setSelectionFromTop(position, y);
  186. // end hack
  187. }
  188. try {
  189. layoutChildren(); // force children to be recreated where needed
  190. v = getChildAt(i);
  191. } catch (IllegalStateException ex) {
  192. // layoutChildren throws this sometimes, presumably because we’re
  193. // in the process of being torn down but are still getting touch
  194. // events
  195. }
  196. if (v == null) {
  197. return;
  198. }
  199. }
  200. ViewGroup.LayoutParams params = v.getLayoutParams();
  201. params.height = mItemHeightNormal;
  202. v.setLayoutParams(params);
  203. v.setVisibility(View.VISIBLE);
  204. }
  205. }
  206. /* Adjust visibility and size to make it appear as though
    • an item is being dragged around and other items are making
    • room for it:
    • If dropping the item would result in it still being in the
    • same place, then make the dragged listitem’s size normal,
    • but make the item invisible.
    • Otherwise, if the dragged listitem is still on screen, make
    • it as small as possible and expand the item below the insert
    • point.
    • If the dragged item is not on screen, only expand the item
    • below the current insertpoint.
  207. */
  208. private void doExpansion() {
  209. int childnum = mDragPos - getFirstVisiblePosition();
  210. if (mDragPos > mSrcDragPos) {
  211. childnum++;
  212. }
  213. int numheaders = getHeaderViewsCount();
  214. View first = getChildAt(mSrcDragPos - getFirstVisiblePosition());
  215. for (int i = 0;; i++) {
  216. View vv = getChildAt(i);
  217. if (vv == null) {
  218. break;
  219. }
  220. int height = mItemHeightNormal;
  221. int visibility = View.VISIBLE;
  222. if (mDragPos < numheaders && i == numheaders) {
  223. // dragging on top of the header item, so adjust the item below
  224. // instead
  225. if (vv.equals(first)) {
  226. visibility = View.INVISIBLE;
  227. } else {
  228. height = mItemHeightExpanded;
  229. }
  230. } else if (vv.equals(first)) {
  231. // processing the item that is being dragged
  232. if (mDragPos == mSrcDragPos || getPositionForView(vv) == getCount() - 1) {
  233. // hovering over the original location
  234. visibility = View.INVISIBLE;
  235. } else {
  236. // not hovering over it
  237. // Ideally the item would be completely gone, but neither
  238. // setting its size to 0 nor settings visibility to GONE
  239. // has the desired effect.
  240. height = 1;
  241. }
  242. } else if (i == childnum) {
  243. if (mDragPos >= numheaders && mDragPos < getCount() - 1) {
  244. height = mItemHeightExpanded;
  245. }
  246. }
  247. ViewGroup.LayoutParams params = vv.getLayoutParams();
  248. params.height = height;
  249. vv.setLayoutParams(params);
  250. vv.setVisibility(visibility);
  251. }
  252. }
  253. @Override
  254. public boolean onTouchEvent(MotionEvent ev) {
  255. if (mGestureDetector != null) {
  256. mGestureDetector.onTouchEvent(ev);
  257. }
  258. if ((mDragListener != null || mDropListener != null) && mDragView != null) {
  259. int action = ev.getAction();
  260. switch (action) {
  261. case MotionEvent.ACTION_UP:
  262. case MotionEvent.ACTION_CANCEL:
  263. Rect r = mTempRect;
  264. mDragView.getDrawingRect(r);
  265. stopDragging();
  266. if (mRemoveMode == SLIDE && ev.getX() > r.right * 3 / 4) {
  267. if (mRemoveListener != null) {
  268. mRemoveListener.remove(mSrcDragPos);
  269. }
  270. unExpandViews(true);
  271. } else {
  272. if (mDropListener != null && mDragPos >= 0 && mDragPos < getCount()) {
  273. mDropListener.drop(mSrcDragPos, mDragPos);
  274. }
  275. unExpandViews(false);
  276. }
  277. break;
  278. case MotionEvent.ACTION_DOWN:
  279. case MotionEvent.ACTION_MOVE:
  280. int x = (int) ev.getX();
  281. int y = (int) ev.getY();
  282. dragView(x, y);
  283. int itemnum = getItemForPosition(y);
  284. if (itemnum >= 0) {
  285. if (action == MotionEvent.ACTION_DOWN || itemnum != mDragPos) {
  286. if (mDragListener != null) {
  287. mDragListener.drag(mDragPos, itemnum);
  288. }
  289. mDragPos = itemnum;
  290. doExpansion();
  291. }
  292. int speed = 0;
  293. adjustScrollBounds(y);
  294. if (y > mLowerBound) {
  295. // scroll the list up a bit
  296. if (getLastVisiblePosition() < getCount() - 1) {
  297. speed = y > (mHeight + mLowerBound) / 2 ? 16 : 4;
  298. } else {
  299. speed = 1;
  300. }
  301. } else if (y < mUpperBound) {
  302. // scroll the list down a bit
  303. speed = y < mUpperBound / 2 ? -16 : -4;
  304. if (getFirstVisiblePosition() == 0
  305. && getChildAt(0).getTop() >= getPaddingTop()) {
  306. // if we’re already at the top, don’t try to scroll, because
  307. // it causes the framework to do some extra drawing that messes
  308. // up our animation
  309. speed = 0;
  310. }
  311. }
  312. if (speed != 0) {
  313. smoothScrollBy(speed, 30);
  314. }
  315. }
  316. break;
  317. }
  318. return true;
  319. }
  320. return super.onTouchEvent(ev);
  321. }
  322. private void startDragging(Bitmap bm, int x, int y) {
  323. stopDragging();
  324. mWindowParams = new WindowManager.LayoutParams();
  325. mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
  326. mWindowParams.x = x - mDragPointX + mXOffset;
  327. mWindowParams.y = y - mDragPointY + mYOffset;
  328. mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
  329. mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
  330. mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
  331. | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
  332. | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
  333. | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
  334. | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
  335. mWindowParams.format = PixelFormat.TRANSLUCENT;
  336. mWindowParams.windowAnimations = 0;
  337. Context context = getContext();
  338. ImageView v = new ImageView(context);
  339. v.setBackgroundResource(R.drawable.drag_and_drop_image);
  340. v.setPadding(0, 0, 0, 0);
  341. v.setImageBitmap(bm);
  342. mDragBitmap = bm;
  343. mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
  344. mWindowManager.addView(v, mWindowParams);
  345. mDragView = v;
  346. }
  347. private void dragView(int x, int y) {
  348. if (mRemoveMode == SLIDE) {
  349. float alpha = 1.0f;
  350. int width = mDragView.getWidth();
  351. if (x > width / 2) {
  352. alpha = ((float)(width - x)) / (width / 2);
  353. }
  354. mWindowParams.alpha = alpha;
  355. }
  356. if (mRemoveMode == FLING || mRemoveMode == TRASH) {
  357. mWindowParams.x = x - mDragPointX + mXOffset;
  358. } else {
  359. mWindowParams.x = 0;
  360. }
  361. mWindowParams.y = y - mDragPointY + mYOffset;
  362. mWindowManager.updateViewLayout(mDragView, mWindowParams);
  363. if (mTrashcan != null) {
  364. int width = mDragView.getWidth();
  365. if (y > getHeight() * 3 / 4) {
  366. mTrashcan.setLevel(2);
  367. } else if (width > 0 && x > width / 4) {
  368. mTrashcan.setLevel(1);
  369. } else {
  370. mTrashcan.setLevel(0);
  371. }
  372. }
  373. }
  374. private void stopDragging() {
  375. if (mDragView != null) {
  376. mDragView.setVisibility(GONE);
  377. WindowManager wm = (WindowManager)getContext().getSystemService(Context.WINDOW_SERVICE);
  378. wm.removeView(mDragView);
  379. mDragView.setImageDrawable(null);
  380. mDragView = null;
  381. }
  382. if (mDragBitmap != null) {
  383. mDragBitmap.recycle();
  384. mDragBitmap = null;
  385. }
  386. if (mTrashcan != null) {
  387. mTrashcan.setLevel(0);
  388. }
  389. }
  390. public void setTrashcan(Drawable trash) {
  391. mTrashcan = trash;
  392. mRemoveMode = TRASH;
  393. }
  394. public void setDragListener(DragListener l) {
  395. mDragListener = l;
  396. }
  397. public void setDropListener(DropListener l) {
  398. mDropListener = l;
  399. }
  400. public void setRemoveListener(RemoveListener l) {
  401. mRemoveListener = l;
  402. }
  403. public interface DragListener {
  404. void drag(int from, int to);
  405. }
  406. public interface DropListener {
  407. void drop(int from, int to);
  408. }
  409. public interface RemoveListener {
  410. void remove(int which);
  411. }
  412. }

分辨率相关DPI,SIZE,RESOLUTION,COLOR,DENSITY

  1. Screen size (屏幕尺寸):具体的屏幕物理长度,以对角线长度做为标识,平时我们说的3”屏,7”屏就是指这个,是物理尺寸
  2. Resolution (分辨率):屏幕上总共的物理像素点,虽然经常被以800X600之类的来描述,但是在android中,他并不指代具体的屏幕宽高比例,注意,分辨率和屏幕大小没有任何联系,分辨率只是描述点的而已,所以相同分辨率下,屏幕越小,越清晰
  3. density(密度) :表示每英寸有多少个显示点,density是以分辨率为基础,即指在固定分辨率上散开的像素点,也即是说屏幕的density越大,单位上分散的像素就越多,可以理解为点距就越小,这样如果某个元素是以px为单位的,那么在低密度的屏幕上就会变大,应用程序可以通过指定high-dpi等三种资源来实现平台的独立性 ASPECT RATIO (宽高比例):也就是平时我们说的4比3之流
  4. Density-independent pixel(dip):dip是一种虚拟的像素单位,专门用来给程序定义UI用,Android高度推荐使用这个,可以为不同的dip设置不同的资源进行自动切换 pixels = dips (density / 160)即dip相当于屏幕density=160时的一个像素点,density=160时是一个点显示一个像素,而density=240时是3个点显示两个像素,图像看起来大一些,真实像素只有1280\2/3px,800*2/3px。
  5. Dot per inch(DPI) :就是一英寸上显示的点,而这个点并不是意义上的像素。

一般来说,显示器是96DPI,也就是说96像素等于1inch,但实际上不应该是这样,因为显示器的分辨率可以调整。 对于你上面所说的显示器设置,96DPI可以理解为用96象素来表示一英寸,而变成120DPI的时候,是用120像素来表示一英寸,而系统的对象(字体,图像)的是用英寸数来表示的,所以120DPI时,图象和字体就变大了。 就是一英寸上显示的点,而这个点并不是意义上的像素。 一般来说,显示器是96DPI,也就是说96像素等于1inch,但实际上不应该是这样,因为显示器的分辨率可以调整。 对于你上面所说的显示器设置,96DPI可以理解为用96象素来表示一英寸,而变成120DPI的时候,是用120像素来表示一英寸,而系统的对象(字体,图像)的是用英寸数来表示的,所以120DPI时,图象和字体就变大了。 色阶 :也就是平时我们说的 65536色,26万色,1600万色并没有数字看起来差别那么大,这实际上只是表示相邻的三个色阶而已,当然,1600万色显示效果是最好的