Java Code Examples for com.hippo.yorozuya.LayoutUtils#dp2pix()

The following examples show how to use com.hippo.yorozuya.LayoutUtils#dp2pix() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryInfoScene.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_info, container, false);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    InfoAdapter adapter = new InfoAdapter();
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL,
            AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setOnItemClickListener(this);
    return view;
}
 
Example 2
Source File: GalleryInfoScene.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_info, container, false);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);

    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    InfoAdapter adapter = new InfoAdapter();
    mRecyclerView.setAdapter(adapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL,
            AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(context.getResources().getDimensionPixelOffset(R.dimen.keyline_margin));
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setOnItemClickListener(this);
    return view;
}
 
Example 3
Source File: Slider.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void updatePopup() {
    int width = getWidth();
    int paddingTop = getPaddingTop();
    int paddingBottom = getPaddingBottom();

    getLocationInWindow(mTemp);

    mPopupWidth = (int) (width - mRadius - mRadius + mBubbleWidth);
    int popupHeight = mBubbleHeight;
    mPopupX = (int) (mTemp[0] + mRadius - (mBubbleWidth / 2));
    mPopupY = (int) (mTemp[1] - popupHeight + paddingTop +
            ((getHeight() - paddingTop - paddingBottom) / 2) -
            mRadius -LayoutUtils.dp2pix(mContext, 2));

    mPopup.update(mPopupX, mPopupY, mPopupWidth, popupHeight, false);
}
 
Example 4
Source File: Slider.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
private void updatePopup() {
    int width = getWidth();
    int paddingTop = getPaddingTop();
    int paddingBottom = getPaddingBottom();

    getLocationInWindow(mTemp);

    mPopupWidth = (int) (width - mRadius - mRadius + mBubbleWidth);
    int popupHeight = mBubbleHeight;
    mPopupX = (int) (mTemp[0] + mRadius - (mBubbleWidth / 2));
    mPopupY = (int) (mTemp[1] - popupHeight + paddingTop +
            ((getHeight() - paddingTop - paddingBottom) / 2) -
            mRadius -LayoutUtils.dp2pix(mContext, 2));

    mPopup.update(mPopupX, mPopupY, mPopupWidth, popupHeight, false);
}
 
Example 5
Source File: DoodleView.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    mBitmapPaint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

    mBgColor = ResourcesUtils.getAttrColor(context, R.attr.colorPure);

    mColor = ResourcesUtils.getAttrColor(context, R.attr.colorPureInverse);
    mWidth = LayoutUtils.dp2pix(context, 4);

    mPath = new Path();

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    mRecycler = new Recycler();
}
 
Example 6
Source File: ContentLayout.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
private void init(ContentLayout contentLayout) {
    mNextPageScrollSize = LayoutUtils.dp2pix(contentLayout.getContext(), 48);

    mProgressView = contentLayout.mProgressView;
    mTipView = contentLayout.mTipView;
    mContentView = contentLayout.mContentView;

    mRefreshLayout = contentLayout.mRefreshLayout;
    mRecyclerView = contentLayout.mRecyclerView;

    Drawable drawable = DrawableManager.getVectorDrawable(getContext(), R.drawable.big_sad_pandroid);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    mTipView.setCompoundDrawables(null, drawable, null, null);

    mViewTransition = new ViewTransition(mContentView, mProgressView, mTipView);
    mViewTransition.setOnShowViewListener(this);

    mRecyclerView.addOnScrollListener(mOnScrollListener);
    mRefreshLayout.setOnRefreshListener(mOnRefreshListener);

    mTipView.setOnClickListener(refreshListener);
}
 
Example 7
Source File: ContentLayout.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void init(ContentLayout contentLayout) {
    mNextPageScrollSize = LayoutUtils.dp2pix(contentLayout.getContext(), 48);

    mProgressView = contentLayout.mProgressView;
    mTipView = contentLayout.mTipView;
    mContentView = contentLayout.mContentView;

    mRefreshLayout = contentLayout.mRefreshLayout;
    mRecyclerView = contentLayout.mRecyclerView;
    mImageView = contentLayout.mImageView;
    mTextView = contentLayout.mTextView;

    mViewTransition = new ViewTransition(mContentView, mProgressView, mTipView);
    mViewTransition.showView(2, false);

    mRecyclerView.addOnScrollListener(mOnScrollListener);
    mRefreshLayout.setOnRefreshListener(mOnRefreshListener);

    mTipView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            refresh();
        }
    });
}
 
