public virtual int getScreenWidth(OfficeThing thing)
        {
            string key = getCacheKey(thing);

            if (!mWidthCache.ContainsKey(key))
            {
                string packageName = mContext.PackageName;
                int    resourceId  = mContext.Resources.getIdentifier(thing.Type, "drawable", packageName);

                BitmapFactory.Options dimensions = new BitmapFactory.Options();
                dimensions.inJustDecodeBounds = true;
                BitmapFactory.decodeResource(mContext.Resources, resourceId, dimensions);

                int screenWidth;
                if (thing.Rotation == 0 || thing.Rotation == 180)
                {
                    screenWidth = (int)((dimensions.outWidth / 2D) * mCanvasRatio);
                }
                else
                {
                    screenWidth = (int)((dimensions.outHeight / 2D) * mCanvasRatio);
                }
                mWidthCache[key] = screenWidth;
            }
            return(mWidthCache[key].Value);
        }
Example #2
0
            public override void thingChanged(OfficeThing officeThing)
            {
                outerInstance.mSelectedThing = officeThing;

                if (outerInstance.mActionMenu != null)
                {
                    // Clean things up, if they're there
                    outerInstance.mActionMenu.removeItem(R.id.action_delete);
                    outerInstance.mActionMenu.removeItem(R.id.action_edit);
                    outerInstance.mActionMenu.removeItem(R.id.action_rotate);

                    // If I have a new thing, add menu items back to it
                    if (officeThing != null)
                    {
                        outerInstance.mActionMenu.add(Menu.NONE, R.id.action_delete, Menu.NONE, getString([email protected]_delete));

                        // Only desks can be edited
                        if (officeThing.Type.Equals("desk"))
                        {
                            outerInstance.mActionMenu.add(Menu.NONE, R.id.action_edit, Menu.NONE, getString([email protected]_edit));
                        }

                        outerInstance.mActionMenu.add(Menu.NONE, R.id.action_rotate, Menu.NONE, getString([email protected]_rotate));
                    }
                }
            }
        public virtual Bitmap getBitmap(OfficeThing thing)
        {
            if (thing == null || thing.Type == null)
            {
                throw new Exception("Thing must be defined and not null");
            }

            string cacheKey = getCacheKey(thing);

            if (mBitmapCache.get(cacheKey) == null)
            {
                string packageName    = mContext.PackageName;
                int    resourceId     = mContext.Resources.getIdentifier(thing.Type, "drawable", packageName);
                Bitmap bitmap         = BitmapFactory.decodeResource(mContext.Resources, resourceId);
                int    resourceWidth  = bitmap.Width;
                int    resourceHeight = bitmap.Height;

                // rotate counter clockwise
                Matrix matrix = new Matrix();
                matrix.postRotate(-thing.Rotation);
                matrix.postScale(0.93F, 0.93F);                 //TODO: figure out why this hack makes android match web
                // Is it render ratio / px per dp -> 1.5 / 1.8

                bitmap = Bitmap.createBitmap(bitmap, 0, 0, resourceWidth, resourceHeight, matrix, true);
                mBitmapCache.put(cacheKey, bitmap);
            }
            return(mBitmapCache.get(cacheKey));
        }
Example #4
0
            public override void onChildMoved(DataSnapshot dataSnapshot, string s)
            {
                string      key           = dataSnapshot.Key;
                OfficeThing existingThing = dataSnapshot.getValue(typeof(OfficeThing));

                Log.v(TAG, "Thing moved " + existingThing);

                outerInstance.addUpdateThingToLocalModel(key, existingThing);
            }
Example #5
0
        public virtual void deleteOfficeThing(string key, OfficeThing officeThing)
        {
            if (null == key || null == officeThing)
            {
                throw new System.ArgumentException();
            }

            mFirebaseRef.child("furniture").child(key).removeValue();
        }
 private string getCacheKey(OfficeThing thing, bool isGlowing)
 {
     if (isGlowing)
     {
         return(thing.Type + "-" + thing.Rotation + "-glowing");
     }
     else
     {
         return(getCacheKey(thing));
     }
 }
