Skip to content

Instantly share code, notes, and snippets.

@IsabelManiega
Created March 10, 2017 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IsabelManiega/03c1cfdde1d25e9b157d1cc519aad8ae to your computer and use it in GitHub Desktop.
Save IsabelManiega/03c1cfdde1d25e9b157d1cc519aad8ae to your computer and use it in GitHub Desktop.
TourGuideLeon
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:orientation="vertical"
tools:context="com.example.isa.tourguideleon.MainActivity">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/CategoryTab"/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
package com.example.isa.tourguideleon;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class CategoryAdapter extends FragmentPagerAdapter {
/** Context of the app */
private Context mContext;
/**
* Create a new {@link CategoryAdapter} object.
*
* @param context is the context of the app
* @param fm is the fragment manager that will keep each fragment's state in the adapter
* across swipes.
*/
public CategoryAdapter(Context context, FragmentManager fm) {
super(fm);
mContext = context;
}
@Override
public CharSequence getPageTitle(int position) {
if (position == 0) {
return mContext.getString(R.string.category_monuments);
} else if (position == 1) {
return mContext.getString(R.string.category_gastronomy);
} else if (position == 2) {
return mContext.getString(R.string.category_tapas);
} else {
return mContext.getString(R.string.category_more);
}
}
public CategoryAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
return new MonumentsFragment();
} else if (position == 1) {
return new GastronomyFragment();
} else if (position == 2) {
return new TapasFragment();
} else {
return new MoreFragment();
}
}
@Override
public int getCount() {
return 4;
}
}
package com.example.isa.tourguideleon;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.util.ArrayList;
/**
* A simple {@link Fragment} subclass.
*/
public class GastronomyFragment extends Fragment {
public GastronomyFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.word_list, container, false);
// Create a list of words
final ArrayList<Word> words = new ArrayList<Word>();
words.add(new Word("The botillo is a meat product made with pieces cut from the cutting of the pig, seasoned and embedded in the blind of the pig that is then smoked and semi-cured.", "Botillo", R.drawable.botillo,R.drawable.mapa_ponferrada));
words.add(new Word("It is a typical sweet of the city of Astorga (Leon, autonomous community of Castile and Leon, in Spain).", "Mantecadas de Astorga", R.drawable.matecadas,R.drawable.mapa_astorga));
words.add(new Word("It is a type of dehydrated meat, similar to ham but made by curing beef, equine and less frequently, of goat and even rabbit, ox or hare.", "Cecina", R.drawable.cecina,R.drawable.mapa_cecina));
words.add(new Word("It consists basically of the elements of the field, soup, cabbage, chickpeas and seven meats.", "Cocido Maragato", R.drawable.cocido,R.drawable.mapa_cocido));
// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
// adapter knows how to create list items for each item in the list.
WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_gastronomy);
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
ListView listView = (ListView) rootView.findViewById(R.id.list);
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
// {@link ListView} will display list items for each {@link Word} in the list.
listView.setAdapter(adapter);
return rootView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for a single list item -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="320dp"
android:background="@color/tan_background"
android:orientation="vertical"
android:id="@+id/text_container"
android:layout_below="@id/image"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="@+id/image"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"/>
<ImageView
android:id="@+id/mapa"
android:layout_width="@dimen/list_item_height"
android:layout_height="@dimen/list_item_height"/>
</LinearLayout>
<TextView
android:id="@+id/title_text_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="bottom"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white"
android:textStyle="bold"
tools:text="Catedral"/>
<TextView
android:id="@+id/text_text_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="top"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@android:color/white"
tools:text="The Cathedral of León is undoubtedly one of the most beautiful Gothic cathedrals in Spain" />
</LinearLayout>
package com.example.isa.tourguideleon;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity to use the activity_main.xml layout file
setContentView(R.layout.activity_main);
// Find the view pager that will allow the user to swipe between fragments
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
// Create an adapter that knows which fragment should be shown on each page
CategoryAdapter adapter = new CategoryAdapter(this, getSupportFragmentManager());
// Set the adapter onto the view pager
viewPager.setAdapter(adapter);
// Find the tab layout that shows the tabs
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
// Connect the tab layout with the view pager. This will
// 1. Update the tab layout when the view pager is swiped
// 2. Update the view pager when a tab is selected
// 3. Set the tab layout's tab names with the view pager's adapter's titles
// by calling onPageTitle()
tabLayout.setupWithViewPager(viewPager);
}
}
package com.example.isa.tourguideleon;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.util.ArrayList;
/**
* A simple {@link Fragment} subclass.
*/
public class MonumentsFragment extends Fragment {
public MonumentsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.word_list, container, false);
// Create a list of words
final ArrayList<Word> words = new ArrayList<Word>();
words.add(new Word("The Cathedral of León is undoubtedly one of the most beautiful Gothic cathedrals in Spain", "Cathedral", R.drawable.catedral,R.drawable.mapa_catedral));
words.add(new Word("The Botine house is a modernist style building designed by the Spanish architect Antoni Gaudí between 1891 and 1894", "Palacio de botines", R.drawable.botines,R.drawable.mapa_botines));
words.add(new Word("The palace of the Guzmanes is a Renaissance palace of the sixteenth century.", "Palacio de Guzmanes", R.drawable.palacio,R.drawable.mapa_palacio));
words.add(new Word("The Royal Collegiate Basilica of San Isidoro is one of the most outstanding Romanesque architectural ensembles in Spain.", "Basílica de San Isidoro", R.drawable.sanisidoro,R.drawable.mapa_sanisidoro));
words.add(new Word("One of the most important monuments of the Spanish Renaissance.", "San Marcos", R.drawable.marcos,R.drawable.mapa_marcos));
words.add(new Word("The Museum of Contemporary Art of Castilla y León, also known by its initials MUSAC.", "Musac", R.drawable.musac,R.drawable.mapa_musac));
// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
// adapter knows how to create list items for each item in the list.
WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_monuments);
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
ListView listView = (ListView) rootView.findViewById(R.id.list);
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
// {@link ListView} will display list items for each {@link Word} in the list.
listView.setAdapter(adapter);
return rootView;
}
}
package com.example.isa.tourguideleon;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.util.ArrayList;
/**
* A simple {@link Fragment} subclass.
*/
public class MoreFragment extends Fragment {
public MoreFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.word_list, container, false);
// Create a list of words
final ArrayList<Word> words = new ArrayList<Word>();
words.add(new Word("The interest of the Holy Week of Leon is that the processions are carried out in a very quiet and traditional way.", "Semana Santa", R.drawable.semanasanta,R.drawable.mapa_catedral));
words.add(new Word("The dawn of Holy Thursday welcomes the celebration of the pagan procession of the Burial of Genarín.", "Genarín", R.drawable.genarin,R.drawable.mapa_humedo));
words.add(new Word("This feast commemorates the Christian victory in the Battle of Clavijo and the liberation of the legendary \"Tribute of the hundred maidens\".", "Cantaderas", R.drawable.cantaderas,R.drawable.mapa_catedral));
words.add(new Word("It is denominated pennants of Leon to the banners or banners preserved in the old Region of Leon.", "Pendones", R.drawable.pendones, R.drawable.mapa_pendones));
words.add(new Word("Cars pulled with oxen or donkeys adorned with all kinds of products of the area to celebrate the patron of the city.", "Carros Engalanados", R.drawable.carros,R.drawable.mapa_pendones));
words.add(new Word("Celebrations of the summer.", "San Juan y San Pedro", R.drawable.fiestas,R.drawable.mapa_marcos));
// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
// adapter knows how to create list items for each item in the list.
WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_more);
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
ListView listView = (ListView) rootView.findViewById(R.id.list);
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
// {@link ListView} will display list items for each {@link Word} in the list.
listView.setAdapter(adapter);
return rootView;
}
}
package com.example.isa.tourguideleon;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import java.util.ArrayList;
/**
* A simple {@link Fragment} subclass.
*/
public class TapasFragment extends Fragment {
public TapasFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.word_list, container, false);
// Create a list of words
final ArrayList<Word> words = new ArrayList<Word>();
words.add(new Word("Differents bars where they give us with free consumption something to eat.", "Tapeo", R.drawable.tapas,R.drawable.mapa_humedo));
words.add(new Word("Mainly the Plaza de San Martin where we find many bars where you can tapear.", "Barrio Húmedo", R.drawable.humedo,R.drawable.mapa_humedo));
words.add(new Word("Mainly the Plaza de Torres de Omaña where we find many bars where you can tapas.", "Barrio Romántico", R.drawable.romantico,R.drawable.mapa_romantico));
// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
// adapter knows how to create list items for each item in the list.
WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_tapas);
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
ListView listView = (ListView) rootView.findViewById(R.id.list);
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
// {@link ListView} will display list items for each {@link Word} in the list.
listView.setAdapter(adapter);
return rootView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment