Skip to content

Commit 9e53041

Browse files
committed
init commit
including host, tools, and helloworld sample
1 parent 751afca commit 9e53041

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+9003
-0
lines changed

Host/.classpath

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
8+
<classpathentry kind="output" path="bin/classes"/>
9+
</classpath>

Host/.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Host</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

Host/AndroidManifest.xml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.dianping.loader"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="14"
9+
android:targetSdkVersion="16" />
10+
11+
<uses-permission android:name="android.permission.INTERNET" />
12+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
13+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
14+
15+
<application
16+
android:label="@string/app_name"
17+
android:name="com.dianping.app.MyApplication"
18+
android:theme="@android:style/Theme.Holo.Light" >
19+
<activity
20+
android:name="com.dianping.loader.HomeActivity"
21+
android:label="@string/app_name" >
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
26+
</intent-filter>
27+
</activity>
28+
<activity
29+
android:name="com.dianping.loader.LoaderActivity"
30+
android:configChanges="orientation|keyboardHidden"
31+
android:label="@string/app_name"
32+
android:screenOrientation="nosensor" >
33+
</activity>
34+
<activity
35+
android:name="com.dianping.loader.MainActivity"
36+
android:configChanges="orientation|keyboardHidden"
37+
android:label="@string/app_name"
38+
android:screenOrientation="nosensor" >
39+
</activity>
40+
<activity
41+
android:name="com.dianping.loader.ForwardActivity"
42+
android:label="@string/app_name"
43+
android:screenOrientation="nosensor"
44+
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
45+
<intent-filter>
46+
<action android:name="android.intent.action.VIEW" />
47+
48+
<category android:name="android.intent.category.DEFAULT" />
49+
<category android:name="android.intent.category.BROWSABLE" />
50+
51+
<data android:scheme="app" />
52+
</intent-filter>
53+
</activity>
54+
<activity
55+
android:name="com.dianping.loader.DevLoaderActivity"
56+
android:label="@string/app_name"
57+
android:screenOrientation="nosensor"
58+
android:theme="@android:style/Theme.Holo.NoActionBar" >
59+
<intent-filter>
60+
<action android:name="android.intent.action.VIEW" />
61+
</intent-filter>
62+
</activity>
63+
</application>
64+
65+
</manifest>

Host/proguard-project.txt

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# To enable ProGuard in your project, edit project.properties
2+
# to define the proguard.config property as described in that file.
3+
#
4+
# Add project specific ProGuard rules here.
5+
# By default, the flags in this file are appended to flags specified
6+
# in ${sdk.dir}/tools/proguard/proguard-android.txt
7+
# You can edit the include path and order by changing the ProGuard
8+
# include property in project.properties.
9+
#
10+
# For more details, see
11+
# http://developer.android.com/guide/developing/tools/proguard.html
12+
13+
# Add any project specific keep options here:
14+
15+
# If your project uses WebView with JS, uncomment the following
16+
# and specify the fully qualified class name to the JavaScript interface
17+
# class:
18+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19+
# public *;
20+
#}

Host/project.properties

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=android-16

Host/res/layout/activity_home.xml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".HomeActivity" >
6+
7+
<TextView
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:text="@string/hello_world" />
11+
12+
</RelativeLayout>

