public abstract class SonicRuntime
extends java.lang.Object
SonicRuntime
is a class which interacts with the overall running information in the system,
including Context, UA, ID (which is the unique identification for the saved data) and other information.限定符和类型 | 字段和说明 |
---|---|
protected android.content.Context |
context
A context for this runtime, it's expected to be ApplicationContext
|
构造器和说明 |
---|
SonicRuntime(android.content.Context context) |
限定符和类型 | 方法和说明 |
---|---|
abstract java.lang.Object |
createWebResourceResponse(java.lang.String mimeType,
java.lang.String encoding,
java.io.InputStream data,
java.util.Map<java.lang.String,java.lang.String> headers)
We add this method to decoupling webview since some application may use x5 webview or others.
|
android.content.Context |
getContext() |
abstract java.lang.String |
getCookie(java.lang.String url)
Get cookies of the input url, this method will be called before sonic session make a
session connection to request data.
|
abstract java.lang.String |
getCurrentUserAccount()
Get the current user account, this method will be called when makeSessionId's params is
account related.
|
java.lang.String |
getHostDirectAddress(java.lang.String url)
Get the direct address of a url(host),format as[ip:port],the default http port is 80 and
443 for https.
|
java.util.Set<java.lang.String> |
getQueryParameterNames(android.net.Uri uri)
Returns a set of the unique names of all query parameters.
|
java.io.File |
getSonicCacheDir()
The sonic cache root dir which sonic cache such like .html/.template/.data will be storage.
|
SonicHeadersProvider |
getSonicHeadersProvider()
Get headers provider to get headers for sonic session to do something.
|
abstract java.lang.String |
getUserAgent()
Get user agent of current runtime, this method will be called before sonic session make a
session connection to request data.
|
abstract boolean |
isNetworkValid()
This method is used to judge is network valid or not
|
abstract boolean |
isSonicUrl(java.lang.String url)
This method is used to judge the input url is support sonic or not, when this method return
true, it means it's allow to create a sonic session for this url.
|
abstract void |
log(java.lang.String tag,
int level,
java.lang.String message) |
java.lang.String |
makeSessionId(java.lang.String url,
boolean isAccountRelated)
Make a unique session id for the url, it can be account related.
|
abstract void |
notifyError(SonicSessionClient client,
java.lang.String url,
int errorCode)
Notify error for host application to do report or statics
|
void |
postTaskToMainThread(java.lang.Runnable task,
long delayMillis)
Post a task in main thread
|
void |
postTaskToSessionThread(java.lang.Runnable task)
Post a task to session thread(a high priority thread is better)
|
abstract void |
postTaskToThread(java.lang.Runnable task,
long delayMillis)
Post a task to the thread(a io thread is better) which used to separate template and data.
|
abstract boolean |
setCookie(java.lang.String url,
java.util.List<java.lang.String> cookies)
Det cookies to webview after session connection response with cookies in it's headers.
|
boolean |
shouldLog(int level)
Logger function
|
abstract void |
showToast(java.lang.CharSequence text,
int duration)
Show toast
|
protected final android.content.Context context
public android.content.Context getContext()
public java.lang.String makeSessionId(java.lang.String url, boolean isAccountRelated)
url
- Url which need to make session idisAccountRelated
- Is account related or notpublic java.util.Set<java.lang.String> getQueryParameterNames(android.net.Uri uri)
uri
- The urijava.lang.UnsupportedOperationException
- if this isn't a hierarchical URIpublic boolean shouldLog(int level)
level
- Level of this log,such like Log.DEBUG.public abstract void log(java.lang.String tag, int level, java.lang.String message)
public abstract java.lang.String getCookie(java.lang.String url)
url
- The url which need to get cookiespublic abstract boolean setCookie(java.lang.String url, java.util.List<java.lang.String> cookies)
url
- The url which need to set cookiescookies
- The cookies for current input urlpublic abstract java.lang.String getUserAgent()
public java.io.File getSonicCacheDir()
public abstract java.lang.String getCurrentUserAccount()
public abstract boolean isSonicUrl(java.lang.String url)
url
- The url which need to judgepublic abstract java.lang.Object createWebResourceResponse(java.lang.String mimeType, java.lang.String encoding, java.io.InputStream data, java.util.Map<java.lang.String,java.lang.String> headers)
InputStream.read(byte[])
for the input
stream.mimeType
- The resource response's MIME type, for example text/htmlencoding
- The resource response's encodingdata
- The input stream that provides the resource response's data. Must not be a
StringBufferInputStream.headers
- The headerspublic abstract boolean isNetworkValid()
public java.lang.String getHostDirectAddress(java.lang.String url)
url
- The input url which need to get direct addresspublic abstract void showToast(java.lang.CharSequence text, int duration)
text
- Contentduration
- See Toast.LENGTH_SHORT/Toast.LENGTH_LONGpublic abstract void postTaskToThread(java.lang.Runnable task, long delayMillis)
task
- A runnable taskdelayMillis
- The delay (in milliseconds) until the Runnable
will be executed.public void postTaskToSessionThread(java.lang.Runnable task)
task
- A runnable taskpublic void postTaskToMainThread(java.lang.Runnable task, long delayMillis)
task
- A runnable taskdelayMillis
- Delay millispublic abstract void notifyError(SonicSessionClient client, java.lang.String url, int errorCode)
client
- The error clienturl
- The error urlerrorCode
- Error codepublic SonicHeadersProvider getSonicHeadersProvider()