Permalink
Browse files

null pointer, widget size, ontouch

  • Loading branch information...
1 parent d9f62f0 commit 989e257292fd5cf8bdf6fa3e91fa514e0063cd70 Carles Sentis committed Sep 6, 2012
Showing with 37 additions and 36 deletions.
  1. +1 −1 .project
  2. +8 −8 res/layout/widget.xml
  3. +18 −21 src/com/codeskraps/lolo/LoloProvider.java
  4. +10 −6 src/com/codeskraps/lolo/UpdateWidgetReceiver.java
View
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>091 Labs lo-lo</name>
+ <name>091labs_lo-lo</name>
<comment></comment>
<projects>
</projects>
View
@@ -2,40 +2,40 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:layout_gravity="center"
- android:orientation="vertical" >
+ android:layout_gravity="center" >
<ImageView
android:id="@+id/imgLolo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
android:contentDescription="@string/contentDescription"
- android:padding="10dip"
+ android:paddingBottom="5dip"
+ android:paddingLeft="10dip"
+ android:paddingRight="10dip"
android:src="@drawable/closed" />
<ProgressBar
android:id="@+id/prgBar"
style="@android:style/Widget.ProgressBar.Small"
android:layout_width="20dp"
android:layout_height="20dp"
+ android:layout_alignBottom="@id/imgLolo"
+ android:layout_alignTop="@id/imgLolo"
android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
android:visibility="gone" />
<TextView
android:id="@+id/txtSync"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
+ android:layout_alignBottom="@id/imgLolo"
android:gravity="center_horizontal"
android:shadowColor="#000000"
android:shadowDx="1"
android:shadowDy="1"
android:shadowRadius="1"
- android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceSmall"
- android:typeface="monospace" />
+ android:textColor="#FFFFFF" />
</RelativeLayout>
@@ -31,6 +31,7 @@
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
+import android.widget.RemoteViews;
public class LoloProvider extends AppWidgetProvider {
private static final String TAG = LoloProvider.class.getSimpleName();
@@ -47,32 +48,28 @@ public void onReceive(Context context, Intent intent) {
if (BuildConfig.DEBUG) Log.d(TAG, "onReceive");
final String action = intent.getAction();
Log.d(TAG, "Action: " + action);
- if (action.equals(Constants.FORCE_WIDGET_UPDATE)) updateWidget(context);
- super.onReceive(context, intent);
- }
-
- public void updateWidget(Context context) {
- if (BuildConfig.DEBUG) Log.d(TAG, "updateWidget");
-
- ComponentName thisWidget = new ComponentName(context, LoloProvider.class);
- AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
- int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
+ if (action.equals(Constants.FORCE_WIDGET_UPDATE)) {
+ ComponentName thisWidget = new ComponentName(context, LoloProvider.class);
+ AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
+ int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
- updateWidget(context, appWidgetManager, appWidgetIds);
+ updateWidget(context, appWidgetManager, appWidgetIds);
+ }
+ super.onReceive(context, intent);
}
private void updateWidget(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
- if (BuildConfig.DEBUG) Log.d(TAG, "updateWidget2");
+ if (BuildConfig.DEBUG) Log.d(TAG, "updateWidget");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
-// RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
-//
-// if (appWidgetIds.length > 0) {
-// for (int appWidgetId : appWidgetIds) {
-//
-// remoteViews.setOnClickPendingIntent(R.id.imgLolo, Utils.getOnTouchIntent(context));
-// appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
-// }
-// }
+ RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
+
+ if (appWidgetIds.length > 0) {
+ for (int appWidgetId : appWidgetIds) {
+ remoteViews.setOnClickPendingIntent(R.id.imgLolo,
+ Utils.getOnTouchIntent(context));
+ appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
+ }
+ }
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(Constants.BROADCAST_RECEIVER);
@@ -70,17 +70,21 @@ public void run() {
try {
lolo = Utils.getLolo();
} catch (UnsupportedEncodingException e) {
- if (BuildConfig.DEBUG && e != null) Log.e(TAG, e.getMessage());
+ if (BuildConfig.DEBUG)
+ Log.e(TAG, (e == null) ? "UnsupportedEncodingException" : e.getMessage());
} catch (ClientProtocolException e) {
- if (BuildConfig.DEBUG && e != null) Log.e(TAG, e.getMessage());
+ if (BuildConfig.DEBUG)
+ Log.e(TAG, (e == null) ? "ClientProtocolException" : e.getMessage());
} catch (IOException e) {
- if (BuildConfig.DEBUG && e != null) Log.e(TAG, e.getMessage());
+ if (BuildConfig.DEBUG) Log.e(TAG, (e == null) ? "IOException" : e.getMessage());
} catch (IllegalArgumentException e) {
- if (BuildConfig.DEBUG && e != null) Log.e(TAG, e.getMessage());
+ if (BuildConfig.DEBUG)
+ Log.e(TAG, (e == null) ? "IllegalArgumentException" : e.getMessage());
} catch (NullPointerException e) {
- if (BuildConfig.DEBUG && e != null) Log.e(TAG, e.getMessage());
+ if (BuildConfig.DEBUG)
+ Log.e(TAG, (e == null) ? "NullPointerException" : e.getMessage());
} catch (JSONException e) {
- if (BuildConfig.DEBUG && e != null) Log.e(TAG, e.getMessage());
+ if (BuildConfig.DEBUG) Log.e(TAG, (e == null) ? "JSONException" : e.getMessage());
} finally {
handler.post(new MyRunnable());
}

0 comments on commit 989e257

Please sign in to comment.