示例#1
0
        void WritePrintedPdfDoc(ParcelFileDescriptor destination)
        {
            var javaStream = new Java.IO.FileOutputStream(destination.FileDescriptor);
            var osi        = new OutputStreamInvoker(javaStream);

            using (var mem = new MemoryStream()) {
                document.WriteTo(mem);
                var bytes = mem.ToArray();
                osi.Write(bytes, 0, bytes.Length);
            }
        }
示例#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");
            }
        }
示例#3
0
        public async Task ConnectAsync(int TargetId)
        {
            ReconectId = TargetId;
            socket     = BluetoothDevices[TargetId].CreateRfcommSocketToServiceRecord(mDeviceUUID);
            try
            {
                await socket.ConnectAsync();

                if (socket != null && socket.IsConnected)
                {
                    outStream       = (OutputStreamInvoker)socket.OutputStream;
                    conncetionState = ConncetionSate.sucsesful;
                    inStream        = (InputStreamInvoker)socket.InputStream;
                }
                else
                {
                    conncetionState = ConncetionSate.failed;
                }
            }
            catch (Java.IO.IOException)
            {
                conncetionState = ConncetionSate.failed;
            }
        }
示例#4
0
        public async Task <bool> ConnectAsync(string _deviceName)
        {
            try
            {
                BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
                if (adapter == null)
                {
                    Log("No Bluetooth adapter found.");
                }
                else if (!adapter.IsEnabled)
                {
                    Log("Bluetooth adapter is not enabled.");
                }

                List <BluetoothDevice> L = new List <BluetoothDevice>();
                foreach (BluetoothDevice d in adapter.BondedDevices)
                {
                    Log("D: " + d.Name + " " + d.Address + " " + d.BondState.ToString());
                    L.Add(d);
                }

                BluetoothDevice device = null;
                device = L.Find(j => j.Name == _deviceName);

                if (device == null)
                {
                    Log("Named device not found.");
                }
                else
                {
                    Log("Device has been found: " + device.Name + " " + device.Address + " " + device.BondState.ToString());
                }

                socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString(TARGET_UUID));
                await socket.ConnectAsync();

                if (socket != null && socket.IsConnected)
                {
                    Log("Connection successful!");
                }
                else
                {
                    Log("Connection failed!");
                }

                inStream  = (InputStreamInvoker)socket.InputStream;
                outStream = (OutputStreamInvoker)socket.OutputStream;

                if (socket != null && socket.IsConnected)
                {
                    Task t = new Task(() => Listen(inStream));
                    t.Start();

                    //Task t1 = new Task(() => PingEvent());
                    //t1.Start();
                }
                else
                {
                    //throw new Exception("Socket not existing or not connected.");
                }
            }
            catch (Exception e)
            {
                //throw new Exception("Socket not existing or not connected.");
            }

            return(socket.IsConnected);
        }