void setMode(int mode) {
    if (mMode == mode) {
      return;
    }
    View slideshowPanel = findViewById(R.id.slideShowContainer);
    View normalPanel = findViewById(R.id.abs);

    Window win = getWindow();
    mMode = mode;
    if (mode == MODE_SLIDESHOW) {
      slideshowPanel.setVisibility(View.VISIBLE);
      normalPanel.setVisibility(View.GONE);

      win.addFlags(
          WindowManager.LayoutParams.FLAG_FULLSCREEN
              | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

      mImageView.clear();
      mActionIconPanel.setVisibility(View.GONE);

      slideshowPanel.getRootView().requestLayout();

      // The preferences we want to read:
      //   mUseShuffleOrder
      //   mSlideShowLoop
      //   mAnimationIndex
      //   mSlideShowInterval

      mUseShuffleOrder = mPrefs.getBoolean(PREF_SHUFFLE_SLIDESHOW, false);
      mSlideShowLoop = mPrefs.getBoolean(PREF_SLIDESHOW_REPEAT, false);
      mAnimationIndex = getPreferencesInteger(mPrefs, "pref_gallery_slideshow_transition_key", 0);
      mSlideShowInterval =
          getPreferencesInteger(mPrefs, "pref_gallery_slideshow_interval_key", 3) * 1000;
    } else {
      slideshowPanel.setVisibility(View.GONE);
      normalPanel.setVisibility(View.VISIBLE);

      win.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      if (mFullScreenInNormalMode) {
        win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      } else {
        win.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
      }

      if (mGetter != null) {
        mGetter.cancelCurrent();
      }

      if (mShowActionIcons) {
        Animation animation = new AlphaAnimation(0F, 1F);
        animation.setDuration(500);
        mActionIconPanel.setAnimation(animation);
        mActionIconPanel.setVisibility(View.VISIBLE);
      }

      ImageViewTouchBase dst = mImageView;
      for (ImageViewTouchBase ivt : mSlideShowImageViews) {
        ivt.clear();
      }

      mShuffleOrder = null;

      // mGetter null is a proxy for being paused
      if (mGetter != null) {
        setImage(mCurrentPosition, true);
      }
    }
  }
  @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();
    }
  }
  private void loadNextImage(final int requestedPos, final long delay, final boolean firstCall) {
    if (firstCall && mUseShuffleOrder) {
      generateShuffleOrder();
    }

    final long targetDisplayTime = System.currentTimeMillis() + delay;

    ImageGetterCallback cb =
        new ImageGetterCallback() {
          public void completed() {}

          public boolean wantsThumbnail(int pos, int offset) {
            return true;
          }

          public boolean wantsFullImage(int pos, int offset) {
            return false;
          }

          public int[] loadOrder() {
            return sOrderSlideshow;
          }

          public int fullImageSizeToUse(int pos, int offset) {
            return 480; // TODO compute this
          }

          public void imageLoaded(
              final int pos, final int offset, final RotateBitmap bitmap, final boolean isThumb) {
            long timeRemaining = Math.max(0, targetDisplayTime - System.currentTimeMillis());
            mHandler.postDelayedGetterCallback(
                new Runnable() {
                  public void run() {
                    if (mMode == MODE_NORMAL) {
                      return;
                    }

                    ImageViewTouchBase oldView = mSlideShowImageViews[mSlideShowImageCurrent];

                    if (++mSlideShowImageCurrent == mSlideShowImageViews.length) {
                      mSlideShowImageCurrent = 0;
                    }

                    ImageViewTouchBase newView = mSlideShowImageViews[mSlideShowImageCurrent];
                    newView.setVisibility(View.VISIBLE);
                    newView.setImageRotateBitmapResetBase(bitmap, true);
                    newView.bringToFront();

                    int animation = 0;

                    if (mAnimationIndex == -1) {
                      int n = mRandom.nextInt(mSlideShowInAnimation.length);
                      animation = n;
                    } else {
                      animation = mAnimationIndex;
                    }

                    Animation aIn = mSlideShowInAnimation[animation];
                    newView.startAnimation(aIn);
                    newView.setVisibility(View.VISIBLE);

                    Animation aOut = mSlideShowOutAnimation[animation];
                    oldView.setVisibility(View.INVISIBLE);
                    oldView.startAnimation(aOut);

                    mCurrentPosition = requestedPos;

                    if (mCurrentPosition == mLastSlideShowImage && !firstCall) {
                      if (mSlideShowLoop) {
                        if (mUseShuffleOrder) {
                          generateShuffleOrder();
                        }
                      } else {
                        setMode(MODE_NORMAL);
                        return;
                      }
                    }

                    loadNextImage(
                        (mCurrentPosition + 1) % mAllImages.getCount(), mSlideShowInterval, false);
                  }
                },
                timeRemaining);
          }
        };
    // Could be null if we're stopping a slide show in the course of pausing
    if (mGetter != null) {
      int pos = requestedPos;
      if (mShuffleOrder != null) {
        pos = mShuffleOrder[pos];
      }
      mGetter.setPosition(pos, cb, mAllImages, mHandler);
    }
  }
  void setImage(int pos, boolean showControls) {
    mCurrentPosition = pos;

    Bitmap b = mCache.getBitmap(pos);
    if (b != null) {
      IImage image = mAllImages.getImageAt(pos);
      mImageView.setImageRotateBitmapResetBase(
          new RotateBitmap(b, image.getDegreesRotated()), true);
      updateZoomButtonsEnabled();
    }

    ImageGetterCallback cb =
        new ImageGetterCallback() {
          public void completed() {}

          public boolean wantsThumbnail(int pos, int offset) {
            return !mCache.hasBitmap(pos + offset);
          }

          public boolean wantsFullImage(int pos, int offset) {
            return offset == 0;
          }

          public int fullImageSizeToUse(int pos, int offset) {
            // this number should be bigger so that we can zoom.  we may
            // need to get fancier and read in the fuller size image as the
            // user starts to zoom.
            // Originally the value is set to 480 in order to avoid OOM.
            // Now we set it to 2048 because of using
            // native memory allocation for Bitmaps.
            final int imageViewSize = 2048;
            return imageViewSize;
          }

          public int[] loadOrder() {
            return sOrderAdjacents;
          }

          public void imageLoaded(int pos, int offset, RotateBitmap bitmap, boolean isThumb) {
            // shouldn't get here after onPause()

            // We may get a result from a previous request. Ignore it.
            if (pos != mCurrentPosition) {
              bitmap.recycle();
              return;
            }

            if (isThumb) {
              mCache.put(pos + offset, bitmap.getBitmap());
            }
            if (offset == 0) {
              // isThumb: We always load thumb bitmap first, so we will
              // reset the supp matrix for then thumb bitmap, and keep
              // the supp matrix when the full bitmap is loaded.
              mImageView.setImageRotateBitmapResetBase(bitmap, isThumb);
              updateZoomButtonsEnabled();
            }
          }
        };

    // Could be null if we're stopping a slide show in the course of pausing
    if (mGetter != null) {
      mGetter.setPosition(pos, cb, mAllImages, mHandler);
    }
    updateActionIcons();
    if (showControls) showOnScreenControls();
    scheduleDismissOnScreenControls();
  }
