FileDocCategorySizeDatePackage
DemoDataSet.javaAPI DocAndroid 1.5 API4152Wed May 06 22:42:00 BST 2009com.android.server

DemoDataSet

public class DemoDataSet extends Object

Fields Summary
private static final String
LOG_TAG
private android.content.ContentResolver
mContentResolver
Constructors Summary
Methods Summary
public final voidadd(android.content.Context context)


        
    
        mContentResolver = context.getContentResolver();

        // Remove all the old data
        mContentResolver.delete(Contacts.People.CONTENT_URI, null, null);

        // Add the new data
        addDefaultData();
        
        // Add images from /android/images
        addDefaultImages();
    
private final voidaddDefaultData()

        Log.i(LOG_TAG, "Adding default data...");

//       addImage("Violet", "images/violet.png");
//       addImage("Corky", "images/corky.png");

        // PENDING: should this be done here?!?!
        Intent intent = new Intent(
                Intent.ACTION_CALL, Uri.fromParts("voicemail", "", null));
        addShortcut("1", intent);
    
private final voidaddDefaultImages()

        File rootDirectory = Environment.getRootDirectory();
        String [] files
            = new File(rootDirectory, "images").list();
        int count = files.length;

        if (count == 0) {
            Log.i(LOG_TAG, "addDefaultImages: no images found!");
            return;
        }

        for (int i = 0; i < count; i++)
        {
            String name = files[i];
            String path = rootDirectory + "/" + name;
            
            try {
                Images.Media.insertImage(mContentResolver, path, name, null);
            } catch (FileNotFoundException e) {
                Log.e(LOG_TAG, "Failed to import image " + path, e);
            }
        }
    
private final android.net.UriaddImage(java.lang.String name, android.net.Uri file)

        ContentValues imagev = new ContentValues();
        imagev.put("name", name);

        Uri url = null;

        AssetManager ass = AssetManager.getSystem();
        InputStream in = null;
        OutputStream out = null;
        
        try
        {
            in = ass.open(file.toString());

            url = mContentResolver.insert(Images.Media.INTERNAL_CONTENT_URI, imagev);
            out = mContentResolver.openOutputStream(url);

            final int size = 8 * 1024;
            byte[] buf = new byte[size];

            int count = 0;
            do
            {
                count = in.read(buf, 0, size);
                if (count > 0) {
                    out.write(buf, 0, count);
                }
            } while (count > 0);
        }
        catch (Exception e)
        {
            Log.e(LOG_TAG, "Failed to insert image '" + file + "'", e);
            url = null;
        }

        return url;
    
private final android.net.UriaddShortcut(java.lang.String shortcut, android.content.Intent intent)

        if (Config.LOGV) Log.v(LOG_TAG, "addShortcut: shortcut=" + shortcut + ", intent=" + intent);
        return Settings.Bookmarks.add(mContentResolver, intent, null, null,
                                      shortcut != null ? shortcut.charAt(0) : 0, 0);