Advertisement
alawerda

java

May 1st, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.71 KB | None | 0 0
  1. package com.example.ala.ccc;
  2.  
  3. import android.app.ListActivity;
  4. import android.app.ProgressDialog;
  5. import android.content.Intent;
  6. import android.os.AsyncTask;
  7. import android.os.Bundle;
  8. import android.support.design.widget.FloatingActionButton;
  9. import android.support.design.widget.Snackbar;
  10. import android.view.View;
  11. import android.support.design.widget.NavigationView;
  12. import android.support.v4.view.GravityCompat;
  13. import android.support.v4.widget.DrawerLayout;
  14. import android.support.v7.app.ActionBarDrawerToggle;
  15. import android.support.v7.app.AppCompatActivity;
  16. import android.support.v7.widget.Toolbar;
  17. import android.view.Menu;
  18. import android.view.MenuItem;
  19. import android.widget.ListAdapter;
  20. import android.widget.ListView;
  21. import android.widget.SimpleAdapter;
  22. import android.widget.Toast;
  23.  
  24. import org.json.JSONArray;
  25. import org.json.JSONException;
  26. import org.json.JSONObject;
  27. import java.util.ArrayList;
  28. import java.util.HashMap;
  29. import java.util.List;
  30.  
  31. import retrofit.Callback;
  32. import retrofit.RestAdapter;
  33. import retrofit.RetrofitError;
  34. import retrofit.client.Response;
  35.  
  36. public class Actus extends ListActivity
  37.         implements NavigationView.OnNavigationItemSelectedListener {
  38.     public static final String KEY_BOOK_ID = "key_book_id";
  39.     public static final String KEY_BOOK_NAME = "key_book_name";
  40.     public static final String KEY_BOOK_PRICE = "key_book_price";
  41.     public static final String KEY_BOOK_STOCK = "key_book_stock";
  42.     public static final String KEY_BOOK_date = "key_book_date";
  43.     public static final String KEY_ID = "key_book_i";
  44.     final String EXTRA_LOGIN = "user_login";
  45.     public String a;
  46.  
  47.     List<Actu> flowerLis;
  48.  
  49.  
  50.     @Override
  51.     protected void onCreate(Bundle savedInstanceState) {
  52.         super.onCreate(savedInstanceState);
  53.         setContentView(R.layout.activity_services);
  54.         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  55.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  56.         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  57.                 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  58.         drawer.setDrawerListener(toggle);
  59.         toggle.syncState();
  60.  
  61.         NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  62.         navigationView.setNavigationItemSelectedListener(this);
  63.         final RestAdapter restadapter = new RestAdapter.Builder().setEndpoint("http://alawerda.com/cc").build();
  64.  
  65.         api flowerapi = restadapter.create(api.class);
  66.  
  67.         flowerapi.getActus(new Callback<List<Actu>>() {
  68.  
  69.  
  70.             @Override
  71.             public void success(List<Actu> bout, Response response) {
  72.                 flowerLis = bout;
  73.                 ActusAdapter adapt = new ActusAdapter(getApplicationContext(), R.layout.item_file, flowerLis);
  74.                 setListAdapter(adapt);
  75.  
  76.             }
  77.  
  78.             @Override
  79.             public void failure(RetrofitError error) {
  80.                 Toast.makeText(getApplicationContext(), "Failed", Toast.LENGTH_SHORT).show();
  81.             }
  82.         });
  83.  
  84.     }
  85.  
  86.  
  87.     protected void onListItemClick(ListView l, View v, int position, long id) {
  88.         super.onListItemClick(l, v, position, id);
  89.  
  90.  
  91.         Actu actu = flowerLis.get(position);
  92.  
  93.         Intent intent2 = getIntent();
  94.         // String a= intent2.getStringExtra(EXTRA_LOGIN);
  95.         a = intent2.getStringExtra(EXTRA_LOGIN);
  96.         switch (a) {
  97.             case "alawerda":
  98.  
  99.                 Intent intent4 = new Intent(this, ShoActu.class);
  100.  
  101.                 intent4.putExtra(KEY_BOOK_ID, actu.getId());
  102.                 intent4.putExtra(KEY_BOOK_NAME, actu.getNomactus());
  103.                 intent4.putExtra(KEY_BOOK_PRICE, actu.getInfoactu());
  104.                 intent4.putExtra(KEY_BOOK_STOCK, actu.getImage());
  105.                 startActivity(intent4);
  106.                 break;
  107.             case "akramwerda":
  108.                 //Intent intent = new Intent(this, ShowBoutique.class);
  109.  
  110.                 //startActivity(intent);
  111.  
  112.                 break;
  113.         }
  114.  
  115.  
  116.  
  117.  
  118.     }
  119.  
  120.  
  121.     @Override
  122.     public void onBackPressed() {
  123.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  124.         if (drawer.isDrawerOpen(GravityCompat.START)) {
  125.             drawer.closeDrawer(GravityCompat.START);
  126.         } else {
  127.             super.onBackPressed();
  128.         }
  129.     }
  130.  
  131.     @Override
  132.     public boolean onCreateOptionsMenu(Menu menu) {
  133.         // Inflate the menu; this adds items to the action bar if it is present.
  134.         getMenuInflater().inflate(R.menu.boutiques2, menu);
  135.         return true;
  136.     }
  137.  
  138.     @Override
  139.     public boolean onOptionsItemSelected(MenuItem item) {
  140.         // Handle action bar item clicks here. The action bar will
  141.         // automatically handle clicks on the Home/Up button, so long
  142.         // as you specify a parent activity in AndroidManifest.xml.
  143.         int id = item.getItemId();
  144.  
  145.         //noinspection SimplifiableIfStatement
  146.         if (id == R.id.action_settings) {
  147.             return true;
  148.         }
  149.  
  150.         return super.onOptionsItemSelected(item);
  151.     }
  152.  
  153.     @SuppressWarnings("StatementWithEmptyBody")
  154.     @Override
  155.     public boolean onNavigationItemSelected(MenuItem item) {
  156.         // Handle navigation view item clicks here.
  157.         int id = item.getItemId();
  158.  
  159.         if (id == R.id.nav_camera) {
  160.             Intent intent = new Intent(this, Boutiques2.class);
  161.             this.startActivity(intent);
  162.             // Handle the camera action
  163.         } else if (id == R.id.nav_gallery) {
  164.             Intent intent = new Intent(this, Promos.class);
  165.             this.startActivity(intent);
  166.         } else if (id == R.id.nav_slideshow) {
  167.             Intent intent = new Intent(this, Services.class);
  168.             this.startActivity(intent);
  169.  
  170.         } else if (id == R.id.nav_manag) {
  171.             Intent intent = new Intent(this, Actus.class);
  172.             this.startActivity(intent);
  173.         } else if (id == R.id.nav_share) {
  174.             Intent intent = new Intent(this, Loginadminboutique.class);
  175.             this.startActivity(intent);
  176.  
  177.  
  178.         } else if (id == R.id.nav_send) {
  179.             Intent intent = new Intent(this, LoginActivity.class);
  180.             this.startActivity(intent);
  181.  
  182.         } else if (id == R.id.nav_hor){
  183.             Intent intent = new Intent(this, Horraires.class);
  184.             this.startActivity(intent);
  185.         }else if (id == R.id.nav_home) {
  186.             Intent intent = new Intent(this, MainActivity.class);
  187.             this.startActivity(intent);
  188.  
  189.         }
  190.  
  191.  
  192.         DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  193.         drawer.closeDrawer(GravityCompat.START);
  194.         return true;
  195.     }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement