0822002 chapter3 andro

44
BAB III PEMBAHASAN MASALAH 3.1. Cara Kerja Aplikasi Pada aplikasi ini mula-mula setelah aplikasi ini diinstall pada perangkat seluler dan dibuka atau diaktifkan, maka pengguna akan dibawa pada halaman utama yaitu list kategori dari barang-barang yang dijual. Di sana pengguna akan melihat list yang dapat dipilih. Setelah pengguna memilih kategori mana yang diinginkan, kemudian pengguna akan diteruskan ke halaman list barang atau produk yang dijual yang berada di kategori tersebut. Di halaman tersebut terdapat list barang atau produk beserta dengan harganya. Apabila pengguna tertarik dengan salah satu barang atau produk yang tertera di sana, pengguna dapat memilih barang tersebut untuk menuju ke halaman keterangan dan gambar produk beserta harga yang diberikan pada barang atau produk tersebut. Pengguna akan dengan mudah dapat kembali ke halaman sebelumnya 13 Universitas Kristen Maranatha

Upload: ben-hadi

Post on 26-Jan-2016

240 views

Category:

Documents


0 download

DESCRIPTION

fasdasdasdasdasfasfxcdf

TRANSCRIPT

Page 1: 0822002 Chapter3 Andro

BAB III

PEMBAHASAN MASALAH

3.1. Cara Kerja Aplikasi

Pada aplikasi ini mula-mula setelah aplikasi ini diinstall pada perangkat

seluler dan dibuka atau diaktifkan, maka pengguna akan dibawa pada halaman

utama yaitu list kategori dari barang-barang yang dijual. Di sana pengguna akan

melihat list yang dapat dipilih. Setelah pengguna memilih kategori mana yang

diinginkan, kemudian pengguna akan diteruskan ke halaman list barang atau

produk yang dijual yang berada di kategori tersebut. Di halaman tersebut terdapat

list barang atau produk beserta dengan harganya. Apabila pengguna tertarik

dengan salah satu barang atau produk yang tertera di sana, pengguna dapat

memilih barang tersebut untuk menuju ke halaman keterangan dan gambar

produk beserta harga yang diberikan pada barang atau produk tersebut. Pengguna

akan dengan mudah dapat kembali ke halaman sebelumnya dengan menekan

tombol back (kembali) pada smartphone miliknya untuk melihat barang lain atau

menuju ke kategori yang lain. Apabila pengguna sudah memilih dan menentukan

barang mana yang ingin dibeli, di halaman yang berisi keterangan dan gambar

tadi terdapat tombol BUY yang dapat dipilih untuk membeli barang tersebut dan

menuju ke halaman pengisian data pembeli. Di halaman tersebut, pengguna akan

mengisi form berisi Nama, Alamat, Kota, Nomor Telepon/ Handphone, dan

Alamat email untuk proses pengiriman. Nilai ongkos kirim akan dihitung dari

kota pengirim (penjual), dalam hal ini dimisalkan dari Bandung ke kota penerima

13Universitas Kristen Maranatha

Page 2: 0822002 Chapter3 Andro

yang diisikan pada form pembelian tadi. Semua field pada form pembelian harus

diisi, apabila ada yang tidak diisi, maka tidak bias berlanjut ke halaman

berikutnya. Setelah selesai mengisi form, pengguna tinggal menekan tombol

FINISH yang ada di bagian bawah dan kemudian pengguna akan mendapat

notifikasi bahwa order atau pesanannya telah berhasil disimpan. Di halaman

notifikasi tersebut akan dijabarkan lagi data yang tadi diisikan pada form beserta

detail order yaitu nama barang, harga, kuantiti, nilai ongkos kirim, total biaya,

dan keterangan nomor rekening untuk pembeli transfer dana pembayarannya.

3.2. List Kode Pemrograman Aplikasi

3.2.1. List Kode Database

USE [OptimaToys]

GO

