- private void patchHiddenAccents(Menu menu) {
- for (int i = 0; i < mMenuIdentifiersToPatch.length ; i++) {
- MenuItem aboutItem = menu.findItem(mMenuIdentifiersToPatch[i]);
- if (aboutItem != null && aboutItem.getIcon() instanceof BitmapDrawable) {
- // Clip off the bottom three (density independent) pixels of transparent padding
- Bitmap original = ((BitmapDrawable) aboutItem.getIcon()).getBitmap();
- float scale = getResources().getDisplayMetrics().density;
- int clippedHeight = (int) (original.getHeight() - (3 * scale));
- Bitmap scaled = Bitmap.createBitmap(original, 0, 0, original.getWidth(), clippedHeight);
- aboutItem.setIcon(new BitmapDrawable(getResources(), scaled));
+ private void setSecondFragment(Fragment fragment) {
+ FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.right_fragment_container, fragment, TAG_SECOND_FRAGMENT);
+ transaction.commit();
+ }
+
+
+ private void updateFragmentsVisibility(boolean existsSecondFragment) {
+ if (mDualPane) {
+ if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
+ mLeftFragmentContainer.setVisibility(View.VISIBLE);
+ }
+ if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
+ mRightFragmentContainer.setVisibility(View.VISIBLE);
+ }
+
+ } else if (existsSecondFragment) {
+ if (mLeftFragmentContainer.getVisibility() != View.GONE) {
+ mLeftFragmentContainer.setVisibility(View.GONE);
+ }
+ if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
+ mRightFragmentContainer.setVisibility(View.VISIBLE);
+ }
+
+ } else {
+ if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
+ mLeftFragmentContainer.setVisibility(View.VISIBLE);
+ }
+ if (mRightFragmentContainer.getVisibility() != View.GONE) {
+ mRightFragmentContainer.setVisibility(View.GONE);
+ }
+ }
+ }
+
+
+ private OCFileListFragment getListOfFilesFragment() {
+ Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_LIST_OF_FILES);
+ if (listOfFiles != null) {
+ return (OCFileListFragment)listOfFiles;
+ }
+ Log_OC.wtf(TAG, "Access to unexisting list of files fragment!!");
+ return null;
+ }
+
+ protected FileFragment getSecondFragment() {
+ Fragment second = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT);
+ if (second != null) {
+ return (FileFragment)second;
+ }
+ return null;
+ }
+
+ public void cleanSecondFragment() {
+ Fragment second = getSecondFragment();
+ if (second != null) {
+ FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
+ tr.remove(second);
+ tr.commit();
+ }
+ updateFragmentsVisibility(false);
+ updateNavigationElementsInActionBar(null);
+ }
+
+ protected void refeshListOfFilesFragment() {
+ OCFileListFragment fileListFragment = getListOfFilesFragment();
+ if (fileListFragment != null) {
+ fileListFragment.listDirectory();
+ }
+ }
+
+ protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath, boolean success) {
+ FileFragment secondFragment = getSecondFragment();
+ boolean waitedPreview = (mWaitingToPreview != null && mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
+ if (secondFragment != null && secondFragment instanceof FileDetailFragment) {
+ FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
+ OCFile fileInFragment = detailsFragment.getFile();
+ if (fileInFragment != null && !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
+ // the user browsed to other file ; forget the automatic preview
+ mWaitingToPreview = null;
+
+ } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_ADDED_MESSAGE)) {
+ // grant that the right panel updates the progress bar
+ detailsFragment.listenForTransferProgress();
+ detailsFragment.updateFileDetails(true, false);
+
+ } else if (downloadEvent.equals(FileDownloader.DOWNLOAD_FINISH_MESSAGE)) {
+ // update the right panel
+ boolean detailsFragmentChanged = false;
+ if (waitedPreview) {
+ if (success) {
+ mWaitingToPreview = mStorageManager.getFileById(mWaitingToPreview.getFileId()); // update the file from database, for the local storage path
+ if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
+ startMediaPreview(mWaitingToPreview, 0, true);
+ detailsFragmentChanged = true;
+ } else {
+ openFile(mWaitingToPreview);
+ }
+ }
+ mWaitingToPreview = null;
+ }
+ if (!detailsFragmentChanged) {
+ detailsFragment.updateFileDetails(false, (success));
+ }