心情不好

09Dec14

心情不好

在工作時我集中不了。
如何是好?

願主保守我的心。只有祢可以幫助我。


Quoted from somebody else… (http://www.amsn-project.net/forums/viewtopic.php?t=414&postdays=0&postorder=asc&start=45)

How to make SCIM to work within aMSN wrote:
1) Install tcl/tk >= 8.4.13, amsn >= 0.96, scim, and scim’s language-specific packages (for instance, scim-pinyin for Chinese, scim-anthy for Japanese or scim-hangul for Korean).

2) If you have only one user or you want to enable SCIM for a specific user, create or modify the ~/.xinitrc file and add these lines at the beginning :

Code:
# SCIM
export XMODIFIERS=’@im=SCIM’
export GTK_IM_MODULE=”scim”
export XIM_PROGRAM=”scim -d”
export QT_IM_MODULE=”scim”
scim -d

If you want SCIM to be enabled for all users, you can put these lines in /etc/profile or create an initialization script.

3) Be sure to have your current locale in the first line of /etc/scim/global. For instance, if you use fr_FR.UTF-8 (you can know it by typing locale in a terminal), this line should look like :

Code:
/SupportedUnicodeLocales = fr_FR.UTF-8,en_US.UTF-8

If this is not the case, edit it (as root).

4) Restart your X server or reboot.

5) Enjoy ! Very Happy


I’m not sure about the finding that I have but it seems to me it serves the same purpose: I found a method called

IntRect WebCore::Node::getRect();

which seems to return a rectangle object like getBoundingClientRect does.


I see that android’s webkit hasn’t been providing enough method for Adroid’s application programming purpose. Say, with the current API it seems impossible to me to read some properties from the DOM. (I might be wrong, of course🙂 ) I therefore decided to find some simplest way to add my own method so that my Android’s application in Java can get access to more.. The following jots down the steps that I performed for my (or your, if you find it useful) reference in some later days..

MY WISH is to get the number of DOM elements in a document being viewed by one of the tab.

MY STEPS are to:

  1. Add the following public method in class android.webkit.WebView (defined in WebView.java in  ${mydroid}/frameworks/base/core/java/android/webkit):
  2.     public int getNumberOfDomNodesOfDocument() {
        	BrowserFrame f = this.mWebViewCore.getBrowserFrame();
        	return f.getNumberOfDomNodes();
        }

    This exposes the getNumberOfDomNodesOfDocument() method for use by the developers of the application level.

  3. Then, add a native method declaration, getNumberOfDomNodes(), to the class android.webkit.BrowserFrame (so still in the same directory), like the following:
  4. public native int getNumberOfDomNodes();
  5. Next I’m going to implement that native method in C++. All other native method definitions of class BrowserFrame are in ${mydroid}/external/webkit/WebCore/platform/android/jni/WebCoreFrameBridge.cpp, so I’m adding my own implmentation there as well.Here’s what I added (NOTE: in the android namespace)
    static jint GetNumberOfDomNodes(JNIEnv *env, jobject obj)
    {
    #ifdef ANDROID_INSTRUMENT
        TimeCounterFB counter(true);
    #endif
        WebCore::FrameAndroid* pFrame = GET_NATIVE_FRAME(env, obj);
        LOG_ASSERT(pFrame, "DocumentHasImages must take a valid frame pointer!");
    
        int number = 0;
    
        WebCore::Document* doc = pFrame->document();
        WebCore::Element* documentElement = doc->documentElement();
        int exception = 0;
    
        RefPtr<TreeWalker> walker = doc->createTreeWalker
                           (documentElement,
                           WebCore::NodeFilter::SHOW_ELEMENT,
                           NULL,
                           false,
                           exception);
        WebCore::Node *node;
        while ( (node = walker->nextNode()) != NULL ) {
            number++;
        }
    
        return number;
    
    }

    Of course I also included the following 2 lines of header file references:

    #include "TreeWalker.h"
    #include "NodeFilter.h"
  6. Before the native method can really be used in Java, I need to register it. I find the JNI registration part at the bottom of the whole WebCoreFrameBridge.cpp file:
    /*
     * JNI registration.
     */
    static JNINativeMethod gBrowserFrameNativeMethods[] = {
        /* name, signature, funcPtr */
        { "nativeCallPolicyFunction", "(II)V",
            (void*) CallPolicyFunction },
    
        // .... (and many other registration entries here)
    
        { "setUsernamePassword", "(Ljava/lang/String;Ljava/lang/String;)V",
            (void*) SetUsernamePassword },
        { "getFormTextData", "()Ljava/util/HashMap;",
            (void*) GetFormTextData }
    };

    I added my own registration entry like this:

     { "getNumberOfDomNodes", "()I",
            (void*) GetNumberOfDomNodes }

    “()I” denotes the signature of a function picking no arguments but returning an integer. There is an exhaustive list of how this kind of descriptors are used in sections 12.3.2-4 in the JNI Specification.

  7. Finally, run ‘make’ once again.

And That’s it!


kennyyu@kennyyu-laptop:~/mydroid$ make
build/core/product_config.mk:229: WARNING: adding test OTA key
build/core/main.mk:177: implicitly installing apns-conf_sdk.xml
make: *** No rule to make target `/usr/lib/tools.jar', needed by `out/target/common/docs/framework-timestamp'. Stop.
[1]+ Done out/host/linux-x86/bin/emulator
kennyyu@kennyyu-laptop:~/mydroid$

The solution is to
export ANDROID_JAVA_HOME=$JAVA_HOME


Just a quick sticky note about what i’ve tried on my Ubuntu PC:…

1. I wrote the following code in JAVA:

class JniTest {
   static {
      System.loadLibrary("nativelib");
   }

   static public native String getName();

   public static void main(String args[]) {
      System.out.println(getName());
   }

}

and compiled it by, obviously :

javac JniTest.java

2. then I used ‘javah’ to generate a header file for C/C++-side to include it..:
javah -jni JniTest
This generates JniTest.h.

3. then I wrote the following code, in C++, to implement the method that i didn’t supply:

#include
#include "JniTest.h"

JNIEXPORT jstring JNICALL Java_JniTest_getName
(JNIEnv * env, jclass c) {

   char * nameStr = "Kenny Yu";
   return(env->NewStringUTF(nameStr));

}

and saved it as JniTest.cpp

4. here comes the trickiest part (that i still haven’t yet have time to figure out why this happened so): i used the following command to have it finally successfully compiled :

 g++ -o libnativelib.so \
-shared  \
-I$JAVA_HOME//include \
-I$JAVA_HOME//include/linux \
./JniTest.cpp

(note: for ubuntu 8.10, JAVA_HOME should be set something like /usr/lib/jvm/java-6-sun)

This is all! I believe you know how to run the program. Just execute:

export LD_LIBRARY_PATH=.; java JniTest



Follow

Get every new post delivered to your Inbox.