Exemplo n.º 1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case R.id.share:
        if (firstTrailer.getKey() != null) {
          String subject = mMovie.getTitle() + " - " + firstTrailer.getName();
          Intent shareIntent = new Intent(Intent.ACTION_SEND);
          if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            //noinspection deprecation
            shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
          } else {
            shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
          }
          shareIntent.setType("text/plain");
          shareIntent.putExtra(Intent.EXTRA_TEXT, Utils.getVideoUrl(firstTrailer.getKey()));
          shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
          startActivity(Intent.createChooser(shareIntent, getString(R.string.share_trailer)));
        } else {
          showMessage("No Trailer available", Snackbar.LENGTH_LONG);
        }

        return true;
      case android.R.id.home:
        getActivity().supportFinishAfterTransition();
        return true;
      default:
        return super.onOptionsItemSelected(item);
    }
  }
Exemplo n.º 2
0
  private void setUpToolBar() {

    ((AppCompatActivity) getActivity()).setSupportActionBar(mToolbar);
    mToolbar.inflateMenu(R.menu.menu_movie_details);

    if (!Utils.isTablet(mContext)) {
      ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(true);
      ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    collapsingToolbarLayout.setTitle(mMovie.getTitle());
    collapsingToolbarLayout.setExpandedTitleColor(
        getResources().getColor(android.R.color.transparent));
    Glide.with(mContext)
        .load(mMovie.getBackdrop_url())
        .asBitmap()
        .error(R.drawable.not_available)
        .placeholder(R.drawable.placeholder)
        .into(
            new BitmapImageViewTarget(backdrop) {
              @Override
              public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                super.onResourceReady(bitmap, anim);
                Palette.from(bitmap)
                    .generate(
                        new Palette.PaletteAsyncListener() {
                          @SuppressWarnings("ResourceType")
                          @Override
                          public void onGenerated(Palette palette) {
                            mutedColor = palette.getMutedColor(R.color.colorPrimary);
                            if (getLuminance(mutedColor) < 240) {
                              collapsingToolbarLayout.setContentScrimColor(mutedColor);
                              collapsingToolbarLayout.setStatusBarScrimColor(
                                  getDarkerColor(mutedColor));
                              return;
                            }
                          }
                        });
              }
            });

    collapsingToolbarLayout.setContentScrimColor(getResources().getColor(R.color.colorPrimary));
    collapsingToolbarLayout.setStatusBarScrimColor(
        getResources().getColor(R.color.colorPrimaryDark));
  }