Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "me.jakir.androidxmlparsing" | ||
minSdkVersion 14 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.1.1' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in C:\Users\Jack\AppData\Local\Android\sdk1/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.jakir.androidxmlparsing; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="me.jakir.androidxmlparsing"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package me.jakir.androidxmlparsing; | ||
|
||
import android.app.Activity; | ||
import android.os.AsyncTask; | ||
import android.view.View; | ||
import android.widget.ProgressBar; | ||
import android.widget.TextView; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by Jack on 2/17/2016. | ||
*/ | ||
public class BackgroundTask extends AsyncTask<String, String, String> { | ||
|
||
Activity mainActivity; | ||
ProgressBar progressBar; | ||
TextView output; | ||
List<Food> foodList; | ||
|
||
|
||
public BackgroundTask(Activity activity) { | ||
mainActivity = activity; | ||
} | ||
|
||
|
||
@Override | ||
protected void onPreExecute() { | ||
// show progress bar | ||
progressBar = (ProgressBar) mainActivity.findViewById(R.id.progressBar); | ||
progressBar.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
protected String doInBackground(String... params) { | ||
|
||
String content = getData(params[0]); | ||
return content; | ||
} | ||
|
||
|
||
@Override | ||
protected void onPostExecute(String result) { | ||
// Hide Progress bar | ||
progressBar.setVisibility(View.INVISIBLE); | ||
output = (TextView) mainActivity.findViewById(R.id.output); | ||
|
||
|
||
|
||
|
||
|
||
foodList = XmlParser.parse(result); | ||
|
||
|
||
if(foodList != null){ | ||
for (Food foodItem: foodList) { | ||
output.append("Item name: " + foodItem.getName() + "\n"); | ||
output.append("Item price: " + foodItem.getPrice() + "\n"); | ||
output.append("Item Description: " + foodItem.getDescription() + "\n \n \n"); | ||
|
||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
// Method for get XML data using HTTP Request | ||
private String getData(String uri) { | ||
BufferedReader reader; | ||
|
||
try { | ||
URL url = new URL(uri); | ||
|
||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
|
||
StringBuilder stringBuilder = new StringBuilder(); | ||
|
||
reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
|
||
String line; | ||
|
||
while ((line = reader.readLine()) != null) { | ||
stringBuilder.append(line + "\n"); | ||
} | ||
return stringBuilder.toString(); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package me.jakir.androidxmlparsing; | ||
|
||
/** | ||
* Created by Jack on 2/17/2016. | ||
*/ | ||
public class Food { | ||
|
||
// food info variables | ||
private String name; | ||
private String price; | ||
private String description; | ||
|
||
|
||
// getters and setters | ||
|
||
public String getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(String price) { | ||
this.price = price; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
|
||
|
||
} |