/****** Object: Table [dbo].[OngkosKirim] Script Date: 02/11/2014 21:36:15

******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[OngkosKirim](

[OngkirID] [int] IDENTITY(1,1) NOT NULL,

[Destination] [nvarchar](50) NULL,

[Price] [int] NULL,

CONSTRAINT [PK_OngkosKirim] PRIMARY KEY CLUSTERED

(

[OngkirID] ASC

14Universitas Kristen Maranatha

Page 3: 0822002 Chapter3 Andro

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,

IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,

ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET IDENTITY_INSERT [dbo].[OngkosKirim] ON

INSERT [dbo].[OngkosKirim] ([OngkirID], [Destination], [Price]) VALUES (1,

N'Bandung', 5000)

INSERT [dbo].[OngkosKirim] ([OngkirID], [Destination], [Price]) VALUES (2,

N'Jakarta', 10000)

INSERT [dbo].[OngkosKirim] ([OngkirID], [Destination], [Price]) VALUES (3,

N'Semarang', 15000)

INSERT [dbo].[OngkosKirim] ([OngkirID], [Destination], [Price]) VALUES (4,

N'Surabaya', 20000)

SET IDENTITY_INSERT [dbo].[OngkosKirim] OFF

/****** Object: Table [dbo].[Category] Script Date: 02/11/2014 21:36:15 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Category](

[CategoryID] [int] IDENTITY(1,1) NOT NULL,

[CategoryName] [nvarchar](50) NULL,

CONSTRAINT [PK_Category] PRIMARY KEY CLUSTERED

(

[CategoryID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,

IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,

ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET IDENTITY_INSERT [dbo].[Category] ON

15Universitas Kristen Maranatha

Page 4: 0822002 Chapter3 Andro

INSERT [dbo].[Category] ([CategoryID], [CategoryName]) VALUES (1,

N'DABAN - Master Grade 1:100')

INSERT [dbo].[Category] ([CategoryID], [CategoryName]) VALUES (2,

N'HONGLI - Master Grade 1:100')

INSERT [dbo].[Category] ([CategoryID], [CategoryName]) VALUES (3,

N'HONGLI - High Grade 1:100')

INSERT [dbo].[Category] ([CategoryID], [CategoryName]) VALUES (4,

N'HONGLI - High Grade 1:144')

SET IDENTITY_INSERT [dbo].[Category] OFF

/****** Object: Table [dbo].[OrderTable] Script Date: 02/11/2014 21:36:15

******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[OrderTable](

[OrderID] [int] IDENTITY(1,1) NOT NULL,

[Name] [nvarchar](50) NULL,

[Address] [nvarchar](500) NULL,

[OrderDate] [datetime] NULL,

[PhoneNumber] [nchar](12) NULL,

[Email] [nvarchar](50) NULL,

[Status] [int] NULL,

[OngkosKirim] [int] NULL,

CONSTRAINT [PK_OrderTable] PRIMARY KEY CLUSTERED

(

[OrderID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,

IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,

ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

16Universitas Kristen Maranatha

Page 5: 0822002 Chapter3 Andro

SET IDENTITY_INSERT [dbo].[OrderTable] ON

INSERT [dbo].[OrderTable] ([OrderID], [Name], [Address], [OrderDate],

[PhoneNumber], [Email], [Status], [OngkosKirim]) VALUES (2,

N'najajjs', N'shsjsja', CAST(0x0000A2CF01609478 AS DateTime),

N'2134648 ', N'hahaja', 0, NULL)

INSERT [dbo].[OrderTable] ([OrderID], [Name], [Address], [OrderDate],

[PhoneNumber], [Email], [Status], [OngkosKirim]) VALUES (3,

N'jajahabs', N'ahajKajs', CAST(0x0000A2CF01612306 AS DateTime),

N'349494 ', N'gauahahajs', 0, NULL)

INSERT [dbo].[OrderTable] ([OrderID], [Name], [Address], [OrderDate],

[PhoneNumber], [Email], [Status], [OngkosKirim]) VALUES (4,

N'hahaha', N'hahaja', CAST(0x0000A2CF0161CD18 AS DateTime),

N'64646464 ', N'hahaha', 0, NULL)

SET IDENTITY_INSERT [dbo].[OrderTable] OFF

/****** Object: Table [dbo].[Product] Script Date: 02/11/2014 21:36:15 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Product](

[ProductID] [int] IDENTITY(1,1) NOT NULL,

[ProductName] [nvarchar](50) NULL,

[ProductPict] [nvarchar](50) NULL,

[Price] [int] NULL,

[Qty] [int] NULL,

[CategoryID] [int] NULL,

CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED

(

[ProductID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,

IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,

ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

17Universitas Kristen Maranatha

Page 6: 0822002 Chapter3 Andro

) ON [PRIMARY]

GO

SET IDENTITY_INSERT [dbo].[Product] ON

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (1, N'00 Raiser', N'-', 330000, 1, 1)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (2, N'00 Seven Swords', N'-', 300000, 2, 1)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (3, N'Deathscythe EW', N'-', 160000, 5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (4, N'Deathscythe Hell Custom', N'-', 200000, 4,

2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (5, N'Heavyarms EW', N'-', 210000, 4, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (6, N'Astraea', N'-', 130000, 4, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (7, N'Astraea Type F', N'-', 140000, 1, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (8, N'00 Raiser', N'-', 100000, 1, 4)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (9, N'Blu Duel', N'-', 85000, 0, 4)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (10, N'Astray Blue Frame', N'-', 30000, 5, 1)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (11, N'Duel Assault Shroud', N'-', 270000, 5, 1)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (12, N'Rickdom', N'-', 250000, 5, 1)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (13, N'Heavyarms EW', N'-', 210000, 5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (14, N'Sandrock EW', N'-', 180000, 5, 2)

18Universitas Kristen Maranatha

Page 7: 0822002 Chapter3 Andro

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (15, N'Wing EW', N'-', 240000, 5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (16, N'Exia', N'-', 200000, 5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (17, N'Hi-V Gundam', N'-', 350000, 5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (18, N'Infinite Justice', N'-', 240000, 5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (19, N'Strike E + I.W.S.P Lucas', N'-', 240000,

5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (20, N'Shinmusha Sengoku no Jin', N'-', 330000,

5, 2)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (21, N'Exia Trans-Am Mode', N'-', 150000, 5, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (22, N'Akatsuki Gold Fullset', N'-', 240000, 5, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (23, N'Overflag', N'-', 130000, 5, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (24, N'Astray Green Frame', N'-', 85000, 5, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (25, N'00 Seven Swords', N'-', 120000, 5, 3)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (26, N'00 Seven Swords', N'-', 120000, 5, 4)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (27, N'GN-Arms Type E+Exia', N'-', 280000, 5,

4)

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (28, N'GN-Arms Type D+Dynames', N'-',

300000, 5, 4)

19Universitas Kristen Maranatha

Page 8: 0822002 Chapter3 Andro

INSERT [dbo].[Product] ([ProductID], [ProductName], [ProductPict], [Price], [Qty],

[CategoryID]) VALUES (29, N'Arche Gundam ', N'-', 80000, 5, 4)

SET IDENTITY_INSERT [dbo].[Product] OFF

/****** Object: View [dbo].[ProductDetail] Script Date: 02/11/2014 21:36:17

******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE VIEW [dbo].[ProductDetail]

AS

SELECT dbo.Product.*, dbo.Category.CategoryName

FROM dbo.Product INNER JOIN

dbo.Category ON dbo.Product.CategoryID = dbo.Category.CategoryID

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1',

@value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]

Begin DesignProperties =

Begin PaneConfigurations =

Begin PaneConfiguration = 0

NumPanes = 4

Configuration = "(H (1[40] 4[20] 2[20] 3) )"

End

Begin PaneConfiguration = 1

NumPanes = 3

Configuration = "(H (1 [50] 4 [25] 3))"

End

Begin PaneConfiguration = 2

NumPanes = 3

Configuration = "(H (1 [50] 2 [25] 3))"

End

Begin PaneConfiguration = 3

20Universitas Kristen Maranatha

Page 9: 0822002 Chapter3 Andro

NumPanes = 3

Configuration = "(H (4 [30] 2 [40] 3))"

End

Begin PaneConfiguration = 4

NumPanes = 2

Configuration = "(H (1 [56] 3))"

End

Begin PaneConfiguration = 5

NumPanes = 2

Configuration = "(H (2 [66] 3))"

End

Begin PaneConfiguration = 6

NumPanes = 2

Configuration = "(H (4 [50] 3))"

End

Begin PaneConfiguration = 7

NumPanes = 1

Configuration = "(V (3))"

End

Begin PaneConfiguration = 8

NumPanes = 3

Configuration = "(H (1[56] 4[18] 2) )"

End

Begin PaneConfiguration = 9

NumPanes = 2

Configuration = "(H (1 [75] 4))"

End

Begin PaneConfiguration = 10

NumPanes = 2

Configuration = "(H (1[66] 2) )"

End

Begin PaneConfiguration = 11

21Universitas Kristen Maranatha

Page 10: 0822002 Chapter3 Andro

NumPanes = 2

Configuration = "(H (4 [60] 2))"

End

Begin PaneConfiguration = 12

NumPanes = 1

Configuration = "(H (1) )"

End

Begin PaneConfiguration = 13

NumPanes = 1

Configuration = "(V (4))"

End

Begin PaneConfiguration = 14

NumPanes = 1

Configuration = "(V (2))"

End

ActivePaneConfig = 0

End

Begin DiagramPane =

Begin Origin =

Top = 0

Left = 0

End

Begin Tables =

Begin Table = "Product"

Begin Extent =

Top = 6

Left = 237

Bottom = 125

Right = 397

End

DisplayFlags = 280

TopColumn = 0

22Universitas Kristen Maranatha

Page 11: 0822002 Chapter3 Andro

End

Begin Table = "Category"

Begin Extent =

Top = 6

Left = 38

Bottom = 95

Right = 199

End

DisplayFlags = 280

TopColumn = 0

End

End

End

Begin SQLPane =

End

Begin DataPane =

Begin ParameterDefaults = ""

End

Begin ColumnWidths = 9

Width = 284

Width = 1500

Width = 1500

Width = 1500

Width = 1500

Width = 1500

Width = 1500

Width = 1500

Width = 1500

End

End

Begin CriteriaPane =

Begin ColumnWidths = 11

23Universitas Kristen Maranatha

Page 12: 0822002 Chapter3 Andro

Column = 1440

Alias = 900

Table = 1170

Output = 720

Append = 1400

NewValue = 1170

SortType = 1350

SortOrder = 1410

GroupBy = 1350

Filter = 1350

Or = 1350

Or = 1350

Or = 1350

End

End

End

' , @level0type=N'SCHEMA',@level0name=N'dbo',

@level1type=N'VIEW',@level1name=N'ProductDetail'

GO

EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 ,

@level0type=N'SCHEMA',@level0name=N'dbo',

@level1type=N'VIEW',@level1name=N'ProductDetail'

GO

/****** Object: Table [dbo].[OrderDetail] Script Date: 02/11/2014 21:36:15

******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[OrderDetail](

[OrderDetailID] [int] IDENTITY(1,1) NOT NULL,

[OrderID] [int] NULL,

24Universitas Kristen Maranatha

Page 13: 0822002 Chapter3 Andro

[ProductID] [int] NULL,

[Qty] [int] NULL,

[Price] [int] NULL,

CONSTRAINT [PK_OrderDetail] PRIMARY KEY CLUSTERED

(

[OrderDetailID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,

IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,

ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET IDENTITY_INSERT [dbo].[OrderDetail] ON

INSERT [dbo].[OrderDetail] ([OrderDetailID], [OrderID], [ProductID], [Qty],

[Price]) VALUES (1, 2, 1, 1, 330000)

INSERT [dbo].[OrderDetail] ([OrderDetailID], [OrderID], [ProductID], [Qty],

[Price]) VALUES (2, 3, 1, 1, 330000)

INSERT [dbo].[OrderDetail] ([OrderDetailID], [OrderID], [ProductID], [Qty],

[Price]) VALUES (3, 4, 1, 1, 330000)

SET IDENTITY_INSERT [dbo].[OrderDetail] OFF

/****** Object: ForeignKey [FK_OrderDetail_OrderTable] Script Date:

02/11/2014 21:36:15 ******/

ALTER TABLE [dbo].[OrderDetail] WITH CHECK ADD CONSTRAINT

[FK_OrderDetail_OrderTable] FOREIGN KEY([OrderID])

REFERENCES [dbo].[OrderTable] ([OrderID])

GO

ALTER TABLE [dbo].[OrderDetail] CHECK CONSTRAINT

[FK_OrderDetail_OrderTable]

GO

/****** Object: ForeignKey [FK_OrderDetail_Product] Script Date: 02/11/2014

21:36:15 ******/

ALTER TABLE [dbo].[OrderDetail] WITH CHECK ADD CONSTRAINT

[FK_OrderDetail_Product] FOREIGN KEY([ProductID])

25Universitas Kristen Maranatha

Page 14: 0822002 Chapter3 Andro

REFERENCES [dbo].[Product] ([ProductID])

GO

ALTER TABLE [dbo].[OrderDetail] CHECK CONSTRAINT

[FK_OrderDetail_Product]

GO

/****** Object: ForeignKey [FK_Product_Category] Script Date: 02/11/2014

21:36:15 ******/

ALTER TABLE [dbo].[Product] WITH CHECK ADD CONSTRAINT

[FK_Product_Category] FOREIGN KEY([CategoryID])

REFERENCES [dbo].[Category] ([CategoryID])

GO

ALTER TABLE [dbo].[Product] CHECK CONSTRAINT [FK_Product_Category]

GO

3.2.2. List Kode Eclipse

1. CategoryActivity.java

package com.optimatoys;

import java.util.ArrayList;

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ListView;

import com.adapter.CategoryListAdapter;

import com.pojo.Category;

26Universitas Kristen Maranatha

Page 15: 0822002 Chapter3 Andro

import com.retrievedata.CallService;

public class CategoryActivity extends Activity {

ListView lv_category;

CallService callws = new CallService();

ArrayList<Category> listcontent;

CategoryListAdapter adapter;

Intent intent;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.categorylayout);

lv_category = (ListView)

findViewById(R.id.listViewCategory);

lv_category

.setOnItemClickListener(new

AdapterView.OnItemClickListener() {

public void

onItemClick(AdapterView<?> parent, View view,

int position, long

id) {

// TODO Auto-generated

method stub

Category item =

(Category) lv_category

27Universitas Kristen Maranatha

Page 16: 0822002 Chapter3 Andro

.getItemAtPosition(position);

intent = new

Intent(getApplicationContext(),

ProductListActivity.class);

intent.putExtra("categoryid", item.get_categoryid()

+ "");

startActivity(intent);

}

});

new loadContent().execute();

}

