Exemple #1
0
        protected internal override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            ContentView = R.layout.activity_office_mover;

            // Initialize Firebase
            mFirebaseRef = new Firebase(FIREBASE);

            // Process authentication
            Bundle extras = Intent.Extras;
            string authToken;

            if (extras != null)
            {
                authToken = extras.getString(LoginActivity.AUTH_TOKEN_EXTRA);
            }
            else
            {
                Log.w(TAG, "Users must be authenticated to do this activity. Redirecting to login activity.");
                Intent loginIntent = new Intent(ApplicationContext, typeof(LoginActivity));
                loginIntent.Flags = Intent.FLAG_ACTIVITY_CLEAR_TOP;
                startActivity(loginIntent);
                finish();
                return;
            }

            mFirebaseRef.authWithOAuthToken("google", authToken, new AuthResultHandlerAnonymousInnerClassHelper(this));

            // Initialize the view stuff
            mOfficeLayout     = new OfficeLayout();
            mOfficeCanvasView = (OfficeCanvasView)findViewById(R.id.office_canvas);
            mOfficeCanvasView.OfficeLayout = mOfficeLayout;
            mOfficeFloorView = (FrameLayout)findViewById(R.id.office_floor);

            // Listen for floor changes
            mFirebaseRef.child("background").addValueEventListener(new ValueEventListenerAnonymousInnerClassHelper(this));

            // Listen for furniture changes
            mFirebaseRef.child("furniture").addChildEventListener(new ChildEventListenerAnonymousInnerClassHelper(this));

            // Handles menu changes that happen when an office thing is selected or de-selected
            mOfficeCanvasView.ThingFocusChangeListener = new SelectedThingChangeListenerAnonymousInnerClassHelper(this);

            // Triggers whenever an office thing changes on the screen. This binds the
            // user interface to the scheduler that throttles updates to Firebase
            mOfficeCanvasView.ThingChangedListener = new ThingChangeListenerAnonymousInnerClassHelper(this);

            // A scheduled executor that throttles updates to Firebase to about 40ms each.
            // This prevents the high frequency change events from swamping Firebase.
            ScheduledExecutorService firebaseUpdateScheduler = Executors.newScheduledThreadPool(1);

            firebaseUpdateScheduler.scheduleAtFixedRate(() =>
            {
                if (mStuffToUpdate != null && mStuffToUpdate.Count > 0)
                {
                    foreach (OfficeThing officeThing in mStuffToUpdate.Values)
                    {
                        updateOfficeThing(officeThing.Key, officeThing);
                        mStuffToUpdate.Remove(officeThing.Key);
                    }
                }
            }, UPDATE_THROTTLE_DELAY, UPDATE_THROTTLE_DELAY, TimeUnit.MILLISECONDS);
        }
		protected internal override void onCreate(Bundle savedInstanceState)
		{
			base.onCreate(savedInstanceState);

			ContentView = R.layout.activity_office_mover;

			// Initialize Firebase
			mFirebaseRef = new Firebase(FIREBASE);

			// Process authentication
			Bundle extras = Intent.Extras;
			string authToken;
			if (extras != null)
			{
				authToken = extras.getString(LoginActivity.AUTH_TOKEN_EXTRA);
			}
			else
			{
				Log.w(TAG, "Users must be authenticated to do this activity. Redirecting to login activity.");
				Intent loginIntent = new Intent(ApplicationContext, typeof(LoginActivity));
				loginIntent.Flags = Intent.FLAG_ACTIVITY_CLEAR_TOP;
				startActivity(loginIntent);
				finish();
				return;
			}

			mFirebaseRef.authWithOAuthToken("google", authToken, new AuthResultHandlerAnonymousInnerClassHelper(this));

			// Initialize the view stuff
			mOfficeLayout = new OfficeLayout();
			mOfficeCanvasView = (OfficeCanvasView) findViewById(R.id.office_canvas);
			mOfficeCanvasView.OfficeLayout = mOfficeLayout;
			mOfficeFloorView = (FrameLayout) findViewById(R.id.office_floor);

			// Listen for floor changes
			mFirebaseRef.child("background").addValueEventListener(new ValueEventListenerAnonymousInnerClassHelper(this));

			// Listen for furniture changes
			mFirebaseRef.child("furniture").addChildEventListener(new ChildEventListenerAnonymousInnerClassHelper(this));

			// Handles menu changes that happen when an office thing is selected or de-selected
			mOfficeCanvasView.ThingFocusChangeListener = new SelectedThingChangeListenerAnonymousInnerClassHelper(this);

			// Triggers whenever an office thing changes on the screen. This binds the
			// user interface to the scheduler that throttles updates to Firebase
			mOfficeCanvasView.ThingChangedListener = new ThingChangeListenerAnonymousInnerClassHelper(this);

			// A scheduled executor that throttles updates to Firebase to about 40ms each.
			// This prevents the high frequency change events from swamping Firebase.
			ScheduledExecutorService firebaseUpdateScheduler = Executors.newScheduledThreadPool(1);
			firebaseUpdateScheduler.scheduleAtFixedRate(() =>
			{
				if (mStuffToUpdate != null && mStuffToUpdate.Count > 0)
				{
					foreach (OfficeThing officeThing in mStuffToUpdate.Values)
					{
						updateOfficeThing(officeThing.Key, officeThing);
						mStuffToUpdate.Remove(officeThing.Key);
					}
				}
			}, UPDATE_THROTTLE_DELAY, UPDATE_THROTTLE_DELAY, TimeUnit.MILLISECONDS);
		}
			public OnGlobalLayoutListenerAnonymousInnerClassHelper(OfficeCanvasView outerInstance)
			{
				this.outerInstance = outerInstance;
			}
 public OnGlobalLayoutListenerAnonymousInnerClassHelper(OfficeCanvasView outerInstance)
 {
     this.outerInstance = outerInstance;
 }