Skip to content

Commit daf1b21

Browse files
committed
Samples progress
1 parent 9e5f4e6 commit daf1b21

File tree

17 files changed

+207
-261
lines changed

17 files changed

+207
-261
lines changed

sample/src/main/AndroidManifest.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@
1414
android:icon="@drawable/ic_launcher"
1515
android:label="@string/app_name"
1616
android:theme="@style/AppTheme">
17-
<activity android:name="com.loopj.android.http.sample.MainActivity">
17+
<activity android:name=".WaypointsActivity">
1818
<intent-filter>
1919
<action android:name="android.intent.action.MAIN" />
2020
<category android:name="android.intent.category.LAUNCHER" />
2121
</intent-filter>
2222
</activity>
23+
<activity android:name=".GetSample" />
24+
<activity android:name=".PostSample" />
25+
<activity android:name=".DeleteSample" />
26+
<activity android:name=".PutSample" />
27+
<activity android:name=".JsonSample" />
28+
<activity android:name=".FileSample" />
29+
<activity android:name=".BinarySample" />
2330
</application>
2431

2532
</manifest>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
5+
public class BinarySample extends Activity {
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
5+
public class DeleteSample extends Activity {
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
5+
public class FileSample extends Activity {
6+
7+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.os.Bundle;
4+
5+
public class GetSample extends SampleParentActivity {
6+
7+
@Override
8+
protected int getSampleTitle() {
9+
return R.string.get_sample;
10+
}
11+
12+
@Override
13+
protected boolean isRequestBodyAllowed() {
14+
return false;
15+
}
16+
17+
@Override
18+
protected boolean isRequestHeadersAllowed() {
19+
return true;
20+
}
21+
22+
@Override
23+
protected void onCreate(Bundle savedInstanceState) {
24+
super.onCreate(savedInstanceState);
25+
}
26+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
5+
public class JsonSample extends Activity {
6+
7+
}

sample/src/main/java/com/loopj/android/http/sample/MainActivity.java

Lines changed: 0 additions & 161 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
5+
public class PostSample extends Activity {
6+
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
5+
public class PutSample extends Activity {
6+
7+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.text.InputType;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.Button;
9+
import android.widget.EditText;
10+
import android.widget.LinearLayout;
11+
import android.widget.ScrollView;
12+
13+
import com.loopj.android.http.AsyncHttpClient;
14+
15+
public abstract class SampleParentActivity extends Activity {
16+
17+
private LinearLayout headers; // Sample header, inputs and buttons
18+
private LinearLayout contents; // Sample output, states, errors, ...
19+
private AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
20+
private EditText urlEditText;
21+
private Button executeButton;
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
final LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
27+
final LinearLayout content_wrapper = new LinearLayout(this);
28+
content_wrapper.setOrientation(LinearLayout.VERTICAL);
29+
content_wrapper.setLayoutParams(lParams);
30+
contents = new LinearLayout(this);
31+
contents.setLayoutParams(lParams);
32+
contents.setOrientation(LinearLayout.VERTICAL);
33+
headers = new LinearLayout(this);
34+
headers.setLayoutParams(lParams);
35+
headers.setOrientation(LinearLayout.VERTICAL);
36+
ScrollView contents_scroll = new ScrollView(this);
37+
contents_scroll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
38+
contents_scroll.setFillViewport(true);
39+
content_wrapper.addView(headers);
40+
content_wrapper.addView(contents);
41+
contents_scroll.addView(content_wrapper);
42+
setContentView(contents_scroll);
43+
setTitle(getSampleTitle());
44+
setupHeaders();
45+
}
46+
47+
private void setupHeaders() {
48+
LinearLayout urlLayout = new LinearLayout(this);
49+
urlLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
50+
urlLayout.setOrientation(LinearLayout.HORIZONTAL);
51+
urlEditText = new EditText(this);
52+
urlEditText.setHint("URL for request");
53+
urlEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
54+
urlEditText.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
55+
urlLayout.addView(urlEditText);
56+
executeButton = new Button(this);
57+
executeButton.setText("Run");
58+
executeButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
59+
urlLayout.addView(executeButton);
60+
headers.addView(urlLayout);
61+
}
62+
63+
protected final void addView(View v) {
64+
contents.addView(v);
65+
}
66+
67+
protected final void clearOutputs() {
68+
contents.removeAllViews();
69+
}
70+
71+
protected abstract int getSampleTitle();
72+
73+
protected abstract boolean isRequestBodyAllowed();
74+
75+
protected abstract boolean isRequestHeadersAllowed();
76+
77+
protected AsyncHttpClient getAsyncHttpClient() {
78+
return this.asyncHttpClient;
79+
}
80+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.loopj.android.http.sample;
2+
3+
import android.app.ListActivity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.widget.ArrayAdapter;
8+
import android.widget.ListView;
9+
10+
public class WaypointsActivity extends ListActivity {
11+
12+
private static final String[] samples = new String[]{"GET", "POST", "DELETE", "PUT", "JSON", "FILE", "BINARY"};
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, samples));
18+
}
19+
20+
@Override
21+
protected void onListItemClick(ListView l, View v, int position, long id) {
22+
Class<?> targetClass;
23+
switch (position) {
24+
case 0:
25+
default:
26+
targetClass = GetSample.class;
27+
break;
28+
case 1:
29+
targetClass = PostSample.class;
30+
break;
31+
case 2:
32+
targetClass = DeleteSample.class;
33+
break;
34+
case 3:
35+
targetClass = PutSample.class;
36+
break;
37+
case 4:
38+
targetClass = JsonSample.class;
39+
break;
40+
case 5:
41+
targetClass = FileSample.class;
42+
break;
43+
case 6:
44+
targetClass = BinarySample.class;
45+
break;
46+
}
47+
if (targetClass != null)
48+
startActivity(new Intent(this, targetClass));
49+
}
50+
}

0 commit comments

Comments
 (0)