Search in sources :

Example 1 with ImageSelectionMethodDialog

use of com.alphago.alphago.fragment.ImageSelectionMethodDialog in project Alphago by Onedelay.

the class SendImageActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_send_image);
    imageFile = (File) getIntent().getSerializableExtra("sendImage");
    cropImageView = findViewById(R.id.cropImageView);
    cropImageView.setImageUriAsync(Uri.fromFile(imageFile));
    cropImageView.setAspectRatio(1, 1);
    cropImageView.setFixedAspectRatio(true);
    cropImageView.setCropShape(CropImageView.CropShape.RECTANGLE);
    cropImageView.setAutoZoomEnabled(false);
    cropImageView.setCropRect(new Rect(1000, 1000, 1000, 1000));
    cropImageView.setOnCropImageCompleteListener(new CropImageView.OnCropImageCompleteListener() {

        @Override
        public void onCropImageComplete(CropImageView view, CropImageView.CropResult result) {
            Bitmap bitmap = result.getBitmap();
            if (bitmap != null) {
                try {
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
                    byte[] bitmapData = bos.toByteArray();
                    FileOutputStream fos = new FileOutputStream(imageFile);
                    fos.write(bitmapData);
                    fos.flush();
                    fos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            // onComplete(imageFile);
            // new BitmapToFileTask(imageFile, SendImageActivity.this)
            // .execute(bitmap);
            AlphagoServer.getInstance().sendImage(getBaseContext(), imageFile, new Callback<ResponeImageLabel>() {

                @Override
                public void onResponse(Call<ResponeImageLabel> call, Response<ResponeImageLabel> response) {
                    if (response.body() != null) {
                        category = response.body().getCategory();
                        max_label = response.body().getResponseLabel();
                        ID = response.body().getID();
                        cate_ID = response.body().getCate_ID();
                        Intent intent = new Intent(getBaseContext(), ImageRecognitionActivity.class);
                        intent.putExtra("imageFile", imageFile);
                        intent.putExtra("category", category);
                        intent.putExtra("max_label", max_label);
                        intent.putExtra("ID", ID);
                        intent.putExtra("cate_ID", cate_ID);
                        frameLoading.setVisibility(View.GONE);
                        startActivity(intent);
                        finish();
                    }
                }

                @Override
                public void onFailure(Call<ResponeImageLabel> call, Throwable t) {
                    frameLoading.setVisibility(View.GONE);
                    Toast.makeText(SendImageActivity.this, "서버 연결 안됨", Toast.LENGTH_SHORT).show();
                    t.printStackTrace();
                }
            });
        }
    });
    findViewById(R.id.crop_image_menu_rotate_right).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            cropImageView.rotateImage(90);
        }
    });
    findViewById(R.id.btn_retry).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ImageSelectionMethodDialog().show(getSupportFragmentManager(), "dialog");
        }
    });
    findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            frameLoading.setVisibility(View.VISIBLE);
            cropImageView.getCroppedImageAsync();
        }
    });
    frameLoading = (FrameLayout) findViewById(R.id.frame_loading);
}
Also used : Call(retrofit2.Call) Rect(android.graphics.Rect) Intent(android.content.Intent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ImageView(android.widget.ImageView) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) View(android.view.View) Response(retrofit2.Response) Bitmap(android.graphics.Bitmap) Callback(retrofit2.Callback) FileOutputStream(java.io.FileOutputStream) CropImageView(com.theartofdev.edmodo.cropper.CropImageView) ImageSelectionMethodDialog(com.alphago.alphago.fragment.ImageSelectionMethodDialog)

Example 2 with ImageSelectionMethodDialog

use of com.alphago.alphago.fragment.ImageSelectionMethodDialog in project Alphago by Onedelay.

