From 789e7fd68d1faf24f254a384a84f6ff3504cc644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Alcalde?= Date: Sat, 25 Oct 2014 15:47:26 +0200 Subject: [PATCH 1/2] =?UTF-8?q?A=C3=B1adido=20ticket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 5 + .../java/worten/aebd/com/worten/Carro.java | 4 + .../java/worten/aebd/com/worten/Compra.java | 7 +- .../java/worten/aebd/com/worten/Ticket.java | 250 ++++++++++++++++++ app/src/main/res/drawable-mdpi/im_qr.png | Bin 0 -> 2134 bytes app/src/main/res/layout/activity_ticket.xml | 77 ++++++ 6 files changed, 340 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/worten/aebd/com/worten/Ticket.java create mode 100644 app/src/main/res/drawable-mdpi/im_qr.png create mode 100644 app/src/main/res/layout/activity_ticket.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9c9079f..44cde20 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -31,6 +31,11 @@ android:name=".User" android:label="Worten - Perfil" > + + + diff --git a/app/src/main/java/worten/aebd/com/worten/Carro.java b/app/src/main/java/worten/aebd/com/worten/Carro.java index 37f659c..a927d11 100644 --- a/app/src/main/java/worten/aebd/com/worten/Carro.java +++ b/app/src/main/java/worten/aebd/com/worten/Carro.java @@ -35,4 +35,8 @@ public static String tString(){ return "Carro ("+getCarro().size()+")"; } + public static void erase(){ + carro = new ArrayList(); + } + } \ No newline at end of file diff --git a/app/src/main/java/worten/aebd/com/worten/Compra.java b/app/src/main/java/worten/aebd/com/worten/Compra.java index 1f88b7d..7139441 100644 --- a/app/src/main/java/worten/aebd/com/worten/Compra.java +++ b/app/src/main/java/worten/aebd/com/worten/Compra.java @@ -135,9 +135,10 @@ public void onItemClick(AdapterView pariente, View view, int posicion, long i comprar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - CharSequence texto = "Has comprado!!."; - Toast toast = Toast.makeText(Compra.this, texto, Toast.LENGTH_LONG); - toast.show(); + Intent mainIntent = new Intent(); + mainIntent = new Intent().setClass( + Compra.this, Ticket.class); + startActivity(mainIntent); } }); diff --git a/app/src/main/java/worten/aebd/com/worten/Ticket.java b/app/src/main/java/worten/aebd/com/worten/Ticket.java new file mode 100644 index 0000000..5472fc4 --- /dev/null +++ b/app/src/main/java/worten/aebd/com/worten/Ticket.java @@ -0,0 +1,250 @@ +package worten.aebd.com.worten; + +import android.app.ActionBar; +import android.app.Activity; +import android.app.Fragment; +import android.app.FragmentManager; +import android.content.Intent; +import android.os.Bundle; +import android.support.v4.widget.DrawerLayout; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.Toast; + + +public class Ticket extends Activity + implements NavigationDrawerFragment.NavigationDrawerCallbacks { + + /** + * Fragment managing the behaviors, interactions and presentation of the navigation drawer. + */ + private NavigationDrawerFragment mNavigationDrawerFragment; + + /** + * Used to store the last screen title. For use in {@link #restoreActionBar()}. + */ + private CharSequence mTitle; + + private Button ok; + + private boolean cambio = false; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_ticket); + + mNavigationDrawerFragment = (NavigationDrawerFragment) + getFragmentManager().findFragmentById(R.id.navigation_drawer); + mTitle = getTitle(); + + // Set up the drawer. + mNavigationDrawerFragment.setUp( + R.id.navigation_drawer, + (DrawerLayout) findViewById(R.id.drawer_layout),1); + + ok = (Button) findViewById(R.id.button); + /* + mListView = (ListView) findViewById(R.id.product_label); + mListView.setAdapter(new ArrayAdapter(getActionBar().getThemedContext(), + android.R.layout.simple_list_item_1, categorias)); + + mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView pariente, View view, int posicion, long id) { + String elegido = (String) pariente.getItemAtPosition(posicion); + + CharSequence texto = "Seleccionado: " + elegido; + Toast toast = Toast.makeText(Shop.this, texto, Toast.LENGTH_LONG); + toast.show(); + } + });*/ + + ok.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Carro.erase(); + Intent mainIntent = new Intent(); + mainIntent = new Intent().setClass( + Ticket.this, Shop.class); + startActivity(mainIntent); + } + }); + + + } + + @Override + public void onNavigationDrawerItemSelected(int position) { + // update the main content by replacing fragments + FragmentManager fragmentManager = getFragmentManager(); + fragmentManager.beginTransaction() + .replace(R.id.container, PlaceholderFragment.newInstance(position + 1)) + .commit(); + + } + + public void onSectionAttached(int number) { + if(cambio){ + Intent mainIntent = new Intent(); + if(Session.isLogin()){ + switch (number) { + case 1: + mainIntent = new Intent().setClass( + Ticket.this, Shop.class); + startActivity(mainIntent); + break; + case 2: + mainIntent = new Intent().setClass( + Ticket.this, Scaner.class); + startActivity(mainIntent); + break; + case 3: + mainIntent = new Intent().setClass( + Ticket.this, Games.class); + startActivity(mainIntent); + break; + case 4: + mainIntent = new Intent().setClass( + Ticket.this, Ticket.class); + startActivity(mainIntent); + break; + case 5: + mainIntent = new Intent().setClass( + Ticket.this, Compra.class); + startActivity(mainIntent); + break; + default:break; + }}else{ + + switch (number) { + case 1: + mainIntent = new Intent().setClass( + Ticket.this, Shop.class); + startActivity(mainIntent); + break; + case 2: + mainIntent = new Intent().setClass( + Ticket.this, Login.class); + startActivity(mainIntent); + break; + case 3: + mainIntent = new Intent().setClass( + Ticket.this, Login.class); + startActivity(mainIntent); + break; + case 4: + mainIntent = new Intent().setClass( + Ticket.this, Login.class); + startActivity(mainIntent); + break; + case 5: + mainIntent = new Intent().setClass( + Ticket.this, Login.class); + startActivity(mainIntent); + break; + default:break; + } + + + + + + + }}else{ + cambio = true; + } + } + + public void restoreActionBar() { + ActionBar actionBar = getActionBar(); + actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setTitle(mTitle); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + if (!mNavigationDrawerFragment.isDrawerOpen()) { + // Only show items in the action bar relevant to this screen + // if the drawer is not showing. Otherwise, let the drawer + // decide what to show in the action bar. + getMenuInflater().inflate(R.menu.shop, menu); + menu.getItem(1).setVisible(Session.isLogin()); + restoreActionBar(); + return true; + } + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.close_settings) { + + Session.closeSesion(); + + CharSequence texto = "Has cerrado sesion"; + Toast toast = Toast.makeText(Ticket.this, texto, Toast.LENGTH_LONG); + toast.show(); + + Intent mainIntent = new Intent(); + mainIntent = new Intent().setClass( + Ticket.this, Shop.class); + startActivity(mainIntent); + finish(); + + return true; + } + return super.onOptionsItemSelected(item); + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + /** + * The fragment argument representing the section number for this + * fragment. + */ + private static final String ARG_SECTION_NUMBER = "section_number"; + + /** + * Returns a new instance of this fragment for the given section + * number. + */ + public static PlaceholderFragment newInstance(int sectionNumber) { + PlaceholderFragment fragment = new PlaceholderFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + fragment.setArguments(args); + return fragment; + } + + public PlaceholderFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_shop, container, false); + return rootView; + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + ((Ticket) activity).onSectionAttached( + getArguments().getInt(ARG_SECTION_NUMBER)); + } + } + +} diff --git a/app/src/main/res/drawable-mdpi/im_qr.png b/app/src/main/res/drawable-mdpi/im_qr.png new file mode 100644 index 0000000000000000000000000000000000000000..40c5c1573eb38b4879d6e6ac7a3e957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*fOnp20`Jz%kHWeJ`&`*1efEnYCLy(9UKU>6&K*5pcANtF`9LN7mvzE6T X{V;1PZ@mwDJLl={>vruwk(qx2L=V^_ literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_ticket.xml b/app/src/main/res/layout/activity_ticket.xml new file mode 100644 index 0000000..d6a4531 --- /dev/null +++ b/app/src/main/res/layout/activity_ticket.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + +