public void onLongTap(int slotIndex) {
   if (mGetContent || mGetAlbum) return;
   MediaSet set = mAlbumSetDataAdapter.getMediaSet(slotIndex);
   if (set == null) return;
   mSelectionManager.setAutoLeaveSelectionMode(true);
   mSelectionManager.toggle(set.getPath());
   mSlotView.invalidate();
 }
 public void onLongTap(int slotIndex) {
   if (mGetContent) return;
   MediaItem item = mAlbumDataAdapter.get(slotIndex);
   if (item == null) return;
   mSelectionManager.setAutoLeaveSelectionMode(true);
   mSelectionManager.toggle(item.getPath());
   mSlotView.invalidate();
 }
 @Override
 protected boolean onItemSelected(MenuItem item) {
   Activity activity = mActivity;
   switch (item.getItemId()) {
     case R.id.action_more_image:
       Uri moreUri = Uri.parse(mActivity.getString(R.string.website_for_more_image));
       Intent moreIntent = new Intent(Intent.ACTION_VIEW, moreUri);
       mActivity.startActivity(moreIntent);
       return true;
     case R.id.action_cancel:
       activity.setResult(Activity.RESULT_CANCELED);
       activity.finish();
       return true;
     case R.id.action_select:
       mSelectionManager.setAutoLeaveSelectionMode(false);
       mSelectionManager.enterSelectionMode();
       return true;
     case R.id.action_details:
       if (mAlbumSetDataAdapter.size() != 0) {
         if (mShowDetails) {
           hideDetails();
         } else {
           showDetails();
         }
       } else {
         Toast.makeText(activity, activity.getText(R.string.no_albums_alert), Toast.LENGTH_SHORT)
             .show();
       }
       return true;
     case R.id.action_camera:
       {
         GalleryUtils.startCameraActivity(activity);
         return true;
       }
     case R.id.action_manage_offline:
       {
         Bundle data = new Bundle();
         String mediaPath = mActivity.getDataManager().getTopSetPath(DataManager.INCLUDE_ALL);
         data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath);
         mActivity.getStateManager().startState(ManageCachePage.class, data);
         return true;
       }
     case R.id.action_sync_picasa_albums:
       {
         PicasaSource.requestSync(activity);
         return true;
       }
     case R.id.action_settings:
       {
         activity.startActivity(new Intent(activity, GallerySettings.class));
         return true;
       }
     default:
       return false;
   }
 }
 @Override
 public void onBackPressed() {
   if (mShowDetails) {
     hideDetails();
   } else if (mSelectionManager.inSelectionMode()) {
     mSelectionManager.leaveSelectionMode();
   } else {
     super.onBackPressed();
   }
 }
Ejemplo n.º 5
0
  @Override
  protected boolean onItemSelected(MenuItem item) {
    Activity activity = mActivity;
    switch (item.getItemId()) {
      case R.id.action_cancel:
        activity.setResult(Activity.RESULT_CANCELED);
        activity.finish();
        return true;
      case R.id.action_select:
        mSelectionManager.setAutoLeaveSelectionMode(false);
        mSelectionManager.enterSelectionMode();
        return true;
      case R.id.action_details:
        if (mAlbumSetDataAdapter.size() != 0) {
          if (mShowDetails) {
            hideDetails();
          } else {
            showDetails();
          }
        } else {
          Toast.makeText(activity, activity.getText(R.string.no_albums_alert), Toast.LENGTH_SHORT)
              .show();
        }
        return true;
      case R.id.action_camera:
        {
          GalleryUtils.startCameraActivity(activity);
          return true;
        }
      case R.id.action_manage_offline:
        {
          Bundle data = new Bundle();
          String mediaPath = mActivity.getDataManager().getTopSetPath(DataManager.INCLUDE_ALL);
          data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath);
          mActivity.getStateManager().startState(ManageCachePage.class, data);
          return true;
        }
      case R.id.action_sync_picasa_albums:
        {
          PicasaSource.requestSync(activity);
          return true;
        }
        /*   Comment out to enable Settings in menu. This should be done when
             GallerySettings.java has content, as it is currently empty.
             Also comment out the settings item at albumset.xml menu.

                    case R.id.action_settings: {
                        activity.startActivity(new Intent(activity, GallerySettings.class));
                        return true;
                    }
        */
      default:
        return false;
    }
  }
 @Override
 protected boolean onItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case android.R.id.home:
       {
         onUpPressed();
         return true;
       }
     case R.id.action_cancel:
       mActivity.getStateManager().finishState(this);
       return true;
     case R.id.action_select:
       mSelectionManager.setAutoLeaveSelectionMode(false);
       mSelectionManager.enterSelectionMode();
       return true;
     case R.id.action_group_by:
       {
         mActivity.getGalleryActionBar().showClusterDialog(this);
         return true;
       }
     case R.id.action_slideshow:
       {
         mInCameraAndWantQuitOnPause = false;
         Bundle data = new Bundle();
         data.putString(SlideshowPage.KEY_SET_PATH, mMediaSetPath.toString());
         data.putBoolean(SlideshowPage.KEY_REPEAT, true);
         mActivity
             .getStateManager()
             .startStateForResult(SlideshowPage.class, REQUEST_SLIDESHOW, data);
         return true;
       }
     case R.id.action_details:
       {
         if (mShowDetails) {
           hideDetails();
         } else {
           showDetails();
         }
         return true;
       }
     case R.id.action_camera:
       {
         GalleryUtils.startCameraActivity(mActivity);
         return true;
       }
     default:
       return false;
   }
 }
  @Override
  protected void onCreate(Bundle data, Bundle restoreState) {
    super.onCreate(data, restoreState);
    mUserDistance = GalleryUtils.meterToPixel(USER_DISTANCE_METER);
    initializeViews();
    initializeData(data);
    mGetContent = data.getBoolean(GalleryActivity.KEY_GET_CONTENT, false);
    mShowClusterMenu = data.getBoolean(KEY_SHOW_CLUSTER_MENU, false);
    mDetailsSource = new MyDetailsSource();
    Context context = mActivity.getAndroidContext();

    if (data.getBoolean(KEY_AUTO_SELECT_ALL)) {
      mSelectionManager.selectAll();
    }

    mLaunchedFromPhotoPage = mActivity.getStateManager().hasStateClass(FilmstripPage.class);
    mInCameraApp = data.getBoolean(PhotoPage.KEY_APP_BRIDGE, false);

    mHandler =
        new SynchronizedHandler(mActivity.getGLRoot()) {
          @Override
          public void handleMessage(Message message) {
            switch (message.what) {
              case MSG_PICK_PHOTO:
                {
                  pickPhoto(message.arg1);
                  break;
                }
              default:
                throw new AssertionError(message.what);
            }
          }
        };
  }
  private void onSingleTapUp(int slotIndex) {
    if (!mIsActive) return;

    if (mSelectionManager.inSelectionMode()) {
      MediaItem item = mAlbumDataAdapter.get(slotIndex);
      if (item == null) return; // Item not ready yet, ignore the click
      mSelectionManager.toggle(item.getPath());
      mSlotView.invalidate();
    } else {
      // Render transition in pressed state
      mAlbumView.setPressedIndex(slotIndex);
      mAlbumView.setPressedUp();
      mHandler.sendMessageDelayed(
          mHandler.obtainMessage(MSG_PICK_PHOTO, slotIndex, 0), FadeTexture.DURATION);
    }
  }
  public void onSingleTapUp(int slotIndex) {
    if (!mIsActive) return;

    if (mSelectionManager.inSelectionMode()) {
      MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
      if (targetSet == null) return; // Content is dirty, we shall reload soon
      mSelectionManager.toggle(targetSet.getPath());
      mSlotView.invalidate();
    } else {
      // Show pressed-up animation for the single-tap.
      mAlbumSetView.setPressedIndex(slotIndex);
      mAlbumSetView.setPressedUp();
      mHandler.sendMessageDelayed(
          mHandler.obtainMessage(MSG_PICK_ALBUM, slotIndex, 0), FadeTexture.DURATION);
    }
  }
 @Override
 public void onSelectionChange(Path path, boolean selected) {
   int count = mSelectionManager.getSelectedCount();
   String format =
       mActivity.getResources().getQuantityString(R.plurals.number_of_items_selected, count);
   mActionModeHandler.setTitle(String.format(format, count));
   mActionModeHandler.updateSupportedOperation(path, selected);
 }
 private void initializeData(Bundle data) {
   String mediaPath = data.getString(AlbumSetPage.KEY_MEDIA_PATH);
   mMediaSet = mActivity.getDataManager().getMediaSet(mediaPath);
   mSelectionManager.setSourceMediaSet(mMediaSet);
   mAlbumSetDataAdapter = new AlbumSetDataLoader(mActivity, mMediaSet, DATA_CACHE_SIZE);
   mAlbumSetDataAdapter.setLoadingListener(new MyLoadingListener());
   mAlbumSetView.setModel(mAlbumSetDataAdapter);
 }
 private String getSelectedString() {
   int count = mSelectionManager.getSelectedCount();
   int action = mActionBar.getClusterTypeAction();
   int string =
       action == FilterUtils.CLUSTER_BY_ALBUM
           ? R.plurals.number_of_albums_selected
           : R.plurals.number_of_groups_selected;
   String format = mActivity.getResources().getQuantityString(string, count);
   return String.format(format, count);
 }
 private void initializeData(Bundle data) {
   mMediaSetPath = Path.fromString(data.getString(KEY_MEDIA_PATH));
   mParentMediaSetString = data.getString(KEY_PARENT_MEDIA_PATH);
   mMediaSet = mActivity.getDataManager().getMediaSet(mMediaSetPath);
   if (mMediaSet == null) {
     Utils.fail("MediaSet is null. Path = %s", mMediaSetPath);
   }
   mSelectionManager.setSourceMediaSet(mMediaSet);
   mAlbumDataAdapter = new AlbumDataLoader(mActivity, mMediaSet);
   mAlbumDataAdapter.setLoadingListener(new MyLoadingListener());
   mAlbumView.setModel(mAlbumDataAdapter);
 }
 // This are the transitions we want:
 //
 // +--------+           +------------+    +-------+    +----------+
 // | Camera |---------->| Fullscreen |--->| Album |--->| AlbumSet |
 // |  View  | thumbnail |   Photo    | up | Page  | up |   Page   |
 // +--------+           +------------+    +-------+    +----------+
 //     ^                      |               |            ^  |
 //     |                      |               |            |  |         close
 //     +----------back--------+               +----back----+  +--back->  app
 //
 @Override
 protected void onBackPressed() {
   if (mShowDetails) {
     hideDetails();
   } else if (mSelectionManager.inSelectionMode()) {
     mSelectionManager.leaveSelectionMode();
   } else {
     if (mLaunchedFromPhotoPage) {
       mActivity
           .getTransitionStore()
           .putIfNotPresent(PhotoPage.KEY_ALBUMPAGE_TRANSITION, PhotoPage.MSG_ALBUMPAGE_RESUMED);
     }
     // TODO: fix this regression
     // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
     if (mInCameraApp) {
       super.onBackPressed();
     } else {
       onUpPressed();
     }
   }
 }
  @Override
  protected void onPause() {
    super.onPause();
    mIsActive = false;

    if (mSelectionManager.inSelectionMode()) {
      mSelectionManager.leaveSelectionMode();
    }
    mAlbumView.setSlotFilter(null);
    mActionModeHandler.pause();
    mAlbumDataAdapter.pause();
    mAlbumView.pause();
    DetailsHelper.pause();
    if (!mGetContent) {
      mActivity.getGalleryActionBar().disableAlbumModeMenu(true);
    }

    if (mSyncTask != null) {
      mSyncTask.cancel();
      mSyncTask = null;
      clearLoadingBit(BIT_LOADING_SYNC);
    }
  }