Host/res/values/strings.xml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="app_name">Host</string>
5+
<string name="action_settings">Settings</string>
6+
<string name="hello_world">Hello world!</string>
7+
8+
</resources>
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.dianping.app;
2+
3+
import android.app.Activity;
4+
import android.app.Application;
5+
import android.app.Fragment;
6+
import android.content.Intent;
7+
import android.net.Uri;
8+
9+
public class MyActivity extends Activity {
10+
11+
public Intent urlMap(Intent intent) {
12+
Application app = getApplication();
13+
if (app instanceof MyApplication) {
14+
return ((MyApplication) app).urlMap(intent);
15+
} else {
16+
return intent;
17+
}
18+
}
19+
20+
@Override
21+
public void startActivityForResult(Intent intent, int requestCode) {
22+
intent = urlMap(intent);
23+
super.startActivityForResult(intent, requestCode);
24+
}
25+
26+
@Override
27+
public void startActivityFromFragment(Fragment fragment, Intent intent,
28+
int requestCode) {
29+
intent = urlMap(intent);
30+
super.startActivityFromFragment(fragment, intent, requestCode);
31+
}
32+
33+
public void startActivity(String urlSchema) {
34+
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlSchema)));
35+
}
36+
37+
public void startActivityForResult(String urlSchema, int requestCode) {
38+
startActivityForResult(
39+
new Intent(Intent.ACTION_VIEW, Uri.parse(urlSchema)),
40+
requestCode);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package com.dianping.app;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.util.Locale;
6+
7+
import org.json.JSONObject;
8+
9+
import android.app.Application;
10+
import android.content.Intent;
11+
import android.net.Uri;
12+
import android.text.TextUtils;
13+
import android.util.Log;
14+
15+
import com.dianping.loader.LoaderActivity;
16+
import com.dianping.loader.MainActivity;
17+
import com.dianping.loader.MyClassLoader;
18+
import com.dianping.loader.RepositoryManager;
19+
import com.dianping.loader.model.FileSpec;
20+
import com.dianping.loader.model.FragmentSpec;
21+
import com.dianping.loader.model.SiteSpec;
22+
23+
public class MyApplication extends Application {
24+
public static final String PRIMARY_SCHEME = "app";
25+
26+
private static MyApplication instance;
27+
private RepositoryManager repoManager;
28+
29+
public static MyApplication instance() {
30+
if (instance == null) {
31+
throw new IllegalStateException("Application has not been created");
32+
}
33+
34+
return instance;
35+
}
36+
37+
public MyApplication() {
38+
instance = this;
39+
}
40+
41+
public RepositoryManager repositoryManager() {
42+
if (repoManager == null) {
43+
repoManager = new RepositoryManager(this);
44+
}
45+
return repoManager;
46+
}
47+
48+
public SiteSpec readSite() {
49+
File dir = new File(getFilesDir(), "repo");
50+
File local = new File(dir, "site.txt");
51+
if (local.length() > 0) {
52+
try {
53+
FileInputStream fis = new FileInputStream(local);
54+
byte[] bytes = new byte[fis.available()];
55+
int l = fis.read(bytes);
56+
fis.close();
57+
String str = new String(bytes, 0, l, "UTF-8");
58+
JSONObject json = new JSONObject(str);
59+
return new SiteSpec(json);
60+
} catch (Exception e) {
61+
Log.w("loader", "fail to load site.txt from " + local, e);
62+
}
63+
}
64+
return new SiteSpec("empty.0", "0", new FileSpec[0],
65+
new FragmentSpec[0]);
66+
}
67+
68+
public Intent urlMap(Intent intent) {
69+
do {
70+
// already specify a class, no need to map url
71+
if (intent.getComponent() != null)
72+
break;
73+
74+
// only process my scheme uri
75+
Uri uri = intent.getData();
76+
if (uri == null)
77+
break;
78+
if (uri.getScheme() == null)
79+
break;
80+
if (!(PRIMARY_SCHEME.equalsIgnoreCase(uri.getScheme())))
81+
break;
82+
83+
SiteSpec site = null;
84+
if (intent.hasExtra("_site")) {
85+
site = intent.getParcelableExtra("_site");
86+
}
87+
if (site == null) {
88+
site = readSite();
89+
intent.putExtra("_site", site);
90+
}
91+
92+
// i'm responsible
93+
intent.setClass(this, LoaderActivity.class);
94+
95+
String host = uri.getHost();
96+
if (TextUtils.isEmpty(host))
97+
break;
98+
host = host.toLowerCase(Locale.US);
99+
FragmentSpec fragment = site.getFragment(host);
100+
if (fragment == null)
101+
break;
102+
intent.putExtra("_fragment", fragment.name());
103+
104+
// class loader
105+
ClassLoader classLoader;
106+
if (TextUtils.isEmpty(fragment.code())) {
107+
classLoader = getClassLoader();
108+
} else {
109+
intent.putExtra("_code", fragment.code());
110+
FileSpec fs = site.getFile(fragment.code());
111+
if (fs == null)
112+
break;
113+
classLoader = MyClassLoader.getClassLoader(site, fs);
114+
if (classLoader == null)
115+
break;
116+
}
117+
118+
intent.setClass(this, MainActivity.class);
119+
} while (false);
120+
121+
return intent;
122+
}
123+
124+
@Override
125+
public void startActivity(Intent intent) {
126+
intent = urlMap(intent);
127+
super.startActivity(intent);
128+
}
129+
130+
}

0 commit comments

Comments
 (0)