Search in sources :

Example 1 with UserInteractionRequiredException

use of keepass2android.javafilestorage.UserInteractionRequiredException in project keepass2android by PhilippC.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (storageToTest == null) {
        createStorageToTest(this, getApplicationContext(), false);
    }
    findViewById(R.id.button1).setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            storageToTest.startSelectFile(MainActivity.this, false, 1);
        }
    });
    findViewById(R.id.button_test_filechooser).setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            storageToTest.startSelectFile(MainActivity.this, false, 2);
        }
    });
    findViewById(R.id.button_test_filechooser_saveas).setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            storageToTest.startSelectFile(MainActivity.this, true, 3);
        }
    });
    findViewById(R.id.button_test_preparefileusage).setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            final String path = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).getString("selectedPath", "");
            if (path.equals("")) {
                Toast.makeText(MainActivity.this, "select path with file chooser first", Toast.LENGTH_LONG).show();
                return;
            }
            new AsyncTask<Object, Object, Object>() {

                @Override
                protected Object doInBackground(Object... params) {
                    try {
                        createStorageToTest(MainActivity.this, MainActivity.this.getApplicationContext(), false).prepareFileUsage(MainActivity.this, path);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "prepare ok: " + path, Toast.LENGTH_LONG).show();
                            }
                        });
                    } catch (UserInteractionRequiredException e) {
                        final UserInteractionRequiredException e2 = e;
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "this requires user interaction! " + e2.getClass().getName() + " " + e2.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    } catch (Throwable t) {
                        final Throwable t2 = t;
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, t2.getClass().getName() + ": " + t2.getMessage(), Toast.LENGTH_LONG).show();
                            }
                        });
                    }
                    return null;
                }
            }.execute();
        }
    });
}
Also used : UserInteractionRequiredException(keepass2android.javafilestorage.UserInteractionRequiredException) AsyncTask(android.os.AsyncTask) OnClickListener(android.view.View.OnClickListener) View(android.view.View)

Aggregations

AsyncTask (android.os.AsyncTask)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 UserInteractionRequiredException (keepass2android.javafilestorage.UserInteractionRequiredException)1