import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import com.parse.ParseException;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
public class Welcome extends Activity {
// Declare Variables
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewAdapter adapter;
private ArrayList<WorldPopulation> worldpopulationlist = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from listview_main.xml
setContentView(R.layout.welcome);
// Execute RemoteDataTask AsyncTask
new RemoteDataTask().execute();
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick
(AdapterView
<?> parent,
View view,
int position,
long id
) {
//Toast.makeText(getApplicationContext(),"Seleccón: " + position ,Toast.LENGTH_LONG).show();
}
});
}
/*public void infolocal(View view){
Intent i=new Intent(this, InfoLocal.class);
Object o = getListAdapter().getItem(position);
i.putExtra("path", direccion);
startActivity(i);
}*/
/*protected void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
Object o = getListAdapter().getItem(position);
Toast.makeText(this, "Selección: " + Integer.toString(position)
+ " - " + o.toString(),Toast.LENGTH_LONG).show();
//Intent i = new Intent(this, campo.class );
//startActivity(i);
}*/
//crea la ACTIONBAR
public boolean onCreateOptionsMenu
(Menu menu
) { getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
//acciones segun el id seleccionado de la actonbar
@Override
public boolean onOptionsItemSelected
(MenuItem item
) { switch (item.getItemId()) {
case R.id.listview:
ParseUser.logOut();
finish();
return true;
case R.id.list_item:
ParseUser.logOut();
finish();
return true;
case R.id.menu_settings:
ParseUser.logOut();
finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
// RemoteDataTask AsyncTask
private class RemoteDataTask
extends AsyncTask
<Void,
Void, Void
> { @Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(Welcome.this);
// Set progressdialog title
mProgressDialog.setTitle("Estamos buscando ofertas para ti");
// Set progressdialog message
mProgressDialog.setMessage("Cargando..");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground
(Void...
params) { // Create the array
worldpopulationlist = new ArrayList<WorldPopulation>();
try {
// Locate the class table named "Descriptor" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Promo");
// Locate the column named "ranknum" in Parse.com and order list
// by ascending
query.orderByAscending("ranknum");
ob = query.find();
for (ParseObject promo : ob) {
// Locate images in foto column
ParseFile image = (ParseFile) promo.get("foto");
WorldPopulation map = new WorldPopulation();
map.
setLocal((String) promo.
get("local")); map.
setDescriptor((String) promo.
get("descriptor")); map.
setPopulation((String) promo.
get("population")); map.setFoto(image.getUrl());
worldpopulationlist.add(map);
}
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute
(Void result
) { // Locate the listview in listview_main.xml
listview
= (ListView) findViewById
(R.
id.
listview); // Pass the results into ListViewAdapter.java
adapter = new ListViewAdapter(Welcome.this,
worldpopulationlist);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}