private class loadContent extends

AsyncTask<String, Void,

ArrayList<Category>> {

private ProgressDialog dialog = new ProgressDialog(

CategoryActivity.this);

@Override

protected void onPostExecute(ArrayList<Category>

result) {

super.onPostExecute(result);

if (dialog.isShowing()) {

dialog.dismiss();

}

// listview category

28Universitas Kristen Maranatha

Page 17: 0822002 Chapter3 Andro

adapter = new

CategoryListAdapter(CategoryActivity.this,

listcontent);

lv_category.setAdapter(adapter);

}

@Override

protected void onPreExecute() {

dialog.setMessage("loading...");

dialog.setCanceledOnTouchOutside(false);

dialog.show();

super.onPreExecute();

}

@Override

protected ArrayList<Category>

doInBackground(String... params) {

listcontent = callws.getAllCategory();

return listcontent;

}

}

}

2. ProductListActivity.java

package com.optimatoys;

import java.util.ArrayList;

import android.app.Activity;

29Universitas Kristen Maranatha

Page 18: 0822002 Chapter3 Andro

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;

import android.widget.ListView;

import com.adapter.ProductListAdapter;

import com.pojo.Category;

import com.pojo.Product;

import com.retrievedata.CallService;

public class ProductListActivity extends Activity {

ListView lv_category;

CallService callws = new CallService();

ArrayList<Product> listcontent;

ProductListAdapter adapter;

Intent intent;

int categoryid;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.listproductlayout);

lv_category = (ListView)

findViewById(R.id.lv_product);

lv_category

.setOnItemClickListener(new

AdapterView.OnItemClickListener() {

30Universitas Kristen Maranatha

Page 19: 0822002 Chapter3 Andro

public void

onItemClick(AdapterView<?> parent, View view,

int position, long

id) {

// TODO Auto-generated

method stub

Product item = (Product)

lv_category

.getItemAtPosition(position);

intent = new

Intent(getApplicationContext(),

ProductDetailActivity.class);

intent.putExtra("productid", item.get_productid() + "");

startActivity(intent);

}

});

categoryid =

Integer.parseInt(getIntent().getStringExtra("categoryid"));

new loadContent().execute();

}

private class loadContent extends

AsyncTask<String, Void, ArrayList<Product>>

{

private ProgressDialog dialog = new ProgressDialog(

ProductListActivity.this);

31Universitas Kristen Maranatha

Page 20: 0822002 Chapter3 Andro

@Override

protected void onPostExecute(ArrayList<Product>

result) {

super.onPostExecute(result);

if (dialog.isShowing()) {

dialog.dismiss();

}

// listview category

adapter = new

ProductListAdapter(ProductListActivity.this,

listcontent);

lv_category.setAdapter(adapter);

}

@Override

protected void onPreExecute() {

dialog.setMessage("loading...");

dialog.setCanceledOnTouchOutside(false);

dialog.show();

super.onPreExecute();

}

@Override

protected ArrayList<Product>

doInBackground(String... params) {

listcontent =

callws.getproductbycategory(categoryid);

return listcontent;

}

32Universitas Kristen Maranatha

Page 21: 0822002 Chapter3 Andro

}

}

3. ProductDetailActivity.java

package com.optimatoys;

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.TextView;

import com.pojo.Product;

import com.retrievedata.CallService;

public class ProductDetailActivity extends Activity {

TextView tv_categoryname, tv_productname, tv_price, tv_qty;

ImageView img_product;

Button bt_buy;

CallService callws = new CallService();

Product product = new Product();

int productid;

@Override

protected void onCreate(Bundle savedInstanceState) {

33Universitas Kristen Maranatha

Page 22: 0822002 Chapter3 Andro

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.productdetaillayout);

productid =

Integer.parseInt(getIntent().getStringExtra("productid"));

tv_categoryname = (TextView)

findViewById(R.id.tv_categoryname);

tv_productname = (TextView)

findViewById(R.id.tv_productname);

tv_price = (TextView) findViewById(R.id.tv_price);

tv_qty = (TextView) findViewById(R.id.tv_stock);

img_product = (ImageView)

findViewById(R.id.img_product);

bt_buy = (Button) findViewById(R.id.bt_addtocart);

bt_buy.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

Intent intent = new

Intent(getApplicationContext(), CompleteOrder.class);

intent.putExtra("productname",

product.get_productname());

intent.putExtra("productid",

productid+"");

intent.putExtra("productprice",

product.get_productprice()+"");

startActivity(intent);

}

});

new loadContent().execute();

34Universitas Kristen Maranatha

Page 23: 0822002 Chapter3 Andro

}

