編輯:關於Android編程
以下是會使用到的native 函數,以及register_android_server_VirtualInputService;具體實現就不在詳講了。
static JNINativeMethod method_table[] = { {"native_open", "()I",(void *)android_server_VirtualInputService_open}, {"native_close", "()Z", (void *)android_server_VirtualInputService_close}, {"native_sendir", "(II)Z", (void *)android_server_VirtualInputService_sendir}, }; +int register_android_server_VirtualInputService(JNIEnv *env) +{ + jclass clazz = env->FindClass("com/android/server/VirtualInputService"); + if (clazz == NULL) { + ALOGE("Can't find com/android/server/VirtualInputService"); + return -1; + } + + return jniRegisterNativeMethods(env, "com/android/server/VirtualInputService", + method_table, NELEM(method_table)); +} +};
int register_android_server_SerialService(JNIEnv* env); +int register_android_server_VirtualInputService(JNIEnv* env); int register_android_server_UsbDeviceManager(JNIEnv* env); register_android_server_SerialService(env); + register_android_server_VirtualInputService(env); register_android_server_InputApplicationHandle(env);
+++ base/services/jni/Android.mk (working copy) @@ -16,6 +16,7 @@ com_android_server_VibratorService.cpp \ com_android_server_location_GpsLocationProvider.cpp \ com_android_server_connectivity_Vpn.cpp \ + com_android_server_VirtualInputService.cpp \ onload.cpp
+package com.android.server; + +import android.content.Context; +import android.hardware.input.IVirtualInputManager; +import android.util.Log; + +import java.io.File; +import java.util.ArrayList; + +public class VirtualInputService extends IVirtualInputManager.Stub { + private static final String TAG = "VirtualInputManager"; + + private final Context mContext; + private int mVirtualInputFd = -1; + + public VirtualInputService(Context context) { + mContext = context; + if(mVirtualInputFd == -1){ + mVirtualInputFd = native_open(); + Log.d(TAG, "mVirtualInputFd:"+mVirtualInputFd); + }else + Log.d(TAG, "mVirtualInputFd1:"+mVirtualInputFd); + + } + + public boolean SendIR(int keycode){ + if(mVirtualInputFd > 0) + { + Log.d(TAG, "Service SendIR:"+keycode); + return native_sendir(keycode,0); + } + else + return false; + } + + private native static int native_open(); + private native static boolean native_close(); + private native static boolean native_sendir(int keycode, int type); + +}
SerialService serial = null; + VirtualInputService VirtualInput = null; TwilightService twilight = null;
try { + Slog.i(TAG, "VirtualInput Service"); + VirtualInput = new VirtualInputService(context); + ServiceManager.addService(Context.VIRTUALINPUT_SERVICE, VirtualInput); + } catch (Throwable e) { + Slog.e(TAG, "Failure starting VirtualInputService", e); + } + + try { Slog.i(TAG, "Twilight Service"); twilight = new TwilightService(context); } catch (Throwable e) {
+package android.hardware.input; + + +/** @hide */ +interface IVirtualInputManager +{ + boolean SendIR(int keycode); +}
+package android.hardware.input; + +import android.app.PendingIntent; +import android.content.Context; +import android.os.Bundle; +import android.os.ParcelFileDescriptor; +import android.os.RemoteException; +import android.os.SystemProperties; +import android.util.Log; + +import java.io.IOException; +import java.util.HashMap; + +/** + * @hide + */ +public class VirtualInputManager { + private static final String TAG = "VirtualInputManager"; + + private final Context mContext; + private final IVirtualInputManager mService; + + /** + * {@hide} + */ + public VirtualInputManager(Context context, IVirtualInputManager service) { + mContext = context; + mService = service; + Log.d(TAG,"VirtualInputManager"); + } + + public boolean SendIR(int keycode) throws android.os.RemoteException{ + Log.d(TAG,"keycode:"+keycode); + return mService.SendIR(keycode); + } +}
core/java/android/hardware/input/IInputManager.aidl \ + core/java/android/hardware/input/IVirtualInputManager.aidl \ core/java/android/hardware/input/IInputDevicesChangedListener.aidl \
+ public static final String VIRTUALINPUT_SERVICE = "virtualinput";
+ registerService(VIRTUALINPUT_SERVICE, new ServiceFetcher() { + public Object createService(ContextImpl ctx) { + IBinder b = ServiceManager.getService(VIRTUALINPUT_SERVICE); + return new VirtualInputManager(ctx, IVirtualInputManager.Stub.asInterface(b)); + }}); +
效果圖: 在layout中這樣來聲明: activity這樣來調用: private void initStatus(){ ivState =
Tips:此源碼分析基於Android 4.2先來看看一個Activity上的UI控件結構: 圖1-1 Activity中的UI組件結構好了現在開
今天在慕課網看了一個視頻,介紹了幾種圖像處理的方法,其中有一種就是鏡面效果,但是他是通過自定義view的方式實現的,但是算法都大同小異。他的自定義view:package
因為在項目中需要用到繪制餅狀圖,所以對github下的android-charts庫進行了精簡和修改,貌似該庫本身有些bug,例如文字繪制有時候會錯位,我改