Search in sources :

Example 1 with DrawView

use of org.odk.collect.android.views.DrawView in project collect by opendatakit.

the class DrawActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.draw_layout);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    fabActions = findViewById(R.id.fab_actions);
    final FloatingActionButton fabSetColor = findViewById(R.id.fab_set_color);
    final CardView cardViewSetColor = findViewById(R.id.cv_set_color);
    final FloatingActionButton fabSaveAndClose = findViewById(R.id.fab_save_and_close);
    final CardView cardViewSaveAndClose = findViewById(R.id.cv_save_and_close);
    final FloatingActionButton fabClear = findViewById(R.id.fab_clear);
    final CardView cardViewClear = findViewById(R.id.cv_clear);
    fabActions.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int status = Integer.parseInt(view.getTag().toString());
            if (status == 0) {
                status = 1;
                fabActions.animate().rotation(45).setInterpolator(new AccelerateDecelerateInterpolator()).setDuration(100).start();
                AnimateUtils.scaleInAnimation(fabSetColor, 50, 150, new OvershootInterpolator(), true);
                AnimateUtils.scaleInAnimation(cardViewSetColor, 50, 150, new OvershootInterpolator(), true);
                AnimateUtils.scaleInAnimation(fabSaveAndClose, 100, 150, new OvershootInterpolator(), true);
                AnimateUtils.scaleInAnimation(cardViewSaveAndClose, 100, 150, new OvershootInterpolator(), true);
                AnimateUtils.scaleInAnimation(fabClear, 150, 150, new OvershootInterpolator(), true);
                AnimateUtils.scaleInAnimation(cardViewClear, 150, 150, new OvershootInterpolator(), true);
            } else {
                status = 0;
                fabActions.animate().rotation(0).setInterpolator(new AccelerateDecelerateInterpolator()).setDuration(100).start();
                fabSetColor.setVisibility(View.INVISIBLE);
                cardViewSetColor.setVisibility(View.INVISIBLE);
                fabSaveAndClose.setVisibility(View.INVISIBLE);
                cardViewSaveAndClose.setVisibility(View.INVISIBLE);
                fabClear.setVisibility(View.INVISIBLE);
                cardViewClear.setVisibility(View.INVISIBLE);
            }
            view.setTag(status);
        }
    });
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        loadOption = OPTION_DRAW;
        refImage = null;
        savepointImage = new File(Collect.TMPDRAWFILE_PATH);
        savepointImage.delete();
        output = new File(Collect.TMPFILE_PATH);
    } else {
        if (extras.getInt(SCREEN_ORIENTATION) == 1) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        loadOption = extras.getString(OPTION);
        if (loadOption == null) {
            loadOption = OPTION_DRAW;
        }
        // refImage can also be present if resuming a drawing
        Uri uri = (Uri) extras.get(REF_IMAGE);
        if (uri != null) {
            refImage = new File(uri.getPath());
        }
        String savepoint = extras.getString(SAVEPOINT_IMAGE);
        if (savepoint != null) {
            savepointImage = new File(savepoint);
            if (!savepointImage.exists() && refImage != null && refImage.exists()) {
                FileUtils.copyFile(refImage, savepointImage);
            }
        } else {
            savepointImage = new File(Collect.TMPDRAWFILE_PATH);
            savepointImage.delete();
            if (refImage != null && refImage.exists()) {
                FileUtils.copyFile(refImage, savepointImage);
            }
        }
        uri = (Uri) extras.get(EXTRA_OUTPUT);
        if (uri != null) {
            output = new File(uri.getPath());
        } else {
            output = new File(Collect.TMPFILE_PATH);
        }
    }
    if (OPTION_SIGNATURE.equals(loadOption)) {
        alertTitleString = getString(R.string.quit_application, getString(R.string.sign_button));
    } else if (OPTION_ANNOTATE.equals(loadOption)) {
        alertTitleString = getString(R.string.quit_application, getString(R.string.markup_image));
    } else {
        alertTitleString = getString(R.string.quit_application, getString(R.string.draw_image));
    }
    drawView = findViewById(R.id.drawView);
    drawView.setupView(OPTION_SIGNATURE.equals(loadOption));
}
Also used : OvershootInterpolator(android.view.animation.OvershootInterpolator) Bundle(android.os.Bundle) CardView(android.support.v7.widget.CardView) FloatingActionButton(android.support.design.widget.FloatingActionButton) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DrawView(org.odk.collect.android.views.DrawView) View(android.view.View) AdapterView(android.widget.AdapterView) CardView(android.support.v7.widget.CardView) ListView(android.widget.ListView) File(java.io.File) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 CardView (android.support.v7.widget.CardView)1 View (android.view.View)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 OvershootInterpolator (android.view.animation.OvershootInterpolator)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 File (java.io.File)1 DrawView (org.odk.collect.android.views.DrawView)1