Menu Home

Android framework: 获取历史application的截图

Android Framework中的WindowManagerService提供了获取历史Application截图的方法getTaskTopThumbnail,下面演示的只获取了最近一个app的Thumbnail。需要注意的是framework只提供了缩略图,没有提供完整的截图,但是我们可以通过在WindowManagerService中修改getTaskTopThumbnail来提供完整的Application截图。 另:这个方法只能截取Window属性为TYPE_APPLICATION的窗口,对于像属性为TYPE_KEYGUARD等窗口不能使用这个方法,可以通过Surface来截图。 这种方法的意义在于: 你可以获取一个处于pause或stop(可能被另一个窗口遮挡)状态的avtivity的截图,而使用Surface截图只能获取当前显示的画面(也就是framebuffer中的内容)。 ActivityManager am = (ActivityManager) getContext().getSystemService( Context.ACTIVITY_SERVICE); private Bitmap takeScreenshot() { Bitmap bmp = null; final List<ActivityManager.RecentTaskInfo> recentTasks = am.getRecentTasksForUser( 1, ActivityManager.RECENT_IGNORE_UNAVAILABLE, UserHandle.CURRENT.getIdentifier()); if (recentTasks.size() > 0) { ActivityManager.RecentTaskInfo recentInfo = recentTasks.get(0); bmp = am.getTaskTopThumbnail(recentInfo.persistentId); } return bmp; } ref: frameworks/base/services/java/com/android/server/wm/WindowManagerService.java

ubuntu国内软件源

网易163源 deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ trusty-security main restricted universe multiverse […]

使用jpeglib压缩图片

#include <jpeglib.h> void writeJPEG(unsigned char* pixs, int width, int height, char* file) { struct jpeg_compress_struct jcs; struct jpeg_error_mgr jem; jcs.err = jpeg_std_error(&jem); jpeg_create_compress(&jcs); FILE* fp = fopen(file, “wb”); if(fp == NULL) { perror(“writeJPEG”); return; } jpeg_stdio_dest(&jcs, fp); jcs.image_width = width; jcs.image_height = height; jcs.input_components = 3; //RGB jcs.in_color_space = JCS_RGB; […]

Git RPC faild解决方法

在git pull一个很大的库时发生了如下的错误: macbookpro:Experiments sijiewang$ git pull remote: Counting objects: 3466, done. remote: Compressing objects: 100% (2172/2172), done. error: RPC failed; result=56, HTTP code = 200B | 17.00 KiB/s fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed 解决方法 增加git的post缓存大小: git config –global http.postBuffer 500000000 #增加到约500MB

Android: 对ViewGroup使用补间动画

res/anim/layout_anim.xml <?xml version=”1.0″ encoding=”utf-8″?> <layoutAnimation xmlns:android=”http://schemas.android.com/apk/res/android” android:delay=”0.5″ android:animationOrder=”random” android:animation=”@anim/popin”/> res/anim/popin.xml <?xml version=”1.0″ encoding=”utf-8″?> <set xmlns:android=”http://schemas.android.com/apk/res/android” android:interpolator=”@android:anim/accelerate_interpolator” > <scale android:duration=”2000″ android:fromXScale=”0.0″ android:fromYScale=”0.0″ android:pivotX=”50%” android:pivotY=”50%” android:toXScale=”1.0″ android:toYScale=”1.0″ /> </set> res/layout/activity_main.xml <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:layoutAnimation=”@anim/layout_anim” android:paddingBottom=”@dimen/activity_vertical_margin” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” tools:context=”.MainActivity” > <TextView android:id=”@+id/t1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/hello_world” /> <TextView android:id=”@+id/t2″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” […]

Android: PixelFormat定义

PixelFormat定义: public static final int RGBA_8888 = 1; public static final int RGBX_8888 = 2; public static final int RGB_888 = 3; public static final int RGB_565 = 4; public static final int RGBA_5551 = 6; public static final int RGBA_4444 = 7; public static final int A_8 = 8; […]

Android: Bitmap设置灰度

private Bitmap bitmap2Gray(Bitmap bmSrc) { int width = bmSrc.getWidth(); int height = bmSrc.getHeight(); Bitmap bmpGray = null; bmpGray = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas c = new Canvas(bmpGray); Paint paint = new Paint(); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm); paint.setColorFilter(f); c.drawBitmap(bmSrc, 0, 0, paint); return bmpGray; […]

Android Framework: 使用Surface截屏

/** * Takes a screenshot of the current display and shows an animation. */ void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) { // We need to orient the screenshot correctly (and the Surface api seems to take screenshots // only in the natural orientation of the device :!) mDisplay.getRealMetrics(mDisplayMetrics); float[] […]

OrientationEventListener的使用

class MyOrientationEventListener extends OrientationEventListener { public MyOrientationEventListener(Context ctx, int rate) { super(ctx, rate); } @Override public void onOrientationChanged(int orientation) { if (orientation == 0 || orientation == 90 || orientation == 270) { Log.d(“NotificationPanelView”, “onOrientationChanged”); } } } boolean mCanDetectOrientation; MyOrientationEventListener myOrientationEventLister; myOrientationEventLister = new MyOrientationEventListener( getContext(), SensorManager.SENSOR_DELAY_FASTEST); if (myOrientationEventLister.canDetectOrientation()) […]

ubuntu修改MAC地址

OS: ubuntu 12.04 命令行方式 ifconfig eth0 down ifconfig eth0 hw ether [00:00:00:00] ifconfig eth0 up 修改系统文件方式 /etc/network/interfaces iface eth0 inet static pre-up ifconfig eth0 hw ether [00:00:00:00] address 192.168.2.100 netmask 255.255.255.0 gateway 192.168.0.1

onSaveInstanceState的执行时机

在以下情况下系统会自动执行onSaveInstanceState: 即当系统“未经你许可”时销毁了activity,系统会调用onSaveInstanceState。 按下HOME键时 跳转到其他activity时 屏幕旋转时 按下电源键关闭屏幕时 当用户按下返回键或者明确销毁一个Activity的时候,系统是不会执行onSaveInstanceState的。 onRestoreInstanceState方法会在上面描述的步骤基础上并且Activity的确被销毁的情况下才会执行,换言之,如果仅仅发生了上面的操作,但是Activity并没有真正被销毁(还在Activity栈中)的情况下系统是不会执行onRestoreInstanceState方法的。 onSaveInstanceState和onRestoreInstanceState不一定的是成对出现的。 github: https://github.com/lnmcc/TestAction.git

Android JNI优化

在类加载时获取域和方法的ID JAVA端: public class MyClass { static { System.loadLibrary(“mylib”); /*在加载库的时候一次性获取需要访问的域和方法的ID*/ getIds(); } public static int someInteger = 0; public static native void sayHelloToJNI(); public static void helloFromJNI() { Log.i(“MyClass”, “Greetings! someInteger = ” + someInteger); } private static native void getId(); } C/C++端: static jfieldID someIntegerId; static jfieldID helloFromJNIId; void […]

H.264 Profiles

Baseline Profile (BP) Primarily for lower-cost applications with limited computing resources, this profile is used widely in videoconferencing and mobile applications. Main Profile (MP) Originally intended as the mainstream consumer profile for broadcast and storage applications, the importance of this profile faded when the High profile was developed for those […]