Android 是否有一种方法可以全面查看进程分配的所有内存?

Android 是否有一种方法可以全面查看进程分配的所有内存?,android,memory,bitmap,ddms,Android,Memory,Bitmap,Ddms,首先是一些背景故事。我有一个基础vew,我的应用程序的三个主要视图可以扩展。子视图为空、模拟和数字。我将这些子视图放置在gridview(2x3)中,并将gridview放置在slidingdraw中。这个滑动抽屉是我应用程序的关键。这是绝对必要的。滑动抽屉必须位于每个活动中,所以一旦活动发生更改,我只需将状态存储在aaapplication中,并在新活动加载时检索它 当应用程序打开时,gridview会创建六个空视图并将它们添加到其适配器中。现在,虽然所有的视图都是空的,但该应用程序工作得完美

首先是一些背景故事。我有一个基础vew,我的应用程序的三个主要视图可以扩展。子视图为空、模拟和数字。我将这些子视图放置在gridview(2x3)中,并将gridview放置在slidingdraw中。这个滑动抽屉是我应用程序的关键。这是绝对必要的。滑动抽屉必须位于每个活动中,所以一旦活动发生更改,我只需将状态存储在aaapplication中,并在新活动加载时检索它

当应用程序打开时,gridview会创建六个空视图并将它们添加到其适配器中。现在,虽然所有的视图都是空的,但该应用程序工作得完美无缺。我可以在活动中漫游,并完成应用程序的所有其他功能。当我继续从事同样的活动时,我可以创建模拟和数字视图来满足我的内心需求。它们可以正确地移动、删除和执行所有功能。但是,只要我切换到另一个活动并且在gridview中甚至有一个模拟或数字视图,应用程序就会通过
OutOfMemoryError崩溃:位图大小超过虚拟机预算

模拟视图和数字视图都为自己创建了两个位图。一个是视图的背景,另一个是视图的独特外观,很少改变,更适合作为位图。两个位图都相当小(在我的测试Evo上为221x221像素)。这让我觉得我没有在活动更改时正确回收它们。所以我回去检查所有的东西都被清理了,并制作了一个完全破坏每个视图的方法。当活动暂停时,每个变量都被设置为null,所有位图都被循环使用。(注意:使用记录器,我验证了onPause确实被调用,以及destroy方法。)

现在-几天后-我仍然不明白为什么会抛出这个内存错误。我花了很长时间查看DDMS和内存跟踪器,这可能是有史以来最无用的东西。我完全受够了DDMS,我不能让这个愚蠢的东西告诉我任何有用的东西

现在问题来了。是否有一种方法(方法/系统调用或其他方法)可以让我获得进程(我的应用程序)的完整分配列表,并打印/显示/保存到文件等。。。是吗

编辑1:这是对Falmari的回应。我可能会发布一点到很多,我为此道歉。如果你想看一些更具体的东西,我非常乐意帮助你,你没有理由撕毁我的代码

剪辑来自BaseView:

public abstract class GaugeBase extends View implements BroadcastListener {
    protected static final String TAG = "GaugeBase";
    // =======================================
    // --- Declarations 
    /** Animation dynamics. */
    protected float mTarget = 0, position = 0, velocity = 0.0f, acceleration = 0.0f;
    protected long lastMoveTime = -1L;

    /** Background objects. */
    protected Bitmap mBackground;
    protected Bitmap mFaceTexture;
    protected float borderSize = 0.02f;

    /** Face objects. */
    protected Paint mRimShadowPaint, mTitlePaint, mFacePaint, mRimPaint, mRimBorderPaint;
    protected Path mTitlePath;

    /** Bounding rects. */
    protected static RectF mRimRect, mFaceRect;

    /** Text tools. */
    protected static Typeface mTypeface;

    /** The preferred size of the widget. */
    private static final int mPreferredSize = 300;

    /** The Broadcaster the gauge is registered to. */
    protected SensorBroadcaster mCaster;

    /** Is the view instantiated? */
    private boolean isDestroyed = true;
    // ---
    // =======================================

    public GaugeBase(Context context) {
        super(context);
        mCaster = ((AppionApplication)getContext().getApplicationContext())
            .getSensorBroadcaster(AppionApplication.TEST_SENSOR);
        lastMoveTime = System.currentTimeMillis();
        setTarget(mCaster.getReading());
    }

