Skip to content

Commit 88156f9

Browse files
committed
helloworld site test
1 parent 9e53041 commit 88156f9

File tree

5 files changed

+78
-11
lines changed

5 files changed

+78
-11
lines changed

Host/res/layout/activity_home.xml

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,33 @@
44
android:layout_height="match_parent"
55
tools:context=".HomeActivity" >
66

7-
<TextView
7+
<Button
8+
android:id="@+id/go"
9+
style="?android:attr/buttonStyleSmall"
810
android:layout_width="wrap_content"
911
android:layout_height="wrap_content"
10-
android:text="@string/hello_world" />
12+
android:layout_alignParentRight="true"
13+
android:layout_alignParentTop="true"
14+
android:text="Go" />
15+
16+
<EditText
17+
android:id="@+id/siteurl"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_alignBottom="@+id/go"
21+
android:layout_toLeftOf="@+id/go"
22+
android:layout_alignParentLeft="true"
23+
android:hint="http://domain/site.txt"
24+
android:inputType="textUri" />
25+
26+
<Button
27+
android:id="@+id/go_helloworld"
28+
style="?android:attr/buttonStyleSmall"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:layout_below="@+id/siteurl"
32+
android:layout_centerHorizontal="true"
33+
android:layout_marginTop="56dip"
34+
android:text="HelloWorld demo" />
1135

1236
</RelativeLayout>

Host/res/values/strings.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
<resources>
33

44
<string name="app_name">Host</string>
5-
<string name="action_settings">Settings</string>
6-
<string name="hello_world">Hello world!</string>
75

86
</resources>

Host/src/com/dianping/loader/HomeActivity.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,45 @@
99

1010
import org.json.JSONObject;
1111

12-
import android.app.Activity;
12+
import android.content.Intent;
13+
import android.net.Uri;
1314
import android.os.Bundle;
1415
import android.util.Log;
16+
import android.view.View;
17+
import android.widget.TextView;
18+
import android.widget.Toast;
1519

20+
import com.dianping.app.MyActivity;
21+
import com.dianping.app.MyApplication;
1622
import com.dianping.loader.model.SiteSpec;
1723

18-
public class HomeActivity extends Activity {
24+
public class HomeActivity extends MyActivity {
25+
TextView siteUrl;
1926

2027
@Override
2128
protected void onCreate(Bundle savedInstanceState) {
2229
super.onCreate(savedInstanceState);
2330
setContentView(R.layout.activity_home);
31+
32+
siteUrl = (TextView) findViewById(R.id.siteurl);
33+
findViewById(R.id.go).setOnClickListener(clickListener);
34+
findViewById(R.id.go_helloworld).setOnClickListener(clickListener);
2435
}
2536

37+
private final View.OnClickListener clickListener = new View.OnClickListener() {
38+
@Override
39+
public void onClick(View v) {
40+
if (v.getId() == R.id.go) {
41+
Worker worker = new Worker(siteUrl.getText().toString());
42+
worker.start();
43+
v.setEnabled(false);
44+
} else if (v.getId() == R.id.go_helloworld) {
45+
siteUrl.setText("https://raw.github.com/mmin18/AndroidDynamicLoader/master/site/helloworld/site.txt");
46+
findViewById(R.id.go).performClick();
47+
}
48+
}
49+
};
50+
2651
private class Worker extends Thread {
2752
private String url;
2853

@@ -38,8 +63,6 @@ public void run() {
3863
HttpURLConnection conn = (HttpURLConnection) url
3964
.openConnection();
4065
conn.setConnectTimeout(15000);
41-
// conn.setRequestProperty("User-Agent",
42-
// Environment.mapiUserAgent());
4366
InputStream ins = conn.getInputStream();
4467
ByteArrayOutputStream bos = new ByteArrayOutputStream(16 * 1024);
4568
byte[] buf = new byte[1024 * 4]; // 4k buffer
@@ -77,15 +100,23 @@ public void run() {
77100
runOnUiThread(new Runnable() {
78101
@Override
79102
public void run() {
80-
// TODO: succeed
103+
findViewById(R.id.go).setEnabled(true);
104+
String url = MyApplication.PRIMARY_SCHEME + "://"
105+
+ fSite.fragments()[0].host();
106+
Intent i = new Intent(Intent.ACTION_VIEW,
107+
Uri.parse(url));
108+
i.putExtra("_site", fSite);
109+
startActivity(i);
81110
}
82111
});
83-
} catch (Exception e) {
112+
} catch (final Exception e) {
84113
Log.w("loader", "fail to download site from " + siteUrl, e);
85114
runOnUiThread(new Runnable() {
86115
@Override
87116
public void run() {
88-
// TODO: failed
117+
findViewById(R.id.go).setEnabled(true);
118+
Toast.makeText(HomeActivity.this, e.toString(),
119+
Toast.LENGTH_LONG).show();
89120
}
90121
});
91122
}
2.75 KB
Binary file not shown.

site/helloworld/site.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"id": "sample.helloworld.20130629.1",
3+
"files": [{
4+
"id": "sample.helloworld.20130629.1",
5+
"md5": "dd63f35c4fdd323db5acaa2704819edb",
6+
"url": "https://raw.github.com/mmin18/AndroidDynamicLoader/master/site/helloworld/sample.helloworld.20130629.1.apk"
7+
}],
8+
"fragments": [{
9+
"host": "helloworld",
10+
"name": "sample.helloworld.HelloFragment",
11+
"code": "sample.helloworld.20130629.1"
12+
}],
13+
"version": "20130629.1"
14+
}

0 commit comments

Comments
 (0)