private class loadContent extends AsyncTask<String, Void,

Product> {

private ProgressDialog dialog = new ProgressDialog(

ProductDetailActivity.this);

@Override

protected void onPostExecute(Product result) {

super.onPostExecute(result);

if (dialog.isShowing()) {

dialog.dismiss();

}

// listview category

tv_categoryname.setText(result.get_categoryname());

tv_price.setText("IDR" +

result.get_productprice() + "");

tv_productname.setText(result.get_productname());

tv_qty.setText("Stock : " + result.get_qty() +

"");

if (result.get_qty() == 0) {

bt_buy.setEnabled(false);

}

}

@Override

35Universitas Kristen Maranatha

Page 24: 0822002 Chapter3 Andro

protected void onPreExecute() {

dialog.setMessage("loading...");

dialog.setCanceledOnTouchOutside(false);

dialog.show();

super.onPreExecute();

}

@Override

protected Product doInBackground(String... params) {

product = callws.getcontent(productid);

return product;

}

}

}

4. MainActivity.java

package com.optimatoys;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;

import android.view.Menu;

public class MainActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

36Universitas Kristen Maranatha

Page 25: 0822002 Chapter3 Andro

new Handler().postDelayed(new Runnable() {

public void run() {

Intent gointent = new Intent(MainActivity.this,

CategoryActivity.class);

MainActivity.this.startActivity(gointent);

MainActivity.this.finish();

}

}, 2000);

}

5. CompleteOrderActivity.java

package com.optimatoys;

import java.util.ArrayList;

import android.app.Activity;

import android.app.ProgressDialog;

import android.content.Intent;

import android.os.AsyncTask;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.ArrayAdapter;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Spinner;

import android.widget.Toast;

import com.pojo.Ongkir;

import com.retrievedata.CallService;

37Universitas Kristen Maranatha

Page 26: 0822002 Chapter3 Andro

public class CompleteOrder extends Activity {

Spinner sp_ongkir;

EditText tb_nama, tb_email, tb_telepon, tb_alamat;

Button bt_finish;

String productname, productid, productprice;

ArrayAdapter<String> adapterspinner;

String[] cityvalue;

CallService callws = new CallService();

ArrayList<Ongkir> listongkir = new ArrayList<Ongkir>();

int ongkir = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.completeorderlayout);

sp_ongkir = (Spinner)

findViewById(R.id.spinner_kota);

tb_alamat = (EditText) findViewById(R.id.tb_alamat);

tb_email = (EditText) findViewById(R.id.tb_email);

tb_nama = (EditText) findViewById(R.id.tb_nama);

tb_telepon = (EditText)

findViewById(R.id.tb_telepon);

bt_finish = (Button) findViewById(R.id.bt_finish);

bt_finish.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

if (tb_alamat.getText().length() == 0

38Universitas Kristen Maranatha

Page 27: 0822002 Chapter3 Andro

||

tb_email.getText().length() == 0

||

tb_nama.getText().length() == 0

||

tb_telepon.getText().length() == 0) {

Toast.makeText(getApplicationContext(),

"Semua field

harus diisi", Toast.LENGTH_LONG)

.show();

} else {

new saveorder().execute();

}

}

});

productid = getIntent().getStringExtra("productid");

productname =

getIntent().getStringExtra("productname");

productprice =

getIntent().getStringExtra("productprice");

getActionBar().setTitle("Complete Order");

new categoryData().execute();

}

private class categoryData extends AsyncTask<String, Void,

