Skip to content

Instantly share code, notes, and snippets.

@rjlutz rjlutz/1 notes
Last active Apr 1, 2018

Embed
What would you like to do?
Bike and Barge notes and text bits
add drawables
add to strings (can use translations or copy/paste)
create a new TableLayout underlayouts called photos.xml
add rows (can be found below)
create a new LinearLayout underlayouts called tours.xml
add stuff (can be found below)
add permission
<uses-permission android:name="android.permission.INTERNET" />
change item_detail.xml TextView -> WebView (note: not fragement_item_detail.xml!)
change DummyContent and DummyItem
in onCreateView in ItemDetailFragment change if... to snippet below
remove FABs and references to FABS
public class DummyContent {
/**
* An array of sample (dummy) items.
*/
public static List<DummyItem> ITEMS = new ArrayList<DummyItem>();
/**
* A map of sample (dummy) items, by ID.
*/
public static Map<String, DummyItem> ITEM_MAP = new HashMap<String, DummyItem>();
static {
// Add 3 sample items.
addItem(new DummyItem("1", "Photos"));
addItem(new DummyItem("2", "Tour"));
addItem(new DummyItem("3", "Web Site", "http://bikebarge.com"));
}
private static void addItem(DummyItem item) {
ITEMS.add(item);
ITEM_MAP.put(item.id, item);
}
/**
* A dummy item representing a piece of content.
*/
public static class DummyItem {
public String id;
public String content;
public String item_name;
public String item_url;
public DummyItem(String id, String content) {
this.id = id;
this.content = content;
}
public DummyItem(String id, String item_name, String item_url) {
this.id = id;
this.item_name = item_name;
this.item_url = item_url;
content = item_name;
}
@Override
public String toString() {
return content;
}
}
}
add to onCreateView() ...
// Show the dummy content as text in a TextView.
if (mItem.id.equals("1")) {
rootView = inflater.inflate(R.layout.photos, container, false);
}
if (mItem.id.equals("2")) {
rootView = inflater.inflate(R.layout.tour, container, false);
}
if (mItem.id.equals("3")) {
WebView wv = rootView.findViewById(R.id.item_detail); // different than the text!
wv.loadUrl(mItem.item_url); // " "
wv.getSettings().setLoadWithOverviewMode(true); // " "
wv.getSettings().setUseWideViewPort(true);
}
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
<ImageView
android:id="@+id/imgBike"
android:layout_width="240dp"
android:layout_height="160dp"
android:layout_weight="1"
android:contentDescription="@string/txtDescription"
android:padding="15sp"
android:src="@drawable/bike" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="@string/txtBike"
android:textSize="14sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
<ImageView
android:id="@+id/imgBarge"
android:layout_width="240dp"
android:layout_height="160dp"
android:layout_weight="1"
android:contentDescription="@string/txtDescription"
android:padding="15sp"
android:src="@drawable/barge" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingRight="15sp"
android:text="@string/txtBarge"
android:textSize="14sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
<ImageView
android:id="@+id/imgBudapest"
android:layout_width="240dp"
android:layout_height="160dp"
android:layout_weight="1"
android:contentDescription="@string/txtDescription"
android:padding="15sp"
android:src="@drawable/budapest" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="@string/txtBudapest"
android:textSize="14sp" />
</TableRow>
</TableLayout>
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="1">
<TableRow android:layout_width="match_parent">
<ImageView
android:id="@+id/imgBike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/txtDescription"
android:padding="15sp"
android:src="@drawable/bike" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/txtBike"
android:textSize="30sp" />
</TableRow>
<TableRow android:layout_width="match_parent">
<ImageView
android:id="@+id/imgBarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/txtDescription"
android:paddingRight="15sp"
android:src="@drawable/barge" />
<TextView
android:layout_width="700dp"
android:layout_height="wrap_content"
android:paddingRight="15sp"
android:text="@string/txtBarge"
android:textSize="30sp" />
</TableRow>
<TableRow android:layout_width="match_parent">
<ImageView
android:id="@+id/imgBudapest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/txtDescription"
android:padding="15sp"
android:src="@drawable/budapest" />
<TextView
android:layout_width="700dp"
android:layout_height="wrap_content"
android:text="@string/txtBudapest"
android:textSize="30sp" />
</TableRow>
</TableLayout>
<string name="title_item_detail">Bike and Barge</string>
<string name="txtBike">Bikes equipped with gel seats are our mode of transporation to view the landscape, history, customs and traditions.</string>
<string name="txtBarge">This luxury boat leaves beautiful Amsterdam and finishes 7 days later in Budapest, Hungary</string>
<string name="txtBudapest">The majestic Parliament building lies in the center of Budapest, Hungary.</string>
<string name="txtTitle">Summer - Bike and Barge Europe Tour</string>
<string name="txtInfo">Join us for a dream vacation filled with biking in cities throughout Europe from Amsterdam to Budapest. The next trip leaves on June 2.</string>
<string name="txtDescription">Bike and Barge Image</string>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:paddingBottom="10sp"
android:paddingLeft="10sp"
android:text="@string/txtTitle"
android:textSize="50sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txtInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:paddingLeft="10sp"
android:paddingRight="10sp"
android:text="@string/txtInfo"
android:textSize="30sp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtTitle" />
</android.support.constraint.ConstraintLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.