Example #7
0
        public virtual void updateOfficeThing(string key, OfficeThing officeThing)
        {
            if (null == key || null == officeThing)
            {
                throw new System.ArgumentException();
            }

            // re-apply the cached key, just in case
            officeThing.Key = key;

            mFirebaseRef.child("furniture").child(key).setValue(officeThing, new CompletionListenerAnonymousInnerClassHelper2(this));
        }
Example #8
0
            /// <summary>
            /// Saves a new thing to Firebase, which is then picked up and displayed by
            /// the view
            /// </summary>
            /// <param name="thingType"> The type of furniture to add to Firebase </param>
            private void addOfficeThing(string thingType)
            {
                if (null == thingType)
                {
                    throw new System.ArgumentException("Typeless office things are not allowed");
                }

                OfficeThing newThing = new OfficeThing();

                newThing.Type = thingType;
                newThing.setzIndex(outerInstance.mOfficeLayout.HighestzIndex + 1);
                newThing.Rotation = 0;
                newThing.Name     = "";
                newThing.Left     = OfficeCanvasView.LOGICAL_WIDTH / 2;
                newThing.Top      = OfficeCanvasView.LOGICAL_HEIGHT / 2;

                Log.w(TAG, "Added thing to firebase " + newThing);

                Firebase newThingFirebaseRef = outerInstance.mFirebaseRef.child("furniture").push();

                newThingFirebaseRef.setValue(newThing, new CompletionListenerAnonymousInnerClassHelper(this));
            }
        public virtual Bitmap getGlowingBitmap(OfficeThing thing)
        {
            if (thing == null || thing.Type == null)
            {
                throw new Exception("Thing must be defined and not null");
            }

            string cacheKey = getCacheKey(thing, true);

            if (mBitmapCache.get(cacheKey) == null)
            {
                // Get the non-glowy bitmap
                Bitmap bitmap = this.getBitmap(thing);

                // Blur it
                Paint blurPaint = new Paint();
                int[] offsetXY  = new int[2];
                blurPaint.MaskFilter = new BlurMaskFilter(15, BlurMaskFilter.Blur.NORMAL);
                Bitmap bmAlpha = bitmap.extractAlpha(blurPaint, offsetXY);

                Paint glowPaint = new Paint();
                glowPaint.Color = 0xFF2896DD;

                // Create a virtual canvas on which to do the transformation and draw it
                Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.Width + (-offsetXY[0] * 2), bitmap.Height + (-offsetXY[0] * 2), Bitmap.Config.ARGB_8888);
                Canvas canvas        = new Canvas(glowingBitmap);
                canvas.drawColor(0, PorterDuff.Mode.CLEAR);
                canvas.drawBitmap(bmAlpha, 0, 0, glowPaint);
                bmAlpha.recycle();
                canvas.drawBitmap(bitmap, -offsetXY[0], -offsetXY[1], null);

                // Put it into the cache for later use
                mBitmapCache.put(cacheKey, glowingBitmap);
            }
            return(mBitmapCache.get(cacheKey));
        }
 public virtual int getModelHeight(OfficeThing thing)
 {
     return((int)(getScreenHeight(thing) / mCanvasRatio));
 }
		public virtual void updateOfficeThing(string key, OfficeThing officeThing)
		{
			if (null == key || null == officeThing)
			{
				throw new System.ArgumentException();
			}

			// re-apply the cached key, just in case
			officeThing.Key = key;

			mFirebaseRef.child("furniture").child(key).setValue(officeThing, new CompletionListenerAnonymousInnerClassHelper2(this));
		}
 public virtual int getModelWidth(OfficeThing thing)
 {
     return((int)(getScreenWidth(thing) / mCanvasRatio));
 }