Ejemplo n.º 16
0
  private void initializeViews() {
    mSelectionManager = new SelectionManager(mActivity, true);
    mSelectionManager.setSelectionListener(this);

    mConfig = Config.AlbumSetPage.get(mActivity);
    mSlotView = new SlotView(mActivity, mConfig.slotViewSpec);
    mAlbumSetView =
        new AlbumSetSlotRenderer(
            mActivity, mSelectionManager, mSlotView, mConfig.labelSpec, mConfig.placeholderColor);
    mSlotView.setSlotRenderer(mAlbumSetView);
    mSlotView.setListener(
        new SlotView.SimpleListener() {
          @Override
          public void onDown(int index) {
            AlbumSetPage.this.onDown(index);
          }

          @Override
          public void onUp(boolean followedByLongPress) {
            AlbumSetPage.this.onUp(followedByLongPress);
          }

          @Override
          public void onSingleTapUp(int slotIndex) {
            AlbumSetPage.this.onSingleTapUp(slotIndex);
          }

          @Override
          public void onLongTap(int slotIndex) {
            AlbumSetPage.this.onLongTap(slotIndex);
          }

          @Override
          public void onGestureLongTap(int slotIndex) {
            AlbumSetPage.this.onGestureLongTap(slotIndex);
          }
        });

    mActionModeHandler = new ActionModeHandler(mActivity, mSelectionManager);
    mActionModeHandler.setActionModeListener(
        new ActionModeListener() {
          @Override
          public boolean onActionItemClicked(MenuItem item) {
            return onItemSelected(item);
          }
        });
    mRootPane.addComponent(mSlotView);
  }