Example 8
Source File: ListActivity.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public void onClickCommonPosts() {
    AutoWrapLayout layout = new AutoWrapLayout(ListActivity.this);
    final Dialog dialog = new AlertDialog.Builder(this).setView(layout).show();

    List<CommonPost> list = DB.getAllACCommentPost();
    int padding = LayoutUtils.dp2pix(this, 4);
    layout.setPadding(padding, 0, padding, 0);
    LayoutInflater inflater = getLayoutInflater();
    for (final CommonPost cp : list) {
        inflater.inflate(R.layout.item_dialog_comment_post, layout);
        TextView tv = (TextView) layout.getChildAt(layout.getChildCount() - 1);
        tv.setText(cp.name);
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();

                Intent intent = new Intent(ListActivity.this, PostActivity.class);
                intent.setAction(PostActivity.ACTION_SITE_ID);
                intent.putExtra(PostActivity.KEY_SITE, ACSite.getInstance().getId());
                intent.putExtra(PostActivity.KEY_ID, cp.id);
                startActivity(intent);
            }
        });
    }
}
 
Example 9
Source File: HostsActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  hosts = EhApplication.getHosts(this);
  data = hosts.getAll();

  setContentView(R.layout.activity_hosts);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  recyclerView = findViewById(R.id.recycler_view);
  tip = findViewById(R.id.tip);
  FloatingActionButton fab = findViewById(R.id.fab);

  adapter = new HostsAdapter();
  recyclerView.setAdapter(adapter);
  recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
  LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
      LinearDividerItemDecoration.VERTICAL,
      AttrResources.getAttrColor(this, R.attr.dividerColor),
      LayoutUtils.dp2pix(this, 1));
  decoration.setShowLastDivider(true);
  recyclerView.addItemDecoration(decoration);
  recyclerView.setSelector(Ripple.generateRippleDrawable(this, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
  recyclerView.setHasFixedSize(true);
  recyclerView.setOnItemClickListener(this);
  recyclerView.setPadding(
      recyclerView.getPaddingLeft(),
      recyclerView.getPaddingTop(),
      recyclerView.getPaddingRight(),
      recyclerView.getPaddingBottom() + getResources().getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab));

  fab.setOnClickListener(this);

  recyclerView.setVisibility(data.isEmpty() ? View.GONE : View.VISIBLE);
  tip.setVisibility(data.isEmpty() ? View.VISIBLE : View.GONE);
}
 
Example 10
Source File: ThicknessPreviewView.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    if (!mInitPath) {
        mInitPath = true;
        int padding = LayoutUtils.dp2pix(getContext(), 16);
        Path path = mPath;
        path.reset();
        path.moveTo(padding, h - padding);
        path.cubicTo(padding, h / 2, w - padding, h / 2, w - padding,  padding);
        mIsDot = false;
        invalidate();
    }
}
 
Example 11
Source File: HostsActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  hosts = EhApplication.getHosts(this);
  data = hosts.getAll();

  setContentView(R.layout.activity_hosts);
  setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
  recyclerView = findViewById(R.id.recycler_view);
  tip = findViewById(R.id.tip);
  FloatingActionButton fab = findViewById(R.id.fab);

  adapter = new HostsAdapter();
  recyclerView.setAdapter(adapter);
  recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
  LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
      LinearDividerItemDecoration.VERTICAL,
      AttrResources.getAttrColor(this, R.attr.dividerColor),
      LayoutUtils.dp2pix(this, 1));
  decoration.setShowLastDivider(true);
  recyclerView.addItemDecoration(decoration);
  recyclerView.setSelector(Ripple.generateRippleDrawable(this, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
  recyclerView.setHasFixedSize(true);
  recyclerView.setOnItemClickListener(this);
  recyclerView.setPadding(
      recyclerView.getPaddingLeft(),
      recyclerView.getPaddingTop(),
      recyclerView.getPaddingRight(),
      recyclerView.getPaddingBottom() + getResources().getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab));

  fab.setOnClickListener(this);

  recyclerView.setVisibility(data.isEmpty() ? View.GONE : View.VISIBLE);
  tip.setVisibility(data.isEmpty() ? View.VISIBLE : View.GONE);
}
 
