Java Code Examples for com.nbsp.materialfilepicker.ui.FilePickerActivity

The following examples show how to use com.nbsp.materialfilepicker.ui.FilePickerActivity. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {

  if (requestCode == 1 && resultCode == AppCompatActivity.RESULT_OK) {
    String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);

    if (onDone != null) {
      onDone.invoke(filePath);
    }

    onDone = null;
  } else if (requestCode == 1 && resultCode == AppCompatActivity.RESULT_CANCELED) {
    if (onCancel != null) {
      onCancel.invoke();
    }

    onCancel = null;
  }
}
 
Example 2
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == Constants.FILE_PICKER_REQUEST_CODE && resultCode == Activity.RESULT_OK){
        String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);

        if(filePath != null){
            fileSender.setGcodeFile(new File(filePath));
            if(fileSender.getGcodeFile().exists()){
                fileSender.setElapsedTime("00:00:00");
                new ReadFileAsyncTask().execute(fileSender.getGcodeFile());
                sharedPref.edit().putString(getString(R.string.most_recent_selected_file), fileSender.getGcodeFile().getAbsolutePath()).apply();
            }else{
                EventBus.getDefault().post(new UiToastEvent(getString(R.string.text_file_not_found), true, true));
            }
        }
    }

}
 
Example 3
Source Project: Pano360   Source File: MaterialFilePicker.java    License: MIT License 6 votes vote down vote up
/**
 * @return Intent that can be used to start Material File Picker
 */
public Intent getIntent() {
    CompositeFilter filter = getFilter();

    Activity activity = null;
    if (mActivity != null) {
        activity = mActivity;
    } else if (mFragment != null) {
        activity = mFragment.getActivity();
    } else if (mSupportFragment != null) {
        activity = mSupportFragment.getActivity();
    }

    Intent intent = new Intent(activity, FilePickerActivity.class);
    intent.putExtra(FilePickerActivity.ARG_FILTER, filter);

    if (mRootPath != null) {
        intent.putExtra(FilePickerActivity.ARG_START_PATH, mRootPath);
    }

    if (mCurrentPath != null) {
        intent.putExtra(FilePickerActivity.ARG_CURRENT_PATH, mCurrentPath);
    }

    return intent;
}
 
Example 4
Source Project: Easy_xkcd   Source File: FavoritesFragment.java    License: Apache License 2.0 6 votes vote down vote up
public void importFavorites(Intent intent) {
    String filePath = intent.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
    try {
        File file = new File(filePath);
        InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file));
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line;

        Stack<Integer> newFavorites = new Stack<>();
        while ((line = bufferedReader.readLine()) != null) {
            String[] numberTitle = line.split(" - ");
            int number = Integer.parseInt(numberTitle[0]);
            //if (Arrays.binarySearch(favorites, number) < 0) {
            if (!databaseManager.isFavorite(number)) {
                newFavorites.push(number);
                databaseManager.setFavorite(number, true);
            }
        }
        if (!prefHelper.fullOfflineEnabled()) {
            new DownloadImageTask(newFavorites).execute();
        }
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getActivity(), "Import failed", Toast.LENGTH_SHORT).show();
    }
}
 
Example 5
Source Project: qBittorrent-Controller   Source File: SettingsActivity.java    License: MIT License 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    String keystore_path_value = "";

    // MaterialDesignPicker
    if (requestCode == 1 && resultCode == RESULT_OK) {
        keystore_path_value = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
    }

    // Save keystore path
    SharedPreferences sharedPrefs = getPreferenceManager().getSharedPreferences();
    Editor editor = sharedPrefs.edit();

    editor.putString("keystore_path" + currentServerValue, keystore_path_value);
    editor.commit();

    keystore_path.setSummary(keystore_path_value);
}
 
