Beispiel #1
0
  /**
   * build the MiniDrawer
   *
   * @param ctx
   * @return
   */
  public View build(Context ctx) {
    mContainer = new LinearLayout(ctx);
    if (mInnerShadow) {
      if (!mInRTL) {
        mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_left);
      } else {
        mContainer.setBackgroundResource(R.drawable.material_drawer_shadow_right);
      }
    }

    // create and append recyclerView
    mRecyclerView = new RecyclerView(ctx);
    mContainer.addView(
        mRecyclerView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // set the itemAnimator
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    // some style improvements on older devices
    mRecyclerView.setFadingEdgeLength(0);
    // set the drawing cache background to the same color as the slider to improve performance
    // mRecyclerView.setDrawingCacheBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mActivity,
    // R.attr.material_drawer_background, R.color.material_drawer_background));
    mRecyclerView.setClipToPadding(false);
    // additional stuff
    mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
    // adapter
    mDrawerAdapter = new DrawerAdapter();
    mRecyclerView.setAdapter(mDrawerAdapter);

    // if the activity with the drawer should be fullscreen add the padding for the statusbar
    if (mDrawer != null
        && mDrawer.mDrawerBuilder != null
        && (mDrawer.mDrawerBuilder.mFullscreen || mDrawer.mDrawerBuilder.mTranslucentStatusBar)) {
      mRecyclerView.setPadding(
          mRecyclerView.getPaddingLeft(),
          UIUtils.getStatusBarHeight(ctx),
          mRecyclerView.getPaddingRight(),
          mRecyclerView.getPaddingBottom());
    }

    // if the activity with the drawer should be fullscreen add the padding for the navigationBar
    if (mDrawer != null
        && mDrawer.mDrawerBuilder != null
        && (mDrawer.mDrawerBuilder.mFullscreen
            || mDrawer.mDrawerBuilder.mTranslucentNavigationBar)) {
      mRecyclerView.setPadding(
          mRecyclerView.getPaddingLeft(),
          mRecyclerView.getPaddingTop(),
          mRecyclerView.getPaddingRight(),
          UIUtils.getNavigationBarHeight(ctx));
    }

    // set the adapter with the items
    createItems();

    return mContainer;
  }
