/// <summary>
        /// @brief Starts the activity in the sapa environment
        ///
        /// Setup intent by adding custom class loader and extras edit_mode
        /// TODO: Description on what's the edit_mode
        /// </summary>
        /// <param name="mode"> </param>
        private bool startSapaActivity(string instanceId, int mode)
        {
            Context context = Context;

            Log.d(TAG, "Start sapa app");
            Log.d(TAG, "instanceId:" + instanceId);
            if (null == context)
            {
                Log.w(TAG, "Cannot start activity for instance " + instanceId + ": null context");
                return(false);
            }

            if (null == mSapaServiceConnector)
            {
                Log.w(TAG, "Cannot start activity for instance " + instanceId + ": service connector not set to the FC context");
                return(false);
            }

            Intent intent = mSapaServiceConnector.getLaunchIntent(instanceId);

            if (null == intent)
            {
                Log.w(TAG, "Cannot start activity for instance " + instanceId + ": launch intent is null");
                return(false);
            }

            intent.ExtrasClassLoader = typeof(SapaAppInfo).ClassLoader;
            intent.putExtra("Edit_mode", mode);
            intent.Flags = Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT;

            context.startActivity(intent);

            return(true);
        }
Beispiel #2
0
            public override void onLogMessage(int level, string area, string message)
            {
                switch (level)
                {
                case Log.DEBUG:
                    Log.d(area, message);
                    break;

                case Log.ERROR:
                    Log.e(area, message);
                    break;

                case Log.INFO:
                    Log.i(area, message);
                    break;

                case Log.VERBOSE:
                    Log.v(area, message);
                    break;

                case Log.WARN:
                    Log.w(area, message);
                    break;
                }
            }
Beispiel #3
0
            protected internal override string doInBackground(params Void[] @params)
            {
                string token = null;

                try
                {
                    string scope = string.Format("oauth2:{0}", Scopes.PLUS_LOGIN);
                    token = GoogleAuthUtil.getToken(outerInstance, Plus.AccountApi.getAccountName(outerInstance.mGoogleApiClient), scope);
                }
                catch (IOException transientEx)
                {
                    /* Network or server error */
                    Log.e(TAG, "Error authenticating with Google: " + transientEx);
                    errorMessage = "Network error: " + transientEx.Message;
                }
                catch (UserRecoverableAuthException e)
                {
                    Log.w(TAG, "Recoverable Google OAuth error: " + e.ToString());
                    /* We probably need to ask for permissions, so start the intent if there is none pending */
                    if (!outerInstance.mGoogleIntentInProgress)
                    {
                        outerInstance.mGoogleIntentInProgress = true;
                        Intent recover = e.Intent;
                        startActivityForResult(recover, RC_GOOGLE_LOGIN);
                    }
                }
                catch (GoogleAuthException authEx)
                {
                    /* The call is not ever expected to succeed assuming you have already verified that
                     * Google Play services is installed. */
                    Log.e(TAG, "Error authenticating with Google: " + authEx.Message, authEx);
                    errorMessage = "Error authenticating with Google: " + authEx.Message;
                }
                return(token);
            }
        /// <summary>
        /// @brief Read application name (label) from package manager
        /// </summary>
        /// <param name="packageName">   application package
        /// </param>
        /// <returns> Application name retrieved from PackageManager </returns>
        public virtual string getApplicationName(string packageName)
        {
            string  appName = "<None>";
            Context context = Context;

            if (null == context)
            {
                Log.w(TAG, "Cannot retrieve application name: context is null");
                return(appName);
            }

            PackageManager  pm      = context.PackageManager;
            ApplicationInfo appInfo = null;

            try
            {
                appInfo = pm.getApplicationInfo(packageName, NO_FLAGS);
            }
            catch (PackageManager.NameNotFoundException)
            {
                Log.w(TAG, "Cannot retrieve application info for package: " + packageName);
            }

            if (null != appInfo)
            {
                appName = pm.getApplicationLabel(appInfo).ToString();
            }
            return(appName);
        }
        /// <summary>
        /// @brief Retrieve drawable from resources of application given by package name
        ///
        /// Drawable is retrieved using PackageManager.
        /// </summary>
        /// <param name="packageName">   package name of the application to retrieve drawables from </param>
        /// <param name="drawableId">    id of the drawable to retrieve
        /// </param>
        /// <returns> Drawable or null in case of problems </returns>
        public virtual Drawable getApplicationDrawable(string packageName, int drawableId)
        {
            Context context = Context;

            if (null == context)
            {
                Log.w(TAG, "Cannot retrieve drawable from application (" + packageName + ") " + "as the context is null");
                return(null);
            }

            if (drawableId < 0)
            {
                Log.w(TAG, "Cannot retrieve drawable of negative Id");
                return(null);
            }

            PackageManager pm       = context.PackageManager;
            Drawable       drawable = null;

            try
            {
                Resources res = pm.getResourcesForApplication(packageName);
                drawable = res.getDrawable(drawableId);
            }
            catch (PackageManager.NameNotFoundException)
            {
                Log.w(TAG, "Cannot retrieve drawable from application (" + packageName + "): " + "name not found");
            }

            return(drawable);
        }
        /// <summary>
        /// @brief Returns <seealso cref="Drawable"/> for given resource ID
        /// </summary>
        /// <param name="resId"> Resource ID </param>
        /// <returns> <seealso cref="Drawable"/> for given resource ID </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public android.graphics.drawable.Drawable getDrawable(final int resId)
        public virtual Drawable getDrawable(int resId)
        {
            Context context = Context;

            if (null == context)
            {
                Log.w(TAG, "Cannot retrieve Drawable for resource ID=" + resId + " as the context is null");
                return(null);
            }

            return(context.Resources.getDrawable(resId));
        }