Example 6
Source Project: bridgefy-android-samples   Source File: FileActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {


    if (requestCode==1987 && data!=null)
    {
        String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
        Log.i(TAG, "onActivityResult: file path "+filePath);
        File file=new File(filePath);
        byte fileContent[] = new byte[(int)file.length()];

        try {
            FileInputStream fin = new FileInputStream(file);
            fin.read(fileContent);
            HashMap<String, Object> content = new HashMap<>();
            content.put("file",file.getName());

            com.bridgefy.sdk.client.Message.Builder builder=new com.bridgefy.sdk.client.Message.Builder();
            com.bridgefy.sdk.client.Message message = builder.setReceiverId(conversationId).setContent(content).setData(fileContent).build();
            Bridgefy.sendMessage(message);
            BridgefyFile bridgefyFile = new BridgefyFile(filePath);
            bridgefyFile.setDirection(BridgefyFile.OUTGOING_FILE);
            bridgefyFile.setData(fileContent);
            messagesAdapter.addMessage(bridgefyFile);




        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
 
Example 7
Source Project: Pano360   Source File: HomeActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1 && resultCode == RESULT_OK) {
        filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
        mimeType= MimeType.LOCAL_FILE | MimeType.VIDEO;
        planeModeEnabled=planeMode.isChecked();
        start();
    }
}
 
Example 8
Source Project: android-notepad   Source File: BackupRestoreDelegate.java    License: MIT License 5 votes vote down vote up
public void handleFilePickedWithFilePicker(int resultCode, Intent data){
	if (resultCode == Activity.RESULT_OK){
		showRestoreDialog(data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH));
	}else{
		Toast.makeText(activity, "Couldn't pick the file", Toast.LENGTH_SHORT).show();
	}
}
 
Example 9
Source Project: friendly-plans   Source File: AssetTestRule.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void chooseTestAsset(File testAsset, final AssetType assetType)
        throws InterruptedException {
    final Intent data = new Intent();
    data.putExtra(FilePickerActivity.RESULT_FILE_PATH, testAsset.getAbsolutePath());
    final Fragment fragment = getTaskFragment();
    activityRule.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            fragment.onActivityResult(assetType.ordinal(),
                    FilePickerActivity.RESULT_OK, data);
        }
    });
    Thread.sleep(CHOOSE_FILE_TIMEOUT);
}
 
Example 10
@Test
public void whenActivityResultIsCalledWithNonExistingPictureDataExpectToastWithErrorMessageIsShown() {
    fragment.onActivityResult(
            AssetType.PICTURE.ordinal(),
            FilePickerActivity.RESULT_OK,
            new Intent()
    );
    String expectedMessage = activity.getResources().getString(R.string.picking_file_error);
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage));
}
 
Example 11
@Test
public void whenActivityResultIsCalledWithNonExistingSoundDataExpectToastWithErrorMessageIsShown() {
    fragment.onActivityResult(
            AssetType.SOUND.ordinal(),
            FilePickerActivity.RESULT_OK,
            new Intent()
    );
    String expectedMessage = activity.getResources().getString(R.string.picking_file_error);
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage));
}
 
Example 12
@Test
public void whenActivityResultIsCalledWithNonExistingPictureDataExpectToastWithErrorMessageIsShown() {
    fragment.onActivityResult(
            AssetType.PICTURE.ordinal(),
            FilePickerActivity.RESULT_OK,
            new Intent()
    );
    String expectedMessage = activity.getResources().getString(R.string.picking_file_error);
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage));
}
 
Example 13
@Test
public void whenActivityResultIsCalledWithNonExistingSoundDataExpectToastWithErrorMessageIsShown() {
    fragment.onActivityResult(
            AssetType.SOUND.ordinal(),
            FilePickerActivity.RESULT_OK,
            new Intent()
    );
    String expectedMessage = activity.getResources().getString(R.string.picking_file_error);
    assertThat(ShadowToast.getTextOfLatestToast(), equalTo(expectedMessage));
}
 