Example 12
Source File: GalleryPreviewsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    ContentLayout contentLayout = (ContentLayout) inflater.inflate(
            R.layout.scene_gallery_previews, container, false);
    contentLayout.hideFastScroll();
    mRecyclerView = contentLayout.getRecyclerView();

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Resources resources = context.getResources();

    mAdapter = new GalleryPreviewAdapter();
    mRecyclerView.setAdapter(mAdapter);
    int columnWidth = resources.getDimensionPixelOffset(Settings.getThumbSizeResId());
    AutoGridLayoutManager layoutManager = new AutoGridLayoutManager(context, columnWidth);
    layoutManager.setStrategy(AutoGridLayoutManager.STRATEGY_SUITABLE_SIZE);
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setOnItemClickListener(this);
    int padding = LayoutUtils.dp2pix(context, 4);
    MarginItemDecoration decoration = new MarginItemDecoration(padding, padding, padding, padding, padding);
    mRecyclerView.addItemDecoration(decoration);
    decoration.applyPaddings(mRecyclerView);

    mHelper = new GalleryPreviewHelper();
    contentLayout.setHelper(mHelper);

    // Only refresh for the first time
    if (!mHasFirstRefresh) {
        mHasFirstRefresh = true;
        mHelper.firstRefresh();
    }

    return contentLayout;
}
 