    @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); }
    @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); }
    @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { regenerate(); } 
    @Override public void onBroadcastReceived() { setTarget(mCaster.getReading()); }

    @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int chosenWidth = chooseDimension(widthMode, widthSize);
        int chosenHeight = chooseDimension(heightMode, heightSize);
        int chosenDimension = Math.min(chosenWidth, chosenHeight);
        setMeasuredDimension(chosenDimension, chosenDimension);
    }
    @Override protected void onDraw(Canvas canvas) {
        if (isDestroyed) return;
        if (mBackground == null) regenerate(); 
        canvas.drawBitmap(mBackground, 0, 0, null);
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.scale((float)getWidth(), (float)getWidth());
        drawForeground(canvas); canvas.restore(); animate();
    }

    public HashMap<String, Object> onSavePersistentState() {
        HashMap<String, Object> mState = new HashMap<String, Object>();
        mState.put("sensor_broadcaster", mCaster.getBroadcasterName());
        mState.put("type", this.getClass().getSimpleName());
        return mState;
    }

    public void onRestorePersistentState(HashMap<String, Object> state) {
        mCaster = ((AppionApplication)getContext().getApplicationContext())
            .getSensorBroadcaster((String)state.get("sensor_broadcaster"));
    }

    private final void setTarget(float target) { mTarget = target; animate(); }

    private static final int chooseDimension(int mode, int size) {
        if (mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) return size;
        else return mPreferredSize;
    }

    private final void animate() {
        if (! (Math.abs(position - mTarget) > 0.01f)) return;
        if (lastMoveTime != -1L) {
            long currentTime = System.currentTimeMillis();
            float delta = (currentTime - lastMoveTime) / 1000.0f;
            float direction = Math.signum(velocity);
            if (Math.abs(velocity) < 90.0f) acceleration = 10.0f * (mTarget - position);
            else acceleration = 0.0f;
            position += velocity * delta;
            velocity += acceleration * delta;
            if ((mTarget - position) * direction < 0.01f * direction) {
                position = mTarget;
                velocity = 0.0f;
                acceleration = 0.0f;
                lastMoveTime = -1L;
            } else lastMoveTime = System.currentTimeMillis();               
            invalidate();
        } else {
            lastMoveTime = System.currentTimeMillis();
            animate();
        }
    }

    public void preInit() {
        mTypeface = Typeface.createFromAsset(getContext().getAssets(),
                "fonts/SFDigitalReadout-Heavy.ttf");
        mFaceTexture = BitmapFactory.decodeResource(getContext().getResources(),
                R.drawable.gauge_face);
        BitmapShader shader = new BitmapShader(mFaceTexture, 
                Shader.TileMode.MIRROR, Shader.TileMode.MIRROR);

        Matrix matrix = new Matrix();
        mRimRect = new RectF(0.05f, 0.05f, 0.95f, 0.95f);
        mFaceRect = new RectF(mRimRect.left + borderSize, mRimRect.top + borderSize,
                             mRimRect.right - borderSize, mRimRect.bottom - borderSize);


        mFacePaint = new Paint();
        mFacePaint.setFilterBitmap(true);
        matrix.setScale(1.0f / mFaceTexture.getWidth(), 1.0f / mFaceTexture.getHeight());
        shader.setLocalMatrix(matrix);
        mFacePaint.setStyle(Paint.Style.FILL);
        mFacePaint.setShader(shader);

        mRimShadowPaint = new Paint();
        mRimShadowPaint.setShader(new RadialGradient(0.5f, 0.5f, mFaceRect.width() / 2.0f,
                new int[] { 0x00000000, 0x00000500, 0x50000500 },
                new float[] { 0.96f, 0.96f, 0.99f },
                Shader.TileMode.MIRROR));
        mRimShadowPaint.setStyle(Paint.Style.FILL);

        mRimPaint = new Paint();
        mRimPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
        mRimPaint.setShader(new LinearGradient(0.4f, 0.6f, 0.6f, 1.0f,
                Color.rgb(0xff0, 0xf5, 0xf0), Color.rgb(0x30, 0x31, 0x30),
                Shader.TileMode.CLAMP));

        mRimBorderPaint = new Paint();
        mRimBorderPaint.setAntiAlias(true);
        mRimBorderPaint.setStyle(Paint.Style.STROKE);
        mRimBorderPaint.setColor(Color.argb(0x4f, 0x33, 0x36, 0x33));
        mRimBorderPaint.setStrokeWidth(0.005f);

        mTitlePaint = new Paint();
        mTitlePaint.setColor(0xff000000);
        mTitlePaint.setAntiAlias(true);
        mTitlePaint.setTypeface(mTypeface);
        mTitlePaint.setTextAlign(Paint.Align.CENTER);
        mTitlePaint.setTextSize(0.2f);
        mTitlePaint.setTextScaleX(0.8f);        

        // Now we prepare the gauge
        init();
        isDestroyed = false;
    }

    /** Update the gauge independent static buffer cache for the background. */
    private void regenerate() {
        if (isDestroyed) return;
        if(mBackground != null) { mBackground.recycle(); mBackground = null; } 
        // Our new drawing area
        mBackground = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
        Canvas backCanvas = new Canvas(mBackground);
        float scale = (float)getWidth();
        backCanvas.scale(scale, scale);
        drawRim(backCanvas);
        drawFace(backCanvas);
        drawTitle(backCanvas);
        if (!(this instanceof EmptySpace)) { mCaster.getGroup().draw(backCanvas); }
        regenerateBackground(backCanvas);
    }

    /** Prepare the view to be cleaned up. This is called to prevent memory leaks. */
    public void destroy() { 
        isDestroyed = true;
        if (mFaceTexture != null) { mFaceTexture.recycle(); mBackground = null; }
        if (mBackground != null) { mBackground.recycle(); mBackground = null; }
        mRimShadowPaint = null;
        mRimShadowPaint = null;
        mFacePaint = null;
        mRimPaint = null;
        mRimBorderPaint = null;
        mTitlePath = null;
        mRimRect = null; mFaceRect = null;
        mTypeface = null;
        destroyDrawingCache();
    }

    /**
     * Create a bitmap of the gauge. The bitmap is to scale. 
     * @return The bitmap of the gauge.
     */
    int tobitmap = 0;
    public Bitmap toBitmap() {
        Bitmap b = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas();
        canvas.setBitmap(b);
        draw(canvas);
        return b;
    }

    /** Update the gauge dependent static buffer cache for the background. */
    protected abstract void regenerateBackground(Canvas canvas);
    /** Initializes all of the objects the gauge widget will need before use. */
    protected abstract void init();
    /** This is called when drawing the background. Draws the bordered edge of the gauge. */
    protected abstract void drawRim(Canvas canvas);
    /** This is called when drawing the background. Draws the face of the gauge. */
    protected abstract void drawFace(Canvas canvas);
    /** This is called when drawing the background. Draws the title to the gauge. */
    protected abstract void drawTitle(Canvas canvas);
    /**
     *  This is called when drawing the foreground. The foreground includes items like the 
     *  scale of an analog gauge, or the text of a digital gauge. Also any other necessary
     *  items that need drawing go here. Note: drawForeground is called quickly, repeatedly, 
     *  make it run fast and clean.
     */
    protected abstract void drawForeground(Canvas canvas);
}
至于通过应用程序的状态,我将视图的类型和视图所表示的caster的字符串名称放入hashmap中。我将该hashmap传递给gridview,gridview将把所有六个映射放入一个数组中,该数组将表示gridview中视图的位置。然后将该数组保存在应用程序中,并根据需要进行检索

这是gridview。我越想,这门课是我认为可能存在的问题

public class Workbench extends GridView {
    /** Our debugging tag */
    private static final String TAG = "Workbench";
    /** Name of the Workbench. */
    private String mId = "-1";
    /** The title of the Workbench. */
    private String mTitle = "Workbench";
    /** The list of Widgets that will be handled by the bench */
    private GaugeBase[] mContent = new GaugeBase[6];
    /** The current selection from the bench */
    private int mSelection = -1;

    /** When a GaugeBase is moves we want to remove from the adapter. Now we won't lose it.*/
    private GaugeBase mHeldGaugeBase = null;
    private Bitmap mHold = null;
    private boolean mIsHolding = false;
    private float x = -1000f, y = -1000f; // Where the held bitmap should be
    private Bitmap trash;
    private RectF trashBox;

    // The touch listener we will use if we need to move a widget around
    private OnTouchListener mWidgetExchanger = new OnTouchListener() {
        @Override public boolean onTouch(View v, MotionEvent e) {
            int w = getWidth(); int h = getHeight(); 
            float xx = e.getX(); float yy = e.getY();
            switch (e.getAction()) {
            case MotionEvent.ACTION_DOWN: // Fall through
            case MotionEvent.ACTION_MOVE: 
                if (mIsHolding) {
                    x = e.getX() - mHold.getWidth()/2; y = e.getY() - mHold.getHeight()/2;
                    postInvalidate(); break;
                }
            case MotionEvent.ACTION_UP: 
                if (mIsHolding) {
                    if (trashBox.contains(xx, yy)) removeGaugeBase(mSelection);
                    else {
                        if ((xx < w / 2) && (yy < h /3)) makeSwitch(0);
                        else if ((xx > w / 2) && (yy < h /3)) makeSwitch(1);
                        else if ((xx < w / 2) && (yy > h /3) && (yy < h * .666)) makeSwitch(2);
                        else if ((xx > w / 2) && (yy > h /3) && (yy < h * .666)) makeSwitch(3);
                        else if ((xx < w / 2) && (yy > h *.666)) makeSwitch(4);
                        else if ((xx > w / 2) && (yy > h *.666)) makeSwitch(5);
                    }
                    mSelection = -1;
                    //mHeldGaugeBase.destroy(); mHeldGaugeBase = null;
                    mHold.recycle(); mHold = null;
                    trash.recycle(); trash = null;
                    mIsHolding = false;
                    setOnTouchListener(null);
                    x = -1000f; y = -1000f;
                    ((AppionApplication)getContext().getApplicationContext()).vibrate(200); update();
                }
                break;
            }
            return true;
        }
    };