Example 14
Source Project: Easy_xkcd   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Timber.d( "received result" +  resultCode + "from request" + requestCode);
    if (requestCode == 1) {
        switch (resultCode) {
            case RESULT_OK: //restart the activity when something major was changed in the settings
                updateTaskRunning = true; // Prevents creation of a new updateTask in onRestart()
                finish();
                startActivity(getIntent());
                break;
            case UPDATE_ALARM:
                JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
                if (prefHelper.getNotificationInterval() != 0) {
                    jobScheduler.cancel(UPDATE_JOB_ID);
                    jobScheduler.schedule(new JobInfo.Builder(UPDATE_JOB_ID, new ComponentName(this, ComicNotifierJob.class))
                            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
                            .setPeriodic(prefHelper.getNotificationInterval())
                            .setPersisted(true)
                            .build()
                    );
                    Timber.d("Job rescheduled!");
                } else {
                    jobScheduler.cancel(UPDATE_JOB_ID);
                    Timber.d("Job canceled!");
                }
                break;
        }
    } else if (requestCode == 2 && resultCode == FilePickerActivity.RESULT_OK) {
        ((FavoritesFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG)).importFavorites(data); //The import can only be started when FavoritesFragment is visible, so this cast should never fail
    } else if (requestCode == 3 && resultCode == Activity.RESULT_OK) {
        finish();
        startActivity(getIntent());
        //TODO select drawer item here, do this after merge
    }
}
 
Example 15
Source Project: MaterialFilePicker   Source File: MaterialFilePicker.java    License: Apache License 2.0 5 votes vote down vote up
public Intent getIntent() {
    CompositeFilter filter = getFilter();

    Activity activity = null;
    if (mActivity != null) {
        activity = mActivity;
    } else if (mFragment != null) {
        activity = mFragment.getActivity();
    } else if (mSupportFragment != null) {
        activity = mSupportFragment.getActivity();
    }

    Intent intent = new Intent(activity, mFilePickerClass);
    intent.putExtra(FilePickerActivity.ARG_FILTER, filter);
    intent.putExtra(FilePickerActivity.ARG_CLOSEABLE, mCloseable);

    if (mRootPath != null) {
        intent.putExtra(FilePickerActivity.ARG_START_FILE, new File(mRootPath));
    }
    if (mCurrentPath != null) {
        intent.putExtra(FilePickerActivity.ARG_CURRENT_FILE, new File(mCurrentPath));
    }

    if (mTitle != null) {
        intent.putExtra(FilePickerActivity.ARG_TITLE, mTitle);
    }

    return intent;
}
 
Example 16
Source Project: qBittorrent-Controller   Source File: SettingsActivity.java    License: MIT License 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode,
                                       String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // Permissions granted, open file picker
                Intent intent = new Intent(getApplicationContext(), FilePickerActivity.class);
                intent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.bks"));
                startActivityForResult(intent, 1);


            } else {

                // Permission denied


                // Should we show an explanation?
                if (!ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                    genericOkCancelDialog(R.string.error_grant_permission2,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                    Intent appIntent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                    appIntent.setData(Uri.parse("package:" + MainActivity.packageName));
                                    startActivityForResult(appIntent, 0);
                                }
                            });
                }
                return;
            }
        }
    }
}
 