Example 13
Source File: PluginsActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    data = MHPluginManager.Companion.getINSTANCE().plugins();

    setContentView(R.layout.activity_plugins);
    setNavigationIcon(R.drawable.v_arrow_left_dark_x24);
    recyclerView = findViewById(R.id.recycler_view);
    tip = findViewById(R.id.tip);
    FloatingActionButton fab = findViewById(R.id.fab);

    adapter = new PluginsAdapter();
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL,
            AttrResources.getAttrColor(this, R.attr.dividerColor),
            LayoutUtils.dp2pix(this, 1));
    decoration.setShowLastDivider(true);
    recyclerView.addItemDecoration(decoration);
    recyclerView.setSelector(Ripple.generateRippleDrawable(this, !AttrResources.getAttrBoolean(this, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    recyclerView.setHasFixedSize(true);
    recyclerView.setOnItemClickListener(this);
    recyclerView.setPadding(
            recyclerView.getPaddingLeft(),
            recyclerView.getPaddingTop(),
            recyclerView.getPaddingRight(),
            recyclerView.getPaddingBottom() + getResources().getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab));

    fab.setOnClickListener(this);

    recyclerView.setVisibility(data.isEmpty() ? View.GONE : View.VISIBLE);
    tip.setVisibility(data.isEmpty() ? View.VISIBLE : View.GONE);
}
 
Example 14
Source File: Slider.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(@NonNull Canvas canvas) {
    int width = getWidth();
    int height = getHeight();
    if (width < LayoutUtils.dp2pix(mContext, 24)) {
        canvas.drawRect(0, 0, width, getHeight(), mPaint);
    } else {
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();
        float thickness = mThickness;
        float radius = mRadius;
        float halfThickness = thickness / 2;

        int saved = canvas.save();

        canvas.translate(0, paddingTop + ((height - paddingTop - paddingBottom) / 2));

        float currentX = paddingLeft + radius + (width - radius - radius - paddingLeft - paddingRight) *
                (mReverse ? (1.0f - mDrawPercent) : mDrawPercent);

        mLeftRectF.set(paddingLeft + radius, -halfThickness, currentX, halfThickness);
        mRightRectF.set(currentX, -halfThickness, width - paddingRight - radius, halfThickness);

        // Draw bar
        if (mReverse) {
            canvas.drawRect(mRightRectF, mPaint);
            canvas.drawRect(mLeftRectF, mBgPaint);
        } else {
            canvas.drawRect(mLeftRectF, mPaint);
            canvas.drawRect(mRightRectF, mBgPaint);
        }

        // Draw controller
        float scale = 1.0f - mDrawBubbleScale;
        if (scale != 0.0f) {
            canvas.scale(scale, scale, currentX, 0);
            canvas.drawCircle(currentX, 0, radius, mPaint);
        }

        canvas.restoreToCount(saved);
    }
}
 
Example 15
Source File: GalleryCommentsScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
        @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_comments, container, false);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
    mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
    mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Resources resources = context.getResources();
    int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mSendDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_send_dark_x24);
    mPencilDrawable = DrawableManager.getVectorDrawable(context, R.drawable.v_pencil_dark_x24);

    mAdapter = new CommentAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context,
            RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setShowLastDivider(true);
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
            mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + paddingBottomFab);
    // Cancel change animator
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof DefaultItemAnimator) {
        ((DefaultItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }

    mSendImage.setOnClickListener(this);
    mFab.setOnClickListener(this);

    addAboveSnackView(mEditPanel);
    addAboveSnackView(mFabLayout);

    mViewTransition = new ViewTransition(mRecyclerView, tip);

    updateView(false);

    return view;
}
 
Example 16
Source File: Slider.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(@NonNull Canvas canvas) {
    int width = getWidth();
    int height = getHeight();
    if (width < LayoutUtils.dp2pix(mContext, 24)) {
        canvas.drawRect(0, 0, width, getHeight(), mPaint);
    } else {
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();
        float thickness = mThickness;
        float radius = mRadius;
        float halfThickness = thickness / 2;

        int saved = canvas.save();

        canvas.translate(0, paddingTop + ((height - paddingTop - paddingBottom) / 2));

        float currentX = paddingLeft + radius + (width - radius - radius - paddingLeft - paddingRight) *
                (mReverse ? (1.0f - mDrawPercent) : mDrawPercent);

        mLeftRectF.set(paddingLeft + radius, -halfThickness, currentX, halfThickness);
        mRightRectF.set(currentX, -halfThickness, width - paddingRight - radius, halfThickness);

        // Draw bar
        if (mReverse) {
            canvas.drawRect(mRightRectF, mPaint);
            canvas.drawRect(mLeftRectF, mBgPaint);
        } else {
            canvas.drawRect(mLeftRectF, mPaint);
            canvas.drawRect(mRightRectF, mBgPaint);
        }

        // Draw controller
        float scale = 1.0f - mDrawBubbleScale;
        if (scale != 0.0f) {
            canvas.scale(scale, scale, currentX, 0);
            canvas.drawCircle(currentX, 0, radius, mPaint);
        }

        canvas.restoreToCount(saved);
    }
}
 
Example 17
Source File: GalleryCommentsScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InflateParams")
public void showVoteStatusDialog(Context context, String voteStatus) {
    String[] temp = StringUtils.split(voteStatus, ',');
    final int length = temp.length;
    final String[] userArray = new String[length];
    final String[] voteArray = new String[length];
    for (int i = 0; i < length; i++) {
        String str = StringUtils.trim(temp[i]);
        int index = str.lastIndexOf(' ');
        if (index < 0) {
            Log.d(TAG, "Something wrong happened about vote state");
            userArray[i] = str;
            voteArray[i] = "";
        } else {
            userArray[i] = StringUtils.trim(str.substring(0, index));
            voteArray[i] = StringUtils.trim(str.substring(index + 1));
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    context = builder.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
    rv.setAdapter(new RecyclerView.Adapter<InfoHolder>() {
        @Override
        public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new InfoHolder(inflater.inflate(R.layout.item_drawer_favorites, parent, false));
        }

        @Override
        public void onBindViewHolder(InfoHolder holder, int position) {
            holder.key.setText(userArray[position]);
            holder.value.setText(voteArray[position]);
        }

        @Override
        public int getItemCount() {
            return length;
        }
    });
    rv.setLayoutManager(new LinearLayoutManager(context));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
    rv.addItemDecoration(decoration);
    rv.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    rv.setClipToPadding(false);
    builder.setView(rv).show();
}
 
Example 18
Source File: GalleryCommentsScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InflateParams")
public void showVoteStatusDialog(Context context, String voteStatus) {
    String[] temp = StringUtils.split(voteStatus, ',');
    final int length = temp.length;
    final String[] userArray = new String[length];
    final String[] voteArray = new String[length];
    for (int i = 0; i < length; i++) {
        String str = StringUtils.trim(temp[i]);
        int index = str.lastIndexOf(' ');
        if (index < 0) {
            Log.d(TAG, "Something wrong happened about vote state");
            userArray[i] = str;
            voteArray[i] = "";
        } else {
            userArray[i] = StringUtils.trim(str.substring(0, index));
            voteArray[i] = StringUtils.trim(str.substring(index + 1));
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    context = builder.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
    rv.setAdapter(new RecyclerView.Adapter<InfoHolder>() {
        @Override
        public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new InfoHolder(inflater.inflate(R.layout.item_drawer_favorites, parent, false));
        }

        @Override
        public void onBindViewHolder(InfoHolder holder, int position) {
            holder.key.setText(userArray[position]);
            holder.value.setText(voteArray[position]);
        }

        @Override
        public int getItemCount() {
            return length;
        }
    });
    rv.setLayoutManager(new LinearLayoutManager(context));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
    rv.addItemDecoration(decoration);
    rv.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    rv.setClipToPadding(false);
    builder.setView(rv).show();
}
 
Example 19
Source File: Slider.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
protected void onDraw(@NonNull Canvas canvas) {
    int width = getWidth();
    int height = getHeight();
    if (width < LayoutUtils.dp2pix(mContext, 24)) {
        canvas.drawRect(0, 0, width, getHeight(), mPaint);
    } else {
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();
        float thickness = mThickness;
        float radius = mRadius;
        float halfThickness = thickness / 2;

        int saved = canvas.save();

        canvas.translate(0, paddingTop + ((height - paddingTop - paddingBottom) / 2));

        float currentX = paddingLeft + radius + (width - radius - radius - paddingLeft - paddingRight) *
                (mReverse ? (1.0f - mDrawPercent) : mDrawPercent);

        mLeftRectF.set(paddingLeft + radius, -halfThickness, currentX, halfThickness);
        mRightRectF.set(currentX, -halfThickness, width - paddingRight - radius, halfThickness);

        // Draw bar
        if (mReverse) {
            canvas.drawRect(mRightRectF, mPaint);
            canvas.drawRect(mLeftRectF, mBgPaint);
        } else {
            canvas.drawRect(mLeftRectF, mPaint);
            canvas.drawRect(mRightRectF, mBgPaint);
        }

        // Draw controller
        float scale = 1.0f - mDrawBubbleScale;
        if (scale != 0.0f) {
            canvas.scale(scale, scale, currentX, 0);
            canvas.drawCircle(currentX, 0, radius, mPaint);
        }

        canvas.restoreToCount(saved);
    }
}
 
Example 20
Source File: GalleryCommentsScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView3(LayoutInflater inflater,
                          @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.scene_gallery_comments, container, false);
    mRecyclerView = (EasyRecyclerView) ViewUtils.$$(view, R.id.recycler_view);
    TextView tip = (TextView) ViewUtils.$$(view, R.id.tip);
    mEditPanel = ViewUtils.$$(view, R.id.edit_panel);
    mSendImage = (ImageView) ViewUtils.$$(mEditPanel, R.id.send);
    mEditText = (EditText) ViewUtils.$$(mEditPanel, R.id.edit_text);
    mFabLayout = (FabLayout) ViewUtils.$$(view, R.id.fab_layout);
    mFab = (FloatingActionButton) ViewUtils.$$(view, R.id.fab);

    Context context = getContext2();
    AssertUtils.assertNotNull(context);
    Resources resources = context.getResources();
    int paddingBottomFab = resources.getDimensionPixelOffset(R.dimen.gallery_padding_bottom_fab);

    Drawable drawable = DrawableManager.getVectorDrawable(context, R.drawable.big_sad_pandroid);
    drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
    tip.setCompoundDrawables(null, drawable, null, null);

    mAdapter = new CommentAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context,
            RecyclerView.VERTICAL, false));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setShowLastDivider(true);
    mRecyclerView.addItemDecoration(decoration);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setPadding(mRecyclerView.getPaddingLeft(), mRecyclerView.getPaddingTop(),
            mRecyclerView.getPaddingRight(), mRecyclerView.getPaddingBottom() + paddingBottomFab);
    // Cancel change animator
    RecyclerView.ItemAnimator itemAnimator = mRecyclerView.getItemAnimator();
    if (itemAnimator instanceof DefaultItemAnimator) {
        ((DefaultItemAnimator) itemAnimator).setSupportsChangeAnimations(false);
    }

    mSendImage.setOnClickListener(this);
    mFab.setOnClickListener(this);

    addAboveSnackView(mEditPanel);
    addAboveSnackView(mFabLayout);

    mViewTransition = new ViewTransition(mRecyclerView, tip);

    updateView(false);

    return view;
}