示例#1
0
        public static void makeText(Context context, string msg, ToastLength length, int type)
        {
            Toast    toast = new Toast(context);
            View     layout;
            TextView text;

            switch (type)
            {
            case 1:
                layout           = LayoutInflater.From(context).Inflate(Resource.Layout.success_toast_layout, null, false);
                text             = (TextView)layout.FindViewById(Resource.Id.toastMessage);
                text.Text        = msg;
                successToastView = (SuccessToastView)layout.FindViewById(Resource.Id.successView);
                successToastView.startAnim();
                text.SetBackgroundResource(Resource.Drawable.success_toast);
                text.SetTextColor(Color.ParseColor("#FFFFFF"));
                toast.View = layout;
                break;

            case 2:
                layout    = LayoutInflater.From(context).Inflate(Resource.Layout.warning_toast_layout, null, false);
                text      = (TextView)layout.FindViewById(Resource.Id.toastMessage);
                text.Text = msg;

                warningToastView = (WarningToastView)layout.FindViewById(Resource.Id.warningView);
                SpringSystem springSystem = SpringSystem.create();

                Spring spring = springSystem.createSpring();
                spring.setCurrentValue(1.8);
                SpringConfig config = new SpringConfig(40, 5);
                spring.setSpringConfig(config);
                spring.addListener(new SimpleSpringListener()
                {
                    SpringUpdate = (_spring) =>
                    {
                        float value = (float)_spring.getCurrentValue();
                        float scale = (float)(0.9f - (value * 0.5f));

                        warningToastView.ScaleX = scale;
                        warningToastView.ScaleY = scale;
                    }
                });

                Thread t = new Thread(new Runnable(() =>
                {
                    try
                    {
                        Thread.Sleep(500);
                    }
                    catch (InterruptedException e)
                    {
                    }
                    spring.setEndValue(0.4f);
                }));
                t.Start();
                text.SetBackgroundResource(Resource.Drawable.warning_toast);
                text.SetTextColor(Color.ParseColor("#FFFFFF"));
                toast.View = layout;
                break;

            case 3:
                layout         = LayoutInflater.From(context).Inflate(Resource.Layout.error_toast_layout, null, false);
                text           = (TextView)layout.FindViewById(Resource.Id.toastMessage);
                text.Text      = msg;
                errorToastView = (ErrorToastView)layout.FindViewById(Resource.Id.errorView);
                errorToastView.startAnim();
                text.SetBackgroundResource(Resource.Drawable.error_toast);
                text.SetTextColor(Color.ParseColor("#FFFFFF"));
                toast.View = layout;
                break;

            case 4:
                layout        = LayoutInflater.From(context).Inflate(Resource.Layout.info_toast_layout, null, false);
                text          = (TextView)layout.FindViewById(Resource.Id.toastMessage);
                text.Text     = msg;
                infoToastView = (InfoToastView)layout.FindViewById(Resource.Id.infoView);
                infoToastView.startAnim();
                text.SetBackgroundResource(Resource.Drawable.info_toast);
                text.SetTextColor(Color.ParseColor("#FFFFFF"));
                toast.View = layout;
                break;

            case 5:
                layout           = LayoutInflater.From(context).Inflate(Resource.Layout.default_toast_layout, null, false);
                text             = (TextView)layout.FindViewById(Resource.Id.toastMessage);
                text.Text        = msg;
                defaultToastView = (DefaultToastView)layout.FindViewById(Resource.Id.defaultView);
                defaultToastView.startAnim();
                text.SetBackgroundResource(Resource.Drawable.default_toast);
                text.SetTextColor(Color.ParseColor("#FFFFFF"));
                toast.View = layout;
                break;

            case 6:
                layout             = LayoutInflater.From(context).Inflate(Resource.Layout.confusing_toast_layout, null, false);
                text               = (TextView)layout.FindViewById(Resource.Id.toastMessage);
                text.Text          = msg;
                confusingToastView = (ConfusingToastView)layout.FindViewById(Resource.Id.confusingView);
                confusingToastView.startAnim();
                text.SetBackgroundResource(Resource.Drawable.confusing_toast);
                text.SetTextColor(Color.ParseColor("#FFFFFF"));
                toast.View = layout;
                break;
            }
            toast.Duration = length;
            toast.Show();
        }
示例#2
0
        // @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public SpringConfiguratorView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
        {
            SpringSystem springSystem = SpringSystem.create();

            springConfigRegistry = SpringConfigRegistry.getInstance();
            spinnerAdapter       = new SpinnerAdapter(context);

            Resources resources = this.Resources;

            mRevealPx = Util.dpToPx(40, resources);
            mStashPx  = Util.dpToPx(280, resources);

            mRevealerSpring = springSystem.createSpring();
            mRevealerSpring
            .setCurrentValue(1)
            .setEndValue(1)
            .addListener(new SimpleSpringListener()
            {
                SpringUpdate = (spring) =>
                {
                    float val          = (float)spring.getCurrentValue();
                    float minTranslate = mRevealPx;
                    float maxTranslate = mStashPx;
                    float range        = maxTranslate - minTranslate;
                    float yTranslate   = (val * range) + minTranslate;
                    this.TranslationY  = yTranslate;
                }
            });

            AddView(generateHierarchy(context));

            SeekbarListener seekbarListener = new SeekbarListener()
            {
                ProgressChanged = (seekBar, val, b) =>
                {
                    float tensionRange  = MAX_TENSION - MIN_TENSION;
                    float frictionRange = MAX_FRICTION - MIN_FRICTION;
                    if (seekBar == mTensionSeekBar)
                    {
                        float scaledTension = ((val) * tensionRange) / MAX_SEEKBAR_VAL + MIN_TENSION;
                        mSelectedSpringConfig.tension =
                            OrigamiValueConverter.tensionFromOrigamiValue(scaledTension);
                        string roundedTensionLabel = DECIMAL_FORMAT.Format(scaledTension);
                        mTensionLabel.Text = "T:" + roundedTensionLabel;
                    }

                    if (seekBar == mFrictionSeekBar)
                    {
                        float scaledFriction = ((val) * frictionRange) / MAX_SEEKBAR_VAL + MIN_FRICTION;
                        mSelectedSpringConfig.friction =
                            OrigamiValueConverter.frictionFromOrigamiValue(scaledFriction);
                        string roundedFrictionLabel = DECIMAL_FORMAT.Format(scaledFriction);
                        mFrictionLabel.Text = "F:" + roundedFrictionLabel;
                    }
                }
            };

            mTensionSeekBar.Max = MAX_SEEKBAR_VAL;
            mTensionSeekBar.SetOnSeekBarChangeListener(seekbarListener);

            mFrictionSeekBar.Max = MAX_SEEKBAR_VAL;
            mFrictionSeekBar.SetOnSeekBarChangeListener(seekbarListener);

            mSpringSelectorSpinner.Adapter = spinnerAdapter;
            mSpringSelectorSpinner.OnItemSelectedListener = new SpringSelectedListener()
            {
                ItemSelected = (ad, v, i, l) =>
                {
                    mSelectedSpringConfig = mSpringConfigs[i];
                    updateSeekBarsForSpringConfig(mSelectedSpringConfig);
                }
            };
            refreshSpringConfigurations();
            this.TranslationY = mStashPx;
        }