Permalink
Browse files

Added a basic widget.

  • Loading branch information...
adamsp committed Dec 24, 2013
1 parent d710354 commit 813d1ec9a60c01277dad256877aacfe5b4e3178a
@@ -5,21 +5,21 @@

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
android:targetSdkVersion="19" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
android:required="true" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />

<!-- Maps. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<application
android:icon="@drawable/ic_launcher"
@@ -28,7 +28,8 @@
<activity
android:name=".activities.MainActivity"
android:label="@string/title_activity_main"
android:launchMode="singleInstance" >
android:launchMode="singleInstance"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

@@ -50,11 +51,10 @@
android:name=".activities.AboutActivity"
android:label="@string/title_activity_about" >
</activity>
<activity
android:name=".activities.QuakeActivity" >
<activity android:name=".activities.QuakeActivity" >
</activity>
<activity
android:name=".activities.PreferenceActivity" >
<activity android:name=".activities.PreferenceActivity"
android:exported="true" >
</activity>

<service
@@ -65,7 +65,17 @@
<!-- See https://developers.google.com/maps/documentation/android/start for details on acquiring an API key. -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBmfpr8MHUrpQxjnqVXA-T4tdhyJB0Izig"/>
android:value="AIzaSyBmfpr8MHUrpQxjnqVXA-T4tdhyJB0Izig" />

<receiver android:name=".widget.WhatsShakingWidgetProvider" android:label="@string/widget_label" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_info" />
</receiver>
</application>

</manifest>
@@ -13,6 +13,7 @@
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt

# Project target.
target=Google Inc.:Google APIs:15
target=Google Inc.:Google APIs:19
android.library=false
android.library.reference.1=../ActionBarSherlock/library
android.library.reference.2=../google-play-services_lib
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_detail_parent_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/widget_margin"
android:background="@drawable/card_background"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="@dimen/widget_padding" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
style="@style/WidgetFont.Heading"
android:text="@string/widget_heading" />

<TextView
android:id="@+id/widget_detail_latest_datetime"
style="@style/WidgetFont.Detail"
android:ellipsize="end"
android:lines="1"
android:text="@string/widget_loading" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >

<TextView
style="@style/WidgetFont.Heading"
android:text="@string/magnitude_heading_text" />

<TextView
android:id="@+id/widget_detail_latest_magnitude"
style="@style/WidgetFont.Detail"
android:text="@string/widget_loading" />
</LinearLayout>

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >

<TextView
style="@style/WidgetFont.Heading"
android:text="@string/depth_heading_text" />

<TextView
android:id="@+id/widget_detail_latest_depth"
style="@style/WidgetFont.Detail"
android:text="@string/widget_loading" />
</LinearLayout>
</LinearLayout>

</LinearLayout>
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_error_parent_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/widget_margin"
android:background="@drawable/card_background" >

<TextView
android:id="@+id/widget_detail_background_service_not_enabled_message"
style="@style/WidgetFont.ErrorMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="@dimen/widget_padding"
android:text="@string/widget_background_service_not_enabled_message" />

</RelativeLayout>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- The docs say don't include a margin for API > 14. Bugger that; this way it's flush with the Google Now widget. -->
<dimen name="widget_margin">6dp</dimen>
<dimen name="widget_padding">8dp</dimen>

</resources>
@@ -30,5 +30,12 @@
<dimen name="detail_fragment_heading_padding_left">2dp</dimen>

<dimen name="detail_fragment_padding">4dp</dimen>


<dimen name="widget_margin">8dp</dimen>
<dimen name="widget_padding">8dp</dimen>
<dimen name="widget_error_text_size">12sp</dimen>
<dimen name="widget_heading_text_size">10sp</dimen>
<dimen name="widget_detail_text_size">16sp</dimen>
<dimen name="widget_detail_padding_left">10dp</dimen>
<dimen name="widget_heading_padding_left">6dp</dimen>
</resources>
@@ -14,6 +14,8 @@
<string name="depth_heading_text">DEPTH</string>
<string name="date_heading_text">DATE</string>
<string name="status_heading_text">STATUS</string>

<string name="depth_detail">%s km</string>

<string name="earthquake_status_automatic">An automatic earthquake location that has not been reviewed by a duty officer or analyst.</string>
<string name="earthquake_status_deleted">Oops! This was not a real earthquake and has been deleted.</string>
@@ -85,5 +87,11 @@

<string name="tab_title_list">List</string>
<string name="tab_title_map">Map</string>

<!-- Widget strings -->
<string name="widget_label">What\'s Shaking, NZ?</string>
<string name="widget_heading">LATEST EARTHQUAKE</string>
<string name="widget_loading">Loading...</string>
<string name="widget_background_service_not_enabled_message">Automatic updates not enabled. Tap here to turn on.</string>

</resources>
@@ -10,7 +10,7 @@
<item name="android:ellipsize">end</item>
</style>