Example 17
Source Project: Pano360   Source File: HomeActivity.java    License: MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    HomeActivityPermissionsDispatcher.initWithPermissionCheck(this);
    mViewPager = (ViewPager) findViewById(R.id.viewPager);
    mCardAdapter = new CardPagerAdapter();
    mCardAdapter.addCardItem(new CardItem(R.string.title_1, R.string.content_text_1));
    mCardAdapter.addCardItem(new CardItem(R.string.title_2, R.string.content_text_2));
    mCardAdapter.addCardItem(new CardItem(R.string.title_3, R.string.content_text_3));
    mCardAdapter.addCardItem(new CardItem(R.string.title_4, R.string.content_text_4));
    mCardAdapter.addCardItem(new CardItem(R.string.title_5, R.string.content_text_5));
    mCardAdapter.addCardItem(new CardItem(R.string.title_6, R.string.content_text_6));

    planeMode= (CheckBox) findViewById(R.id.plane_mode);

    mCardAdapter.setOnClickCallback(new CardPagerAdapter.OnClickCallback() {
        @Override
        public void onClick(int position) {
            videoHotspotPath=null;
            switch (position){
                case 0:
                    //filePath= "gz256.mp4";
                    //mimeType= MimeType.ASSETS | MimeType.VIDEO;
                    filePath= "android.resource://" + getPackageName() + "/" + R.raw.demo_video;
                    mimeType= MimeType.RAW | MimeType.VIDEO;
                    break;
                case 1:
                    Intent intent=new Intent(HomeActivity.this, FilePickerActivity.class);
                    intent.putExtra(FilePickerActivity.ARG_FILTER, Pattern.compile("(.*\\.mp4$)||(.*\\.avi$)||(.*\\.wmv$)"));
                    startActivityForResult(intent, 1);
                    return;
                case 2:
                    filePath="images/vr_cinema.jpg";
                    videoHotspotPath="android.resource://" + getPackageName() + "/" + R.raw.demo_video;
                    mimeType= MimeType.ASSETS | MimeType.PICTURE;
                    break;
                case 3:
                    //filePath= "android.resource://" + getPackageName() + "/" + R.raw.vr_cinema;
                    //mimeType= MimeType.RAW | MimeType.PICTURE;

                    //mimeType= MimeType.BITMAP | MimeType.PICTURE;

                    filePath="images/texture_360_n.jpg";
                    mimeType= MimeType.ASSETS | MimeType.PICTURE;
                    break;
                case 4:
                    filePath="http://cache.utovr.com/201508270528174780.m3u8";
                    mimeType= MimeType.ONLINE | MimeType.VIDEO;
                    break;
                case 5:
                    if(flag) throw new GirlFriendNotFoundException();
                    else {
                        Toast.makeText(HomeActivity.this,"再点会点坏的哦~",Toast.LENGTH_LONG).show();
                        flag=true;
                    }
                    return;
            }
            planeModeEnabled=planeMode.isChecked();
            start();
        }
    });
    mCardShadowTransformer = new ShadowTransformer(mViewPager, mCardAdapter);

    mViewPager.setAdapter(mCardAdapter);
    mViewPager.setPageTransformer(false, mCardShadowTransformer);

    mViewPager.setOffscreenPageLimit(3);

    mCardShadowTransformer.enableScaling(true);
}
 
Example 18
public boolean isFilePicked(int resultCode) {
    return resultCode == FilePickerActivity.RESULT_OK;
}
 
Example 19
public String getFilePath(Intent data) {
    return data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
}
 
Example 20
@Before
public void setUp() {
    filePickerProxy = new FilePickerProxy();
    when(intentMock.getStringExtra(FilePickerActivity.RESULT_FILE_PATH)).thenReturn(FILE_PATH);
}
 
Example 21
@Test
public void whenCheckingFilePickedWithOkExpectTrue() {
    assertTrue(filePickerProxy.isFilePicked(FilePickerActivity.RESULT_OK));
}
 
Example 22
@Test
public void whenCheckingFilePickedWithCanceledExpectFalse() {
    assertFalse(filePickerProxy.isFilePicked(FilePickerActivity.RESULT_CANCELED));
}
 
Example 23
Source Project: MaterialFilePicker   Source File: MaterialFilePicker.java    License: Apache License 2.0 4 votes vote down vote up
public MaterialFilePicker withCustomActivity(Class<? extends FilePickerActivity> customActivityClass) {
    mFilePickerClass = customActivityClass;
    return this;
}
 
Example 24
Source Project: qBittorrent-Controller   Source File: SettingsActivity.java    License: MIT License 3 votes vote down vote up
private void openFilePicker() {

        // Check Dangerous permissions (Android 6.0+, API 23+)
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {


            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                genericOkDialog(R.string.error_permission2,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                                        MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
                            }
                        });

            }else{

                // No explanation needed, request the permission.
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);

            }


        } else {

            // Permissions granted, open file picker
            Intent intent = new Intent(getApplicationContext(), FilePickerActivity.class);
            intent.putExtra(FilePickerActivity.ARG_FILE_FILTER, Pattern.compile(".*\\.bks"));
            startActivityForResult(intent, 1);

        }


    }