Integer> {

private ProgressDialog dialog = new

ProgressDialog(CompleteOrder.this);

@Override

39Universitas Kristen Maranatha

Page 28: 0822002 Chapter3 Andro

protected void onPostExecute(Integer result) {

super.onPostExecute(result);

if (dialog.isShowing()) {

dialog.dismiss();

}

// spinner university

adapterspinner = new

ArrayAdapter<String>(CompleteOrder.this,

android.R.layout.simple_spinner_item, cityvalue);

adapterspinner

.setDropDownViewResource(android.R.layout.simple_spinner

_dropdown_item);

sp_ongkir.setAdapter(adapterspinner);

}

@Override

protected void onPreExecute() {

dialog.setMessage("Loading...");

dialog.setCanceledOnTouchOutside(false);

dialog.show();

super.onPreExecute();

}

@Override

protected Integer doInBackground(String... params) {

listongkir = callws.getongkir();

cityvalue = new

String[callws.getongkir().size()];

40Universitas Kristen Maranatha

Page 29: 0822002 Chapter3 Andro

for (int i = 0; i < callws.getongkir().size(); i++)

{

cityvalue[i] =

callws.getongkir().get(i).get_city().toString();

}

return 1;

}

}

private class saveorder extends AsyncTask<String, Void,

Integer> {

private ProgressDialog dialog = new

ProgressDialog(CompleteOrder.this);

@Override

protected void onPostExecute(Integer result) {

super.onPostExecute(result);

if (dialog.isShowing()) {

dialog.dismiss();

}

if (result == 0) {

Toast.makeText(CompleteOrder.this,

"Gagal menyimpan

order. Terjadi kesalahan.",

Toast.LENGTH_LONG).show();

} else {

Toast.makeText(CompleteOrder.this,

"Berhasil menyimpan order.",

41Universitas Kristen Maranatha

Page 30: 0822002 Chapter3 Andro

Toast.LENGTH_LONG).show();

Intent intent = new

Intent(CompleteOrder.this,

EndOrderActivity.class);

intent.putExtra("nama",

tb_nama.getText().toString());

intent.putExtra("alamat",

tb_alamat.getText().toString());

intent.putExtra("telepon",

tb_telepon.getText().toString());

intent.putExtra("email",

tb_email.getText().toString());

intent.putExtra("ongkir", ongkir + "");

intent.putExtra("productname",

productname);

intent.putExtra("productprice",

productprice + "");

startActivity(intent);

}

}

@Override

protected void onPreExecute() {

dialog.setMessage("Loading...");

dialog.setCanceledOnTouchOutside(false);

dialog.show();

super.onPreExecute();

}

42Universitas Kristen Maranatha

Page 31: 0822002 Chapter3 Andro

6. EndOrderActivity.java

package com.optimatoys;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class EndOrderActivity extends Activity {

TextView tv_nama, tv_alamat, tv_email, tv_notelepon,

tv_detail;

@Override

protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(R.layout.endorderlayout);

tv_nama = (TextView) findViewById(R.id.tv_nama);

tv_alamat = (TextView)

findViewById(R.id.tv_alamat);

tv_detail = (TextView) findViewById(R.id.tv_detail);

tv_email = (TextView) findViewById(R.id.tv_email);

tv_notelepon = (TextView)

findViewById(R.id.tv_telp);

tv_nama.setText("Nama :

"+getIntent().getStringExtra("nama"));

tv_alamat.setText("Alamat :

"+getIntent().getStringExtra("alamat"));

tv_email.setText("Email :

"+getIntent().getStringExtra("email"));

43Universitas Kristen Maranatha

Page 32: 0822002 Chapter3 Andro

tv_notelepon.setText("Telepon :

"+getIntent().getStringExtra("telepon"));

String detail = "Produk : "

+

getIntent().getStringExtra("productname")

+ "\n"

+ "Harga : IDR"

+

getIntent().getStringExtra("productprice")

+ "\n"

+ "Qty : 1\n"

+ "Ongkos Kirim : IDR"

+ getIntent().getStringExtra("ongkir")

+ "\n"

+ "Total : IDR"

+

(Integer.parseInt(getIntent().getStringExtra("productprice")) + Integer

.parseInt(getIntent().getStringExtra("ongkir")))

+ "\nBiaya dikirim ke BCA 123456789

An Irwan";

tv_detail.setText(detail);

}

}

44Universitas Kristen Maranatha