Beispiel #2
0
 public int asPixel(Context ctx) {
   if (mPixel != Integer.MIN_VALUE) {
     return mPixel;
   } else if (mDp != Integer.MIN_VALUE) {
     return (int) UIUtils.convertDpToPixel(mDp, ctx);
   } else if (mResource != Integer.MIN_VALUE) {
     return ctx.getResources().getDimensionPixelSize(mResource);
   }
   return 0;
 }
  /**
   * binds the data of this item onto the viewHolder
   *
   * @param viewHolder the viewHolder of this item
   */
  @Override
  public void bindView(SimpleImageItem.ViewHolder viewHolder) {
    super.bindView(viewHolder);

    // get the context
    Context ctx = viewHolder.itemView.getContext();

    // define our data for the view
    viewHolder.imageName.setText(mName);
    viewHolder.imageDescription.setText(mDescription);
    viewHolder.imageView.setImageBitmap(null);

    // set the background for the item
    int color = UIUtils.getThemeColor(ctx, R.attr.colorPrimary);
    viewHolder.view.setForeground(
        FastAdapterUIUtils.getSelectablePressedBackground(
            ctx, FastAdapterUIUtils.adjustAlpha(color, 100), 50, true));

    // load glide
    Glide.clear(viewHolder.imageView);
    Glide.with(ctx).load(mImageUrl).animate(R.anim.alpha_on).into(viewHolder.imageView);
  }
  public Materialize build() {
    // we need an activity for this
    if (mActivity == null) {
      throw new RuntimeException("please pass an activity");
    }

    // if the user has not set a drawerLayout use the default one :D
    mScrimInsetsLayout =
        (ScrimInsetsFrameLayout)
            mActivity.getLayoutInflater().inflate(R.layout.materialize, mRootView, false);

    // check if the activity was initialized correctly
    if (mRootView == null || mRootView.getChildCount() == 0) {
      throw new RuntimeException(
          "You have to set your layout for this activity with setContentView() first. Or you build the drawer on your own with .buildView()");
    }

    // get the content view
    View originalContentView = mRootView.getChildAt(0);

    boolean alreadyInflated = originalContentView.getId() == R.id.materialize_root;

    // define the statusBarColor
    if (mStatusBarColor == 0 && mStatusBarColorRes != -1) {
      mStatusBarColor = mActivity.getResources().getColor(mStatusBarColorRes);
    } else if (mStatusBarColor == 0) {
      mStatusBarColor =
          UIUtils.getThemeColorFromAttrOrRes(
              mActivity, R.attr.colorPrimaryDark, R.color.materialize_primary_dark);
    }

    // handling statusBar / navigationBar tinting
    mScrimInsetsLayout.setInsetForeground(mStatusBarColor);
    mScrimInsetsLayout.setTintStatusBar(mTintStatusBar);
    mScrimInsetsLayout.setTintNavigationBar(mTintNavigationBar);

    // if we are fullscreen remove all insets
    mScrimInsetsLayout.setSystemUIVisible(!mFullscreen && !mSystemUIHidden);

    // do some magic specific to the statusBar
    if (!alreadyInflated && mTranslucentStatusBar) {
      if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
        UIUtils.setTranslucentStatusFlag(mActivity, true);
      }
      if (Build.VERSION.SDK_INT >= 19) {
        if (mTranslucentStatusBarProgrammatically) {
          mActivity
              .getWindow()
              .getDecorView()
              .setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
      }
      if (Build.VERSION.SDK_INT >= 21) {
        UIUtils.setTranslucentStatusFlag(mActivity, false);
        if (mTranslucentStatusBarProgrammatically) {
          mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
      }
      mScrimInsetsLayout.getView().setPadding(0, UIUtils.getStatusBarHeight(mActivity), 0, 0);
    }

    // do some magic specific to the navigationBar
    if (!alreadyInflated && mTranslucentNavigationBar) {
      if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
        UIUtils.setTranslucentNavigationFlag(mActivity, true);
      }
      if (Build.VERSION.SDK_INT >= 19) {
        if (mTranslucentNavigationBarProgrammatically) {
          mActivity
              .getWindow()
              .getDecorView()
              .setSystemUiVisibility(
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
          UIUtils.setTranslucentNavigationFlag(mActivity, true);
        }
      }
      if (Build.VERSION.SDK_INT >= 21) {
        if (mTranslucentNavigationBarProgrammatically) {
          mActivity.getWindow().setNavigationBarColor(Color.TRANSPARENT);
        }
      }
    }

    // set the flags if we want to hide the system ui
    if (mSystemUIHidden) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        View decorView = this.mActivity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
      }
    }

    // only add the new layout if it wasn't done before
    if (!alreadyInflated) {
      // remove the contentView
      mRootView.removeView(originalContentView);
    } else {
      // if it was already inflated we have to clean up again
      mRootView.removeAllViews();
    }

    // create the layoutParams to use for the contentView
    FrameLayout.LayoutParams layoutParamsContentView =
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // if we have a translucent navigation bar set the bottom margin
    if (!mFullscreen && mTranslucentNavigationBar && Build.VERSION.SDK_INT >= 19) {
      layoutParamsContentView.bottomMargin = UIUtils.getNavigationBarHeight(mActivity);
    }

    // add the contentView to the drawer content frameLayout
    mScrimInsetsLayout.getView().addView(originalContentView, layoutParamsContentView);

    // if we have a mContainer we use this one
    mContentRoot = mScrimInsetsLayout.getView();
    if (mContainer != null) {
      mContentRoot = mContainer;
      mContentRoot.addView(
          mScrimInsetsLayout.getView(),
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    // set the id so we can check if it was already inflated
    mContentRoot.setId(R.id.materialize_root);

    // make sure we have the correct layoutParams
    if (mContainerLayoutParams == null) {
      mContainerLayoutParams =
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
    // add the drawerLayout to the root
    mRootView.addView(mContentRoot, mContainerLayoutParams);

    // set activity to null as we do not need it anymore
    this.mActivity = null;

    // create a Materialize object with the builder
    return new Materialize(this);
  }