2012年11月1日 星期四

Java - Static Inner Classes


Static Inner Classes

Consider the following Java code fragment:
public class A
{
    int y;
    public static class B
    {
 int x;
 void f () {}
    }
}
This fragment defines the class A which contains an static inner class B.
A static inner class behaves like any ``outer'' class. It may contain methods and fields, and it may be instantiated like this:
A.B object = new A.B ();
This statement creates an new instance of the inner class B. Given such an instance, we can invoke the f method in the usual way:
object.f();
Note, it is not necessarily the case that an instance of the outer class A exists even when we have created an instance of the inner class. Similarly, instantiating the outer class A does not create any instances of the inner class B.
The methods of a static inner class may access all the members (fields or methods) of the inner class but they can access only static members (fields or methods) of the outer class. Thus, f can access the field x, but it cannot access the field y.
----------------------
The inner class and outer classes could be considered as two separated classes and the inner class could access the static members of the outer class.


2012年10月28日 星期日

typename in C++

typename as we know in C++ is used in template.
The difference between typename and class is in the nested type.
Take the class sp in RefBase.h of Android Framework as example:


template <typename T>
class sp
{
public:
    typedef typename RefBase::weakref_type weakref_type;
    .........
}



class RefBase
{
public:
           .........
         class weakref_type
         {
          .........
          }
}
--------------------------
Notice that " typedef typename RefBase::weakref_type weakref_type; "
Compiler will  not know that if weakref_type is a variable of RefBase.  Compiler will know that weakref_type is a type or class of RefBase by giving typename .





2012年10月16日 星期二

Android -Google Maps (Webview)

Use WebView to show the map:

1.webView.getSettings().setJavaScriptEnabled(true);
 Open the JavaScript of the web.

2.webView.getSettings().setGeolocationEnabled(true);
 Open the geolocation for the web to get location through Javascript

PS:Use LocationManager to get the location from network or GPS.


Ref:

More info about Webview

2012年10月14日 星期日

Android bindService() notice

There are roughly two ways of using the service in Android,Context.startService() and Context.bindService().

Context.startService(): can be used only by one application.
Context.bindService(): could be exposed to other applications.

Here we focuse on Context.bindService().

bindService() -> onCreate() -> onBind() ->onServiceConnected()-> running.

There is one thing we have to notice.

The onServiceConnected() may not be called immediately and this might cause some problem!


Ref:
http://stackoverflow.com/questions/2486692/onserviceconnected-never-called-after-bindservice-method



Android - Animation


(1) tweened animation
1.alpha
2.scale
(2)frame by frame
1.translate
2.rotate
----------------
Using by two ways:
1.XML

Animation myAnimation= AnimationUtils.loadAnimation(this,R.anim.myanimationxml);

2.Non-XML

Animation myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f);

Reference from:
http://jjnnykimo.pixnet.net/blog/post/30359165-android-amimation


2012年5月21日 星期一

Linux C Select() - multi input trace


fd_set set;
    FD_ZERO(&set);      /*clear set */
    FD_SET(fd, &set);   /*add fd into set */
    FD_CLR(fd, &set);   /*remove fd from set*/
    FD_ISSET(fd, &set); /*return true if fd is in set*/
------------------------------------------------------------------------
int maxfd = MAX (fd1, fd2)+1;

struct timeval tv;
tv.tv_usec = 0;
tv.tv_sec = 2;


while (1) {
     FD_SET(fd1, &readfs);  /* input 1*/
     FD_SET(fd2, &readfs);  /* input 2 */
     /* block until input becomes available */
     int rul = select(maxfd, &readfs, NULL, NULL,  &tv );


     if (FD_ISSET(fd1))         /* if input 1 has signal*/
       handle_input_from_source1();
     if (FD_ISSET(fd2))         /* if input 2 has signal */
       handle_input_from_source2();
/*
     if(rul == -1)
         return errorout;
     if(rul == 0)
        return timeout;
     
*/
   }

2012年5月20日 星期日

C address pointer scope notice

Define:
(A file) : char * tmp
(B  file): function(char *ptr)
             {
                  ptr = open("/tmpfile.txt","w");
             }
--------------------------------------------
(A file)  code:   call (B file)function( tmp )
                        fclose( tmp )            ==> address is null;
             
=============================
the pointer return from open("/tmpfile.txt","w") exist only in (B  file): function(char *address).