Esempio n. 1
0
        protected void createSockets()
        {
            if (sPipeApi == PIPE_API_LS)
            {
                const String LOCAL_ADDR = "net.majorkernelpanic.streaming-";

                for (int i = 0; i < 10; i++)
                {
                    try {
                        mSocketId = new Java.Util.Random().NextInt();
                        mLss      = new LocalServerSocket(LOCAL_ADDR + mSocketId);
                        break;
                    } catch (Java.IO.IOException e1) {}
                }

                mReceiver = new LocalSocket();
                mReceiver.Connect(new LocalSocketAddress(LOCAL_ADDR + mSocketId));
                mReceiver.ReceiveBufferSize = 500000;
                mReceiver.SoTimeout         = 3000;
                mSender = mLss.Accept();
                mSender.SendBufferSize = 500000;
            }
            else
            {
                Log.e(TAG, "parcelFileDescriptors createPipe version = Lollipop");
                mParcelFileDescriptors = ParcelFileDescriptor.CreatePipe();
                mParcelRead            = new ParcelFileDescriptor(mParcelFileDescriptors[0]);
                mParcelWrite           = new ParcelFileDescriptor(mParcelFileDescriptors[1]);
            }
        }
Esempio n. 2
0
        public override ParcelFileDescriptor OpenFile(Android.Net.Uri uri, string mode)
        {
            switch ((UriMatches)UriMatcher.Match(uri))
            {
            case UriMatches.GetIcon:
                var             iconId         = (PwIcon)Enum.Parse(typeof(PwIcon), uri.GetQueryParameter(IconIdParameter));
                var             customIconUuid = new PwUuid(MemUtil.HexStringToByteArray(uri.GetQueryParameter(CustomIconUuidParameter)));
                int             databaseIndex  = int.Parse(uri.GetQueryParameter(DatabaseIndexParameter));
                List <Database> databases      = App.Kp2a.OpenDatabases.ToList();
                Database        database       = databases[databaseIndex];


                var iconDrawable = database.DrawableFactory.GetIconDrawable(App.Context, database.KpDatabase, iconId, customIconUuid, false) as BitmapDrawable;
                if (iconDrawable?.Bitmap != null)

                {
                    var pipe      = ParcelFileDescriptor.CreatePipe();
                    var outStream = new OutputStreamInvoker(new ParcelFileDescriptor.AutoCloseOutputStream(pipe[1]));

                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        var original        = iconDrawable.Bitmap;
                        Bitmap copy         = Bitmap.CreateBitmap(original.Width, original.Height, original.GetConfig() ?? Bitmap.Config.Argb8888);
                        Canvas copiedCanvas = new Canvas(copy);
                        copiedCanvas.DrawBitmap(original, 0f, 0f, null);

                        var bitmap           = copy;
                        float maxSize        = convertDpToPixel(60, App.Context);
                        float scale          = Math.Min(maxSize / bitmap.Width, maxSize / bitmap.Height);
                        var scaleWidth       = (int)(bitmap.Width * scale);
                        var scaleHeight      = (int)(bitmap.Height * scale);
                        var scaledBitmap     = Bitmap.CreateScaledBitmap(bitmap, scaleWidth, scaleHeight, true);
                        Bitmap newRectBitmap = Bitmap.CreateBitmap((int)maxSize, (int)maxSize, Bitmap.Config.Argb8888);

                        Canvas c = new Canvas(newRectBitmap);
                        c.DrawBitmap(scaledBitmap, (maxSize - scaledBitmap.Width) / 2.0f, (maxSize - scaledBitmap.Height) / 2.0f, null);
                        bitmap = newRectBitmap;
                        bitmap.Compress(Bitmap.CompressFormat.Png, 100, outStream);
                        outStream.Close();
                    });

                    return(pipe[0]);
                }

                // Couldn't get an icon for some reason.
                return(null);

            default:
                throw new ArgumentException("Unknown Uri: " + uri, "uri");
            }
        }