the class ImageRecognitionActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_recognition);
    imageFile = (File) getIntent().getSerializableExtra("imageFile");
    if (imageFile.exists()) {
        ImageView myImage = (ImageView) findViewById(R.id.image_recognition);
        Picasso.with(getBaseContext()).load(imageFile).centerInside().fit().into(myImage);
    }
    final String categoryName = getIntent().getStringExtra("category");
    final String maxLabel = getIntent().getStringExtra("max_label");
    final int catID = getIntent().getIntExtra("cate_ID", 0);
    final int ID = getIntent().getIntExtra("ID", 0);
    TextView textView = (TextView) findViewById(R.id.result_recog);
    textView.setText(maxLabel);
    final DbHelper dbHelper = new DbHelper(getBaseContext());
    tts = new TTSHelper(this);
    findViewById(R.id.btn_pronounce).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (maxLabel.equals("usb"))
                tts.speak("U.S.B");
            else
                tts.speak(maxLabel);
        }
    });
    findViewById(R.id.btn_retry).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ImageSelectionMethodDialog().show(getSupportFragmentManager(), "dialog");
        }
    });
    saveBtn = (Button) findViewById(R.id.btn_save);
    saveBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!v.isSelected()) {
                saveBtn.setText("SAVED");
                v.setSelected(true);
                String filePath = storeImageFile(imageFile, maxLabel);
                Toast.makeText(getBaseContext(), "저장되었습니다!", Toast.LENGTH_SHORT).show();
                dbHelper.insertImage(maxLabel, catID, ID, filePath, true);
            } else {
                Toast.makeText(getBaseContext(), "이미 저장되었습니다.", Toast.LENGTH_SHORT).show();
            }
        }
    });
    findViewById(R.id.btn_home).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(ImageRecognitionActivity.this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    });
    findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new RequestImageTrainingFragment().show(getFragmentManager(), "dialog");
        }
    });
}
Also used : Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) TTSHelper(com.alphago.alphago.util.TTSHelper) ImageView(android.widget.ImageView) RequestImageTrainingFragment(com.alphago.alphago.fragment.RequestImageTrainingFragment) DbHelper(com.alphago.alphago.database.DbHelper) ImageSelectionMethodDialog(com.alphago.alphago.fragment.ImageSelectionMethodDialog)

Example 3 with ImageSelectionMethodDialog

use of com.alphago.alphago.fragment.ImageSelectionMethodDialog in project Alphago by Onedelay.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    backPressCloseHandler = new BackPressCloseHandler(this);
    findViewById(R.id.btn_recognition).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new ImageSelectionMethodDialog().show(getSupportFragmentManager(), "dialog");
        }
    });
    findViewById(R.id.btn_card_book).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, CardBookActivity.class);
            startActivity(intent);
        }
    });
    findViewById(R.id.btn_game).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new GameModeSelectionDialog().show(getSupportFragmentManager(), "dialog");
        }
    });
    findViewById(R.id.btn_collection).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, CollectionActivity.class);
            startActivity(intent);
        }
    });
}
Also used : GameModeSelectionDialog(com.alphago.alphago.fragment.GameModeSelectionDialog) Intent(android.content.Intent) View(android.view.View) BackPressCloseHandler(com.alphago.alphago.handler.BackPressCloseHandler) ImageSelectionMethodDialog(com.alphago.alphago.fragment.ImageSelectionMethodDialog)

Aggregations

Intent (android.content.Intent)3 View (android.view.View)3 ImageSelectionMethodDialog (com.alphago.alphago.fragment.ImageSelectionMethodDialog)3 ImageView (android.widget.ImageView)2 Bitmap (android.graphics.Bitmap)1 Rect (android.graphics.Rect)1 TextView (android.widget.TextView)1 DbHelper (com.alphago.alphago.database.DbHelper)1 GameModeSelectionDialog (com.alphago.alphago.fragment.GameModeSelectionDialog)1 RequestImageTrainingFragment (com.alphago.alphago.fragment.RequestImageTrainingFragment)1 BackPressCloseHandler (com.alphago.alphago.handler.BackPressCloseHandler)1 TTSHelper (com.alphago.alphago.util.TTSHelper)1 CropImageView (com.theartofdev.edmodo.cropper.CropImageView)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1