BVNC client source code analysis (android)
- 1) logon Interface
- 2) Desktop Activity
3) Start vnc
4) display Desktop
- 1) logon Interface
- Com. iiordanov. bVNC. bVNC. java
- Create logon interface (fill in IP address, PORT, and so on)
- @ Override
- Public void onCreate (Bundle icicle ){
- GoButton = (Button) findViewById (R. id. buttonGO );
- GoButton. setOnClickListener (new View. OnClickListener (){
- @ Override
- Public void onClick (View view ){
- If (ipText. getText (). length ()! = 0 & portText. getText (). length ()! = 0)
- CanvasStart ();
- Else
- Toast. makeText (view. getContext (), R. string. vnc_server_empty, Toast. LENGTH_LONG). show ();
- }
- });
- }
- Private void canvasStart (){
- If (selected = null) return;
- MemoryInfo info = Utils. getMemoryInfo (this );
- If (info. lowMemory)
- System. gc ();
- Start ();
- }
- /**
- * Starts the activity which makes a VNC connection and displays the remote desktop.
- */
- Private void start (){
- IsConnecting = true;
- // Read data from the login interface and write data to the bean
- UpdateSelectedFromView ();
- SaveAndWriteRecent ();
- // Start RemoteCanvasActivity. The parameter is selected. Gen_getValues ()
- Intent intent = new Intent (this, RemoteCanvasActivity. class );
- Intent. putExtra (Constants. CONNECTION, selected. Gen_getValues ());
- StartActivity (intent );
- }
2) Desktop Activity
- Com. iiordanov. bVNC. RemoteCanvasActivity. java
- @ Override
- Public void onCreate (Bundle icicle ){
- Super. onCreate (icicle );
- // Read the bean Parameters
- Initialize ();
- // Continue the connection, that is, initiate a connection to the VNC Server
- ContinueConnecting ();
- }
- Void continueConnecting (){
- // Initialize and define actions for on-screen keys.
- InitializeOnScreenKeys ();
- // Actually initiate a connection
- Canvas. initializeCanvas (connection, database, new Runnable (){
- Public void run (){
- Try {setModes ();} catch (NullPointerException e ){}
- }
- });
- }
- 3) Start vnc
- Com. iiordanov. bVNC. RemoteCanvas. java
- /**
- * Create a view showing a remote desktop connection
- * @ Param context Containing context (activity)
- * @ Param bean Connection settings
- * @ Param setModes Callback to run on UI thread after connection is set up
- */
- Void initializeCanvas (ConnectionBean bean, Database db, final Runnable setModes ){
- Thread t = new Thread (){
- Public void run (){
- Try {
- If (isSpice ){
- StartSpiceConnection ();
- } Else if (isRdp ){
- StartRdpConnection ();
- } Else if (connection. getConnectionType () <4 ){
- // Start the connection
- StartVncConnection ();
- }
- }
- }
- }
- }
- /**
- * Starts a VNC connection using the TightVNC backend.
- * @ Throws Exception
- */
- Private void startVncConnection () throws Exception {
- Log. I (TAG, "Connecting to:" + connection. getAddress () + ", port:" + connection. getPort ());
- String address = getAddress ();
- Int vncPort = getPort (connection. getPort ());
- Boolean anonTLS = (connection. getConnectionType () = Constants. CONN_TYPE_ANONTLS );
- Try {
- Rfb = new RfbProto (decoder, address, vncPort,
- Connection. getPrefEncoding (), connection. getViewOnly ());
- Log. v (TAG, "Connected to server:" + address + "at port:" + vncPort );
- Rfb. initializeAndAuthenticate (connection. getUserName (), connection. getPassword (),
- Connection. getUseRepeater (), connection. getRepeaterId (), anonTLS );
- } Catch (Exception e ){
- Throw new Exception (getContext (). getString (R. string. error_vnc_unable_to_connect) + e. getLocalizedMessage ());
- }
- Rfbconn = rfb;
- Pointer = new RemoteVncPointer (rfbconn, RemoteCanvas. this, handler );
- Keyboard = new RemoteVncKeyboard (rfbconn, RemoteCanvas. this, handler );
- Rfb. writeClientInit ();
- Rfb. readServerInit ();
- InitializeBitmap (displayWidth, displayHeight );
- Decoder. setPixelFormat (rfb );
- Handler. post (new Runnable (){
- Public void run (){
- Pd. setMessage (getContext (). getString (R.string.info _ progress_dialog_downloading ));
- }
- });
- SendUnixAuth ();
- If (connection. getUseLocalCursor ())
- InitializeSoftCursor ();
- Handler. post (drawableSetter );
- Handler. post (setModes );
- Handler. post (handle topinfo );
- // Hide progress dialog
- If (pd. isShowing ())
- Pd. dismiss ();
- Rfb. processProtocol (this, connection. getUseLocalCursor ());
- }
- 4) display Desktop
- Com. iiordanov. bVNC. RfbProto. java
- RFB Image Display implemented by java
- Public void processProtocol () throws Exception {
- }