Ejemplo n.º 1
0
            public override View GetView(int position, View convertView, ViewGroup parent)
            {
                ShapeImageViewQs.Src.SampleBubbleFragment.ViewHolder holder;

                int itemViewType = GetItemViewType(position);
                int layout       = layout1;

                if (itemViewType == 1)
                {
                    layout = layout2;
                }

                if (convertView == null)
                {
                    convertView     = LayoutInflater.FromContext(Context).Inflate(layout, parent, false);
                    holder          = new ViewHolder();
                    holder.image    = convertView.FindViewById <ImageView>(Resource.Id.image);
                    holder.text     = convertView.FindViewById <TextView>(Resource.Id.text);
                    convertView.Tag = holder;
                }
                else
                {
                    holder = (ViewHolder)convertView.Tag;
                }

                position = position % MESSAGES.Length;

                string url;
                string text = MESSAGES[position];

                if (position < 4)
                {
                    url = IMAGES[0, 0];
                }
                else
                {
                    url = IMAGES[1, 0];
                }

                holder.text.Text = text;
                picasso.Load(url)
                .Placeholder(Resource.Drawable.placeholder)
                .Into(holder.image);
                return(convertView);
            }
        public Bitmap Transform(Bitmap source)
        {
            Bitmap result = Bitmap.CreateBitmap(source.Width, source.Height, source.GetConfig());
            Bitmap noise;

            try
            {
                noise = picasso.Load(Resource.Drawable.noise).Get();
            }
            catch (Exception)
            {
                throw new Exception("Failed to apply transformation! Missing resource.");
            }

            BitmapShader shader = new BitmapShader(noise, Shader.TileMode.Repeat, Shader.TileMode.Repeat);

            ColorMatrix colorMatrix = new ColorMatrix();

            colorMatrix.SetSaturation(0);
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);

            Paint paint = new Paint(PaintFlags.AntiAlias);

            paint.SetColorFilter(filter);

            Canvas canvas = new Canvas(result);

            canvas.DrawBitmap(source, 0, 0, paint);

            paint.SetColorFilter(null);
            paint.SetShader(shader);
            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Multiply));

            canvas.DrawRect(0, 0, canvas.Width, canvas.Height, paint);

            source.Recycle();
            noise.Recycle();

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// When you want to implement your own slider view, please call this method in the end in `getView()` method </summary>
        /// <param name="v"> the whole view </param>
        /// <param name="targetImageView"> where to place image </param>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not allowed in .NET:
        //ORIGINAL LINE: protected void bindEventAndShow(final android.view.View v, android.widget.ImageView targetImageView)
        protected internal virtual void bindEventAndShow(View v, ImageView targetImageView)
        {
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final BaseSliderView me = this;
            BaseSliderView me = this;

            v.SetOnClickListener(new OnClickListenerAnonymousInnerClassHelper(this, v, me));

            if (targetImageView == null)
            {
                return;
            }

            if (mLoadListener != null)
            {
                mLoadListener.onStart(me);
            }

            Picasso        p  = (mPicasso != null) ? mPicasso : Picasso.With(mContext);
            RequestCreator rq = null;

            if (mUrl != null)
            {
                rq = p.Load(mUrl);
            }
            else if (mFile != null)
            {
                rq = p.Load(mFile);
            }
            else if (mRes != 0)
            {
                rq = p.Load(mRes);
            }
            else
            {
                return;
            }

            if (rq == null)
            {
                return;
            }

            if (Empty != 0)
            {
                rq.Placeholder(Empty);
            }

            if (Error != 0)
            {
                rq.Error(Error);
            }

            switch (mScaleType)
            {
            case ScaleType.Fit:
                rq.Fit();
                break;

            case ScaleType.CenterCrop:
                rq.Fit().CenterCrop();
                break;

            case ScaleType.CenterInside:
                rq.Fit().CenterInside();
                break;
            }

            rq.Into(targetImageView, () => OnSuccess(v), () => OnError(v, me));
            //rq.Into(targetImageView, new CallbackAnonymousInnerClassHelper(this, v, me));
        }
Ejemplo n.º 4
0
 protected override RequestCreator CreateRequestCreator(string value, Type targetType, object parameter, CultureInfo culture)
 => Picasso.Load(value).Fit().CenterCrop();
Ejemplo n.º 5
0
        private void LoadStudents()
        {
            var screenWidth  = Resources.DisplayMetrics.WidthPixels;
            var screenHeight = Resources.DisplayMetrics.HeightPixels;

            var view = FindViewById <RelativeLayout>(Resource.Id.ll_top);

            view.Measure(0, 0);
            var height = view.MeasuredHeight;

            height = screenHeight - height - AppUtils.dip2px(CurrContext, 45 + 30 + 30);

            if ((int)(Build.VERSION.SdkInt) < 21)
            {
                {
                    Rect frame = new Rect();
                    Window.DecorView.GetWindowVisibleDisplayFrame(frame);
                    var statusBarHeight = frame.Top;
                    height = height - statusBarHeight;
                }
            }

            // 计算头像的高度(容器高度-上下padding-姓名的view高度)*0.8
            var avatarHeihgt = (int)(((height / 2 - AppUtils.dip2px(CurrContext, (2 * 15 + 2 * 30))) / 2));


            var wrapperWidth = screenWidth - AppUtils.dip2px(CurrContext, 24);
            var itemWidth    = avatarHeihgt;//(int)Math.Round((wrapperWidth / avatarColumns) * 0.8);
            var marginRight  = (wrapperWidth - itemWidth * avatarColumns) / 3;

            // 设置scrollview高度(2行高度)
            var scrollviewHeight = (itemWidth + AppUtils.dip2px(CurrContext, 30)) * 2;

            LinearLayout.LayoutParams scrollParas = new LinearLayout.LayoutParams(wrapperWidth, scrollviewHeight);
            scrolllview_1.LayoutParameters = scrollParas;
            scrolllview_2.LayoutParameters = scrollParas;

            tv_renewNum.Text = string.Format("已续班({0}人)", renewStudentList.Count);
            for (var i = 0; i < renewStudentList.Count; i++)
            {
                var student = renewStudentList[i];

                var itemBox = LayoutInflater.From(CurrContext).Inflate(Resource.Layout.item_renew_avatar, gridlayout_1, false);

                ImageView ivAvatar = itemBox.FindViewById <ImageView>(Resource.Id.iv_avatar);
                // 设置照片宽度和高度
                var avatarWidth  = itemWidth;
                var avatarHeight = avatarWidth;
                LinearLayout.LayoutParams parasAvatar = new LinearLayout.LayoutParams(avatarWidth, avatarHeight);
                parasAvatar.Gravity       = GravityFlags.Center;
                ivAvatar.LayoutParameters = parasAvatar;
                if (!string.IsNullOrEmpty(student.avatar))
                {
                    picasso.Load(student.avatar).Placeholder(Resource.Drawable.avatar_student).Error(Resource.Drawable.avatar_student)
                    .Transform(new CircleImageTransformation(picasso))
                    .Into(ivAvatar);
                }
                else
                {
                    picasso.Load(Resource.Drawable.avatar_student).Placeholder(Resource.Drawable.avatar_student).Error(Resource.Drawable.avatar_student)
                    .Transform(new CircleImageTransformation(picasso))
                    .Into(ivAvatar);
                }

                TextView tvName = itemBox.FindViewById <TextView>(Resource.Id.tv_name);
                tvName.Text = student.name;
                if (avatarHeihgt < 60)
                {
                    tvName.SetTextSize(Android.Util.ComplexUnitType.Sp, 11);
                }

                GridLayout.LayoutParams parasBox = new GridLayout.LayoutParams();
                parasBox.Width = itemWidth;
                if (i % avatarColumns != 3)
                {
                    parasBox.RightMargin = marginRight;
                }
                itemBox.LayoutParameters = parasBox;
                gridlayout_1.AddView(itemBox);

                // 添加点击事件
                itemBox.Click += (sender, e) =>
                {
                    Intent intent = new Intent(CurrActivity, typeof(StuentClassActivity));
                    intent.PutExtra("studentJsonStr", JsonSerializer.ToJsonString(student));
                    StartActivity(intent);
                    CurrActivity.OverridePendingTransition(Resource.Animation.right_in, Resource.Animation.left_out);
                };
            }

            tv_noRenewNum.Text = string.Format("未续班({0}人)", notRenewStudentList.Count);
            for (var i = 0; i < notRenewStudentList.Count; i++)
            {
                var student = notRenewStudentList[i];

                var itemBox = LayoutInflater.From(CurrContext).Inflate(Resource.Layout.item_renew_avatar, gridlayout_2, false);

                ImageView ivAvatar = itemBox.FindViewById <ImageView>(Resource.Id.iv_avatar);
                // 设置照片宽度和高度
                var avatarWidth  = itemWidth;
                var avatarHeight = avatarWidth;
                LinearLayout.LayoutParams parasAvatar = new LinearLayout.LayoutParams(avatarWidth, avatarHeight);
                parasAvatar.Gravity       = GravityFlags.Center;
                ivAvatar.LayoutParameters = parasAvatar;
                if (!string.IsNullOrEmpty(student.avatar))
                {
                    picasso.Load(student.avatar).Placeholder(Resource.Drawable.avatar_student).Error(Resource.Drawable.avatar_student)
                    .Transform(new CircleImageTransformation(picasso))
                    .Into(ivAvatar);
                }

                TextView tvName = itemBox.FindViewById <TextView>(Resource.Id.tv_name);
                tvName.Text = student.name;

                GridLayout.LayoutParams parasBox = new GridLayout.LayoutParams();
                parasBox.Width = itemWidth;
                if (i % avatarColumns != 3)
                {
                    parasBox.RightMargin = marginRight;
                }
                itemBox.LayoutParameters = parasBox;
                gridlayout_2.AddView(itemBox);

                // 添加点击事件
                itemBox.Click += (sender, e) =>
                {
                    Intent intent = new Intent(CurrActivity, typeof(StuentClassActivity));
                    intent.PutExtra("studentJsonStr", JsonSerializer.ToJsonString(student));
                    StartActivity(intent);
                    CurrActivity.OverridePendingTransition(Resource.Animation.right_in, Resource.Animation.left_out);
                };
            }
        }