Beispiel #7
0
        /// <summary>
        /// @brief Create action executor that requests application to execute action of a
        ///        given <code>actionId</code>
        ///
        /// Action is executed using <seealso cref="FcSapaActionDispatcher"/> object.
        /// </summary>
        /// <param name="instanceId">    Unique instance id of the application </param>
        /// <param name="actionId">      Id of the action
        /// </param>
        /// <returns>  Runnable of the action </returns>
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: private Runnable newCallActionRunnable(final String instanceId, final String actionId)
        private Runnable newCallActionRunnable(string instanceId, string actionId)
        {
            return(() =>
            {
                FcSapaActionDispatcher dispatcher = mFcContext.SapaActionDispatcher;
                if (null == dispatcher)
                {
                    Log.w(TAG, "Logic error: Sapa action dispatcher is null");
                    return;
                }
                dispatcher.callAction(instanceId, actionId);
            });
        }
Beispiel #8
0
        public virtual Drawable getIcon(FcContext fcContext)
        {
            Drawable drawable = null;

            try
            {
                drawable = mActionInfo.getIcon(fcContext.Context);
            }
            catch (NameNotFoundException)
            {
                Log.w(TAG, "Cannot retrieve action icon: name not found");
            }

            return(drawable);
        }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: @Override public void onDraw(final android.graphics.Canvas canv)
        public override void onDraw(Canvas canv)
        {
            if (null == mOfficeLayout || null == mRenderUtil)
            {
                Log.w(TAG, "Tried to render empty office");
                return;
            }

            foreach (OfficeThing thing in mOfficeLayout.ThingsBottomUp)
            {
                Bitmap thingBitmap = mRenderUtil.getBitmap(thing);

                //TODO: reimplement glow rendering
                //            // If it's the selected thing, make it GLOW!
                //            if (thing.getKey().equals(mSelectedThingKey)) {
                //                thingBitmap = mRenderUtil.getGlowingBitmap(thing);
                //            }

                // Draw furniture
                canv.drawBitmap(thingBitmap, modelToScreen(thing.Left), modelToScreen(thing.Top), DEFAULT_PAINT);

                // Draw desk label
                if (thing.Type.Equals("desk") && thing.Name != null)
                {
                    // TODO: these offset numbers were empirically determined. Calculate them instead
                    float centerX = modelToScreen(thing.Left) + 102;
                    float centerY = modelToScreen(thing.Top) + 70;

                    canv.save();
                    // TODO: OMG this is so hacky. Fix it. These numbers were empirically determined
                    if (thing.Rotation == 180)
                    {
                        canv.rotate(-thing.Rotation, centerX, centerY - 10);
                    }
                    else if (thing.Rotation == 90)
                    {
                        canv.rotate(-thing.Rotation, centerX, centerY + 45);
                    }
                    else if (thing.Rotation == 270)
                    {
                        canv.rotate(-thing.Rotation, centerX - 40, centerY);
                    }

                    canv.drawText(thing.Name, centerX, centerY, DESK_LABEL_PAINT);
                    canv.restore();
                }
            }
        }
Beispiel #10
0
        public virtual string getName(FcContext fcContext)
        {
            Log.d(TAG, "getName");
            string name = null;

            try
            {
                name = mActionInfo.getName(fcContext.Context);
            }
            catch (NameNotFoundException)
            {
                Log.w(TAG, "Cannot retrieve action name: name not found");
            }
            Log.d(TAG, "name:" + name);
            return(name);
        }
Beispiel #11
0
        /// <summary>
        /// @brief
        /// </summary>
        /// <param name="item"> </param>
        public virtual void notifyItemChanged(FcModelItem item)
        {
            lock (this)
            {
                lock (mModel)
                {
                    int position = mModel.getItemPosition(item);
                    Log.d(TAG, "notifyItemChanged(" + item + ") position = " + position);
                    if (position < 0)
                    {
                        Log.w(TAG, "The item " + item.InstanceId + " cannot be found in the model");
                        return;
                    }

                    notifyItemChanged(position);
                }
            }
        }
        private bool sendSapaSwitchBroadcast(string packageName, string instanceId)
        {
            Context context = Context;

            if (null == context)
            {
                Log.w(TAG, "Cannot send sapa switch broadcast (pkg: " + packageName + ", instance: " + instanceId + "): context is null");
                return(false);
            }

            Intent intent = new Intent(FcConstants.INTENT_SAPA_SWITCH);

            intent.putExtra(FcConstants.INTENT_SAPA_SWITCH_EXTRAS_INSTANCEID, instanceId);
            intent.putExtra(FcConstants.INTENT_SAPA_SWITCH_EXTRAS_PACKAGE, packageName);

            context.sendBroadcast(intent, FcConstants.PERMISSION_USE_CONNETION_SERVICE);

            return(true);
        }
        /// <summary>
        /// @brief Finish current activity if the package name is matched
        /// </summary>
        /// <param name="packageName">   Package name of the activity to stop </param>
        private bool finishCurrentActivity(string packageName)
        {
            Context context = Context;

            if (null == context)
            {
                Log.w(TAG, "Cannot finish activity " + packageName + ": context is null");
                return(false);
            }

            if (!(context is Activity))
            {
                Log.w(TAG, "Cannot finish activity: " + packageName + ": context not an instance of Activity");
                return(false);
            }

            if (!context.PackageName.contentEquals(packageName))
            {
                ((Activity)context).finish();
            }
            return(true);
        }