Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            UIHelper.init(this);
            string genre = Intent.GetStringExtra("genre") ?? null;

            if (genre == null)
            {
                UIHelper.ShowToast("There is no genre...");
                Finish();
            }
            else
            {
                UIHelper.ShowToast("This genre is " + genre);
            }
            Bitmap noImage = BitmapFactory.DecodeResource(Resources, Resource.Drawable.no_image);

            string datDirectoryPath = MyData.GetDatDirectory(genre);
            string imgDirectoryPath = MyData.GetImgDirectory(genre);

            if (SDCardHelper.ISExistDirectory(datDirectoryPath))
            {
                string[] datFiles = SDCardHelper.GetFiles(datDirectoryPath);
                foreach (var filePath in datFiles)
                {
                    try
                    {
                        string fileName     = System.IO.Path.GetFileNameWithoutExtension(filePath);
                        string json         = SDCardHelper.loadText(datDirectoryPath + "/" + fileName + ".dat");
                        var    parse        = DynamicJson.Parse(json);
                        string title        = (string)parse.title;
                        string caption      = (string)parse.itemCaption;
                        var    listViewItem = new ListViewItem()
                        {
                            Title     = title,
                            Thumbnail = noImage,
                            Caption   = caption
                        };
                        byte[] bytes  = SDCardHelper.loadBytes(imgDirectoryPath + "/" + fileName + ".jpg");
                        Bitmap bitmap = null;
                        if (bytes != null)
                        {
                            bitmap = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
                        }
                        if (bitmap != null)
                        {
//							UIHelper.showImageToast(title, bitmap, caption);
                            listViewItem.Thumbnail = bitmap;
                        }
                        items.Add(listViewItem);
                    }
                    catch (Exception e)
                    {
                        UIHelper.ShowToast(e.Message);
                    }
                }
            }

            listView         = new ListView(this);
            listView.Adapter = new CustomListView(this, items);
            SetContentView(listView);
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            UIHelper.init(this);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            //Create a new instance of our Scanner
            scanner = new MobileBarcodeScanner(this);
            buttonScanDefaultView        = this.FindViewById <Button>(Resource.Id.mainButtonNew);
            buttonScanDefaultView.Click += async delegate {
                //Tell our scanner to use the default overlay
                scanner.UseCustomOverlay = false;
                //We can customize the top and bottom text of the default overlay
                scanner.TopText    = "Hold the camera up to the barcode\nAbout 6 inches away";
                scanner.BottomText = "Wait for the barcode to automatically scan!";
                //Start scanning
                var result = await scanner.Scan();

                HandleScanResult(result);
            };

            var buttonBook = this.FindViewById <Button>(Resource.Id.mainButtonBook);

            buttonBook.Click += delegate
            {
                UIHelper.DelayedToast("Book", 10);
                var activity2 = new Intent(this, typeof(Activity2));
                activity2.PutExtra("genre", "Book");
                StartActivity(activity2);
            };
            var buttonGame = this.FindViewById <Button>(Resource.Id.mainButtonGame);

            buttonGame.Click += delegate
            {
                UIHelper.DelayedToast("Game", 10);
                var activity2 = new Intent(this, typeof(Activity2));
                activity2.PutExtra("genre", "game");
                StartActivity(activity2);
            };
            var buttonCd = this.FindViewById <Button>(Resource.Id.mainButtonCD);

            buttonCd.Click += delegate
            {
                UIHelper.DelayedToast("CD", 10);
                var activity2 = new Intent(this, typeof(Activity2));
                activity2.PutExtra("genre", "CD");
                StartActivity(activity2);
            };
            var buttonDVD = this.FindViewById <Button>(Resource.Id.mainButtonDVD);

            buttonDVD.Click += delegate
            {
                UIHelper.DelayedToast("DVD", 10);
                var activity2 = new Intent(this, typeof(Activity2));
                activity2.PutExtra("genre", "DVD");
                StartActivity(activity2);
            };

            //	円グラフ読み込み及び作成
            var imageViewPieChart = FindViewById <ImageView>(Resource.Id.mainImageViewPieChart);

            if (SDCardHelper.ISExistFile(Constant.APP_NAME + "/PieChart.jpg"))
            {
                byte[] bytes  = SDCardHelper.loadBytes(Constant.APP_NAME + "/PieChart.jpg");
                Bitmap bitmap = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
                imageViewPieChart.SetImageBitmap(bitmap);
            }
            var heartRailsAPI = new HeartRailsAPI();

            string[] genres = { "Book", "Game", "CD", "DVD" };
            int      cnt    = 0;

            for (int i = 0; i < 4; i++)
            {
                string datDirectoryPath = MyData.GetDatDirectory(genres[i]);
                if (!SDCardHelper.ISExistDirectory(datDirectoryPath))
                {
                    continue;
                }
                int num = SDCardHelper.GetFiles(datDirectoryPath).Length;
                heartRailsAPI.AddElement(genres[i], num);
                cnt++;
            }
            if (cnt == 0)
            {
                heartRailsAPI.AddElement("None", 100);
            }
//			heartRailsAPI.Query.title_top = "Genre Pie Chart";
            heartRailsAPI.CallBackBytes += (byte[] bytes) =>
            {
                SDCardHelper.save(Constant.APP_NAME + "/PieChart.jpg", bytes);
                Bitmap bitmap = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
                imageViewPieChart.SetImageBitmap(bitmap);
            };
            heartRailsAPI.start();
        }