Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds footer and fixes view transitions #10

Merged
merged 2 commits into from
Jul 6, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.view.MenuItem
import android.view.View
import android.widget.ImageButton
import android.widget.RadioButton
import android.widget.TextView
import android.widget.Toast
import com.mapzen.android.lost.api.LocationRequest
import com.mapzen.android.lost.api.LocationServices
Expand Down Expand Up @@ -362,13 +363,6 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback
override fun success(route: Route?) {
this.route = route;
runOnUiThread({
getSupportActionBar()?.hide()
findViewById(R.id.route_preview).setVisibility(View.VISIBLE)
(findViewById(R.id.route_preview) as RoutePreviewView).destination =
SimpleFeature.fromFeature(destination);
(findViewById(R.id.route_preview) as RoutePreviewView).route = route;
// TODO: Draw route on Tangram map

if( findViewById(R.id.route_mode).getVisibility() != View.VISIBLE) {
getSupportActionBar()?.hide()
findViewById(R.id.route_preview).setVisibility(View.VISIBLE)
Expand Down Expand Up @@ -491,12 +485,17 @@ public class MainActivity : AppCompatActivity(), ViewController, Router.Callback

val pager = findViewById(R.id.route_mode) as RouteModeView
val adapter = InstructionAdapter(this, route!!.getRouteInstructions(), pager)
val simpleFeature = SimpleFeature.fromFeature(destination)
pager.route = this.route
pager.setAdapter(adapter)
pager.setVisibility(View.VISIBLE)
(findViewById(R.id.destination_name) as TextView).setText(simpleFeature.toString())
}

override fun hideRoutingMode() {
findViewById(R.id.route_mode).setVisibility(View.GONE)
findViewById(R.id.route_preview).setVisibility(View.VISIBLE)
getSupportActionBar()?.hide()
}

private fun getInitializedRouter(): Router {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.mapzen.erasermap.R
import com.mapzen.helpers.DistanceFormatter
import com.mapzen.pelias.SimpleFeature
import com.mapzen.valhalla.Route

public class RouteModeView : LinearLayout , ViewPager.OnPageChangeListener{
var pager : ViewPager? = null
var autoPage : Boolean = true
var pagerPositionWhenPaused : Int? = 0
var route : Route? = null

override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
if(pager?.getCurrentItem() == pagerPositionWhenPaused) {
Expand All @@ -42,6 +44,7 @@ public class RouteModeView : LinearLayout , ViewPager.OnPageChangeListener{
pager = findViewById(R.id.instruction_pager) as ViewPager;
pager?.setAdapter(adapter)
pager?.setOnPageChangeListener(this)
(findViewById(R.id.destination_distance) as TextView).setText(DistanceFormatter.format(route?.getRemainingDistanceToDestination() as Int))
}

public fun pageForward(position: Int) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<com.mapzen.erasermap.view.RouteModeView
android:id="@+id/route_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:visibility="gone" />

</RelativeLayout>
51 changes: 48 additions & 3 deletions app/src/main/res/layout/view_route_mode.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.view.ViewPager
android:id="@+id/instruction_pager"
android:layout_width="match_parent"
android:layout_height="75dp" />
android:layout_height="@dimen/pager_height"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">

<LinearLayout
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a LinearLayout inside a RelativeLayout here? Can these be collapsed into a single container for the footer?

android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="75dp"
android:paddingLeft="@dimen/instruction_padding"
android:paddingTop="@dimen/footer_padding"
android:background="@color/transparent_white"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">

<TextView
android:id="@+id/destination_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="0"
android:fontFamily="sans-serif-condensed"
android:textStyle="bold"
android:textColor="@color/brown"
android:textSize="@dimen/font_medium" />

<TextView
android:id="@+id/destination_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:singleLine="true"
android:textColor="@color/brown"
android:fontFamily="sans-serif-condensed"
android:textSize="@dimen/font_small" />
</LinearLayout>

</RelativeLayout>

</LinearLayout>
4 changes: 3 additions & 1 deletion app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<dimen name="padding_horizontal_default">16dp</dimen>
<dimen name="padding_vertical_default">8dp</dimen>
<dimen name="padding_vertical_small">4dp</dimen>

<dimen name="instruction_padding">4dp</dimen>
<dimen name="footer_padding">8dp</dimen>

<dimen name="pager_height">75dp</dimen>
<dimen name="font_big">28sp</dimen>
<dimen name="font_medium">21sp</dimen>
<dimen name="font_small">15sp</dimen>
Expand Down
25 changes: 20 additions & 5 deletions app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public void routeModeView_shouldNotBeNull() throws Exception {
assertThat(routeModeView).isNotNull();
}

@Test
public void routeFooter_shouldNotBeNull() throws Exception {
assertThat(routeModeView.findViewById(R.id.footer)).isNotNull();
}

@Test
public void adapter_ShouldNotBeNull() throws Exception {
assertThat(adapter).isNotNull();
Expand Down Expand Up @@ -97,17 +102,19 @@ public void arrivedInstruction_shouldHaveDestinationBackground() throws Exceptio

@Test
public void firstPagerView_shouldNotHaveLeftArrow() throws Exception {
ImageButton leftArrow = (ImageButton) routeModeView.findViewById(R.id.left_arrow);
ImageButton rightArrow = (ImageButton) routeModeView.findViewById(R.id.right_arrow);
View view = (View) adapter.instantiateItem(viewGroup, 0);
ImageButton leftArrow = (ImageButton) view.findViewById(R.id.left_arrow);
ImageButton rightArrow = (ImageButton) view.findViewById(R.id.right_arrow);
assertThat(leftArrow.getVisibility()).isNotEqualTo(View.VISIBLE);
assertThat(rightArrow.getVisibility()).isEqualTo(View.VISIBLE);
}

@Test
public void firstInstruction_shouldHaveFirstInstruction() throws Exception {
TextView instructionText = (TextView) routeModeView.findViewById(R.id.instruction_text);
TextView distance = (TextView) routeModeView.findViewById(R.id.distance);
ImageView icon = (ImageView) routeModeView.findViewById(R.id.icon);
View view = (View) adapter.instantiateItem(viewGroup, 0);
TextView instructionText = (TextView) view.findViewById(R.id.instruction_text);
TextView distance = (TextView) view.findViewById(R.id.distance);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
assertThat(instructionText.getText().toString()).isEqualTo("Go north on Adalbertstraße.");
assertThat(distance.getText().toString()).isEqualTo("0.2 mi");
assertThat(icon.getDrawable()).isEqualTo(startActivity.getDrawable(R.drawable.ic_route_1));
Expand Down Expand Up @@ -136,6 +143,14 @@ public void lastIntstruction_shouldHaveFirstInstruction() throws Exception {
assertThat(distance.getText().toString()).isEqualTo("");
assertThat(icon.getDrawable()).isEqualTo(startActivity.getDrawable(R.drawable.ic_route_4));
}

@Test
public void footer_shouldHaveCorrectDistanceAndDestination() throws Exception {
TextView distance = (TextView) startActivity.findViewById(R.id.destination_distance);
TextView destinationText = (TextView) startActivity.findViewById(R.id.destination_name);
assertThat(distance.getText().toString()).isEqualTo("1.2 mi");
assertThat(destinationText.getText()).isEqualTo("Text, Local Admin, Admin1 Abbr");
}

class TestViewGroup extends ViewGroup {
public TestViewGroup(Context context) {
Expand Down