[PHP]package gealvber.cmx.app;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class SingleItemView extends ActionBarActivity {
//First We Declare Titles And Icons For Our Navigation Drawer List View
//This Icons And Titles Are holded in an Array as you can see
String TITLES[] = {"Que es CMX","Ejecutivos(as)","Nuestros Servicios","Certificaciones Vigentes","Normalizaci\u00f3n", "Cursos Online", "", "", "", "Inicio"};
int ICONS[] = {R.mipmap.organization,R.mipmap.conference,R.mipma p.services,R.mipmap.diploma1,R.mipmap.approval,R.m ipmap.donate,R.id.linea,R.id.linea,R.id.linea,R.mi pmap.home};
String NAME = "Certificaci\u00f3n Mexicana";
String EMAIL = "
[email protected]";
int PROFILE = R.drawable.cmxlogo;
private Toolbar toolbar; // Declaring the Toolbar Object
RecyclerView mRecyclerView; // Declaring RecyclerView
RecyclerView.Adapter mAdapter; // Declaring Adapter For Recycler View
RecyclerView.LayoutManager mLayoutManager; // Declaring Layout Manager as a linear layout manager
DrawerLayout Drawer; // Declaring DrawerLayout
ActionBarDrawerToggle mDrawerToggle; // Declaring Action Bar Drawer Toggle
// Declare Variables
Context context;
String rank;
String country;
String population;
String content1;
String content2;
String flag;
ImageLoader imageLoader = new ImageLoader(context);
@
override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from singleitemview.xml
setContentView(R.layout.singleitemview);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
setTitle(R.string.title_activity_main);
mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View
mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size
mAdapter = new MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE,this); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
// And passing the titles,icons,header view name, header view email,
// and header view profile picture
mRecyclerView.setAdapter(mAdapter); // Setting the adapter to RecyclerView
final GestureDetector mGestureDetector = new GestureDetector(SingleItemView.this, new GestureDetector.SimpleOnGestureListener() {
@
override public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
@
override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
View child = recyclerView.findChildViewUnder(motionEvent.getX() ,motionEvent.getY());
if(child !=null && mGestureDetector.onTouchEvent(motionEvent)){
Drawer.closeDrawers();
if (recyclerView.getChildPosition(child) == 0) {
Intent intent = new Intent(SingleItemView.this, Profile.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 1) {
Intent intent = new Intent(SingleItemView.this, CMX.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 2) {
Intent intent = new Intent(SingleItemView.this, Ejecutivos.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 3){
Intent intent = new Intent(SingleItemView.this, Servicios.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 4){
Intent intent = new Intent(SingleItemView.this, Certificaciones.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 5) {
Intent intent = new Intent(SingleItemView.this, Soluciones.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 6){
Intent intent = new Intent(SingleItemView.this, Cursos.class);
startActivity(intent);
finish();
}else if
(recyclerView.getChildPosition(child) == 10 ){
Intent intent = new Intent(SingleItemView.this, MainActivity.class);
startActivity(intent);
finish();
}
return true;
}
return false;
}
@
override
public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
}
});
mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager
mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager
Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view
mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string .openDrawer,R.string.closeDrawer){
@
override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
// code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
// open I am not going to put anything here)
}
@
override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
// Code here will execute once drawer is closed
}
}; // Drawer Toggle Object Made
Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://www.google.com"));
startActivity(myWebLink);
}
});
Intent i = getIntent();
// Get the result of rank
rank = i.getStringExtra("rank");
// Get the result of country
country = i.getStringExtra("country");
// Get the result of population
population = i.getStringExtra("population");
// Get the result of content1
content1 = i.getStringExtra("content1");
// Get the result of content2
content2 = i.getStringExtra("content2");
// Get the result of flag
flag = i.getStringExtra("flag");
// Locate the TextViews in singleitemview.xml
TextView txtrank = (TextView) findViewById(R.id.rank);
TextView txtcountry = (TextView) findViewById(R.id.country);
TextView txtpopulation = (TextView) findViewById(R.id.population);
TextView txtcontent1 = (TextView) findViewById(R.id.content1);
TextView txtcontent2 = (TextView) findViewById(R.id.content2);
// Locate the ImageView in singleitemview.xml
ImageView imgflag = (ImageView) findViewById(R.id.flag);
// Set results to the TextViews
txtrank.setText(rank);
txtcountry.setText(country);
txtpopulation.setText(population);
txtcontent1.setText(content1);
txtcontent2.setText(content2);
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
imageLoader.DisplayImage(flag, imgflag);
}
@
override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
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;
}
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case R.id.about
:
Intent intent = new Intent(SingleItemView.this, About.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}[/PHP]