@Override
  public void onStart() {
    super.onStart();
    mPaused = false;

    if (!init(mSavedUri)) {
      Log.w(TAG, "init failed: " + mSavedUri);
      finish();
      return;
    }

    // normally this will never be zero but if one "backs" into this
    // activity after removing the sdcard it could be zero.  in that
    // case just "finish" since there's nothing useful that can happen.
    int count = mAllImages.getCount();
    if (count == 0) {
      finish();
      return;
    } else if (count <= mCurrentPosition) {
      mCurrentPosition = count - 1;
    }

    if (mGetter == null) {
      makeGetter();
    }

    if (mMode == MODE_SLIDESHOW) {
      loadNextImage(mCurrentPosition, 0, true);
    } else { // MODE_NORMAL
      setImage(mCurrentPosition, mShowControls);
      mShowControls = false;
    }
  }
  @Override
  public void onStop() {
    super.onStop();
    mPaused = true;

    // mGetter could be null if we call finish() and leave early in
    // onStart().
    if (mGetter != null) {
      mGetter.cancelCurrent();
      mGetter.stop();
      mGetter = null;
    }
    setMode(MODE_NORMAL);

    // removing all callback in the message queue
    mHandler.removeAllGetterCallbacks();

    if (mAllImages != null) {
      mSavedUri = getCurrentUri();
      mAllImages.close();
      mAllImages = null;
    }

    hideOnScreenControls();
    mImageView.clear();
    mCache.clear();

    for (ImageViewTouchBase iv : mSlideShowImageViews) {
      iv.clear();
    }
  }
 @Override
 public void onPause() {
   super.onPause();
   ApiService.unregisterListener(mProjectsLoadedListener);
   mAdapter = null;
   mGridView.setAdapter(null);
 }
Example #4
0
 @Override
 protected void onStop() {
   super.onStop();
   for (LifeCycleListener listener : mListeners) {
     listener.onActivityStopped(this);
   }
 }
Example #5
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   for (LifeCycleListener listener : mListeners) {
     listener.onActivityDestroyed(this);
   }
 }