Ejemplo n.º 5
0
  @Override
  public void onCreate(Bundle saved) {
    super.onCreate(saved);
    setContentView(R.layout.layout_person_info);
    searcher = new TmdbQuery(getBaseContext());

    picture = (ImageView) findViewById(R.id.image_person_info);
    name = (TextView) findViewById(R.id.text_person_name);
    birth = (TextView) findViewById(R.id.text_person_birth);
    death = (TextView) findViewById(R.id.text_person_death);
    bio = (TextView) findViewById(R.id.text_person_bio);
    appearsIn = (ListView) findViewById(R.id.listview_credits);

    Bundle extras = getIntent().getExtras();
    personId = extras.getInt("id");
    person = searcher.getPersonById(personId);
    picture.setTag(person.getIdTag());
    ImageGetter imgGetter = new ImageGetter(getBaseContext());
    try {
      String url =
          getString(R.string.baseurl_images)
              + person.getMediumImage(getResources())
              + person.getImagePath();
      imgGetter.DisplayImage(url, picture, 1.2f);
    } catch (RejectedExecutionException e) {
      Log.d(tag, "async task queue full at the moment, imgGet rejected");
    }

    name.setText(person.getName());
    birth.setText(
        Html.fromHtml(
            "born: " + person.getBirthday() + "<br><i>in</i>: " + person.getBirthPlace()));
    String deathString = person.getDeathday();
    if (deathString.equals("")) ((ViewManager) death.getParent()).removeView(death);
    else {
      death.setText("died: " + deathString);
    }
    bio.setText(person.getBiography());

    TabHost creditTabHost = (TabHost) findViewById(R.id.tabhost_credits);
    creditTabHost.setup();

    TabHost.TabSpec appearsSpec = creditTabHost.newTabSpec(APPEARS_TAB);
    appearsSpec.setContent(appearsIn.getId());
    appearsSpec.setIndicator("appears in");

    TabHost.TabSpec directedSpec = creditTabHost.newTabSpec(DIRECTED_TAB);
    directedSpec.setContent(appearsIn.getId());
    directedSpec.setIndicator("directed");

    TabHost.TabSpec wroteSpec = creditTabHost.newTabSpec(WROTE_TAB);
    wroteSpec.setContent(appearsIn.getId());
    wroteSpec.setIndicator("wrote");

    TabHost.TabSpec producedSpec = creditTabHost.newTabSpec(PRODUCED_TAB);
    producedSpec.setContent(appearsIn.getId());
    producedSpec.setIndicator("produced");

    List<CastCredit> castCredits = searcher.getCastCreditsByPersonId(personId);
    appearsIn.setAdapter(
        new ResultListAdapter(
            getBaseContext(), R.layout.list_item_movie_with_picture, castCredits));

    creditTabHost.addTab(appearsSpec);
    creditTabHost.addTab(directedSpec);
    creditTabHost.addTab(wroteSpec);
    creditTabHost.addTab(producedSpec);

    //        List<CrewCredit> crewCredits = searcher.getCrewCreditsByPersonId(personId);
    //
    //        List<CrewCredit> directed = new ArrayList<CrewCredit>();
    //        List<CrewCredit> wrote = new ArrayList<CrewCredit>();
    //        List<CrewCredit> produced = new ArrayList<CrewCredit>();
    //        for (CrewCredit credit : crewCredits) {
    //            if (credit.getDepartment().equals("Directing"))
    //                directed.add(credit);
    //            else if (credit.getDepartment().equals("Writing"))
    //                wrote.add(credit);
    //            else if (credit.getDepartment().equals("Production"))
    //                produced.add(credit);
    //        }
    appearsIn.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Intent infoActivity = new Intent(getBaseContext(), MovieInfoActivity.class);
            infoActivity.putExtra("id", (Integer) view.getTag());
            infoActivity.putExtra("listItemId", R.layout.list_item_movie_with_picture);
            infoActivity.putExtra("infoClass", MovieInfoActivity.class);
            startActivity(infoActivity);
          }
        });
    creditTabHost.setOnTabChangedListener(
        new TabHost.OnTabChangeListener() {
          @Override
          public void onTabChanged(String s) {
            if (s.equals(APPEARS_TAB)) {
              List<CastCredit> castCredits = searcher.getCastCreditsByPersonId(personId);
              appearsIn.setAdapter(
                  new ResultListAdapter(
                      getBaseContext(), R.layout.list_item_movie_with_picture, castCredits));
            } else if (s.equals(DIRECTED_TAB)) {
              List<CrewCredit> crewCredits = searcher.getCrewCreditsByPersonId(personId);

              List<CrewCredit> directed = new ArrayList<CrewCredit>();
              for (CrewCredit credit : crewCredits) {
                if (credit.getDepartment().equals("Directing")) directed.add(credit);
              }
              appearsIn.setAdapter(
                  new ResultListAdapter(
                      getBaseContext(), R.layout.list_item_movie_with_picture, directed));
            } else if (s.equals(WROTE_TAB)) {
              List<CrewCredit> crewCredits = searcher.getCrewCreditsByPersonId(personId);

              List<CrewCredit> wrote = new ArrayList<CrewCredit>();
              for (CrewCredit credit : crewCredits) {
                if (credit.getDepartment().equals("Writing")) wrote.add(credit);
              }
              appearsIn.setAdapter(
                  new ResultListAdapter(
                      getBaseContext(), R.layout.list_item_movie_with_picture, wrote));
            } else if (s.equals(PRODUCED_TAB)) {
              List<CrewCredit> crewCredits = searcher.getCrewCreditsByPersonId(personId);

              List<CrewCredit> produced = new ArrayList<CrewCredit>();
              for (CrewCredit credit : crewCredits) {
                if (credit.getDepartment().equals("Production")) produced.add(credit);
              }
              appearsIn.setAdapter(
                  new ResultListAdapter(
                      getBaseContext(), R.layout.list_item_movie_with_picture, produced));
            }
          }
        });
    creditTabHost.setCurrentTab(0);
  }