├── .DS_Store
├── AndroidConnectingToPhpMySQL
├── .classpath
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── bin
│ ├── AndroidConnectingToPhpMySQL.apk
│ ├── AndroidManifest.xml
│ ├── classes.dex
│ ├── classes
│ │ └── com
│ │ │ └── example
│ │ │ └── androidhive
│ │ │ ├── AllProductsActivity$1.class
│ │ │ ├── AllProductsActivity$LoadAllProducts$1.class
│ │ │ ├── AllProductsActivity$LoadAllProducts.class
│ │ │ ├── AllProductsActivity.class
│ │ │ ├── BuildConfig.class
│ │ │ ├── EditProductActivity$1.class
│ │ │ ├── EditProductActivity$2.class
│ │ │ ├── EditProductActivity$DeleteProduct.class
│ │ │ ├── EditProductActivity$GetProductDetails$1.class
│ │ │ ├── EditProductActivity$GetProductDetails.class
│ │ │ ├── EditProductActivity$SaveProductDetails.class
│ │ │ ├── EditProductActivity.class
│ │ │ ├── JSONParser.class
│ │ │ ├── MainScreenActivity$1.class
│ │ │ ├── MainScreenActivity$2.class
│ │ │ ├── MainScreenActivity.class
│ │ │ ├── NewProductActivity$1.class
│ │ │ ├── NewProductActivity$CreateNewProduct.class
│ │ │ ├── NewProductActivity.class
│ │ │ ├── R$attr.class
│ │ │ ├── R$drawable.class
│ │ │ ├── R$id.class
│ │ │ ├── R$layout.class
│ │ │ ├── R$string.class
│ │ │ └── R.class
│ ├── res
│ │ └── crunch
│ │ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── drawable-ldpi
│ │ │ └── ic_launcher.png
│ │ │ └── drawable-mdpi
│ │ │ └── ic_launcher.png
│ └── resources.ap_
├── gen
│ └── com
│ │ └── example
│ │ └── androidhive
│ │ ├── BuildConfig.java
│ │ └── R.java
├── lint.xml
├── proguard.cfg
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── add_product.xml
│ │ ├── all_products.xml
│ │ ├── edit_product.xml
│ │ ├── list_item.xml
│ │ └── main_screen.xml
│ └── values
│ │ └── strings.xml
└── src
│ └── com
│ └── example
│ └── androidhive
│ ├── AllProductsActivity.java
│ ├── EditProductActivity.java
│ ├── JSONParser.java
│ ├── MainScreenActivity.java
│ └── NewProductActivity.java
└── android_connect
├── create_product.php
├── db_config.php
├── db_connect.php
├── delete_product.php
├── get_all_products.php
├── get_product_details.php
└── update_product.php
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/.DS_Store
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | AndroidConnectingToPhpMySQL
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/AndroidConnectingToPhpMySQL.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/AndroidConnectingToPhpMySQL.apk
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
13 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
28 |
29 |
30 |
31 |
34 |
35 |
36 |
37 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes.dex
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity$1.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity$LoadAllProducts$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity$LoadAllProducts$1.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity$LoadAllProducts.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity$LoadAllProducts.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/AllProductsActivity.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/BuildConfig.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$1.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$2.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$DeleteProduct.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$DeleteProduct.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$GetProductDetails$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$GetProductDetails$1.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$GetProductDetails.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$GetProductDetails.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$SaveProductDetails.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity$SaveProductDetails.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/EditProductActivity.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/JSONParser.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/JSONParser.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/MainScreenActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/MainScreenActivity$1.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/MainScreenActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/MainScreenActivity$2.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/MainScreenActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/MainScreenActivity.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/NewProductActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/NewProductActivity$1.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/NewProductActivity$CreateNewProduct.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/NewProductActivity$CreateNewProduct.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/NewProductActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/NewProductActivity.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$attr.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$drawable.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$id.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$layout.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R$string.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/classes/com/example/androidhive/R.class
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/res/crunch/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/res/crunch/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/bin/resources.ap_
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/gen/com/example/androidhive/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.androidhive;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/gen/com/example/androidhive/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.androidhive;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int ic_launcher=0x7f020000;
15 | }
16 | public static final class id {
17 | public static final int btnCreateProduct=0x7f050003;
18 | public static final int btnDelete=0x7f050005;
19 | public static final int btnSave=0x7f050004;
20 | public static final int btnViewProducts=0x7f050009;
21 | public static final int inputDesc=0x7f050002;
22 | public static final int inputName=0x7f050000;
23 | public static final int inputPrice=0x7f050001;
24 | public static final int name=0x7f050007;
25 | public static final int pid=0x7f050006;
26 | public static final int price=0x7f050008;
27 | }
28 | public static final class layout {
29 | public static final int add_product=0x7f030000;
30 | public static final int all_products=0x7f030001;
31 | public static final int edit_product=0x7f030002;
32 | public static final int list_item=0x7f030003;
33 | public static final int main_screen=0x7f030004;
34 | }
35 | public static final class string {
36 | public static final int addproduct=0x7f040002;
37 | public static final int app_name=0x7f040001;
38 | public static final int createproduct=0x7f040009;
39 | public static final int delete=0x7f040004;
40 | public static final int desc=0x7f040006;
41 | public static final int hello=0x7f040000;
42 | public static final int price=0x7f040007;
43 | public static final int productname=0x7f040008;
44 | public static final int savechanges=0x7f040005;
45 | public static final int viewproduct=0x7f040003;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/proguard.cfg:
--------------------------------------------------------------------------------
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 ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (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 | }
41 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/project.properties:
--------------------------------------------------------------------------------
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-19
12 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/drawable-ldpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/res/drawable-ldpi/ic_launcher.png
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lopezchin/android_connect_with_phpMysql/37784a974e1b5052362b8f60a1d4b024bf3edfde/AndroidConnectingToPhpMySQL/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/layout/add_product.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
15 |
16 |
17 |
24 |
25 |
26 |
33 |
34 |
35 |
42 |
43 |
44 |
51 |
52 |
53 |
61 |
62 |
63 |
67 |
68 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/layout/all_products.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/layout/edit_product.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
15 |
16 |
17 |
24 |
25 |
26 |
33 |
34 |
35 |
42 |
43 |
44 |
51 |
52 |
53 |
61 |
62 |
65 |
66 |
71 |
72 |
73 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/layout/list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
15 |
16 |
24 |
25 |
26 |
34 |
35 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/layout/main_screen.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
20 |
21 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Hello World, AndroidConnectingToPhpMySQLActivity!
5 | MainScreen
6 | Add New Products
7 | View Products
8 | Delete
9 | Save Changes
10 | Description
11 | Price
12 | Product Name
13 | Create Product
14 |
15 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/src/com/example/androidhive/AllProductsActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.androidhive;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 |
7 | import org.apache.http.NameValuePair;
8 | import org.json.JSONArray;
9 | import org.json.JSONException;
10 | import org.json.JSONObject;
11 |
12 | import android.app.ListActivity;
13 | import android.app.ProgressDialog;
14 | import android.content.Intent;
15 | import android.os.AsyncTask;
16 | import android.os.Bundle;
17 | import android.util.Log;
18 | import android.view.View;
19 | import android.widget.AdapterView;
20 | import android.widget.AdapterView.OnItemClickListener;
21 | import android.widget.ListAdapter;
22 | import android.widget.ListView;
23 | import android.widget.SimpleAdapter;
24 | import android.widget.TextView;
25 |
26 | public class AllProductsActivity extends ListActivity {
27 |
28 | // Progress Dialog
29 | private ProgressDialog pDialog;
30 |
31 | // Creating JSON Parser object
32 | JSONParser jParser = new JSONParser();
33 |
34 | ArrayList> productsList;
35 |
36 | // url to get all products list
37 | private static String url_all_products = "http://192.168.1.11/android_connect/get_all_products.php";
38 |
39 | // JSON Node names
40 | private static final String TAG_SUCCESS = "success";
41 | private static final String TAG_PRODUCTS = "products";
42 | private static final String TAG_PID = "pid";
43 | private static final String TAG_NAME = "name";
44 | private static final String TAG_PRICE = "price";
45 |
46 | // products JSONArray
47 | JSONArray products = null;
48 |
49 | @Override
50 | public void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.all_products);
53 |
54 | // Hashmap for ListView
55 | productsList = new ArrayList>();
56 |
57 | // Loading products in Background Thread
58 | new LoadAllProducts().execute();
59 |
60 | // Get listview
61 | ListView lv = getListView();
62 |
63 | // on seleting single product
64 | // launching Edit Product Screen
65 | lv.setOnItemClickListener(new OnItemClickListener() {
66 |
67 | @Override
68 | public void onItemClick(AdapterView> parent, View view,
69 | int position, long id) {
70 | // getting values from selected ListItem
71 | String pid = ((TextView) view.findViewById(R.id.pid)).getText()
72 | .toString();
73 |
74 | // Starting new intent
75 | Intent in = new Intent(getApplicationContext(),
76 | EditProductActivity.class);
77 | // sending pid to next activity
78 | in.putExtra(TAG_PID, pid);
79 |
80 | // starting new activity and expecting some response back
81 | startActivityForResult(in, 100);
82 | }
83 | });
84 |
85 | }
86 |
87 | // Response from Edit Product Activity
88 | @Override
89 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
90 | super.onActivityResult(requestCode, resultCode, data);
91 | // if result code 100
92 | if (resultCode == 100) {
93 | // if result code 100 is received
94 | // means user edited/deleted product
95 | // reload this screen again
96 | Intent intent = getIntent();
97 | finish();
98 | startActivity(intent);
99 | }
100 |
101 | }
102 |
103 | /**
104 | * Background Async Task to Load all product by making HTTP Request
105 | * */
106 | class LoadAllProducts extends AsyncTask {
107 |
108 | /**
109 | * Before starting background thread Show Progress Dialog
110 | * */
111 | @Override
112 | protected void onPreExecute() {
113 | super.onPreExecute();
114 | pDialog = new ProgressDialog(AllProductsActivity.this);
115 | pDialog.setMessage("Loading products. Please wait...");
116 | pDialog.setIndeterminate(false);
117 | pDialog.setCancelable(false);
118 | pDialog.show();
119 | }
120 |
121 | /**
122 | * getting All products from url
123 | * */
124 | protected String doInBackground(String... args) {
125 | // Building Parameters
126 | List params = new ArrayList();
127 | // getting JSON string from URL
128 | JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
129 |
130 | // Check your log cat for JSON reponse
131 | Log.d("All Products: ", json.toString());
132 |
133 | try {
134 | // Checking for SUCCESS TAG
135 | int success = json.getInt(TAG_SUCCESS);
136 |
137 | if (success == 1) {
138 | // products found
139 | // Getting Array of Products
140 | products = json.getJSONArray(TAG_PRODUCTS);
141 |
142 | // looping through All Products
143 | for (int i = 0; i < products.length(); i++) {
144 | JSONObject c = products.getJSONObject(i);
145 |
146 | // Storing each json item in variable
147 | String id = c.getString(TAG_PID);
148 | String name = c.getString(TAG_NAME);
149 | String price = c.getString(TAG_PRICE);
150 |
151 | // creating new HashMap
152 | HashMap map = new HashMap();
153 |
154 | // adding each child node to HashMap key => value
155 | map.put(TAG_PID, id);
156 | map.put(TAG_NAME, name);
157 | map.put(TAG_PRICE, price);
158 |
159 | // adding HashList to ArrayList
160 | productsList.add(map);
161 | }
162 | } else {
163 | // no products found
164 | // Launch Add New product Activity
165 | Intent i = new Intent(getApplicationContext(),
166 | NewProductActivity.class);
167 | // Closing all previous activities
168 | i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
169 | startActivity(i);
170 | }
171 | } catch (JSONException e) {
172 | e.printStackTrace();
173 | }
174 |
175 | return null;
176 | }
177 |
178 | /**
179 | * After completing background task Dismiss the progress dialog
180 | * **/
181 | protected void onPostExecute(String file_url) {
182 | // dismiss the dialog after getting all products
183 | pDialog.dismiss();
184 | // updating UI from Background Thread
185 | runOnUiThread(new Runnable() {
186 | public void run() {
187 | /**
188 | * Updating parsed JSON data into ListView
189 | * */
190 | ListAdapter adapter = new SimpleAdapter(
191 | AllProductsActivity.this, productsList,
192 | R.layout.list_item, new String[] { TAG_PID,
193 | TAG_NAME, TAG_PRICE},
194 | new int[] { R.id.pid, R.id.name, R.id.price });
195 | // updating listview
196 | setListAdapter(adapter);
197 | }
198 | });
199 |
200 | }
201 |
202 | }
203 | }
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/src/com/example/androidhive/EditProductActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.androidhive;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.apache.http.NameValuePair;
7 | import org.apache.http.message.BasicNameValuePair;
8 | import org.json.JSONArray;
9 | import org.json.JSONException;
10 | import org.json.JSONObject;
11 |
12 | import android.app.Activity;
13 | import android.app.ProgressDialog;
14 | import android.content.Intent;
15 | import android.os.AsyncTask;
16 | import android.os.Bundle;
17 | import android.util.Log;
18 | import android.view.View;
19 | import android.widget.Button;
20 | import android.widget.EditText;
21 |
22 | public class EditProductActivity extends Activity {
23 |
24 | EditText txtName;
25 | EditText txtPrice;
26 | EditText txtDesc;
27 | EditText txtCreatedAt;
28 | Button btnSave;
29 | Button btnDelete;
30 |
31 | String pid;
32 |
33 | // Progress Dialog
34 | private ProgressDialog pDialog;
35 |
36 | // JSON parser class
37 | JSONParser jsonParser = new JSONParser();
38 |
39 | // single product url
40 | private static final String url_product_details = "http://192.168.1.11/android_connect/get_product_details.php";
41 |
42 | // url to update product
43 | private static final String url_update_product = "http://192.168.1.11/android_connect/update_product.php";
44 |
45 | // url to delete product
46 | private static final String url_delete_product = "http://192.168.1.11/android_connect/delete_product.php";
47 |
48 | // JSON Node names
49 | private static final String TAG_SUCCESS = "success";
50 | private static final String TAG_PRODUCT = "product";
51 | private static final String TAG_PID = "pid";
52 | private static final String TAG_NAME = "name";
53 | private static final String TAG_PRICE = "price";
54 | private static final String TAG_DESCRIPTION = "description";
55 |
56 | @Override
57 | public void onCreate(Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 | setContentView(R.layout.edit_product);
60 |
61 | // save button
62 | btnSave = (Button) findViewById(R.id.btnSave);
63 | btnDelete = (Button) findViewById(R.id.btnDelete);
64 |
65 | // getting product details from intent
66 | Intent i = getIntent();
67 |
68 | // getting product id (pid) from intent
69 | pid = i.getStringExtra(TAG_PID);
70 |
71 | // Getting complete product details in background thread
72 | new GetProductDetails().execute();
73 |
74 | // save button click event
75 | btnSave.setOnClickListener(new View.OnClickListener() {
76 |
77 | @Override
78 | public void onClick(View arg0) {
79 | // starting background task to update product
80 | new SaveProductDetails().execute();
81 | }
82 | });
83 |
84 | // Delete button click event
85 | btnDelete.setOnClickListener(new View.OnClickListener() {
86 |
87 | @Override
88 | public void onClick(View arg0) {
89 | // deleting product in background thread
90 | new DeleteProduct().execute();
91 | }
92 | });
93 |
94 | }
95 |
96 | /**
97 | * Background Async Task to Get complete product details
98 | * */
99 | class GetProductDetails extends AsyncTask {
100 |
101 | /**
102 | * Before starting background thread Show Progress Dialog
103 | * */
104 | @Override
105 | protected void onPreExecute() {
106 | super.onPreExecute();
107 | pDialog = new ProgressDialog(EditProductActivity.this);
108 | pDialog.setMessage("Loading product details. Please wait...");
109 | pDialog.setIndeterminate(false);
110 | pDialog.setCancelable(true);
111 | pDialog.show();
112 | }
113 |
114 | /**
115 | * Getting product details in background thread
116 | * */
117 | protected String doInBackground(String... params) {
118 |
119 | // updating UI from Background Thread
120 | runOnUiThread(new Runnable() {
121 | public void run() {
122 | // Check for success tag
123 | int success;
124 | try {
125 | // Building Parameters
126 | List params = new ArrayList();
127 | params.add(new BasicNameValuePair("pid", pid));
128 |
129 | // getting product details by making HTTP request
130 | // Note that product details url will use GET request
131 | JSONObject json = jsonParser.makeHttpRequest(
132 | url_product_details, "GET", params);
133 |
134 | // check your log for json response
135 | Log.d("Single Product Details", json.toString());
136 |
137 | // json success tag
138 | success = json.getInt(TAG_SUCCESS);
139 | if (success == 1) {
140 | // successfully received product details
141 | JSONArray productObj = json
142 | .getJSONArray(TAG_PRODUCT); // JSON Array
143 |
144 | // get first product object from JSON Array
145 | JSONObject product = productObj.getJSONObject(0);
146 |
147 | // product with this pid found
148 | // Edit Text
149 | txtName = (EditText) findViewById(R.id.inputName);
150 | txtPrice = (EditText) findViewById(R.id.inputPrice);
151 | txtDesc = (EditText) findViewById(R.id.inputDesc);
152 |
153 | // display product data in EditText
154 | txtName.setText(product.getString(TAG_NAME));
155 | txtPrice.setText(product.getString(TAG_PRICE));
156 | txtDesc.setText(product.getString(TAG_DESCRIPTION));
157 |
158 | }else{
159 | // product with pid not found
160 | }
161 | } catch (JSONException e) {
162 | e.printStackTrace();
163 | }
164 | }
165 | });
166 |
167 | return null;
168 | }
169 |
170 |
171 | /**
172 | * After completing background task Dismiss the progress dialog
173 | * **/
174 | protected void onPostExecute(String file_url) {
175 | // dismiss the dialog once got all details
176 | pDialog.dismiss();
177 | }
178 | }
179 |
180 | /**
181 | * Background Async Task to Save product Details
182 | * */
183 | class SaveProductDetails extends AsyncTask {
184 |
185 | /**
186 | * Before starting background thread Show Progress Dialog
187 | * */
188 | @Override
189 | protected void onPreExecute() {
190 | super.onPreExecute();
191 | pDialog = new ProgressDialog(EditProductActivity.this);
192 | pDialog.setMessage("Saving product ...");
193 | pDialog.setIndeterminate(false);
194 | pDialog.setCancelable(true);
195 | pDialog.show();
196 | }
197 |
198 | /**
199 | * Saving product
200 | * */
201 | protected String doInBackground(String... args) {
202 |
203 | // getting updated data from EditTexts
204 | String name = txtName.getText().toString();
205 | String price = txtPrice.getText().toString();
206 | String description = txtDesc.getText().toString();
207 |
208 | // Building Parameters
209 | List params = new ArrayList();
210 | params.add(new BasicNameValuePair(TAG_PID, pid));
211 | params.add(new BasicNameValuePair(TAG_NAME, name));
212 | params.add(new BasicNameValuePair(TAG_PRICE, price));
213 | params.add(new BasicNameValuePair(TAG_DESCRIPTION, description));
214 |
215 | // sending modified data through http request
216 | // Notice that update product url accepts POST method
217 | JSONObject json = jsonParser.makeHttpRequest(url_update_product,
218 | "POST", params);
219 |
220 | // check json success tag
221 | try {
222 | int success = json.getInt(TAG_SUCCESS);
223 |
224 | if (success == 1) {
225 | // successfully updated
226 | Intent i = getIntent();
227 | // send result code 100 to notify about product update
228 | setResult(100, i);
229 | finish();
230 | } else {
231 | // failed to update product
232 | }
233 | } catch (JSONException e) {
234 | e.printStackTrace();
235 | }
236 |
237 | return null;
238 | }
239 |
240 |
241 | /**
242 | * After completing background task Dismiss the progress dialog
243 | * **/
244 | protected void onPostExecute(String file_url) {
245 | // dismiss the dialog once product uupdated
246 | pDialog.dismiss();
247 | }
248 | }
249 |
250 | /*****************************************************************
251 | * Background Async Task to Delete Product
252 | * */
253 | class DeleteProduct extends AsyncTask {
254 |
255 | /**
256 | * Before starting background thread Show Progress Dialog
257 | * */
258 | @Override
259 | protected void onPreExecute() {
260 | super.onPreExecute();
261 | pDialog = new ProgressDialog(EditProductActivity.this);
262 | pDialog.setMessage("Deleting Product...");
263 | pDialog.setIndeterminate(false);
264 | pDialog.setCancelable(true);
265 | pDialog.show();
266 | }
267 |
268 | /**
269 | * Deleting product
270 | * */
271 | protected String doInBackground(String... args) {
272 |
273 | // Check for success tag
274 | int success;
275 | try {
276 | // Building Parameters
277 | List params = new ArrayList();
278 | params.add(new BasicNameValuePair("pid", pid));
279 |
280 | // getting product details by making HTTP request
281 | JSONObject json = jsonParser.makeHttpRequest(
282 | url_delete_product, "POST", params);
283 |
284 | // check your log for json response
285 | Log.d("Delete Product", json.toString());
286 |
287 | // json success tag
288 | success = json.getInt(TAG_SUCCESS);
289 | if (success == 1) {
290 | // product successfully deleted
291 | // notify previous activity by sending code 100
292 | Intent i = getIntent();
293 | // send result code 100 to notify about product deletion
294 | setResult(100, i);
295 | finish();
296 | }
297 | } catch (JSONException e) {
298 | e.printStackTrace();
299 | }
300 |
301 | return null;
302 | }
303 |
304 | /**
305 | * After completing background task Dismiss the progress dialog
306 | * **/
307 | protected void onPostExecute(String file_url) {
308 | // dismiss the dialog once product deleted
309 | pDialog.dismiss();
310 |
311 | }
312 |
313 | }
314 | }
315 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/src/com/example/androidhive/JSONParser.java:
--------------------------------------------------------------------------------
1 | package com.example.androidhive;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.io.UnsupportedEncodingException;
8 | import java.util.List;
9 |
10 | import org.apache.http.HttpEntity;
11 | import org.apache.http.HttpResponse;
12 | import org.apache.http.NameValuePair;
13 | import org.apache.http.client.ClientProtocolException;
14 | import org.apache.http.client.entity.UrlEncodedFormEntity;
15 | import org.apache.http.client.methods.HttpGet;
16 | import org.apache.http.client.methods.HttpPost;
17 | import org.apache.http.client.utils.URLEncodedUtils;
18 | import org.apache.http.impl.client.DefaultHttpClient;
19 | import org.json.JSONException;
20 | import org.json.JSONObject;
21 |
22 | import android.util.Log;
23 |
24 | public class JSONParser {
25 |
26 | static InputStream is = null;
27 | static JSONObject jObj = null;
28 | static String json = "";
29 |
30 | // constructor
31 | public JSONParser() {
32 |
33 | }
34 |
35 | // function get json from url
36 | // by making HTTP POST or GET mehtod
37 | public JSONObject makeHttpRequest(String url, String method,
38 | List params) {
39 |
40 | // Making HTTP request
41 | try {
42 |
43 | // check for request method
44 | if(method == "POST"){
45 | // request method is POST
46 | // defaultHttpClient
47 | DefaultHttpClient httpClient = new DefaultHttpClient();
48 | HttpPost httpPost = new HttpPost(url);
49 | httpPost.setEntity(new UrlEncodedFormEntity(params));
50 |
51 | HttpResponse httpResponse = httpClient.execute(httpPost);
52 | HttpEntity httpEntity = httpResponse.getEntity();
53 | is = httpEntity.getContent();
54 |
55 | }else if(method == "GET"){
56 | // request method is GET
57 | DefaultHttpClient httpClient = new DefaultHttpClient();
58 | String paramString = URLEncodedUtils.format(params, "utf-8");
59 | url += "?" + paramString;
60 | HttpGet httpGet = new HttpGet(url);
61 |
62 | HttpResponse httpResponse = httpClient.execute(httpGet);
63 | HttpEntity httpEntity = httpResponse.getEntity();
64 | is = httpEntity.getContent();
65 | }
66 |
67 |
68 | } catch (UnsupportedEncodingException e) {
69 | e.printStackTrace();
70 | } catch (ClientProtocolException e) {
71 | e.printStackTrace();
72 | } catch (IOException e) {
73 | e.printStackTrace();
74 | }
75 |
76 | try {
77 | BufferedReader reader = new BufferedReader(new InputStreamReader(
78 | is, "iso-8859-1"), 8);
79 | StringBuilder sb = new StringBuilder();
80 | String line = null;
81 | while ((line = reader.readLine()) != null) {
82 | sb.append(line + "\n");
83 | }
84 | is.close();
85 | json = sb.toString();
86 | } catch (Exception e) {
87 | Log.e("Buffer Error", "Error converting result " + e.toString());
88 | }
89 |
90 | // try parse the string to a JSON object
91 | try {
92 | jObj = new JSONObject(json);
93 | } catch (JSONException e) {
94 | Log.e("JSON Parser", "Error parsing data " + e.toString());
95 | }
96 |
97 | // return JSON String
98 | return jObj;
99 |
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/src/com/example/androidhive/MainScreenActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.androidhive;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 |
10 | public class MainScreenActivity extends Activity{
11 |
12 | Button btnViewProducts;
13 | Button btnNewProduct;
14 |
15 | @Override
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.main_screen);
19 |
20 | // Buttons
21 | btnViewProducts = (Button) findViewById(R.id.btnViewProducts);
22 | btnNewProduct = (Button) findViewById(R.id.btnCreateProduct);
23 |
24 | viewProduct();
25 |
26 | addProduct();
27 |
28 | }
29 |
30 | private void viewProduct() {
31 | // view products click event
32 | btnViewProducts.setOnClickListener(new View.OnClickListener() {
33 |
34 | @Override
35 | public void onClick(View view) {
36 | // Launching All products Activity
37 | Intent i = new Intent(MainScreenActivity.this, AllProductsActivity.class);
38 | startActivity(i);
39 |
40 | }
41 | });
42 |
43 | }
44 |
45 | private void addProduct(){
46 | // view products click event
47 | btnNewProduct.setOnClickListener(new View.OnClickListener() {
48 |
49 | @Override
50 | public void onClick(View view) {
51 | // Launching create new product activity
52 | Intent i = new Intent(MainScreenActivity.this, NewProductActivity.class);
53 | startActivity(i);
54 |
55 | }
56 | });
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/AndroidConnectingToPhpMySQL/src/com/example/androidhive/NewProductActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.androidhive;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import org.apache.http.NameValuePair;
7 | import org.apache.http.message.BasicNameValuePair;
8 | import org.json.JSONException;
9 | import org.json.JSONObject;
10 |
11 | import android.app.Activity;
12 | import android.app.ProgressDialog;
13 | import android.content.Intent;
14 | import android.os.AsyncTask;
15 | import android.os.Bundle;
16 | import android.util.Log;
17 | import android.view.View;
18 | import android.widget.Button;
19 | import android.widget.EditText;
20 |
21 | public class NewProductActivity extends Activity {
22 |
23 | // Progress Dialog
24 | private ProgressDialog pDialog;
25 |
26 | JSONParser jsonParser = new JSONParser();
27 | EditText inputName;
28 | EditText inputPrice;
29 | EditText inputDesc;
30 |
31 | // url to create new product
32 | private static String url_create_product = "http://192.168.1.11/android_connect/create_product.php";
33 |
34 | // JSON Node names
35 | private static final String TAG_SUCCESS = "success";
36 |
37 | @Override
38 | public void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.add_product);
41 |
42 | // Edit Text
43 | inputName = (EditText) findViewById(R.id.inputName);
44 | inputPrice = (EditText) findViewById(R.id.inputPrice);
45 | inputDesc = (EditText) findViewById(R.id.inputDesc);
46 |
47 | // Create button
48 | Button btnCreateProduct = (Button) findViewById(R.id.btnCreateProduct);
49 |
50 | // button click event
51 | btnCreateProduct.setOnClickListener(new View.OnClickListener() {
52 |
53 | @Override
54 | public void onClick(View view) {
55 | // creating new product in background thread
56 | new CreateNewProduct().execute();
57 | }
58 | });
59 | }
60 |
61 | /**
62 | * Background Async Task to Create new product
63 | * */
64 | class CreateNewProduct extends AsyncTask {
65 |
66 | /**
67 | * Before starting background thread Show Progress Dialog
68 | * */
69 | @Override
70 | protected void onPreExecute() {
71 | super.onPreExecute();
72 | pDialog = new ProgressDialog(NewProductActivity.this);
73 | pDialog.setMessage("Creating Product..");
74 | pDialog.setIndeterminate(false);
75 | pDialog.setCancelable(true);
76 | pDialog.show();
77 | }
78 |
79 | /**
80 | * Creating product
81 | * */
82 | protected String doInBackground(String... args) {
83 | String name = inputName.getText().toString();
84 | String price = inputPrice.getText().toString();
85 | String description = inputDesc.getText().toString();
86 |
87 | // Building Parameters
88 | List params = new ArrayList();
89 | params.add(new BasicNameValuePair("name", name));
90 | params.add(new BasicNameValuePair("price", price));
91 | params.add(new BasicNameValuePair("description", description));
92 |
93 | // getting JSON Object
94 | // Note that create product url accepts POST method
95 | JSONObject json = jsonParser.makeHttpRequest(url_create_product,
96 | "POST", params);
97 |
98 | // check log cat fro response
99 | Log.d("Create Response", json.toString());
100 |
101 | // check for success tag
102 | try {
103 | int success = json.getInt(TAG_SUCCESS);
104 |
105 | if (success == 1) {
106 | // successfully created product
107 | Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
108 | startActivity(i);
109 |
110 | // closing this screen
111 | finish();
112 | } else {
113 | // failed to create product
114 | }
115 | } catch (JSONException e) {
116 | e.printStackTrace();
117 | }
118 |
119 | return null;
120 | }
121 |
122 | /**
123 | * After completing background task Dismiss the progress dialog
124 | * **/
125 | protected void onPostExecute(String file_url) {
126 | // dismiss the dialog once done
127 | pDialog.dismiss();
128 | }
129 |
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/android_connect/create_product.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/android_connect/db_config.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/android_connect/db_connect.php:
--------------------------------------------------------------------------------
1 | connect();
12 | }
13 |
14 | // destructor
15 | function __destruct() {
16 | // closing db connection
17 | $this->close();
18 | }
19 |
20 | /**
21 | * Function to connect with database
22 | */
23 | function connect() {
24 | // import database connection variables
25 | require_once __DIR__ . '/db_config.php';
26 |
27 | // Connecting to mysql database
28 | $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
29 |
30 | // Selecing database
31 | $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
32 |
33 | // returing connection cursor
34 | return $con;
35 | }
36 |
37 | /**
38 | * Function to close db connection
39 | */
40 | function close() {
41 | // closing db connection
42 | mysql_close();
43 | }
44 |
45 | }
46 |
47 | ?>
--------------------------------------------------------------------------------
/android_connect/delete_product.php:
--------------------------------------------------------------------------------
1 | 0) {
26 | // successfully updated
27 | $response["success"] = 1;
28 | $response["message"] = "Product successfully deleted";
29 |
30 | // echoing JSON response
31 | echo json_encode($response);
32 | } else {
33 | // no product found
34 | $response["success"] = 0;
35 | $response["message"] = "No product found";
36 |
37 | // echo no users JSON
38 | echo json_encode($response);
39 | }
40 | } else {
41 | // required field is missing
42 | $response["success"] = 0;
43 | $response["message"] = "Required field(s) is missing";
44 |
45 | // echoing JSON response
46 | echo json_encode($response);
47 | }
48 | ?>
--------------------------------------------------------------------------------
/android_connect/get_all_products.php:
--------------------------------------------------------------------------------
1 | 0) {
22 | // looping through all results
23 | // products node
24 | $response["products"] = array();
25 |
26 | while ($row = mysql_fetch_array($result)) {
27 | // temp user array
28 | $product = array();
29 | $product["pid"] = $row["pid"];
30 | $product["name"] = $row["name"];
31 | $product["price"] = $row["price"];
32 | $product["description"] = $row["description"];
33 | $product["created_at"] = $row["created_at"];
34 | $product["updated_at"] = $row["updated_at"];
35 |
36 |
37 |
38 | // push single product into final response array
39 | array_push($response["products"], $product);
40 | }
41 | // success
42 | $response["success"] = 1;
43 |
44 | // echoing JSON response
45 | echo json_encode($response);
46 | } else {
47 | // no products found
48 | $response["success"] = 0;
49 | $response["message"] = "No products found";
50 |
51 | // echo no users JSON
52 | echo json_encode($response);
53 | }
54 | ?>
55 |
--------------------------------------------------------------------------------
/android_connect/get_product_details.php:
--------------------------------------------------------------------------------
1 | 0) {
28 |
29 | $result = mysql_fetch_array($result);
30 |
31 | $product = array();
32 | $product["pid"] = $result["pid"];
33 | $product["name"] = $result["name"];
34 | $product["price"] = $result["price"];
35 | $product["description"] = $result["description"];
36 | $product["created_at"] = $result["created_at"];
37 | $product["updated_at"] = $result["updated_at"];
38 | // success
39 | $response["success"] = 1;
40 |
41 | // user node
42 | $response["product"] = array();
43 |
44 | array_push($response["product"], $product);
45 |
46 | // echoing JSON response
47 | echo json_encode($response);
48 | } else {
49 | // no product found
50 | $response["success"] = 0;
51 | $response["message"] = "No product found";
52 |
53 | // echo no users JSON
54 | echo json_encode($response);
55 | }
56 | } else {
57 | // no product found
58 | $response["success"] = 0;
59 | $response["message"] = "No product found";
60 |
61 | // echo no users JSON
62 | echo json_encode($response);
63 | }
64 | } else {
65 | // required field is missing
66 | $response["success"] = 0;
67 | $response["message"] = "Required field(s) is missing";
68 |
69 | // echoing JSON response
70 | echo json_encode($response);
71 | }
72 | ?>
--------------------------------------------------------------------------------
/android_connect/update_product.php:
--------------------------------------------------------------------------------
1 |
48 |
--------------------------------------------------------------------------------