Skip to content

Commit b9aa334

Browse files
committed
Sample Code
0 parents  commit b9aa334

File tree

17 files changed

+193
-0
lines changed

17 files changed

+193
-0
lines changed

.classpath

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry kind="output" path="bin/classes"/>
8+
</classpath>

.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>AndroidHttpClientSample</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>

AndroidManifest.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="jp.sharakova.android.httpclient"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk android:minSdkVersion="8" />
8+
<uses-permission android:name="android.permission.INTERNET"/>
9+
10+
<application
11+
android:icon="@drawable/ic_launcher"
12+
android:label="@string/app_name" >
13+
<activity
14+
android:name=".TestActivity"
15+
android:label="@string/app_name" >
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>

bin/AndroidHttpClientTest.apk

14.6 KB
Binary file not shown.

bin/classes.dex

4.57 KB
Binary file not shown.

bin/res/drawable-hdpi/ic_launcher.png

3.87 KB
Loading

bin/res/drawable-ldpi/ic_launcher.png

1.5 KB
Loading

bin/res/drawable-mdpi/ic_launcher.png

2.15 KB
Loading

bin/resources.ap_

10.5 KB
Binary file not shown.

proguard.cfg

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
-optimizationpasses 5
2+
-dontusemixedcaseclassnames
3+
-dontskipnonpubliclibraryclasses
4+
-dontpreverify
5+
-verbose
6+
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7+
8+
-keep public class * extends android.app.Activity
9+
-keep public class * extends android.app.Application
10+
-keep public class * extends android.app.Service
11+
-keep public class * extends android.content.BroadcastReceiver
12+
-keep public class * extends android.content.ContentProvider
13+
-keep public class * extends android.app.backup.BackupAgentHelper
14+
-keep public class * extends android.preference.Preference
15+
-keep public class com.android.vending.licensing.ILicensingService
16+
17+
-keepclasseswithmembernames class * {
18+
native <methods>;
19+
}
20+
21+
-keepclasseswithmembers class * {
22+
public <init>(android.content.Context, android.util.AttributeSet);
23+
}
24+
25+
-keepclasseswithmembers class * {
26+
public <init>(android.content.Context, android.util.AttributeSet, int);
27+
}
28+
29+
-keepclassmembers class * extends android.app.Activity {
30+
public void *(android.view.View);
31+
}
32+
33+
-keepclassmembers enum * {
34+
public static **[] values();
35+
public static ** valueOf(java.lang.String);
36+
}
37+
38+
-keep class * implements android.os.Parcelable {
39+
public static final android.os.Parcelable$Creator *;
40+
}

project.properties

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 use,
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
10+
# Project target.
11+
target=android-8

res/drawable-hdpi/ic_launcher.png

4.05 KB
Loading

res/drawable-ldpi/ic_launcher.png

1.68 KB
Loading

res/drawable-mdpi/ic_launcher.png

2.51 KB
Loading

res/layout/main.xml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="fill_parent"
4+
android:layout_height="fill_parent"
5+
android:orientation="vertical" >
6+
7+
<TextView
8+
android:id="@+id/text"
9+
android:layout_width="fill_parent"
10+
android:layout_height="wrap_content"
11+
android:text="loading" />
12+
13+
</LinearLayout>

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="hello">Hello World, AndroidHttpClientTestActivity!</string>
5+
<string name="app_name">AndroidHttpClientTest</string>
6+
<string name="loading">読み込み中</string>
7+
8+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package jp.sharakova.android.httpclient;
2+
3+
import java.io.BufferedReader;
4+
import java.io.InputStreamReader;
5+
6+
import org.apache.http.HttpResponse;
7+
import org.apache.http.client.methods.HttpGet;
8+
9+
import android.app.Activity;
10+
import android.net.http.AndroidHttpClient;
11+
import android.os.AsyncTask;
12+
import android.os.Bundle;
13+
import android.widget.TextView;
14+
15+
public class TestActivity extends Activity {
16+
/** Called when the activity is first created. */
17+
@Override
18+
public void onCreate(Bundle savedInstanceState) {
19+
super.onCreate(savedInstanceState);
20+
21+
setContentView(R.layout.main);
22+
final TextView text = (TextView)findViewById(R.id.text);
23+
24+
new AsyncTask<Void, Void, String>() {
25+
26+
@Override
27+
protected String doInBackground(Void... params) {
28+
try {
29+
// AndroidHttpClientを使ってみた (Android 2.2 Froyoから使えます)
30+
AndroidHttpClient client = AndroidHttpClient.newInstance("Android UserAgent");
31+
HttpResponse res = client.execute(new HttpGet("https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey"));
32+
33+
// HttpResponseのEntityデータをStringへ変換
34+
BufferedReader reader = new BufferedReader(new InputStreamReader(res.getEntity().getContent(), "UTF-8"));
35+
StringBuilder builder = new StringBuilder();
36+
String line = null;
37+
while ((line = reader.readLine()) != null) {
38+
builder.append(line + "\n");
39+
}
40+
41+
return builder.toString();
42+
} catch (Exception e) {
43+
e.getStackTrace();
44+
return "";
45+
}
46+
}
47+
48+
@Override
49+
protected void onPostExecute(String result) {
50+
text.setText(result);
51+
}
52+
53+
}.execute();
54+
55+
}
56+
}

0 commit comments

Comments
 (0)