    public Workbench(Context context) { this(context, null); }
    public Workbench(Context context, AttributeSet attrs) { this(context, attrs, 0); }
    public Workbench(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        for (int i = 0; i < mContent.length; i++) {
            mContent[i] = new EmptySpace(getContext());
        }
        setAdapter(new BenchAdapter());
        this.setOnItemClickListener(new OnItemClickListener() {
            @Override public void onItemClick(AdapterView<?> arg0, View view, final int pos, long arg3) {
                if (mContent[pos] instanceof EmptySpace) {
                    CharSequence[] items = {"Analog", "Digital"};
                    AlertDialog.Builder adb = new AlertDialog.Builder(getContext());
                        adb.setTitle("Add a widget?")
                            .setItems(items, new DialogInterface.OnClickListener () {
                                @Override public void onClick(DialogInterface arg0, int position) {
                                    mContent[pos].destroy();
                                    mContent[pos] = null;
                                    SensorBroadcaster s = ((AppionApplication)getContext().getApplicationContext()).
                                        getSensorBroadcaster(AppionApplication.TEST_SENSOR);
                                    switch (position) {
                                    case 0: // Add an Analog GaugeBase to the Workbench
                                        mContent[pos] = new AnalogGauge(getContext());
                                        // TODO: Option to link to a manager
                                        break;
                                    case 1: // Add a digital GaugeBase to the Workbench
                                        mContent[pos] = new DigitalGauge(getContext());
                                        // TODO: Option to link to a manager
                                        break;
                                    } mContent[pos].preInit();
                                    update();
                                }
                            });
                        adb.show();
                } //else new GaugeBaseDialog(getContext(), Workbench.this, (GaugeBase)view, pos).show();
            }
        });
        setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                    int pos, long arg3) {
                mSelection = pos;
                mHold = mContent[pos].toBitmap();
                mHeldGaugeBase = mContent[pos];
                mHeldGaugeBase.destroy();
                trash = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(),
                        R.drawable.trash), getWidth() / 10, getHeight() / 10, true);
                trashBox = new RectF(getWidth() / 2 - trash.getWidth()/2, getHeight() - trash.getHeight(),
                        getWidth() /2 + trash.getWidth() /2, getHeight());
                mContent[pos] = new EmptySpace(getContext());
                update();
                mIsHolding = true;
                setOnTouchListener(mWidgetExchanger);
                ((AppionApplication)getContext().getApplicationContext()).vibrate(300);
                return false;
            }
        });
    }

    /**
     * Perform a switch in within the bench. Exchange on slot with another.
     * @param slot The slot of the widgets list that we are switching to.
     */
    public void makeSwitch(int slot) {
        if (mSelection == -1) return;
        Log.i(TAG, "Performing a Widget switch");
        mContent[mSelection].destroy();
        mContent[mSelection] = mContent[slot];
        mContent[slot] = mHeldGaugeBase;
        mContent[slot].preInit();
        mContent[slot].invalidate();
        Log.d(TAG, " mSelection = " + mContent[mSelection] + " slot = " +mContent[slot]);
        update();                                                               
    }
