Skip to content

Commit

Permalink
New stuff!
Browse files Browse the repository at this point in the history
  • Loading branch information
chiara committed Mar 31, 2015
1 parent 3d07555 commit c50132f
Show file tree
Hide file tree
Showing 20 changed files with 483 additions and 144 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
#- adb shell input keyevent 82 &

script:
- ./gradlew :londonWeather:assemble
- ls /home/travis/build/kul3r4/droidConf/londonWeather/build/outputs/apk/londonWeather-debug.apk
- ./gradlew :londonWeatherAcceptance:test --stacktrace --debug -DANDROID_HOME=/usr/local/android-sdk/
- ./gradlew :londonWeather:clean build
#- ls /home/travis/build/kul3r4/droidConf/londonWeather/build/outputs/apk/londonWeather-debug.apk
#- ./gradlew :londonWeatherAcceptance:test --stacktrace --debug -DANDROID_HOME=/usr/local/android-sdk/

21 changes: 20 additions & 1 deletion londonWeather/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "com.cchiappini.londonweather"
minSdkVersion 19
targetSdkVersion 21
targetSdkVersion 18
versionCode 1
versionName "1.0"
}
Expand All @@ -21,6 +21,25 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
compile project(':londonweatherlib')
testCompile 'junit:junit:4.12'
testCompile project(':londonweatherlib')
testCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}
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 {

}
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
package com.cchiappini.londonweather;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.cchiappini.londonweather.exception.IconNotFoundException;

import weather.Weather;
import weather.WeatherOracle;

import static com.cchiappini.londonweather.R.id.weather_description;
import static com.cchiappini.londonweather.R.id.weather_icon;
import static com.cchiappini.londonweather.R.id.weather_temp;
import static com.cchiappini.londonweather.R.id.weather_toolbar;
import static com.cchiappini.londonweather.R.layout.activity_main;


public class MainActivity extends Activity {
public class MainActivity extends ActionBarActivity {

public static final String WEATHER_EXTRA = "WEATHER_EXTRA";
public static final String MAIN_ACTIVITY = "MainActivity";

private WeatherOracle weatherOracle = new WeatherOracle();
private Toolbar toolbar;
private TextView tempView;
private TextView descriptionView;
private ImageView iconView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.weather_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String weather = weatherOracle.getWeather();
Intent intent = new Intent(MainActivity.this, WeatherActivity.class);
intent.putExtra(WEATHER_EXTRA,weather);
startActivity(intent);
}
});
setContentView(activity_main);
Weather currentWeather = getWeather();
String weatherDescription = currentWeather.getWeatherDescription();
toolbar = (Toolbar) findViewById(weather_toolbar);
toolbar.setTitle("Richmond");
setSupportActionBar(toolbar);

tempView =(TextView) findViewById(weather_temp);
tempView.setText(String.format("%.0f",currentWeather.getTemperature()));

descriptionView = (TextView) findViewById(weather_description);
descriptionView.setText(weatherDescription);

iconView = (ImageView) findViewById(weather_icon);
try {
iconView.setImageResource(WeatherIconMapper.getIconResourceIdForWeather(currentWeather));
} catch (IconNotFoundException e) {
Log.e(MAIN_ACTIVITY, "no icon found for weather "+currentWeather);
}
}

private Weather getWeather() {
return weatherOracle.getWeather();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cchiappini.londonweather;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -10,7 +10,7 @@
import static com.cchiappini.londonweather.MainActivity.*;


public class WeatherActivity extends Activity {
public class WeatherActivity extends ActionBarActivity {

private String weather;

Expand All @@ -21,7 +21,7 @@ protected void onCreate(Bundle savedInstanceState) {

setContentView(R.layout.activity_weather);
View view = findViewById(R.id.weather_text_layout);
TextView weatherTextView = (TextView) view.findViewById(R.id.weather_text);
TextView weatherTextView = (TextView) view.findViewById(R.id.weather_description);
weatherTextView.setText(weather);
}

Expand Down
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();
}
}
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");
}

}
68 changes: 61 additions & 7 deletions londonWeather/src/main/res/layout/activity_main.xml
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>
2 changes: 1 addition & 1 deletion londonWeather/src/main/res/layout/activity_weather.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/weather_text"/>
android:id="@+id/weather_description"/>

</LinearLayout>
3 changes: 2 additions & 1 deletion londonWeather/src/main/res/values-v21/styles.xml
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>
6 changes: 6 additions & 0 deletions londonWeather/src/main/res/values/colors.xml
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>
20 changes: 17 additions & 3 deletions londonWeather/src/main/res/values/styles.xml
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>
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));
}

}
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));
}
}
Loading

0 comments on commit c50132f

Please sign in to comment.