Skip to content

Commit

Permalink
Add accessibility
Browse files Browse the repository at this point in the history
Add content description to wind text and the complete layout in general
  • Loading branch information
Protino committed Aug 19, 2016
1 parent 5cbff86 commit 0ad58fd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Weather Detail");
if (savedInstanceState == null) {

Bundle arguments = new Bundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return null;
}

public void onLocationChanged( String newLocation ) {
public void onLocationChanged(String newLocation) {
// replace the uri, since the location has changed
Uri uri = mUri;
if (null != uri) {
Expand Down Expand Up @@ -191,6 +191,7 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED);
float windDirStr = data.getFloat(COL_WEATHER_DEGREES);
mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr));
mWindView.setContentDescription(Utility.getFormattedContentDescription(getActivity(), windSpeedStr, windDirStr));

// Read pressure from cursor and update view
float pressure = data.getFloat(COL_WEATHER_PRESSURE);
Expand Down
41 changes: 40 additions & 1 deletion app/src/main/java/com/calgen/prodek/sunshine_v2/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,46 @@ public static String getFormattedWind(Context context, float windSpeed, float de
windFormat = R.string.format_wind_mph;
windSpeed = .621371192237334f * windSpeed;
}
String direction = Utility.getWindDirection(degrees);
return String.format(context.getString(windFormat), windSpeed, direction);
}

public static String getFormattedContentDescription(Context context, float windSpeed, float degrees){
int windFormat;
if (Utility.isMetric(context)) {
windFormat = R.string.format_wind_kmh;
} else {
windFormat = R.string.format_wind_mph;
windSpeed = .621371192237334f * windSpeed;
}
String direction = Utility.getDetailedWindDirection(degrees);
return String.format(context.getString(windFormat), windSpeed, direction);
}

private static String getDetailedWindDirection(float degrees) {
//This is kinda stupid. But I had to do it.
String direction = "Unknown";
if (degrees >= 337.5 || degrees < 22.5) {
direction = "North";
} else if (degrees >= 22.5 && degrees < 67.5) {
direction = "North East";
} else if (degrees >= 67.5 && degrees < 112.5) {
direction = "East";
} else if (degrees >= 112.5 && degrees < 157.5) {
direction = "South East";
} else if (degrees >= 157.5 && degrees < 202.5) {
direction = "South";
} else if (degrees >= 202.5 && degrees < 247.5) {
direction = "South West";
} else if (degrees >= 247.5 && degrees < 292.5) {
direction = "West";
} else if (degrees >= 292.5 && degrees < 337.5) {
direction = "North West";
}
return direction;
}

private static String getWindDirection(float degrees) {
// From wind direction in degrees, determine compass direction as a string (e.g NW)
// You know what's fun, writing really long if/else statements with tons of possible
// conditions. Seriously, try it!
Expand All @@ -158,7 +197,7 @@ public static String getFormattedWind(Context context, float windSpeed, float de
} else if (degrees >= 292.5 && degrees < 337.5) {
direction = "NW";
}
return String.format(context.getString(windFormat), windSpeed, direction);
return direction;
}


Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/fragment_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:contextClickable="true"
android:contentDescription="@string/weather_detail"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".fragment.DetailFragment">

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_detail_wide.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!-- Master layout. -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:contentDescription="@string/weather_detail"
android:layout_height="match_parent"
android:fillViewport="true">

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@

<!-- Humidity format CHAR LIMIT=25]-->
<string name="format_humidity">Humidity: <xliff:g id="humidity">%1.0f</xliff:g> %%</string>
<string name="weather_detail">Select around to read weather detail</string>
</resources>

0 comments on commit 0ad58fd

Please sign in to comment.