Updated the widget to display the currently applied ringer
closes #92 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="action_update" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
@@ -9,8 +10,21 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="15dip"
|
||||
android:background="@drawable/icon"
|
||||
android:contentDescription="@string/start_location_service" />
|
||||
|
||||
<TextView
|
||||
style="@style/styleName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/current_ringer" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="test"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -92,5 +92,6 @@
|
||||
<string name="mark_my_location">Mark my location</string>
|
||||
<string name="my_location">My location</string>
|
||||
<string name="map_mode">Map Mode</string>
|
||||
<string name="current_ringer">Current Ringer:</string>
|
||||
|
||||
</resources>
|
||||
@@ -74,4 +74,7 @@ Copyright (C) 2011 Jake Wharton Licensed under the Apache License, Version 2.0 (
|
||||
<item name="textSize">@dimen/default_title_indicator_text_size</item>
|
||||
<item name="titlePadding">@dimen/default_title_indicator_title_padding</item>
|
||||
</style>
|
||||
<style name="styleName" parent="android:Widget.DeviceDefault.TextView">
|
||||
<item name="android:gravity">center</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -9,6 +9,7 @@ package com.TwentyCodes.android.LocationRinger.receivers;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
@@ -26,7 +27,9 @@ import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
*/
|
||||
public class GetLocationWidget extends AppWidgetProvider {
|
||||
|
||||
public final String TAG = "GetLocationWidget";
|
||||
public final String TAG = "GetLocationWidget";
|
||||
|
||||
public static final String ACTION_UPDATE = "action_update";
|
||||
|
||||
/**
|
||||
* Called in response to the ACTION_APPWIDGET_UPDATE broadcast when this AppWidget provider is being asked to provide RemoteViews for a set of AppWidgets.
|
||||
@@ -57,6 +60,8 @@ public final String TAG = "GetLocationWidget";
|
||||
// Get the layout for the App Widget and attach an on-click listener to the button
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.get_location_widget);
|
||||
views.setOnClickPendingIntent(R.id.widget_get_location_button, pendingIntent);
|
||||
|
||||
views.setTextViewText(R.id.widget_label, context.getSharedPreferences(SettingsActivity.SETTINGS, Debug.SHARED_PREFS_MODE).getString(SettingsActivity.CURRENT, context.getString(R.string.default_ringer)));
|
||||
|
||||
// Tell the AppWidgetManager to perform an update on the current App Widget
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||
@@ -79,14 +84,19 @@ public final String TAG = "GetLocationWidget";
|
||||
Log.v(TAG, "onReceive");
|
||||
// v1.5 fix that doesn't call onDelete Action
|
||||
final String action = intent.getAction();
|
||||
|
||||
if(action.equals(ACTION_UPDATE)){
|
||||
AppWidgetManager mgr=AppWidgetManager.getInstance(context);
|
||||
onUpdate(context, mgr, mgr.getAppWidgetIds(new ComponentName(context, GetLocationWidget.class)));
|
||||
}
|
||||
|
||||
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
|
||||
final int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
this.onDeleted(context, new int[] { appWidgetId });
|
||||
}
|
||||
} else {
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.TwentyCodes.android.LocationRinger.db.RingerDatabase;
|
||||
import com.TwentyCodes.android.LocationRinger.debug.Debug;
|
||||
import com.TwentyCodes.android.LocationRinger.receivers.GetLocationWidget;
|
||||
import com.TwentyCodes.android.LocationRinger.ui.SettingsActivity;
|
||||
import com.TwentyCodes.android.debug.LocationLibraryConstants;
|
||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||
@@ -64,6 +65,10 @@ public class RingerProcessingService extends Service {
|
||||
|
||||
final String name = values.getAsString(RingerDatabase.KEY_RINGER_NAME);
|
||||
|
||||
this.getSharedPreferences(SettingsActivity.SETTINGS, Debug.SHARED_PREFS_MODE).edit().putString(SettingsActivity.CURRENT, name).commit();
|
||||
|
||||
this.sendBroadcast(new Intent(this, GetLocationWidget.class).setAction(GetLocationWidget.ACTION_UPDATE));
|
||||
|
||||
/*
|
||||
* Make it toasty if the user wants to be notified.
|
||||
* This will display a toast msg "Applying <ringer name>"
|
||||
|
||||
@@ -50,6 +50,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
|
||||
public static final String IS_DEFAULT = "is_default";
|
||||
public static final String RESTORE = "restore";
|
||||
public static final String BACKUP = "backup";
|
||||
public static final String CURRENT = "current";
|
||||
|
||||
/**
|
||||
* Backs up the database
|
||||
|
||||
Reference in New Issue
Block a user