Skip to content

Commit eddd5ff

Browse files
committed
improve host
1 parent ad5be54 commit eddd5ff

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

Host/res/layout/activity_home.xml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,31 @@
2424
android:inputType="textUri" />
2525

2626
<Button
27-
android:id="@+id/go_helloworld"
27+
android:id="@+id/go_last"
2828
style="?android:attr/buttonStyleSmall"
2929
android:layout_width="wrap_content"
3030
android:layout_height="wrap_content"
3131
android:layout_below="@+id/siteurl"
3232
android:layout_centerHorizontal="true"
33-
android:layout_marginTop="56dip"
33+
android:layout_marginTop="60dip"
34+
android:text="Launch last plugin" />
35+
36+
<TextView
37+
android:id="@+id/last_url"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_below="@+id/go_last"
41+
android:layout_centerHorizontal="true"
42+
android:textAppearance="?android:attr/textAppearanceSmall" />
43+
44+
<Button
45+
android:id="@+id/go_helloworld"
46+
style="?android:attr/buttonStyleSmall"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:layout_below="@+id/go_last"
50+
android:layout_marginTop="60dip"
51+
android:layout_centerHorizontal="true"
3452
android:text="HelloWorld demo" />
3553

3654
</RelativeLayout>

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ protected void handle(String method, String path,
226226
JSONObject json = new JSONObject(str);
227227
site = new SiteSpec(json);
228228
File file = new File(getFilesDir(), "repo");
229+
new File(file, "lastUrl.txt").delete();
229230
file = new File(file, "site.txt");
230231
FileOutputStream fos = new FileOutputStream(file);
231232
fos.write(buf, 0, n);
@@ -257,6 +258,15 @@ protected void handle(String method, String path,
257258
} else {
258259
startActivity(i);
259260
}
261+
262+
try {
263+
File file = new File(getFilesDir(), "repo");
264+
file = new File(file, "lastUrl.txt");
265+
FileOutputStream fos = new FileOutputStream(file);
266+
fos.write(sb.toString().getBytes("UTF-8"));
267+
fos.close();
268+
} catch (Exception e) {
269+
}
260270
}
261271
}
262272

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.ByteArrayOutputStream;
44
import java.io.File;
5+
import java.io.FileInputStream;
56
import java.io.FileOutputStream;
67
import java.io.InputStream;
78
import java.net.HttpURLConnection;
@@ -31,16 +32,48 @@ protected void onCreate(Bundle savedInstanceState) {
3132

3233
siteUrl = (TextView) findViewById(R.id.siteurl);
3334
findViewById(R.id.go).setOnClickListener(clickListener);
35+
findViewById(R.id.go_last).setOnClickListener(clickListener);
3436
findViewById(R.id.go_helloworld).setOnClickListener(clickListener);
3537
}
3638

39+
@Override
40+
protected void onResume() {
41+
super.onResume();
42+
43+
File dir = new File(getFilesDir(), "repo");
44+
File site = new File(dir, "site.txt");
45+
findViewById(R.id.go_last).setEnabled(site.length() > 0);
46+
TextView lastUrl = (TextView) findViewById(R.id.last_url);
47+
lastUrl.setText(null);
48+
if (site.length() > 0) {
49+
File file = new File(dir, "lastUrl.txt");
50+
try {
51+
FileInputStream fis = new FileInputStream(file);
52+
byte[] bytes = new byte[fis.available()];
53+
fis.read(bytes);
54+
fis.close();
55+
String url = new String(bytes, "UTF-8");
56+
lastUrl.setText(url);
57+
} catch (Exception e) {
58+
SiteSpec lastSite = MyApplication.instance().readSite();
59+
String url = MyApplication.PRIMARY_SCHEME + "://"
60+
+ lastSite.fragments()[0].host();
61+
lastUrl.setText(url);
62+
}
63+
}
64+
}
65+
3766
private final View.OnClickListener clickListener = new View.OnClickListener() {
3867
@Override
3968
public void onClick(View v) {
4069
if (v.getId() == R.id.go) {
4170
Worker worker = new Worker(siteUrl.getText().toString());
4271
worker.start();
4372
v.setEnabled(false);
73+
} else if (v.getId() == R.id.go_last) {
74+
String url = ((TextView) findViewById(R.id.last_url)).getText()
75+
.toString();
76+
startActivity(url);
4477
} else if (v.getId() == R.id.go_helloworld) {
4578
siteUrl.setText("https://raw.github.com/mmin18/AndroidDynamicLoader/master/site/helloworld/site.txt");
4679
findViewById(R.id.go).performClick();
@@ -84,6 +117,7 @@ public void run() {
84117
final SiteSpec fSite = new SiteSpec(json);
85118

86119
File dir = new File(getFilesDir(), "repo");
120+
new File(dir, "lastUrl.txt").delete();
87121
dir.mkdir();
88122
File local = new File(dir, "site.txt");
89123
File tmp = new File(dir, "site_tmp");

tools/lib/anttasks.jar

-17.9 KB
Binary file not shown.

tools/lib/host.jar

4.49 KB
Binary file not shown.

0 commit comments

Comments
 (0)