|
Android example source code file (WebStorage.java)
This example Android source code file (WebStorage.java) is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Android by Example" TM.
The WebStorage.java Android example source code
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.webkit;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import java.util.Collection;
import java.util.Map;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* Functionality for manipulating the webstorage databases.
*/
public final class WebStorage {
/**
* Encapsulates a callback function to be executed when a new quota is made
* available. We primarily want this to allow us to call back the sleeping
* WebCore thread from outside the WebViewCore class (as the native call
* is private). It is imperative that this the setDatabaseQuota method is
* executed once a decision to either allow or deny new quota is made,
* otherwise the WebCore thread will remain asleep.
*/
public interface QuotaUpdater {
public void updateQuota(long newQuota);
};
// Log tag
private static final String TAG = "webstorage";
// Global instance of a WebStorage
private static WebStorage sWebStorage;
// Message ids
static final int UPDATE = 0;
static final int SET_QUOTA_ORIGIN = 1;
static final int DELETE_ORIGIN = 2;
static final int DELETE_ALL = 3;
static final int GET_ORIGINS = 4;
static final int GET_USAGE_ORIGIN = 5;
static final int GET_QUOTA_ORIGIN = 6;
// Message ids on the UI thread
static final int RETURN_ORIGINS = 0;
static final int RETURN_USAGE_ORIGIN = 1;
static final int RETURN_QUOTA_ORIGIN = 2;
private static final String ORIGINS = "origins";
private static final String ORIGIN = "origin";
private static final String CALLBACK = "callback";
private static final String USAGE = "usage";
private static final String QUOTA = "quota";
private Map <String, Origin> mOrigins;
private Handler mHandler = null;
private Handler mUIHandler = null;
static class Origin {
String mOrigin = null;
long mQuota = 0;
long mUsage = 0;
public Origin(String origin, long quota, long usage) {
mOrigin = origin;
mQuota = quota;
mUsage = usage;
}
public Origin(String origin, long quota) {
mOrigin = origin;
mQuota = quota;
}
public Origin(String origin) {
mOrigin = origin;
}
public String getOrigin() {
return mOrigin;
}
public long getQuota() {
return mQuota;
}
public long getUsage() {
return mUsage;
}
}
/**
* @hide
* Message handler, UI side
*/
public void createUIHandler() {
if (mUIHandler == null) {
mUIHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case RETURN_ORIGINS: {
Map values = (Map) msg.obj;
Map origins = (Map) values.get(ORIGINS);
ValueCallback<Map> callback = (ValueCallback
Other Android examples (source code examples)
Here is a short list of links related to this Android WebStorage.java source code file:
|