Example #6
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   for (LifeCycleListener listener : mListeners) {
     listener.onActivityCreated(this);
   }
 }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuItem item =
        menu.add(Menu.NONE, Menu.NONE, MenuHelper.POSITION_SLIDESHOW, R.string.slide_show);
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            setMode(MODE_SLIDESHOW);
            mLastSlideShowImage = mCurrentPosition;
            loadNextImage(mCurrentPosition, 0, true);
            return true;
          }
        });
    item.setIcon(android.R.drawable.ic_menu_slideshow);

    mImageMenuRunnable =
        MenuHelper.addImageMenuItems(
            menu,
            MenuHelper.INCLUDE_ALL,
            ViewImage.this,
            mHandler,
            mDeletePhotoRunnable,
            new MenuHelper.MenuInvoker() {
              public void run(final MenuHelper.MenuCallback cb) {
                if (mPaused) return;
                setMode(MODE_NORMAL);

                IImage image = mAllImages.getImageAt(mCurrentPosition);
                Uri uri = image.fullSizeImageUri();
                cb.run(uri, image);

                // We might have deleted all images in the callback, so
                // call setImage() only if we still have some images.
                if (mAllImages.getCount() > 0) {
                  mImageView.clear();
                  setImage(mCurrentPosition, false);
                }
              }
            });

    item =
        menu.add(
            Menu.NONE, Menu.NONE, MenuHelper.POSITION_GALLERY_SETTING, R.string.camerasettings);
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          public boolean onMenuItemClick(MenuItem item) {
            Intent preferences = new Intent();
            preferences.setClass(ViewImage.this, GallerySettings.class);
            startActivity(preferences);
            return true;
          }
        });
    item.setAlphabeticShortcut('p');
    item.setIcon(android.R.drawable.ic_menu_preferences);

    return true;
  }
 @Override
 protected void onDestroy() {
   // This is necessary to make the ZoomButtonsController unregister
   // its configuration change receiver.
   if (mZoomButtonsController != null) {
     mZoomButtonsController.setVisible(false);
   }
   super.onDestroy();
 }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   Intent intent = getIntent();
   mUriList = intent.getParcelableArrayListExtra("delete-uris");
   if (mUriList == null) {
     finish();
   }
   setContentView(R.layout.delete_image);
   mProgressBar = (ProgressBar) findViewById(R.id.delete_progress);
   mContentResolver = getContentResolver();
 }
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {

    super.onPrepareOptionsMenu(menu);
    if (mPaused) return false;

    setMode(MODE_NORMAL);
    IImage image = mAllImages.getImageAt(mCurrentPosition);

    if (mImageMenuRunnable != null) {
      mImageMenuRunnable.gettingReadyToOpen(menu, image);
    }

    Uri uri = mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri();
    MenuHelper.enableShareMenuItem(menu, MenuHelper.isWhiteListUri(uri));

    MenuHelper.enableShowOnMapMenuItem(menu, MenuHelper.hasLatLngData(image));

    return true;
  }
 @Override
 protected void onPause() {
   super.onPause();
   mPausing = true;
 }
 @Override
 protected void onResume() {
   super.onResume();
   mPausing = false;
   mHandler.post(mDeleteNextRunnable);
 }
 @Override
 public void onSaveInstanceState(Bundle b) {
   super.onSaveInstanceState(b);
   b.putParcelable(STATE_URI, mAllImages.getImageAt(mCurrentPosition).fullSizeImageUri());
   b.putBoolean(STATE_SLIDESHOW, mMode == MODE_SLIDESHOW);
 }
  @Override
  public void onCreate(Bundle instanceState) {
    super.onCreate(instanceState);

    Intent intent = getIntent();
    mFullScreenInNormalMode = intent.getBooleanExtra(MediaStore.EXTRA_FULL_SCREEN, true);
    mShowActionIcons = intent.getBooleanExtra(MediaStore.EXTRA_SHOW_ACTION_ICONS, true);

    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    setDefaultKeyMode(DEFAULT_KEYS_SHORTCUT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.viewimage);

    mImageView = (ImageViewTouch) findViewById(R.id.image);
    mImageView.setEnableTrackballScroll(true);
    mCache = new BitmapCache(3);
    mImageView.setRecycler(mCache);

    makeGetter();

    mAnimationIndex = -1;

    mSlideShowInAnimation =
        new Animation[] {
          makeInAnimation(R.anim.transition_in),
          makeInAnimation(R.anim.slide_in),
          makeInAnimation(R.anim.slide_in_vertical),
        };

    mSlideShowOutAnimation =
        new Animation[] {
          makeOutAnimation(R.anim.transition_out),
          makeOutAnimation(R.anim.slide_out),
          makeOutAnimation(R.anim.slide_out_vertical),
        };

    mSlideShowImageViews[0] = (ImageViewTouchBase) findViewById(R.id.image1_slideShow);
    mSlideShowImageViews[1] = (ImageViewTouchBase) findViewById(R.id.image2_slideShow);
    for (ImageViewTouchBase v : mSlideShowImageViews) {
      v.setVisibility(View.INVISIBLE);
      v.setRecycler(mCache);
    }

    mActionIconPanel = findViewById(R.id.action_icon_panel);

    mParam = getIntent().getParcelableExtra(KEY_IMAGE_LIST);

    boolean slideshow;
    if (instanceState != null) {
      mSavedUri = instanceState.getParcelable(STATE_URI);
      slideshow = instanceState.getBoolean(STATE_SLIDESHOW, false);
      mShowControls = instanceState.getBoolean(STATE_SHOW_CONTROLS, true);
    } else {
      mSavedUri = getIntent().getData();
      slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
    }

    // We only show action icons for URIs that we know we can share and
    // delete. Although we get read permission (for the images) from
    // applications like MMS, we cannot pass the permission to other
    // activities due to the current framework design.
    if (!MenuHelper.isWhiteListUri(mSavedUri)) {
      mShowActionIcons = false;
    }

    if (mShowActionIcons) {
      int[] pickIds = {R.id.attach, R.id.cancel};
      int[] normalIds = {R.id.setas, R.id.play, R.id.share, R.id.discard};
      int[] connectIds = isPickIntent() ? pickIds : normalIds;
      for (int id : connectIds) {
        View view = mActionIconPanel.findViewById(id);
        view.setVisibility(View.VISIBLE);
        view.setOnClickListener(this);
      }
    }

    // Don't show the "delete" icon for SingleImageList.
    if (ImageManager.isSingleImageMode(mSavedUri.toString())) {
      mActionIconPanel.findViewById(R.id.discard).setVisibility(View.GONE);
    }

    if (slideshow) {
      setMode(MODE_SLIDESHOW);
    } else {
      if (mFullScreenInNormalMode) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      }
      if (mShowActionIcons) {
        mActionIconPanel.setVisibility(View.VISIBLE);
      }
    }

    setupOnScreenControls(findViewById(R.id.rootLayout), mImageView);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.project_picker);

    // Show action bar title only on large screens.
    final ActionBar actionBar = getActionBar();
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int widthDip = (int) (displayMetrics.widthPixels / displayMetrics.scaledDensity);
    // Only show title on large screens (width >= 1000 dip).
    if (widthDip >= SHOW_TITLE_THRESHOLD_WIDTH_DIP) {
      actionBar.setDisplayOptions(actionBar.getDisplayOptions() | ActionBar.DISPLAY_SHOW_TITLE);
      actionBar.setTitle(R.string.full_app_name);
    }

    mGridView = (GridView) findViewById(R.id.projects);
    mGridView.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // If user clicks on the last item, then create a new project.
            if (position == mProjects.size()) {
              showDialog(DIALOG_NEW_PROJECT_ID);
            } else {
              openProject(mProjects.get(position).getPath());
            }
          }
        });
    // Upon long press, pop up a menu with a removal option.
    mGridView.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(
              AdapterView<?> parent, View view, final int position, long id) {
            // Open new project dialog when user clicks on the "create new project" card.
            if (position == mProjects.size()) {
              showDialog(DIALOG_NEW_PROJECT_ID);
              return true;
            }
            // Otherwise, pop up a menu with a project removal option.
            final PopupMenu popupMenu = new PopupMenu(ProjectsActivity.this, view);
            popupMenu.getMenuInflater().inflate(R.menu.project_menu, popupMenu.getMenu());
            popupMenu.setOnMenuItemClickListener(
                new PopupMenu.OnMenuItemClickListener() {
                  @Override
                  public boolean onMenuItemClick(MenuItem menuItem) {
                    switch (menuItem.getItemId()) {
                      case R.id.action_remove_project:
                        final Bundle bundle = new Bundle();
                        bundle.putString(PARAM_DIALOG_PATH_ID, mProjects.get(position).getPath());
                        showDialog(DIALOG_REMOVE_PROJECT_ID, bundle);
                        break;
                      default:
                        break;
                    }
                    return true;
                  }
                });
            popupMenu.show();
            return true;
          }
        });
  }
 @Override
 public void onResume() {
   super.onResume();
   ApiService.registerListener(mProjectsLoadedListener);
   ApiService.loadProjects(this);
 }