-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chiara
committed
Mar 31, 2015
1 parent
3d07555
commit c50132f
Showing
20 changed files
with
483 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
londonWeather/src/androidTest/java/com/cchiappini/londonweather/WeatherIconMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.cchiappini.londonweather; | ||
|
||
|
||
import junit.framework.TestCase; | ||
|
||
public class WeatherIconMapperTest extends TestCase { | ||
|
||
} |
58 changes: 43 additions & 15 deletions
58
londonWeather/src/main/java/com/cchiappini/londonweather/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
londonWeather/src/main/java/com/cchiappini/londonweather/WeatherIconMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.cchiappini.londonweather; | ||
|
||
import com.cchiappini.londonweather.exception.IconNotFoundException; | ||
|
||
import weather.Weather; | ||
|
||
public class WeatherIconMapper { | ||
|
||
public static int getIconResourceIdForWeather(Weather weather) throws IconNotFoundException { | ||
if(weather.getWeatherIconId().equals("sun")) { | ||
return R.drawable.sun; | ||
} | ||
throw new IconNotFoundException(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...onWeather/src/main/java/com/cchiappini/londonweather/exception/IconNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.cchiappini.londonweather.exception; | ||
|
||
/** | ||
* Created by cchiappini on 30/03/2015. | ||
*/ | ||
public class IconNotFoundException extends Exception { | ||
public IconNotFoundException(){ | ||
super("Icon for weather not found"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,70 @@ | ||
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
tools:context=".MainActivity"> | ||
|
||
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/weather_toolbar" | ||
android:layout_width="match_parent" | ||
android:layout_height="80dp" | ||
android:background="?attr/colorPrimary" | ||
android:gravity="center" | ||
android:paddingBottom="16dp" | ||
android:paddingLeft="72dp" | ||
app:subtitleTextAppearance="@style/ToolbarSubtitle" | ||
app:theme="@style/ThemeOverlay.AppCompat.Light" | ||
app:titleTextAppearance="@style/Toolbartitle"> | ||
|
||
<Button | ||
</android.support.v7.widget.Toolbar> | ||
|
||
<LinearLayout | ||
android:id="@+id/l1" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerVertical="true" | ||
android:layout_gravity="center" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/weather_description" | ||
style="@style/TextAppearance.AppCompat.Display2" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
<TextView | ||
android:id="@+id/weather_temp" | ||
style="@style/TextAppearance.AppCompat.Display4" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:layout_marginTop="10dp" | ||
android:text="0" /> | ||
|
||
<View | ||
android:layout_width="fill_parent" | ||
android:layout_height="1dp" | ||
android:layout_marginLeft="30dp" | ||
android:layout_marginRight="30dp" | ||
android:layout_marginTop="8dp" | ||
android:background="#177bbd" /> | ||
|
||
<ImageView | ||
android:id="@+id/weather_icon" | ||
android:layout_width="64dp" | ||
android:layout_height="64dp" | ||
android:layout_gravity="center_horizontal" | ||
android:layout_marginTop="8dp" | ||
android:alpha="0.2" /> | ||
</LinearLayout> | ||
|
||
<!--<Button | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/weather_richmond" | ||
android:id="@+id/weather_button" | ||
android:layout_alignParentTop="true" | ||
android:layout_alignParentStart="true" /> | ||
android:layout_alignParentStart="true" />--> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<style name="AppTheme" parent="android:Theme.Material.Light"> | ||
<style name="AppTheme" parent="Theme.AppCompat"> | ||
<item name="windowActionBar">false</item> | ||
</style> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="white">#FFFFFF</color> | ||
<color name="primaryColor_500">#03a9f4</color> | ||
<color name="primaryDarkColor_700">#0288d1</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | ||
<item name="colorPrimary">@color/primaryColor_500</item> | ||
<item name="colorPrimaryDark">@color/primaryDarkColor_700</item> | ||
<item name="android:windowNoTitle">true</item> | ||
<item name="windowActionBar">false</item> | ||
</style> | ||
|
||
<style name="ActionBarPopupThemeOverlay" parent="ThemeOverlay.AppCompat.Light" /> | ||
|
||
<style name="Toolbartitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"> | ||
<item name="android:textColor">@android:color/white</item> | ||
</style> | ||
|
||
<style name="ToolbarSubtitle" parent="@style/TextAppearance.Widget.AppCompat.Toolbar.Subtitle"> | ||
<item name="android:textColor">#56FFFFFF</item> | ||
</style> | ||
|
||
<color name="ColorPrimary">@color/white</color> | ||
|
||
</resources> |
27 changes: 27 additions & 0 deletions
27
londonWeather/src/test/java/com.cchiappini.londonweather/RobolectricGradleTestRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.cchiappini.londonweather; | ||
|
||
|
||
import org.junit.runners.model.InitializationError; | ||
import org.robolectric.AndroidManifest; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
import org.robolectric.res.Fs; | ||
|
||
public class RobolectricGradleTestRunner extends RobolectricTestRunner { | ||
public RobolectricGradleTestRunner(Class<?> testClass) throws InitializationError { | ||
super(testClass); | ||
} | ||
|
||
@Override | ||
protected AndroidManifest getAppManifest(Config config) { | ||
String myAppPath = RobolectricGradleTestRunner.class.getProtectionDomain() | ||
.getCodeSource() | ||
.getLocation() | ||
.getPath(); | ||
String manifestPath = myAppPath + "../../../manifests/full/debug/AndroidManifest.xml"; | ||
String resPath = myAppPath + "../../../res/debug"; | ||
String assetPath = myAppPath + "../../../assets/debug"; | ||
return createAppManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resPath), Fs.fileFromPath(assetPath)); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
londonWeather/src/test/java/com.cchiappini.londonweather/WeatherIconMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.cchiappini.londonweather; | ||
|
||
import com.cchiappini.londonweather.exception.IconNotFoundException; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import weather.Weather; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
@RunWith(com.cchiappini.londonweather.RobolectricGradleTestRunner.class) | ||
public class WeatherIconMapperTest { | ||
|
||
private static final String A_WEATHER_DESCRIPTION = "aWeatherDescription"; | ||
private static final double A_WEATHER_TEMPERATURE = 15.0; | ||
private static final String SUN_ICON_ID = "sun"; | ||
private static final String UNKNOWN_ICON_ID = "unknownIconId"; | ||
|
||
@Test | ||
public void shouldReturnTheRightIconWhenSunny() | ||
throws IconNotFoundException { | ||
Weather weather = new Weather(A_WEATHER_DESCRIPTION, | ||
A_WEATHER_TEMPERATURE, SUN_ICON_ID); | ||
int expectedIcon = R.drawable.sun; | ||
assertEquals(expectedIcon, | ||
WeatherIconMapper.getIconResourceIdForWeather(weather)); | ||
} | ||
|
||
@Test (expected=IconNotFoundException.class) | ||
public void shouldThrowAnExceptionWhenIconIsNotFound() throws IconNotFoundException { | ||
Weather weather = new Weather(A_WEATHER_DESCRIPTION, | ||
A_WEATHER_TEMPERATURE, UNKNOWN_ICON_ID); | ||
int expectedIcon = R.drawable.sun; | ||
assertEquals(expectedIcon, | ||
WeatherIconMapper.getIconResourceIdForWeather(weather)); | ||
} | ||
} |
Oops, something went wrong.