<style name="ListFont.Magnitude">
<style name="ListFont.Magnitude" >
<item name="android:textSize">@dimen/list_row_item_magnitude_text_size</item>
<item name="android:gravity">center</item>
<item name="android:layout_width">@dimen/list_row_item_magnitude_layout_width</item>
@@ -76,5 +76,42 @@
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
</style>

<!-- Widget -->
<style name="WidgetFont">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>

<style name="WidgetFont.Heading">
<item name="android:lines">1</item>
<item name="android:textSize">@dimen/widget_heading_text_size</item>
<item name="android:paddingLeft">@dimen/widget_heading_padding_left</item>
<item name="android:ellipsize">none</item>
</style>

<style name="WidgetFont.Heading.Weighted">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
</style>

<style name="WidgetFont.Detail">
<item name="android:lines">1</item>
<item name="android:textColor">#7F7F7F</item>
<item name="android:textSize">@dimen/widget_detail_text_size</item>
<item name="android:paddingLeft">@dimen/widget_detail_padding_left</item>
<item name="android:ellipsize">end</item>
</style>

<style name="WidgetFont.Detail.Weighted">
<item name="android:layout_width">0dp</item>
<item name="android:layout_weight">1</item>
</style>

<style name="WidgetFont.ErrorMessage">
<item name="android:textColor">#7F7F7F</item>
<item name="android:textSize">@dimen/widget_error_text_size</item>
<item name="android:ellipsize">end</item>
</style>

</resources>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="250dp"
android:minHeight="40dp"
android:minResizeWidth="200dp"
android:minResizeHeight="40dp"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget_detail"
android:resizeMode="horizontal"
android:widgetCategory="home_screen" >
</appwidget-provider>
@@ -1,17 +1,19 @@
package speakman.whatsshakingnz.activities;

import speakman.whatsshakingnz.R;
import speakman.whatsshakingnz.earthquake.Earthquake;
import speakman.whatsshakingnz.geonet.GeonetAlarmListener;
import speakman.whatsshakingnz.preferences.DefaultPrefs;
import speakman.whatsshakingnz.widget.WidgetUpdater;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.widget.Toast;

import com.actionbarsherlock.app.SherlockPreferenceActivity;
import com.actionbarsherlock.view.MenuItem;
import com.commonsware.cwac.wakeful.WakefulIntentService;
import speakman.whatsshakingnz.R;
import speakman.whatsshakingnz.earthquake.Earthquake;
import speakman.whatsshakingnz.geonet.GeonetAlarmListener;
import speakman.whatsshakingnz.preferences.DefaultPrefs;

public class PreferenceActivity extends SherlockPreferenceActivity implements
OnSharedPreferenceChangeListener {
@@ -63,6 +65,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
getString(R.string.pref_backgroundNotificationsDisabled),
Toast.LENGTH_SHORT).show();
}
new WidgetUpdater(this).updateWidgets();
} else if (key.equals(KEY_PREF_BG_NOTIFICATIONS_FREQ)) {
String value = sharedPreferences.getString(key,
DefaultPrefs.BG_NOTIFICATIONS_FREQ_STRING);
@@ -5,12 +5,12 @@

import speakman.whatsshakingnz.R;
import speakman.whatsshakingnz.activities.PreferenceActivity;
import speakman.whatsshakingnz.formatting.DateFormatting;
import speakman.whatsshakingnz.preferences.DefaultPrefs;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -60,12 +60,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
if (itemView != null) {
Date date = quake.getDate();
if (null != date) {
java.text.DateFormat tf = DateFormat
.getTimeFormat(getContext());
java.text.DateFormat df = DateFormat
.getMediumDateFormat(getContext());
String dateString = String.format("%s, %s",
df.format(date), tf.format(date));
String dateString = DateFormatting.getMediumDateString(getContext(), date);
itemView.setText(dateString);
}
}
@@ -0,0 +1,36 @@
package speakman.whatsshakingnz.formatting;

import java.util.Date;

import android.content.Context;
import android.text.format.DateFormat;

public class DateFormatting {

/**
* Returns a date time string formatted similar to 12:13 PM 28/12/2013.
* Respects users device locale & 12/24 hour settings.
*/
public static String getShortDateString(Context context, Date date) {
if (context == null || date == null) return null;
java.text.DateFormat tf = DateFormat.getTimeFormat(context);
java.text.DateFormat df = DateFormat.getDateFormat(context);
String dateString = String.format("%s, %s", df.format(date),
tf.format(date));
return dateString;
}

/**
* Returns a date time string formatted similar to 12:13 PM Dec 28, 2013.
* Respects users device locale & 12/24 hour settings.
*/
public static String getMediumDateString(Context context, Date date) {
if (context == null || date == null) return null;
java.text.DateFormat tf = DateFormat.getTimeFormat(context);
java.text.DateFormat df = DateFormat.getMediumDateFormat(context);
String dateString = String.format("%s, %s", df.format(date),
tf.format(date));
return dateString;
}

}
Oops, something went wrong.

0 comments on commit 813d1ec

Please sign in to comment.