Cleanup a bunch of warnings in app widgets code.

This commit is contained in:
Romain Guy
2009-07-01 17:20:08 -07:00
parent 392282f1e0
commit a54755962c
4 changed files with 55 additions and 61 deletions

View File

@@ -26,7 +26,6 @@ import android.widget.RemoteViews;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.android.internal.appwidget.IAppWidgetHost;
import com.android.internal.appwidget.IAppWidgetService;
@@ -40,7 +39,7 @@ public class AppWidgetHost {
static final int HANDLE_UPDATE = 1;
static final int HANDLE_PROVIDER_CHANGED = 2;
static Object sServiceLock = new Object();
final static Object sServiceLock = new Object();
static IAppWidgetService sService;
Context mContext;
@@ -85,7 +84,7 @@ public class AppWidgetHost {
int mHostId;
Callbacks mCallbacks = new Callbacks();
HashMap<Integer,AppWidgetHostView> mViews = new HashMap();
final HashMap<Integer,AppWidgetHostView> mViews = new HashMap<Integer, AppWidgetHostView>();
public AppWidgetHost(Context context, int hostId) {
mContext = context;
@@ -104,8 +103,8 @@ public class AppWidgetHost {
* becomes visible, i.e. from onStart() in your Activity.
*/
public void startListening() {
int[] updatedIds = null;
ArrayList<RemoteViews> updatedViews = new ArrayList();
int[] updatedIds;
ArrayList<RemoteViews> updatedViews = new ArrayList<RemoteViews>();
try {
if (mPackageName == null) {
@@ -209,7 +208,7 @@ public class AppWidgetHost {
synchronized (mViews) {
mViews.put(appWidgetId, view);
}
RemoteViews views = null;
RemoteViews views;
try {
views = sService.getAppWidgetViews(appWidgetId);
} catch (RemoteException e) {
@@ -231,6 +230,7 @@ public class AppWidgetHost {
/**
* Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
*/
@SuppressWarnings({"UnusedDeclaration"})
protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
}

View File

@@ -22,16 +22,12 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.Config;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.FrameLayout;
import android.widget.RemoteViews;
import android.widget.TextView;
@@ -86,6 +82,7 @@ public class AppWidgetHostView extends FrameLayout {
* @param animationIn Resource ID of in animation to use
* @param animationOut Resource ID of out animation to use
*/
@SuppressWarnings({"UnusedDeclaration"})
public AppWidgetHostView(Context context, int animationIn, int animationOut) {
super(context);
mContext = context;

View File

@@ -20,10 +20,8 @@ import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Parcel;
@@ -36,15 +34,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater.Filter;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import java.lang.Class;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -69,13 +64,7 @@ public class RemoteViews implements Parcelable, Filter {
* The resource ID of the layout file. (Added to the parcel)
*/
private int mLayoutId;
/**
* The Context object used to inflate the layout file. Also may
* be used by actions if they need access to the senders resources.
*/
private Context mContext;
/**
* An array of actions to perform on the view tree once it has been
* inflated
@@ -85,7 +74,7 @@ public class RemoteViews implements Parcelable, Filter {
/**
* This annotation indicates that a subclass of View is alllowed to be used
* with the {@link android.widget.RemoteViews} mechanism.
* with the {@link RemoteViews} mechanism.
*/
@Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@@ -116,7 +105,7 @@ public class RemoteViews implements Parcelable, Filter {
public int describeContents() {
return 0;
}
};
}
/**
* Equivalent to calling
@@ -232,15 +221,17 @@ public class RemoteViews implements Parcelable, Filter {
targetDrawable = imageView.getDrawable();
}
// Perform modifications only if values are set correctly
if (alpha != -1) {
targetDrawable.setAlpha(alpha);
}
if (colorFilter != -1 && filterMode != null) {
targetDrawable.setColorFilter(colorFilter, filterMode);
}
if (level != -1) {
targetDrawable.setLevel(level);
if (targetDrawable != null) {
// Perform modifications only if values are set correctly
if (alpha != -1) {
targetDrawable.setAlpha(alpha);
}
if (colorFilter != -1 && filterMode != null) {
targetDrawable.setColorFilter(colorFilter, filterMode);
}
if (level != -1) {
targetDrawable.setLevel(level);
}
}
}
@@ -289,6 +280,7 @@ public class RemoteViews implements Parcelable, Filter {
this.viewId = in.readInt();
this.methodName = in.readString();
this.type = in.readInt();
//noinspection ConstantIfStatement
if (false) {
Log.d("RemoteViews", "read viewId=0x" + Integer.toHexString(this.viewId)
+ " methodName=" + this.methodName + " type=" + this.type);
@@ -340,31 +332,32 @@ public class RemoteViews implements Parcelable, Filter {
out.writeInt(this.viewId);
out.writeString(this.methodName);
out.writeInt(this.type);
//noinspection ConstantIfStatement
if (false) {
Log.d("RemoteViews", "write viewId=0x" + Integer.toHexString(this.viewId)
+ " methodName=" + this.methodName + " type=" + this.type);
}
switch (this.type) {
case BOOLEAN:
out.writeInt(((Boolean)this.value).booleanValue() ? 1 : 0);
out.writeInt((Boolean) this.value ? 1 : 0);
break;
case BYTE:
out.writeByte(((Byte)this.value).byteValue());
out.writeByte((Byte) this.value);
break;
case SHORT:
out.writeInt(((Short)this.value).shortValue());
out.writeInt((Short) this.value);
break;
case INT:
out.writeInt(((Integer)this.value).intValue());
out.writeInt((Integer) this.value);
break;
case LONG:
out.writeLong(((Long)this.value).longValue());
out.writeLong((Long) this.value);
break;
case FLOAT:
out.writeFloat(((Float)this.value).floatValue());
out.writeFloat((Float) this.value);
break;
case DOUBLE:
out.writeDouble(((Double)this.value).doubleValue());
out.writeDouble((Double) this.value);
break;
case CHAR:
out.writeInt((int)((Character)this.value).charValue());
@@ -430,7 +423,7 @@ public class RemoteViews implements Parcelable, Filter {
}
Class klass = view.getClass();
Method method = null;
Method method;
try {
method = klass.getMethod(this.methodName, getParameterType());
}
@@ -446,6 +439,7 @@ public class RemoteViews implements Parcelable, Filter {
}
try {
//noinspection ConstantIfStatement
if (false) {
Log.d("RemoteViews", "view: " + klass.getName() + " calling method: "
+ this.methodName + "(" + param.getName() + ") with "
@@ -816,13 +810,12 @@ public class RemoteViews implements Parcelable, Filter {
* @return The inflated view hierarchy
*/
public View apply(Context context, ViewGroup parent) {
View result = null;
View result;
Context c = prepareContext(context);
Resources r = c.getResources();
LayoutInflater inflater = (LayoutInflater) c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater inflater = (LayoutInflater)
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater = inflater.cloneInContext(c);
inflater.setFilter(this);
@@ -858,7 +851,7 @@ public class RemoteViews implements Parcelable, Filter {
}
private Context prepareContext(Context context) {
Context c = null;
Context c;
String packageName = mPackage;
if (packageName != null) {
@@ -872,8 +865,6 @@ public class RemoteViews implements Parcelable, Filter {
c = context;
}
mContext = c;
return c;
}

View File

@@ -29,7 +29,6 @@ import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageItemInfo;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.net.Uri;
@@ -57,7 +56,6 @@ import java.util.HashSet;
import com.android.internal.appwidget.IAppWidgetService;
import com.android.internal.appwidget.IAppWidgetHost;
import com.android.internal.util.XmlUtils;
import com.android.internal.util.FastXmlSerializer;
import org.xmlpull.v1.XmlPullParser;
@@ -80,7 +78,7 @@ class AppWidgetService extends IAppWidgetService.Stub
static class Provider {
int uid;
AppWidgetProviderInfo info;
ArrayList<AppWidgetId> instances = new ArrayList();
ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
PendingIntent broadcast;
boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
@@ -91,7 +89,7 @@ class AppWidgetService extends IAppWidgetService.Stub
int uid;
int hostId;
String packageName;
ArrayList<AppWidgetId> instances = new ArrayList();
ArrayList<AppWidgetId> instances = new ArrayList<AppWidgetId>();
IAppWidgetHost callbacks;
boolean zombie; // if we're in safe mode, don't prune this just because nobody references it
@@ -108,10 +106,10 @@ class AppWidgetService extends IAppWidgetService.Stub
Context mContext;
PackageManager mPackageManager;
AlarmManager mAlarmManager;
ArrayList<Provider> mInstalledProviders = new ArrayList();
ArrayList<Provider> mInstalledProviders = new ArrayList<Provider>();
int mNextAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID + 1;
ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList();
ArrayList<Host> mHosts = new ArrayList();
final ArrayList<AppWidgetId> mAppWidgetIds = new ArrayList<AppWidgetId>();
ArrayList<Host> mHosts = new ArrayList<Host>();
boolean mSafeMode;
AppWidgetService(Context context) {
@@ -175,7 +173,7 @@ class AppWidgetService extends IAppWidgetService.Stub
for (int i=0; i<N; i++) {
AppWidgetId id = mAppWidgetIds.get(i);
pw.print(" ["); pw.print(i); pw.print("] id=");
pw.println(id.appWidgetId);;
pw.println(id.appWidgetId);
pw.print(" hostId=");
pw.print(id.host.hostId); pw.print(' ');
pw.print(id.host.packageName); pw.print('/');
@@ -385,7 +383,7 @@ class AppWidgetService extends IAppWidgetService.Stub
public List<AppWidgetProviderInfo> getInstalledProviders() {
synchronized (mAppWidgetIds) {
final int N = mInstalledProviders.size();
ArrayList<AppWidgetProviderInfo> result = new ArrayList(N);
ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>(N);
for (int i=0; i<N; i++) {
Provider p = mInstalledProviders.get(i);
if (!p.zombie) {
@@ -620,7 +618,6 @@ class AppWidgetService extends IAppWidgetService.Stub
// rely on the fact that we've already set it and that
// PendingIntent.getBroadcast will update the extras.
boolean alreadyRegistered = p.broadcast != null;
int instancesSize = p.instances.size();
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
intent.setComponent(p.info.provider);
@@ -780,10 +777,12 @@ class AppWidgetService extends IAppWidgetService.Stub
if (real.exists()) {
readStateFromFileLocked(real);
if (temp.exists()) {
//noinspection ResultOfMethodCallIgnored
temp.delete();
}
} else if (temp.exists()) {
readStateFromFileLocked(temp);
//noinspection ResultOfMethodCallIgnored
temp.renameTo(real);
}
}
@@ -799,18 +798,23 @@ class AppWidgetService extends IAppWidgetService.Stub
// use the temporary one until it's fully written, create an empty file
// for real, which will we'll shortly delete.
try {
//noinspection ResultOfMethodCallIgnored
real.createNewFile();
} catch (IOException e) {
// Ignore
}
}
if (temp.exists()) {
//noinspection ResultOfMethodCallIgnored
temp.delete();
}
writeStateToFileLocked(temp);
//noinspection ResultOfMethodCallIgnored
real.delete();
//noinspection ResultOfMethodCallIgnored
temp.renameTo(real);
}
@@ -873,8 +877,10 @@ class AppWidgetService extends IAppWidgetService.Stub
stream.close();
}
} catch (IOException ex) {
// Ignore
}
if (file.exists()) {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
}
@@ -892,7 +898,7 @@ class AppWidgetService extends IAppWidgetService.Stub
int type;
int providerIndex = 0;
HashMap<Integer,Provider> loadedProviders = new HashMap();
HashMap<Integer,Provider> loadedProviders = new HashMap<Integer, Provider>();
do {
type = parser.next();
if (type == XmlPullParser.START_TAG) {
@@ -993,6 +999,7 @@ class AppWidgetService extends IAppWidgetService.Stub
stream.close();
}
} catch (IOException e) {
// Ignore
}
if (success) {
@@ -1088,7 +1095,7 @@ class AppWidgetService extends IAppWidgetService.Stub
// TODO: If there's a better way of matching an intent filter against the
// packages for a given package, use that.
void updateProvidersForPackageLocked(String pkgName) {
HashSet<String> keep = new HashSet();
HashSet<String> keep = new HashSet<String>();
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
List<ResolveInfo> broadcastReceivers = mPackageManager.queryBroadcastReceivers(intent,
PackageManager.GET_META_DATA);
@@ -1110,7 +1117,6 @@ class AppWidgetService extends IAppWidgetService.Stub
if (parsed != null) {
keep.add(ai.name);
// Use the new AppWidgetProviderInfo.
AppWidgetProviderInfo oldInfo = p.info;
p.info = parsed.info;
// If it's enabled
final int M = p.instances.size();