Example #13
0
 public override void thingChanged(string key, OfficeThing officeThing)
 {
     outerInstance.mStuffToUpdate[key] = officeThing;
     outerInstance.mOfficeCanvasView.invalidate();
 }
			public abstract void thingChanged(OfficeThing officeThing);
 private string getCacheKey(OfficeThing thing)
 {
     return(thing.Type + "-" + thing.Rotation);
 }
			public abstract void thingChanged(string key, OfficeThing officeThing);
			public override void thingChanged(OfficeThing officeThing)
			{
				outerInstance.mSelectedThing = officeThing;

				if (outerInstance.mActionMenu != null)
				{
					// Clean things up, if they're there
					outerInstance.mActionMenu.removeItem(R.id.action_delete);
					outerInstance.mActionMenu.removeItem(R.id.action_edit);
					outerInstance.mActionMenu.removeItem(R.id.action_rotate);

					// If I have a new thing, add menu items back to it
					if (officeThing != null)
					{
						outerInstance.mActionMenu.add(Menu.NONE, R.id.action_delete, Menu.NONE, getString([email protected]_delete));

						// Only desks can be edited
						if (officeThing.Type.Equals("desk"))
						{
							outerInstance.mActionMenu.add(Menu.NONE, R.id.action_edit, Menu.NONE, getString([email protected]_edit));
						}

						outerInstance.mActionMenu.add(Menu.NONE, R.id.action_rotate, Menu.NONE, getString([email protected]_rotate));
					}
				}
			}
Example #18
0
 public abstract void thingChanged(string key, OfficeThing officeThing);
			public override void thingChanged(string key, OfficeThing officeThing)
			{
				outerInstance.mStuffToUpdate[key] = officeThing;
				outerInstance.mOfficeCanvasView.invalidate();
			}
			/// <summary>
			/// Saves a new thing to Firebase, which is then picked up and displayed by
			/// the view
			/// </summary>
			/// <param name="thingType"> The type of furniture to add to Firebase </param>
			private void addOfficeThing(string thingType)
			{
				if (null == thingType)
				{
					throw new System.ArgumentException("Typeless office things are not allowed");
				}

				OfficeThing newThing = new OfficeThing();
				newThing.Type = thingType;
				newThing.setzIndex(outerInstance.mOfficeLayout.HighestzIndex + 1);
				newThing.Rotation = 0;
				newThing.Name = "";
				newThing.Left = OfficeCanvasView.LOGICAL_WIDTH / 2;
				newThing.Top = OfficeCanvasView.LOGICAL_HEIGHT / 2;

				Log.w(TAG, "Added thing to firebase " + newThing);

				Firebase newThingFirebaseRef = outerInstance.mFirebaseRef.child("furniture").push();
				newThingFirebaseRef.setValue(newThing, new CompletionListenerAnonymousInnerClassHelper(this));
			}
Example #21
0
 /// <summary>
 /// Adds a thing to the local model used in rendering
 /// </summary>
 /// <param name="key"> </param>
 /// <param name="officeThing"> </param>
 public virtual void addUpdateThingToLocalModel(string key, OfficeThing officeThing)
 {
     officeThing.Key    = key;
     mOfficeLayout[key] = officeThing;
     mOfficeCanvasView.invalidate();
 }
		public virtual void deleteOfficeThing(string key, OfficeThing officeThing)
		{
			if (null == key || null == officeThing)
			{
				throw new System.ArgumentException();
			}

			mFirebaseRef.child("furniture").child(key).removeValue();
		}
Example #23
0
 public abstract void thingChanged(OfficeThing officeThing);
		/// <summary>
		/// Adds a thing to the local model used in rendering
		/// </summary>
		/// <param name="key"> </param>
		/// <param name="officeThing"> </param>
		public virtual void addUpdateThingToLocalModel(string key, OfficeThing officeThing)
		{
			officeThing.Key = key;
			mOfficeLayout[key] = officeThing;
			mOfficeCanvasView.invalidate();
		}