Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.a4ci.fastorder;
- import android.content.Context;
- import android.content.Intent;
- import android.net.Uri;
- import android.net.wifi.WifiInfo;
- import android.net.wifi.WifiManager;
- import android.os.Bundle;
- import android.support.design.widget.FloatingActionButton;
- import android.support.design.widget.NavigationView;
- import android.support.v4.view.GravityCompat;
- import android.support.v4.widget.DrawerLayout;
- import android.support.v7.app.ActionBarDrawerToggle;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
- //rivate ArrayList<Prodotto> carrello=new ArrayList<>();
- private TextView reteTV;
- private Connection con;
- private Thread t1;
- private ArrayList<Prodotto> prodotti;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
- setSupportActionBar(toolbar);
- FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
- fab.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- startActivity(new Intent(getApplicationContext(), ChoseList.class));
- }
- });
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
- drawer.setDrawerListener(toggle);
- toggle.syncState();
- NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
- navigationView.setNavigationItemSelectedListener(this);
- //OGGETTI GRAFICI
- reteTV = (TextView) findViewById(R.id.reteTV);
- //METODI
- prodotti = new ArrayList<>();
- setConnectionTV();
- importData();
- }
- @Override
- public void onBackPressed() {
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- if (drawer.isDrawerOpen(GravityCompat.START)) {
- drawer.closeDrawer(GravityCompat.START);
- } else {
- super.onBackPressed();
- }
- }
- /* @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }*/
- @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();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- @SuppressWarnings("StatementWithEmptyBody")
- @Override
- public boolean onNavigationItemSelected(MenuItem item) {
- int id = item.getItemId();
- if (id == R.id.menu) {
- Intent intent = new Intent(this, Menu.class);
- Bundle bundle = new Bundle();
- bundle.putSerializable("prodotti", (Serializable) prodotti);
- intent.putExtras(bundle);
- startActivity(intent);
- //startActivity(new Intent(this,MenuList.class));
- } else if (id == R.id.cart) {
- startActivity(new Intent(MainActivity.this, ChoseList.class));
- } else if (id == R.id.chose) {
- startActivity(new Intent(MainActivity.this, ChoseList.class));
- } else if (id == R.id.nav_share) {
- Toast.makeText(this, "Non ancora implementata", Toast.LENGTH_LONG).show();
- } else if (id == R.id.site) {
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://fast-order.wixsite.com/fastorder"));
- startActivity(intent);
- } else if (id == R.id.accountLog) {
- Toast.makeText(this, "Non ancora implementata", Toast.LENGTH_LONG).show();
- }
- DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
- drawer.closeDrawer(GravityCompat.START);
- return true;
- }
- private void setConnectionTV() {
- WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
- WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
- String name = wifiInfo.getSSID();
- reteTV.setText("Rete: " + name);
- }
- private void importData() {
- /*WifiManager wifiMgr = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
- String rete = wifiMgr.getConnectionInfo().getSSID();*/
- //if (wifiMgr.getConnectionInfo().getSupplicantState().isValidState(wifiMgr.getConnectionInfo().getSupplicantState())) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();
- }
- t1 = new Thread(new Runnable() {
- public void run() {
- if (!Thread.interrupted()) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e1) {
- }
- if (con == null) {
- try {
- con = DriverManager.getConnection("jdbc:mysql://mattone.ddns.net:3306/FastOrder", "root", "mattone17");
- System.out.println("connesso");
- //////////////
- try {
- Statement stm = con.createStatement();
- ResultSet rs = stm.executeQuery("SELECT * from Test");
- //ResultSet rs=stm.executeQuery(query);
- while (rs.next()) {
- Prodotto p = new Prodotto(rs.getString("nome"), rs.getFloat("prezzo"));
- prodotti.add(p);
- System.out.println("Nome: " + rs.getString("nome"));
- }
- } catch (SQLException e) {
- System.out.println(e);
- }
- } catch (SQLException e) {
- System.out.println(e);
- con = null;
- }
- }
- }
- }
- });//fine thread
- if ((t1 != null) && (!t1.isAlive())) {
- t1.start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement