Skip to content

Commit a328326

Browse files
author
Nilanchal Panigrahy
committed
Consolidated all UI examples into single repo
1 parent 6969228 commit a328326

26 files changed

Lines changed: 679 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
</configuration>
8+
</facet>
9+
</component>
10+
<component name="NewModuleRootManager" inherit-compiler-output="false">
11+
<output url="file://$MODULE_DIR$/build/classes/main" />
12+
<output-test url="file://$MODULE_DIR$/build/classes/test" />
13+
<exclude-output />
14+
<content url="file://$MODULE_DIR$">
15+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
16+
</content>
17+
<orderEntry type="inheritedJdk" />
18+
<orderEntry type="sourceFolder" forTests="false" />
19+
</component>
20+
</module>
21+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":app" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
13+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
14+
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
15+
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
16+
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
17+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
18+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
19+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
20+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
21+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
22+
</configuration>
23+
</facet>
24+
</component>
25+
<component name="NewModuleRootManager" inherit-compiler-output="false">
26+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
27+
<exclude-output />
28+
<content url="file://$MODULE_DIR$">
29+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
30+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
31+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
41+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
42+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
43+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
62+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
63+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
64+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
65+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
66+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
67+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
68+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
69+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
70+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
71+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
72+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
73+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
76+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
77+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
78+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
83+
</content>
84+
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
85+
<orderEntry type="sourceFolder" forTests="false" />
86+
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
87+
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
88+
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
89+
</component>
90+
</module>
91+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 21
5+
buildToolsVersion "21.1.2"
6+
7+
defaultConfig {
8+
applicationId "com.example.myapplication"
9+
minSdkVersion 15
10+
targetSdkVersion 21
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
compile "com.android.support:appcompat-v7:21.0.+"
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/nilanchalpanigrahy/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.myapplication;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.myapplication">
4+
5+
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@drawable/ic_launcher"
11+
android:label="@string/app_name"
12+
android:theme="@style/AppTheme">
13+
14+
15+
<activity
16+
android:name=".MainActivity"
17+
android:label="@string/app_name">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.example.myapplication;
2+
3+
import android.os.AsyncTask;
4+
import android.os.Bundle;
5+
import android.support.v4.widget.SwipeRefreshLayout;
6+
import android.support.v7.app.ActionBarActivity;
7+
import android.util.Log;
8+
import android.widget.ArrayAdapter;
9+
import android.widget.ListView;
10+
import org.apache.http.HttpEntity;
11+
import org.apache.http.HttpResponse;
12+
import org.apache.http.client.methods.HttpPost;
13+
import org.apache.http.impl.client.DefaultHttpClient;
14+
import org.json.JSONArray;
15+
import org.json.JSONException;
16+
import org.json.JSONObject;
17+
import java.io.BufferedReader;
18+
import java.io.InputStream;
19+
import java.io.InputStreamReader;
20+
21+
public class MainActivity extends ActionBarActivity {
22+
23+
private ListView mListView = null;
24+
private ArrayAdapter mAdapter = null;
25+
private SwipeRefreshLayout mSwipeRefreshLayout = null;
26+
27+
private String[] feedList = null;
28+
private String feedUrl = "http://javatechig.com/api/get_category_posts/?dev=1&slug=android";
29+
30+
@Override
31+
protected void onCreate(Bundle savedInstanceState) {
32+
super.onCreate(savedInstanceState);
33+
34+
setContentView(R.layout.activity_main);
35+
36+
mListView = (ListView) findViewById(R.id.listView);
37+
38+
//Start Downloading data
39+
new DownloadFilesTask().execute(feedUrl);
40+
41+
//Initialize swipe to refresh view
42+
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
43+
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
44+
@Override
45+
public void onRefresh() {
46+
//Refreshing data on server
47+
new DownloadFilesTask().execute(feedUrl);
48+
}
49+
});
50+
}
51+
52+
53+
private void updateList() {
54+
ArrayAdapter mAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, feedList);
55+
mListView.setAdapter(mAdapter);
56+
57+
if (mSwipeRefreshLayout.isRefreshing()) {
58+
mSwipeRefreshLayout.setRefreshing(false);
59+
}
60+
}
61+
62+
63+
private class DownloadFilesTask extends AsyncTask<String, Void, Void> {
64+
65+
@Override
66+
protected void onProgressUpdate(Void... values) {
67+
}
68+
69+
@Override
70+
protected void onPostExecute(Void result) {
71+
if (null != feedList) {
72+
updateList();
73+
}
74+
}
75+
76+
@Override
77+
protected Void doInBackground(String... params) {
78+
// getting JSON string from URL
79+
JSONObject json = getJSONFromUrl(params[0]);
80+
81+
//parsing json data
82+
parseJson(json);
83+
return null;
84+
}
85+
}
86+
87+
public JSONObject getJSONFromUrl(String url) {
88+
InputStream is = null;
89+
JSONObject jObj = null;
90+
String json = null;
91+
92+
try {
93+
DefaultHttpClient httpClient = new DefaultHttpClient();
94+
HttpPost httpPost = new HttpPost(url);
95+
96+
HttpResponse httpResponse = httpClient.execute(httpPost);
97+
HttpEntity httpEntity = httpResponse.getEntity();
98+
is = httpEntity.getContent();
99+
100+
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
101+
StringBuilder sb = new StringBuilder();
102+
String line = null;
103+
while ((line = reader.readLine()) != null) {
104+
sb.append(line + "\n");
105+
}
106+
is.close();
107+
json = sb.toString();
108+
109+
jObj = new JSONObject(json);
110+
111+
} catch (Exception e) {
112+
Log.e("Error", "Error parsing data " + e.toString());
113+
}
114+
return jObj;
115+
}
116+
117+
118+
public void parseJson(JSONObject json) {
119+
try {
120+
if (json.getString("status").equalsIgnoreCase("ok")) {
121+
JSONArray posts = json.getJSONArray("posts");
122+
123+
feedList = new String[posts.length()];
124+
for (int i = 0; i < posts.length(); i++) {
125+
JSONObject post = (JSONObject) posts.getJSONObject(i);
126+
feedList[i] = post.getString("title");
127+
}
128+
}
129+
} catch (JSONException e) {
130+
e.printStackTrace();
131+
}
132+
}
133+
}
9.18 KB
Loading
5.11 KB
Loading

0 commit comments

Comments
 (0)