公共类工作台扩展了GridView{
/**我们的调试标签*/
私有静态最终字符串TAG=“Workbench”;
/**工作台的名称*/
私有字符串mId=“-1”;
/**工作台的标题*/
私有字符串mTitle=“Workbench”;
/**将由工作台处理的小部件列表*/
专用计量基础[]mContent=新计量基础[6];
/**从工作台上选择当前选项*/
私有int mSelection=-1;
/**当测量基准移动时,我们要从适配器中移除。现在我们不会丢失它*/
专用计量基础mHeldGaugeBase=null;
私有位图mHold=null;
私有布尔错误保存=false;
私有浮点x=-1000f,y=-1000f;//保存位图的位置
私人垃圾;
私人RectF垃圾箱;
//如果需要移动小部件,我们将使用触摸监听器
私有OnTouchListener mWidgetExchanger=新OnTouchListener(){
@覆盖公共布尔onTouch(视图v,运动事件e){
int w=getWidth();int h=getHeight();
浮点xx=e.getX();浮点yy=e.getY();
开关(如getAction()){
case MotionEvent.ACTION_DOWN://Fall-through
case MotionEvent.ACTION\u移动:
如果(错误持有){
x=e.getX()-mHold.getWidth()/2;y=e.getY()-mHold.getHeight()/2;
后验证();中断;
}
case MotionEvent.ACTION\u UP:
如果(错误持有){
如果(垃圾箱包含(xx,yy))移除垃圾箱(mSelection);
否则{
如果((xxw/2)和(&(yyh/3)和&(yyw/2)和&(yy>h/3)和&(yyh*.666))使开关(4);
否则如果((xx>w/2)和(&(yy>h*.666))使开关(5);
}
mSelection=-1;
//mHeldGaugeBase.destroy();mHeldGaugeBase=null;
mHold.recycle();mHold=null;
trash.recycle();trash=null;
错误处理=错误;
setOnTouchListener(空);
x=-1000f;y=-1000f;
((应用程序应用程序)getContext().getApplicationContext()).vibrate(200);update();
}
打破
}
返回true;
}
};
公共工作台(上下文){this(上下文,null);}
公共工作台(上下文,属性集attrs){this(上下文,attrs,0);}
公共工作台(上下文、属性集属性、int-defSty
public class Workbench extends GridView {
    /** Our debugging tag */
    private static final String TAG = "Workbench";
    /** Name of the Workbench. */
    private String mId = "-1";
    /** The title of the Workbench. */
    private String mTitle = "Workbench";
    /** The list of Widgets that will be handled by the bench */
    private GaugeBase[] mContent = new GaugeBase[6];
    /** The current selection from the bench */
    private int mSelection = -1;

    /** When a GaugeBase is moves we want to remove from the adapter. Now we won't lose it.*/
    private GaugeBase mHeldGaugeBase = null;
    private Bitmap mHold = null;
    private boolean mIsHolding = false;
    private float x = -1000f, y = -1000f; // Where the held bitmap should be
    private Bitmap trash;
    private RectF trashBox;

    // The touch listener we will use if we need to move a widget around
    private OnTouchListener mWidgetExchanger = new OnTouchListener() {
        @Override public boolean onTouch(View v, MotionEvent e) {
            int w = getWidth(); int h = getHeight(); 
            float xx = e.getX(); float yy = e.getY();
            switch (e.getAction()) {
            case MotionEvent.ACTION_DOWN: // Fall through
            case MotionEvent.ACTION_MOVE: 
                if (mIsHolding) {
                    x = e.getX() - mHold.getWidth()/2; y = e.getY() - mHold.getHeight()/2;
                    postInvalidate(); break;
                }
            case MotionEvent.ACTION_UP: 
                if (mIsHolding) {
                    if (trashBox.contains(xx, yy)) removeGaugeBase(mSelection);
                    else {
                        if ((xx < w / 2) && (yy < h /3)) makeSwitch(0);
                        else if ((xx > w / 2) && (yy < h /3)) makeSwitch(1);
                        else if ((xx < w / 2) && (yy > h /3) && (yy < h * .666)) makeSwitch(2);
                        else if ((xx > w / 2) && (yy > h /3) && (yy < h * .666)) makeSwitch(3);
                        else if ((xx < w / 2) && (yy > h *.666)) makeSwitch(4);
                        else if ((xx > w / 2) && (yy > h *.666)) makeSwitch(5);
                    }
                    mSelection = -1;
                    //mHeldGaugeBase.destroy(); mHeldGaugeBase = null;
                    mHold.recycle(); mHold = null;
                    trash.recycle(); trash = null;
                    mIsHolding = false;
                    setOnTouchListener(null);
                    x = -1000f; y = -1000f;
                    ((AppionApplication)getContext().getApplicationContext()).vibrate(200); update();
                }
                break;
            }
            return true;
        }
    };

    public Workbench(Context context) { this(context, null); }
    public Workbench(Context context, AttributeSet attrs) { this(context, attrs, 0); }
    public Workbench(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        for (int i = 0; i < mContent.length; i++) {
            mContent[i] = new EmptySpace(getContext());
        }
        setAdapter(new BenchAdapter());
        this.setOnItemClickListener(new OnItemClickListener() {
            @Override public void onItemClick(AdapterView<?> arg0, View view, final int pos, long arg3) {
                if (mContent[pos] instanceof EmptySpace) {
                    CharSequence[] items = {"Analog", "Digital"};
                    AlertDialog.Builder adb = new AlertDialog.Builder(getContext());
                        adb.setTitle("Add a widget?")
                            .setItems(items, new DialogInterface.OnClickListener () {
                                @Override public void onClick(DialogInterface arg0, int position) {
                                    mContent[pos].destroy();
                                    mContent[pos] = null;
                                    SensorBroadcaster s = ((AppionApplication)getContext().getApplicationContext()).
                                        getSensorBroadcaster(AppionApplication.TEST_SENSOR);
                                    switch (position) {
                                    case 0: // Add an Analog GaugeBase to the Workbench
                                        mContent[pos] = new AnalogGauge(getContext());
                                        // TODO: Option to link to a manager
                                        break;
                                    case 1: // Add a digital GaugeBase to the Workbench
                                        mContent[pos] = new DigitalGauge(getContext());
                                        // TODO: Option to link to a manager
                                        break;
                                    } mContent[pos].preInit();
                                    update();
                                }
                            });
                        adb.show();
                } //else new GaugeBaseDialog(getContext(), Workbench.this, (GaugeBase)view, pos).show();
            }
        });
        setOnItemLongClickListener(new OnItemLongClickListener() {
            @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                    int pos, long arg3) {
                mSelection = pos;
                mHold = mContent[pos].toBitmap();
                mHeldGaugeBase = mContent[pos];
                mHeldGaugeBase.destroy();
                trash = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getContext().getResources(),
                        R.drawable.trash), getWidth() / 10, getHeight() / 10, true);
                trashBox = new RectF(getWidth() / 2 - trash.getWidth()/2, getHeight() - trash.getHeight(),
                        getWidth() /2 + trash.getWidth() /2, getHeight());
                mContent[pos] = new EmptySpace(getContext());
                update();
                mIsHolding = true;
                setOnTouchListener(mWidgetExchanger);
                ((AppionApplication)getContext().getApplicationContext()).vibrate(300);
                return false;
            }
        });
    }

    /**
     * Perform a switch in within the bench. Exchange on slot with another.
     * @param slot The slot of the widgets list that we are switching to.
     */
    public void makeSwitch(int slot) {
        if (mSelection == -1) return;
        Log.i(TAG, "Performing a Widget switch");
        mContent[mSelection].destroy();
        mContent[mSelection] = mContent[slot];
        mContent[slot] = mHeldGaugeBase;
        mContent[slot].preInit();
        mContent[slot].invalidate();
        Log.d(TAG, " mSelection = " + mContent[mSelection] + " slot = " +mContent[slot]);
        update();                                                               
    }
mBackground = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
Canvas backCanvas = new Canvas(mBackground);