diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..27f4372
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ant.properties b/ant.properties
new file mode 100644
index 0000000..b0971e8
--- /dev/null
+++ b/ant.properties
@@ -0,0 +1,17 @@
+# This file is used to override default values used by the Ant build system.
+#
+# This file must be checked into Version Control Systems, as it is
+# integral to the build system of your project.
+
+# This file is only used by the Ant script.
+
+# You can use this to override default values such as
+# 'source.dir' for the location of your java source folder and
+# 'out.dir' for the location of your output folder.
+
+# You can also use it define how the release builds are signed by declaring
+# the following properties:
+# 'key.store' for the location of your keystore and
+# 'key.alias' for the name of the key to use.
+# The password will be asked during the build when you use the 'release' target.
+
diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..2b3e131
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,92 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/exam2.apk b/exam2.apk
new file mode 100644
index 0000000..67a0fba
Binary files /dev/null and b/exam2.apk differ
diff --git a/proguard-project.txt b/proguard-project.txt
new file mode 100644
index 0000000..f2fe155
--- /dev/null
+++ b/proguard-project.txt
@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# 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 *;
+#}
diff --git a/project.properties b/project.properties
new file mode 100644
index 0000000..ce39f2d
--- /dev/null
+++ b/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-18
diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 0000000..96a442e
Binary files /dev/null and b/res/drawable-hdpi/ic_launcher.png differ
diff --git a/res/drawable-ldpi/ic_launcher.png b/res/drawable-ldpi/ic_launcher.png
new file mode 100644
index 0000000..9923872
Binary files /dev/null and b/res/drawable-ldpi/ic_launcher.png differ
diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 0000000..359047d
Binary files /dev/null and b/res/drawable-mdpi/ic_launcher.png differ
diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..71c6d76
Binary files /dev/null and b/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/res/layout/about_pizza.xml b/res/layout/about_pizza.xml
new file mode 100644
index 0000000..5a76585
--- /dev/null
+++ b/res/layout/about_pizza.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/adapter.xml b/res/layout/adapter.xml
new file mode 100644
index 0000000..6f4d148
--- /dev/null
+++ b/res/layout/adapter.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/add_pizza_activity.xml b/res/layout/add_pizza_activity.xml
new file mode 100644
index 0000000..1acce8f
--- /dev/null
+++ b/res/layout/add_pizza_activity.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/layout/main.xml b/res/layout/main.xml
new file mode 100644
index 0000000..180bda0
--- /dev/null
+++ b/res/layout/main.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
diff --git a/res/layout/pizzas_list.xml b/res/layout/pizzas_list.xml
new file mode 100644
index 0000000..0473140
--- /dev/null
+++ b/res/layout/pizzas_list.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..9ef485c
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,26 @@
+
+
+ Pizza manager
+ Введите название пицерии
+ пицца вкусная
+ Введите количество курьеров
+ 3
+ Ок
+ Введите тип пиццы
+ Введите телефон
+ Время
+ Тип пиццы
+ Номер телефона
+ Доставляет курьер
+ Время доставки
+ Удалить
+ Время необходимое для доставки
+ Время необходимое для доставки
+ Начало доставки
+
+
+ - 0:30
+
+
+
+
diff --git a/src/com/alimantu/exam2/AboutPizza.java b/src/com/alimantu/exam2/AboutPizza.java
new file mode 100644
index 0000000..ba607c6
--- /dev/null
+++ b/src/com/alimantu/exam2/AboutPizza.java
@@ -0,0 +1,32 @@
+package com.alimantu.exam2;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.TextView;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:55
+ * To change this template use File | Settings | File Templates.
+ */
+public class AboutPizza extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState); //To change body of overridden methods use File | Settings | File Templates.
+ setContentView(R.layout.about_pizza);
+ Intent intent = getIntent();
+ Pizza pizza = (Pizza) intent.getSerializableExtra("result");
+ TextView textView = (TextView) findViewById(R.id.textView);
+ TextView textView1 = (TextView) findViewById(R.id.textView1);
+ TextView textView2 = (TextView) findViewById(R.id.textView2);
+ TextView textView3 = (TextView) findViewById(R.id.textView3);
+
+ textView.setText(pizza.getPizzaType());
+ textView1.setText(pizza.getTelNumber());
+ textView2.setText(pizza.getDeliver());
+ textView3.setText(pizza.getTime());
+ }
+}
diff --git a/src/com/alimantu/exam2/AddPizzaActivity.java b/src/com/alimantu/exam2/AddPizzaActivity.java
new file mode 100644
index 0000000..d366a95
--- /dev/null
+++ b/src/com/alimantu/exam2/AddPizzaActivity.java
@@ -0,0 +1,142 @@
+package com.alimantu.exam2;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:44
+ * To change this template use File | Settings | File Templates.
+ */
+public class AddPizzaActivity extends Activity {
+
+ private EditText editText1, editText2;
+ private Pizza pizza = new Pizza();
+ private PizzaType database;
+ private Spinner spinner, spinner1;
+ private Button button;
+ private String current_time;
+ int firstNotBusyWindows = -1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.add_pizza_activity);
+
+ editText1 = (EditText) findViewById(R.id.editTextAdd1);
+ editText2 = (EditText) findViewById(R.id.editTextAdd2);
+ button = (Button) findViewById(R.id.button);
+ spinner = (Spinner) findViewById(R.id.spinner);
+ spinner.setEnabled(false);
+ spinner1 = (Spinner) findViewById(R.id.spinner1);
+
+ spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
+ current_time = String.valueOf(spinner.getSelectedItem());
+
+ spinner.setEnabled(true);
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> adapterView) {
+ }
+ });
+
+
+ List list = new ArrayList();
+ for (int i = 8; i < 22; i++) {
+ String value = null;
+ if (i < 10)
+ value = "0" + String.valueOf(i) + ":00";
+ else
+ value = String.valueOf(i) + ":00";
+ String halfValue = null;
+ if (i < 10)
+ halfValue = "0" + String.valueOf(i) + ":30";
+ else
+ halfValue = String.valueOf(i) + ":30";
+ boolean ok = false;
+ for (int j = 1; j <= MyActivity.delivers_count; j++)
+ if (free(String.valueOf(j), value))
+ ok = true;
+ if (ok)
+ list.add(value);
+
+ for (int j = 1; j <= MyActivity.delivers_count; j++)
+ if (free(String.valueOf(j), halfValue))
+ ok = true;
+ if (ok)
+ list.add(halfValue);
+ }
+ if (list.isEmpty()) {
+ Toast toast = Toast.makeText(getApplicationContext(),
+ "Извините, всё время занято!",
+ Toast.LENGTH_SHORT);
+ toast.setGravity(Gravity.CENTER, 0, 0);
+ button.setEnabled(false);
+ toast.show();
+ }
+ ArrayAdapter dataAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, list);
+ dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(dataAdapter);
+ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
+ String current = String.valueOf(spinner.getSelectedItem());
+ for (int j = 1; j <= MyActivity.delivers_count; j++)
+ if (free(String.valueOf(j), current)) {
+ pizza.setDeliver(String.valueOf(j));
+ break;
+ }
+
+ pizza.setTime(String.valueOf(spinner.getSelectedItem()));
+
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView> adapterView) {
+ }
+ });
+
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ pizza.setPizzaType(editText1.getText().toString());
+ pizza.setTelNumber(editText2.getText().toString());
+ if (!pizza.getDeliver().equals("") &&
+ !pizza.getTime().equals("") &&
+ !pizza.getPizzaType().equals("") &&
+ !pizza.getTelNumber().equals("")) {
+
+ button.setEnabled(true);
+ database = new PizzaType(view.getContext());
+ database.open();
+ database.addChannel(pizza);
+ database.close();
+ Intent intent = new Intent(view.getContext(), PizzaList.class);
+ intent.putExtra("name", MyActivity.name);
+ startActivity(intent);
+ }
+ }
+ });
+ }
+
+ private boolean free(String s, String time) {
+ for (Pizza pizza : PizzaList.pizzas) {
+ if (pizza.getDeliver().equals(s) && pizza.getTime().equals(time))
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/alimantu/exam2/DBHelper.java b/src/com/alimantu/exam2/DBHelper.java
new file mode 100644
index 0000000..9375bcb
--- /dev/null
+++ b/src/com/alimantu/exam2/DBHelper.java
@@ -0,0 +1,31 @@
+package com.alimantu.exam2;
+
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteOpenHelper;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:04
+ * To change this template use File | Settings | File Templates.
+ */
+public class DBHelper extends SQLiteOpenHelper{
+
+ public DBHelper(Context context, String dbName, Object o, int dbVersion) {
+ super(context, dbName, (SQLiteDatabase.CursorFactory) o, dbVersion);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase sqLiteDatabase) {
+ sqLiteDatabase.execSQL(PizzaDataBase.DB_CREATE);
+ sqLiteDatabase.execSQL(PizzaType.DB_CREATE);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
+
+ }
+
+}
diff --git a/src/com/alimantu/exam2/MyActivity.java b/src/com/alimantu/exam2/MyActivity.java
new file mode 100644
index 0000000..1b0cc55
--- /dev/null
+++ b/src/com/alimantu/exam2/MyActivity.java
@@ -0,0 +1,68 @@
+package com.alimantu.exam2;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+
+import java.util.ArrayList;
+
+public class MyActivity extends Activity {
+ /**
+ * Called when the activity is first created.
+ */
+
+ private PizzaDataBase database;
+ public static int delivers_count;
+ public static String name;
+ private Button button;
+ private EditText editText1, editText2;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+
+ database = new PizzaDataBase(this);
+ database.open();
+
+ ArrayList pizzaDeliveries = database.getAll();
+ if(!pizzaDeliveries.isEmpty())
+ {
+ Intent intent = new Intent(this, PizzaList.class);
+ intent.putExtra("name",pizzaDeliveries.get(0).getName());
+ delivers_count = pizzaDeliveries.get(0).getNumber();
+ name = pizzaDeliveries.get(0).getName();
+ startActivity(intent);
+ finish();
+ }
+
+ button = (Button) findViewById(R.id.OK);
+ editText1 = (EditText) findViewById(R.id.editText1);
+ editText2 = (EditText) findViewById(R.id.editText2);
+
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String name = editText1.getText().toString();
+ String number = editText2.getText().toString();
+ database.addChannel(name, number);
+ Intent intent = new Intent(view.getContext(), PizzaList.class);
+ intent.putExtra("name", name);
+ name = name;
+ delivers_count = Integer.parseInt(number);
+ startActivity(intent);
+ finish();
+ }
+ });
+
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ database.close();
+ }
+}
diff --git a/src/com/alimantu/exam2/Pizza.java b/src/com/alimantu/exam2/Pizza.java
new file mode 100644
index 0000000..6353230
--- /dev/null
+++ b/src/com/alimantu/exam2/Pizza.java
@@ -0,0 +1,63 @@
+package com.alimantu.exam2;
+
+import java.io.Serializable;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:10
+ * To change this template use File | Settings | File Templates.
+ */
+public class Pizza implements Serializable {
+
+ private String pizzaType;
+ private String time;
+ private String deliver;
+ private String telNumber;
+
+ public Pizza() {
+ }
+
+ public String getPizzaType() {
+ return pizzaType;
+ }
+
+ public void setPizzaType(String pizzaType) {
+ this.pizzaType = pizzaType;
+ }
+
+ public String getTime() {
+ return time;
+ }
+
+ public void setTime(String time) {
+ this.time = time;
+
+ }
+
+ public String getDeliver() {
+ return deliver;
+ }
+
+ public String getTelNumber() {
+ return telNumber;
+ }
+
+ public void setTelNumber(String telNumber) {
+ this.telNumber = telNumber;
+ }
+
+ public void setDeliver(String deliver) {
+ this.deliver = deliver;
+ }
+
+ public Pizza(String pizzaType, String time, String deliver) {
+
+ this.pizzaType = pizzaType;
+ this.time = time;
+ this.deliver = deliver;
+ }
+
+
+}
diff --git a/src/com/alimantu/exam2/PizzaDataBase.java b/src/com/alimantu/exam2/PizzaDataBase.java
new file mode 100644
index 0000000..8e26b8c
--- /dev/null
+++ b/src/com/alimantu/exam2/PizzaDataBase.java
@@ -0,0 +1,78 @@
+package com.alimantu.exam2;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import java.util.ArrayList;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 14:59
+ * To change this template use File | Settings | File Templates.
+ */
+public class PizzaDataBase {
+
+ private static final String DB_NAME = "pizza_delivery";
+ private static final int DB_VERSION = 1;
+ private static final String DB_TABLE = "information";
+ public static final String COLUMN_ID = "_id";
+ public static final String COLUMN_TITLE = "name";
+ public static final String COLUMN_NUMBER = "number";
+
+ public static final String DB_CREATE =
+ "create table " + DB_TABLE + "(" +
+ COLUMN_ID + " integer primary key autoincrement, " +
+ COLUMN_TITLE + " text, " +
+ COLUMN_NUMBER + " text" +
+ ");";
+
+ private final Context context;
+ private DBHelper dbHelper;
+ private SQLiteDatabase mDB;
+
+ public PizzaDataBase(Context context) {
+ this.context = context;
+ }
+
+ public void open() {
+ dbHelper = new DBHelper(context, DB_NAME, null, DB_VERSION);
+ mDB = dbHelper.getWritableDatabase();
+ }
+
+ public void close() {
+ if (dbHelper != null) dbHelper.close();
+ }
+
+
+ public Cursor getAllData() {
+ return mDB.query(DB_TABLE, null, null, null, null, null, null);
+ }
+
+ public ArrayList getAll() {
+ Cursor cursor = getAllData();
+ ArrayList result = new ArrayList();
+ while (cursor.moveToNext()) {
+ PizzaDelivery current = new PizzaDelivery();
+ current.setName(cursor.getString(cursor.getColumnIndex(COLUMN_TITLE)));
+ current.setNumber(cursor.getInt(cursor.getColumnIndex(COLUMN_NUMBER)));
+ result.add(current);
+ }
+ return result;
+ }
+
+ public void addChannel(String name, String number) {
+ ContentValues cv = new ContentValues();
+ cv.put(COLUMN_TITLE, name);
+ cv.put(COLUMN_NUMBER, number);
+ mDB.insert(DB_TABLE, null, cv);
+ }
+
+ public void deleteChannel(long id) {
+ mDB.delete(DB_TABLE, COLUMN_ID + " = " + id, null);
+ }
+
+}
diff --git a/src/com/alimantu/exam2/PizzaDelivery.java b/src/com/alimantu/exam2/PizzaDelivery.java
new file mode 100644
index 0000000..6a3116a
--- /dev/null
+++ b/src/com/alimantu/exam2/PizzaDelivery.java
@@ -0,0 +1,37 @@
+package com.alimantu.exam2;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:22
+ * To change this template use File | Settings | File Templates.
+ */
+public class PizzaDelivery {
+ private String name;
+ private int number;
+
+ public PizzaDelivery() {
+ }
+
+ public PizzaDelivery(String name, int number) {
+ this.name = name;
+ this.number = number;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+}
diff --git a/src/com/alimantu/exam2/PizzaList.java b/src/com/alimantu/exam2/PizzaList.java
new file mode 100644
index 0000000..b9a4c13
--- /dev/null
+++ b/src/com/alimantu/exam2/PizzaList.java
@@ -0,0 +1,119 @@
+package com.alimantu.exam2;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.database.Cursor;
+import android.os.Bundle;
+import android.view.ContextMenu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.*;
+
+import java.util.ArrayList;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:31
+ * To change this template use File | Settings | File Templates.
+ */
+public class PizzaList extends Activity {
+
+ public static final int DELETE = 0;
+
+ private TextView textView;
+ private ListView listView;
+ private Cursor cursor;
+ private SimpleCursorAdapter adapter;
+ private PizzaType database;
+ private Button button;
+ static ArrayList pizzas;
+
+ @SuppressWarnings("deprecation")
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState); //To change body of overridden methods use File | Settings | File Templates.
+ setContentView(R.layout.pizzas_list);
+
+ Intent intent = getIntent();
+ String name = intent.getStringExtra("name");
+ textView = (TextView) findViewById(R.id.pizzaType);
+ textView.setText(name);
+ listView = (ListView) findViewById(R.id.listView);
+ button = (Button) findViewById(R.id.addButton);
+
+ database = new PizzaType(this);
+ database.open();
+
+ cursor = database.getAllData();
+ pizzas = database.getAll();
+ startManagingCursor(cursor);
+
+ String[] from = new String[]{
+ PizzaType.COLUMN_PIZZA,
+ PizzaType.COLUMN_DELIVER,
+ PizzaType.COLUMN_TIME
+ };
+
+ int[] to = new int[]{
+ R.id.pizzaTypeName,
+ R.id.pizzaDeliver,
+ R.id.pizzaTime
+ };
+
+ adapter = new SimpleCursorAdapter(this, R.layout.adapter, cursor, from, to);
+ listView.setAdapter(adapter);
+
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Intent nextIntent = new Intent(view.getContext(), AddPizzaActivity.class);
+ startActivity(nextIntent);
+ }
+ });
+
+ registerForContextMenu(listView);
+ listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
+ String name = ((TextView) view.findViewById(R.id.pizzaTypeName)).getText().toString();
+ PizzaType pizzaType = new PizzaType(view.getContext());
+ pizzaType.open();
+ Pizza result = pizzaType.selectPizzas(name);
+ Intent currentIntent = new Intent(view.getContext(), AboutPizza.class);
+ currentIntent.putExtra("result", result);
+ startActivity(currentIntent);
+ }
+
+ });
+ }
+
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo); //To change body of overridden methods use File | Settings | File Templates.
+ menu.add(0, DELETE, 0, getString(R.string.delete_pizza));
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ if (DELETE == item.getItemId()) {
+ AdapterView.AdapterContextMenuInfo adapterContextMenuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
+ database.deleteChannel((int) adapterContextMenuInfo.id);
+
+ PizzaType database1 = new PizzaType(this);
+ database1.open();
+ database1.deleteChannel(adapterContextMenuInfo.id);
+
+ cursor.requery();
+ pizzas = database1.getAll();
+
+ database1.close();
+ return true;
+ }
+
+ return super.onContextItemSelected(item);
+ }
+
+}
diff --git a/src/com/alimantu/exam2/PizzaType.java b/src/com/alimantu/exam2/PizzaType.java
new file mode 100644
index 0000000..7a922b9
--- /dev/null
+++ b/src/com/alimantu/exam2/PizzaType.java
@@ -0,0 +1,96 @@
+package com.alimantu.exam2;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import java.util.ArrayList;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: PWR
+ * Date: 21.01.14
+ * Time: 15:05
+ * To change this template use File | Settings | File Templates.
+ */
+public class PizzaType {
+
+ private static final String DB_NAME = "pizzadelivery1";
+ private static final int DB_VERSION = 1;
+ private static final String DB_TABLE = "schedule1";
+
+ public static final String COLUMN_ID = "_id";
+ public static final String COLUMN_PIZZA = "pizzatype";
+ public static final String COLUMN_TEL_NUMB = "telnumb";
+ public static final String COLUMN_TIME = "time";
+ public static final String COLUMN_DELIVER = "deliver";
+
+ public static final String DB_CREATE =
+ "create table " + DB_TABLE + "(" +
+ COLUMN_ID + " integer primary key autoincrement, " +
+ COLUMN_PIZZA + " text, " +
+ COLUMN_TEL_NUMB + " text, " +
+ COLUMN_TIME + " text, " +
+ COLUMN_DELIVER + " text" +
+ ");";
+
+ private final Context context;
+
+ private DBHelper dbHelper;
+ private SQLiteDatabase mDB;
+
+ public PizzaType(Context context) {
+ this.context = context;
+ }
+
+ public void open() {
+ dbHelper = new DBHelper(context, DB_NAME, null, DB_VERSION);
+ mDB = dbHelper.getWritableDatabase();
+ }
+
+ public void close() {
+ if (dbHelper != null) dbHelper.close();
+ }
+
+
+ public Cursor getAllData() {
+ return mDB.query(DB_TABLE, null, null, null, null, null, COLUMN_TIME);
+ }
+
+ public void addChannel(Pizza pizza) {
+ ContentValues cv = new ContentValues();
+ cv.put(COLUMN_PIZZA, pizza.getPizzaType());
+ cv.put(COLUMN_TIME, pizza.getTime());
+ cv.put(COLUMN_TEL_NUMB, pizza.getTelNumber());
+ cv.put(COLUMN_DELIVER, pizza.getDeliver());
+ mDB.insert(DB_TABLE, null, cv);
+ }
+
+ public void deleteChannel(long id) {
+ mDB.delete(DB_TABLE, COLUMN_ID + " = " + id, null);
+ }
+
+ public ArrayList getAll() {
+ Cursor cursor = getAllData();
+ ArrayList result = new ArrayList();
+ while (cursor.moveToNext()) {
+ Pizza current = new Pizza();
+ current.setPizzaType(cursor.getString(cursor.getColumnIndex(COLUMN_PIZZA)));
+ current.setTime(cursor.getString(cursor.getColumnIndex(COLUMN_TIME)));
+ current.setTelNumber(cursor.getString(cursor.getColumnIndex(COLUMN_TEL_NUMB)));
+ current.setDeliver(cursor.getString(cursor.getColumnIndex(COLUMN_DELIVER)));
+ result.add(current);
+ }
+ return result;
+ }
+
+ public Pizza selectPizzas(String name) {
+ ArrayList pizzas = getAll();
+ for (int i = 0; i < pizzas.size(); i++)
+ if (pizzas.get(i).getPizzaType().equals(name))
+ return pizzas.get(i);
+ return null;
+ }
+
+}