From b5da69249331e54d9f4d3bf71ab88ae4111aa720 Mon Sep 17 00:00:00 2001 From: kingofirony Date: Thu, 2 Jul 2015 12:23:54 -0400 Subject: [PATCH 1/2] adds footer and fixes view transitions --- .../com/mapzen/erasermap/view/MainActivity.kt | 13 +++-- .../mapzen/erasermap/view/RouteModeView.kt | 3 ++ app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/layout/view_route_mode.xml | 51 +++++++++++++++++-- app/src/main/res/values/dimens.xml | 4 +- .../erasermap/view/RouteModeViewTest.java | 25 +++++++-- 6 files changed, 81 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt index 4f799f77..e694f0ab 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/view/MainActivity.kt @@ -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 @@ -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) @@ -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 { diff --git a/app/src/main/kotlin/com/mapzen/erasermap/view/RouteModeView.kt b/app/src/main/kotlin/com/mapzen/erasermap/view/RouteModeView.kt index d28c7745..9805c1cb 100644 --- a/app/src/main/kotlin/com/mapzen/erasermap/view/RouteModeView.kt +++ b/app/src/main/kotlin/com/mapzen/erasermap/view/RouteModeView.kt @@ -10,6 +10,7 @@ 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 @@ -17,6 +18,7 @@ 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) { @@ -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) { diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index defe7a54..f4176168 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -66,7 +66,7 @@ diff --git a/app/src/main/res/layout/view_route_mode.xml b/app/src/main/res/layout/view_route_mode.xml index 8b96ad4e..bbf2f9ea 100644 --- a/app/src/main/res/layout/view_route_mode.xml +++ b/app/src/main/res/layout/view_route_mode.xml @@ -1,11 +1,56 @@ + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + android:layout_height="@dimen/pager_height"/> + + + + + + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index a2c19663..99ef24f5 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -2,8 +2,10 @@ 16dp 8dp 4dp - 4dp + 8dp + + 75dp 28sp 21sp 15sp diff --git a/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java b/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java index 0f2c4d68..a91884a6 100644 --- a/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java +++ b/app/src/test/java/com/mapzen/erasermap/view/RouteModeViewTest.java @@ -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(); @@ -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)); @@ -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) { From 3d34ffef3a1193009df85d2500a18ea52a8f0b96 Mon Sep 17 00:00:00 2001 From: kingofirony Date: Mon, 6 Jul 2015 16:09:23 -0400 Subject: [PATCH 2/2] removes unecessary linearlayout in xml --- app/src/main/res/layout/view_route_mode.xml | 71 ++++++++++----------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/app/src/main/res/layout/view_route_mode.xml b/app/src/main/res/layout/view_route_mode.xml index bbf2f9ea..ec4ee64a 100644 --- a/app/src/main/res/layout/view_route_mode.xml +++ b/app/src/main/res/layout/view_route_mode.xml @@ -1,5 +1,6 @@ - @@ -7,50 +8,44 @@ + android:layout_height="@dimen/pager_height" /> + android:background="@color/transparent_white" + android:paddingBottom="@dimen/padding_vertical_small" + android:paddingLeft="@dimen/instruction_padding" + android:paddingTop="@dimen/footer_padding"> - - - + android:layout_weight="0" + android:fontFamily="sans-serif-condensed" + android:textColor="@color/brown" + android:textSize="@dimen/font_medium" + android:textStyle="bold" /> - - + - +