How could I get the size of android.graphics.picture

by A.TNG » Mon, 07 Sep 2009 11:48:29 GMT


Sponsored Links
 


It seems the only way is to add your own getSize() member function.
Please refer to skia library, class SkPicture, macro SK_DEBUG_SIZE.
You could find more information.

Thanks
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Socket is leak when use server socket

Dear all,

I create a server to listen request from peer.
When client socket is connected, it will be leak after close socket.
The fd will increase and finally the process may be killed due to too
many fd.

Does anyone know how to safely close the socket?

The sample code is below.
=========================================================================
package com.android.test.serversocket;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;

public class Test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        ServerSocketChannel mainSocket = null;
        InetAddress serverAddress = null;
        try {
                mainSocket = ServerSocketChannel.open();
                mainSocket.configureBlocking(false);
                mainSocket.socket().setReuseAddress(true);
                mainSocket.socket().setSoTimeout(1000);
                String wifiIp = getWifiIpAsString();
                serverAddress = InetAddress.getByName(wifiIp);
                mainSocket.socket().bind(new InetSocketAddress
(serverAddress, 5002));
        } catch (IOException e) {
                e.printStackTrace();
        }

        while(mainSocket != null) {
            SocketChannel clientSocket;
            try {
                while((clientSocket = mainSocket.accept()) != null) {
                        clientSocket.close();
                        clientSocket = null;
                        System.gc();
                }
            } catch(IOException e) {
                e.printStackTrace();
            }
            try {
                System.gc();
                Thread.sleep(1000);
            } catch(InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public int getWifiIpAsInt() {
        Context myContext = getApplicationContext();
        if(myContext == null) {
            throw new NullPointerException("Global context is null");
        }
        WifiManager wifiMgr = (WifiManager)myContext
                                .getSystemService
(Context.WIFI_SERVICE);
        if(isWifiEnabled()) {
            return wifiMgr.getConnectionInfo().getIpAddress();
        } else {
            return 0;
        }
    }

    public boolean isWifiEnabled() {
        Context myContext = getApplicationContext();
        if(myContext == null) {
            throw new NullPointerException("Global context is null");
        }
        WifiManager wifiMgr = (WifiManager)myContext
                                .getSystemService
(Context.WIFI_SERVICE);
        if(wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
            return true;
        } else {
            return false;
        }
    }

    public String getWifiIpAsString() {
        int addr = getWifiIpAsInt();
        if(addr != 0) {
            StringBuffer buf = new StringBuffer();
            buf.append(addr & 0xff).append('.').
            append((addr >>>= 8) & 0xff).append('.').
            append((addr >>>= 8) & 0xff).append('.').
            append((addr >>>= 8) & 0xff);
            return buf.toString();
        } else {
            return null;
        }
    }
}

-- 

2. Avoiding String allocation in TextView.setText()



Answering to myself, for the records: the String allocation can be avoided by
using the setText(char[] text, int start, int len) variant.

--
  Olivier

-- 

3. Is there an app for this?

4. System wide properties

5. router yang cocok dan kompatibel untuk android

6. Disappointed by poor maps quality of Google Maps

7. sharing: between android & iPhone