Java Code Examples for com.hippo.yorozuya.ResourcesUtils

The following examples show how to use com.hippo.yorozuya.ResourcesUtils. These examples are extracted from open source projects. 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 Project: Nimingban   Source File: PostFragment.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressLint("InflateParams")
public ReferenceDialogHelper(Site site, String id) {
    mSite = site;
    mId = id;

    mView = getActivity().getLayoutInflater().inflate(R.layout.dialog_reference, null);

    View progress = mView.findViewById(R.id.progress_view);
    View reference = mView.findViewById(R.id.reference);
    mViewTransition = new ViewTransition(progress, reference);

    mLeftText = (TextView) reference.findViewById(R.id.left_text);
    mCenterText = (TextView) reference.findViewById(R.id.center_text);
    mRightText = (TextView) reference.findViewById(R.id.right_text);
    mContent = (LinkifyTextView) reference.findViewById(R.id.content);
    mThumb = (LoadImageView) reference.findViewById(R.id.thumb);
    mButton = reference.findViewById(R.id.button);

    mContent.setOnClickListener(this);
    mThumb.setOnClickListener(this);
    Ripple.addRipple(mButton, ResourcesUtils.getAttrBoolean(getContext(), R.attr.dark));
}
 
Example 2
Source Project: Nimingban   Source File: GalleryActivity2.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!handlerIntent(getIntent())) {
        finish();
        return;
    }

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    ToolbarActivityHelper.setContentView(this, R.layout.activity_gallery_2);
    setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));

    mViewPager = (ViewPager) findViewById(R.id.view_pager);

    mViewPager.setAdapter(mGalleryAdapter);
}
 
Example 3
Source Project: Nimingban   Source File: SortForumsActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void showEyeGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setPaddingTop(LayoutUtils.dp2pix(this, 56))
            .setPaddingBottom(LayoutUtils.dp2pix(this, 56))
            .setMessagePosition(Gravity.LEFT)
            .setMessage(getString(R.string.click_eye_icon))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    tryShowSecondGuide();
                    Settings.putGuideSortForumsActivity(false);
                }
            }).show();
}
 
Example 4
Source Project: Nimingban   Source File: SortForumsActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void showFourBarsGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setPaddingTop(LayoutUtils.dp2pix(this, 56))
            .setPaddingBottom(LayoutUtils.dp2pix(this, 56))
            .setMessagePosition(Gravity.RIGHT)
            .setMessage(getString(R.string.drag_four_bars_exchange))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Settings.putGuideSortingFourBars(false);
                }
            }).show();
}
 
Example 5
Source Project: Nimingban   Source File: SortForumsActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void showStarGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setPaddingTop(LayoutUtils.dp2pix(this, 56))
            .setPaddingBottom(LayoutUtils.dp2pix(this, 56))
            .setMessagePosition(Gravity.RIGHT)
            .setMessage(getString(R.string.click_star_icon_pin))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Settings.putGuidePinningStar(false);
                }
            }).show();
}
 
Example 6
Source Project: Nimingban   Source File: DoodleView.java    License: 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 7
Source Project: Nimingban   Source File: ListActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void showLeftDrawerGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setMessagePosition(Gravity.LEFT)
            .setMessage(getString(R.string.swipe_right_open_menu))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showRightDrawerGuide();
                }
            }).show();
}
 
Example 8
Source Project: Nimingban   Source File: ListActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void showRightDrawerGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setMessagePosition(Gravity.RIGHT)
            .setMessage(getString(R.string.swipe_left_open_forum_list))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showToolbarGuide();
                }
            }).show();
}
 
Example 9
Source Project: Nimingban   Source File: ListActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void showToolbarGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setMessagePosition(Gravity.TOP)
            .setMessage(getString(R.string.double_click_toolbar_refresh))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Settings.putGuideListActivity(false);
                }
            }).show();
}
 
Example 10
Source Project: Nimingban   Source File: PostActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void showSwipeGuide() {
    new GuideHelper.Builder(this)
            .setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
            .setPadding(LayoutUtils.dp2pix(this, 16))
            .setMessagePosition(Gravity.TOP)
            .setMessage(getString(R.string.swipe_toolbar_hide_show))
            .setButton(getString(R.string.get_it))
            .setBackgroundColor(0x73000000)
            .setOnDissmisListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Settings.putGuideTypeSend(false);
                }
            }).show();
}
 
Example 11
Source Project: Nimingban   Source File: LeftDrawer.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    setFillViewport(true);
    setHorizontalScrollBarEnabled(false);
    setVerticalScrollBarEnabled(false);

    LayoutInflater.from(context).inflate(R.layout.widget_left_drawer, this);
    mHeader = (HeaderImageView) findViewById(R.id.header);
    mDrawerListView = (DrawerListView) findViewById(R.id.drawer_list_view);
    mDarkTheme = (TextView) findViewById(R.id.dark_theme);

    mHeader.setOnLongClickImageListener(this);

    Resources resources = context.getResources();

    Drawable search = DrawableManager.getDrawable(context, R.drawable.v_magnify_x24);
    Drawable feed = DrawableManager.getDrawable(context, R.drawable.v_rss_x24);
    Drawable record = DrawableManager.getDrawable(context, R.drawable.v_history_x24);
    Drawable settings = DrawableManager.getDrawable(context, R.drawable.v_settings_x24);

    Drawable[] drawables = {
            search,
            feed,
            record,
            settings
    };
    String[] strings = {
            resources.getString(R.string.search),
            resources.getString(R.string.feed),
            resources.getString(R.string.record),
            resources.getString(R.string.settings)
    };

    mDrawerListView.setData(drawables, strings);
    mDrawerListView.setOnItemClickListener(this);

    mDarkTheme.setText(Settings.getDarkTheme() ? R.string.let_there_light : R.string.let_there_dark);
    mDarkTheme.setOnClickListener(this);
    Ripple.addRipple(mDarkTheme, ResourcesUtils.getAttrBoolean(context, R.attr.dark));
}
 
Example 12
Source Project: Nimingban   Source File: PopupTextView.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    for (int i = 0; i < MAX_TEXT_VIEW; i++) {
        TextView tv = new TextView(context);
        tv.setTextColor(ResourcesUtils.getAttrColor(context, R.attr.colorPureInverse));
        tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
        tv.setVisibility(INVISIBLE);
        LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.BOTTOM;
        addView(tv, lp);
        mFreePool.push(tv);
    }
}
 
Example 13
Source Project: Nimingban   Source File: RightDrawer.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    mForums = new ArrayList<>();
    mAdapter = new ForumAdapter();
    setAdapter(mAdapter);
    setLayoutManager(new LinearLayoutManager(context));
    setOnItemClickListener(this);
    setSelector(Ripple.generateRippleDrawable(
            context, ResourcesUtils.getAttrBoolean(context, R.attr.dark)));

    mActionBarHeight = ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.actionBarSize);
}
 
Example 14
Source Project: Nimingban   Source File: ContentLayout.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    LayoutInflater.from(context).inflate(R.layout.widget_content_layout, this);

    mProgressView = (ProgressView) findViewById(R.id.progress);
    mTipView = (ViewGroup) findViewById(R.id.tip);
    mContentView = (ViewGroup) findViewById(R.id.content_view);

    mRefreshLayout = (RefreshLayout) mContentView.findViewById(R.id.refresh_layout);
    mFastScroller = (FastScroller) mContentView.findViewById(R.id.fast_scroller);
    mRecyclerView = (EasyRecyclerView) mRefreshLayout.findViewById(R.id.recycler_view);
    mImageView = mTipView.getChildAt(0);
    mTextView = (TextView) mTipView.getChildAt(1);

    mFastScroller.attachToRecyclerView(mRecyclerView);
    HandlerDrawable drawable = new HandlerDrawable();
    drawable.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorAccent));
    mFastScroller.setHandlerDrawable(drawable);

    mRefreshLayout.setHeaderColorSchemeResources(
            R.color.loading_indicator_red,
            R.color.loading_indicator_purple,
            R.color.loading_indicator_blue,
            R.color.loading_indicator_cyan,
            R.color.loading_indicator_green,
            R.color.loading_indicator_yellow);
    mRefreshLayout.setFooterColorSchemeResources(
            R.color.loading_indicator_red,
            R.color.loading_indicator_blue,
            R.color.loading_indicator_green,
            R.color.loading_indicator_orange);
    mRefreshLayout.setHeaderProgressBackgroundColorSchemeColor(ResourcesUtils.getAttrColor(context, R.attr.colorPure));

    mRecyclerViewOriginTop = mRecyclerView.getPaddingTop();
    mRecyclerViewOriginBottom = mRecyclerView.getPaddingBottom();
}
 
Example 15
Source Project: MHViewer   Source File: GalleryCommentsScene.java    License: 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 16
Source Project: MHViewer   Source File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate2(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);

    mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
    mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
    mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
    View headerLayout = mNavView.getHeaderView(0);
    mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
    mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
    mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);

    mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    // Pre-L need shadow drawable
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
    }

    updateProfile();

    if (mNavView != null) {
        mNavView.setNavigationItemSelectedListener(this);
    }

    mChangeTheme.setText(getThemeText());
    mChangeTheme.setOnClickListener(v -> {
        Settings.putTheme(getNextTheme());
        ((EhApplication) getApplication()).recreate();
    });

    if (savedInstanceState == null) {
        onInit();
        CommonOperations.checkUpdate(this, false);
        checkDownloadLocation();
        if (Settings.getCellularNetworkWarning()) {
            checkCellularNetwork();
        }
    } else {
        onRestore(savedInstanceState);
    }

    EhTagDatabase.update(this);
}
 
Example 17
Source Project: Nimingban   Source File: RecordActivity.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    ToolbarActivityHelper.setContentView(this, R.layout.activity_record);
    setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));

    View tip = findViewById(R.id.tip);
    mRecyclerView = (EasyRecyclerView) findViewById(R.id.recycler_view);
    mViewTransition = new ViewTransition(tip, mRecyclerView);

    // Layout Manager
    int interval = getResources().getDimensionPixelOffset(R.dimen.card_interval);
    if (getResources().getBoolean(R.bool.two_way)) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        MarginItemDecoration decoration = new MarginItemDecoration(interval, interval, interval, interval, interval);
        mRecyclerView.addItemDecoration(decoration);
        decoration.applyPaddings(mRecyclerView);
        mRecyclerView.setItemAnimator(new SlideInUpAnimator());
    } else {
        int halfInterval = interval / 2;
        mRecyclerView.addItemDecoration(new RawMarginItemDecoration(0, halfInterval, 0, halfInterval));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setPadding(0, halfInterval, 0, halfInterval);
    }

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    mAdapter = new RecordAdapter();
    mAdapter.setHasStableIds(true);
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mAdapter);      // wrap for swiping

    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.hasFixedSize();
    mRecyclerView.setAdapter(mWrappedAdapter);  // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(this, ResourcesUtils.getAttrBoolean(this, R.attr.dark)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setClipChildren(false);

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);

    updateLazyList();
    checkEmpty(false);

    Messenger.getInstance().register(Constants.MESSENGER_ID_UPDATE_RECORD, this);
}
 
Example 18
Source Project: Nimingban   Source File: PostFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.activity_toolbar, container, false);
    ViewGroup contentPanel = (ViewGroup) view.findViewById(R.id.content_panel);
    ViewGroup contentView = (ViewGroup) inflater.inflate(R.layout.fragment_post, contentPanel, true);

    mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
    // I like hardcode
    mToolbar.setSubtitle("A岛·adnmb.com");
    if (mId != null) {
        mToolbar.setTitle(mSite.getPostTitle(getContext(), mId));
    } else {
        mToolbar.setTitle(getString(R.string.thread));
    }
    mToolbar.setNavigationIcon(DrawableManager.getDrawable(getContext(), R.drawable.v_arrow_left_dark_x24));
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getFragmentHost().finishFragment(PostFragment.this);
        }
    });
    mToolbar.inflateMenu(R.menu.activity_post);
    mToolbar.setOnMenuItemClickListener(this);

    mContentLayout = (ContentLayout) contentView.findViewById(R.id.content_layout);
    mRecyclerView = mContentLayout.getRecyclerView();

    mReplyHelper = new ReplyHelper();
    mReplyHelper.setEmptyString(getString(R.string.not_found));
    mContentLayout.setHelper(mReplyHelper);
    if (Settings.getFastScroller()) {
        mContentLayout.showFastScroll();
    } else {
        mContentLayout.hideFastScroll();
    }

    mReplyAdapter = new ReplyAdapter();
    mRecyclerView.setAdapter(mReplyAdapter);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(
            getContext(), ResourcesUtils.getAttrBoolean(getContext(), R.attr.dark)));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setOnItemLongClickListener(this);
    mRecyclerView.hasFixedSize();
    mOnScrollListener = new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (RecyclerView.SCROLL_STATE_DRAGGING == newState) {
                pauseHolders();
            } else if (RecyclerView.SCROLL_STATE_IDLE == newState) {
                resumeHolders();
            }
        }
    };
    mRecyclerView.addOnScrollListener(mOnScrollListener);

    mOpColor = getResources().getColor(R.color.colorAccent);

    // Refresh
    mReplyHelper.firstRefresh();

    Messenger.getInstance().register(Constants.MESSENGER_ID_REPLY, this);
    Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this);

    isLoaded = false;

    return view;
}
 
Example 19
Source Project: Nimingban   Source File: DoodleActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    File dir = NMBAppConfig.getDoodleDir();
    if (dir != null) {
        String filename = "doodle-" + ReadableTime.getFilenamableTime(System.currentTimeMillis()) + ".png";
        mOutputFile = new File(dir, filename);
    }

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    setContentView(R.layout.activity_doodle);

    mDoodleView = (DoodleView) findViewById(R.id.doodle_view);
    mSide = findViewById(R.id.side);
    mPalette = findViewById(R.id.palette);
    mThickness = findViewById(R.id.thickness);
    mDrawAction = (ImageView) findViewById(R.id.draw_action);
    mImage = (ImageView) findViewById(R.id.image);
    mUndo = (ImageView) findViewById(R.id.undo);
    mRedo = (ImageView) findViewById(R.id.redo);
    mClear = findViewById(R.id.clear);
    mOk = findViewById(R.id.ok);
    mMenu = findViewById(R.id.menu);

    mDoodleView.setHelper(this);

    StateListDrawable undoDrawable = new StateListDrawable();
    undoDrawable.addState(new int[]{-android.R.attr.state_enabled},
            DrawableManager.getDrawable(this, R.drawable.v_undo_disabled_dark_x24));
    undoDrawable.addState(new int[]{},
            DrawableManager.getDrawable(this, R.drawable.v_undo_default_dark_x24));
    mUndo.setImageDrawable(undoDrawable);

    StateListDrawable redoDrawable = new StateListDrawable();
    redoDrawable.addState(new int[]{-android.R.attr.state_enabled},
            DrawableManager.getDrawable(this, R.drawable.v_redo_disabled_dark_x24));
    redoDrawable.addState(new int[]{},
            DrawableManager.getDrawable(this, R.drawable.v_redo_default_dark_x24));
    mRedo.setImageDrawable(redoDrawable);

    StateListDrawable actionDrawable = new StateListDrawable();
    actionDrawable.addState(new int[]{android.R.attr.state_activated},
            DrawableManager.getDrawable(this, R.drawable.v_eraser_dark_x24));
    actionDrawable.addState(new int[]{},
            DrawableManager.getDrawable(this, R.drawable.v_brush_dark_x24));
    mDrawAction.setImageDrawable(actionDrawable);

    StateListDrawable imageDrawable = new StateListDrawable();
    imageDrawable.addState(new int[]{android.R.attr.state_activated},
            DrawableManager.getDrawable(this, R.drawable.v_image_off_dark_x24));
    imageDrawable.addState(new int[]{},
            DrawableManager.getDrawable(this, R.drawable.v_image_dark_x24));
    mImage.setImageDrawable(imageDrawable);

    Ripple.addRipple(mPalette, true);
    Ripple.addRipple(mThickness, true);
    Ripple.addRipple(mDrawAction, true);
    Ripple.addRipple(mImage, true);
    Ripple.addRipple(mUndo, true);
    Ripple.addRipple(mRedo, true);
    Ripple.addRipple(mClear, true);
    Ripple.addRipple(mOk, true);
    Ripple.addRipple(mMenu, ResourcesUtils.getAttrBoolean(this, R.attr.dark));

    mSide.setOnClickListener(this);
    mPalette.setOnClickListener(this);
    mThickness.setOnClickListener(this);
    mDrawAction.setOnClickListener(this);
    mImage.setOnClickListener(this);
    mUndo.setOnClickListener(this);
    mRedo.setOnClickListener(this);
    mClear.setOnClickListener(this);
    mOk.setOnClickListener(this);
    mMenu.setOnClickListener(this);

    updateUndoRedo();

    if (mOutputFile == null) {
        Toast.makeText(this, R.string.cant_create_image_file, Toast.LENGTH_SHORT).show();
    }

    mSideAnimator = new ValueAnimator();
    mSideAnimator.setDuration(300);
    mSideAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mSide.setTranslationX((Float) animation.getAnimatedValue());
        }
    });

    mHideSideRunnable = new Runnable() {
        @Override
        public void run() {
            hideSide();
        }
    };
    SimpleHandler.getInstance().postDelayed(mHideSideRunnable, 3000);
}
 
Example 20
Source Project: Nimingban   Source File: DraftActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    ToolbarActivityHelper.setContentView(this, R.layout.activity_draft);
    setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));

    mTip = findViewById(R.id.tip);
    mRecyclerView = (EasyRecyclerView) findViewById(R.id.recycler_view);
    mViewTransition = new ViewTransition(mTip, mRecyclerView);

    // Layout Manager
    mLayoutManager = new LinearLayoutManager(this);

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    mAdapter = new DraftAdapter();
    mAdapter.setHasStableIds(true);
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mAdapter);      // wrap for swiping

    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.hasFixedSize();
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter);  // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setOnItemClickListener(this);

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);

    updateLazyList();
    checkEmpty(false);
}
 
Example 21
Source Project: Nimingban   Source File: SortForumsActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!handlerIntent(getIntent())) {
        finish();
        return;
    }

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    ToolbarActivityHelper.setContentView(this, R.layout.activity_forum_sort);
    setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));

    mTip = findViewById(R.id.tip);
    mRecyclerView = (EasyRecyclerView) findViewById(R.id.recycler_view);
    mViewTransition = new ViewTransition(mTip, mRecyclerView);

    // Layout Manager
    mLayoutManager = new LinearLayoutManager(this);

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // drag & drop manager
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(
            (NinePatchDrawable) getResources().getDrawable(R.drawable.shadow_8dp));

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    mAdapter = new ForumAdapter();
    mAdapter.setHasStableIds(true);
    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mAdapter);      // wrap for dragging
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter);      // wrap for swiping

    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.hasFixedSize();
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter);  // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    updateLazyList(false);

    if (Settings.getGuideSortForumsActivity()) {
        showEyeGuide();
    } else {
        // Eye guide was shown
        tryShowSecondGuide();
    }
}
 
Example 22
Source Project: Nimingban   Source File: SearchActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (!handlerIntent(getIntent())) {
        finish();
        return;
    }

    mNMBClient = NMBApplication.getNMBClient(this);

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    ToolbarActivityHelper.setContentView(this, R.layout.activity_search);
    setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));

    mContentLayout = (ContentLayout) findViewById(R.id.content_layout);
    EasyRecyclerView recyclerView = mContentLayout.getRecyclerView();
    mRecyclerView = recyclerView;

    mSearchHelper = new SearchHelper();
    mSearchHelper.setEmptyString(getString(R.string.not_found));
    mContentLayout.setHelper(mSearchHelper);
    if (Settings.getFastScroller()) {
        mContentLayout.showFastScroll();
    } else {
        mContentLayout.hideFastScroll();
    }

    mSearchAdapter = new SearchAdapter();
    recyclerView.setAdapter(mSearchAdapter);
    recyclerView.setSelector(Ripple.generateRippleDrawable(this, ResourcesUtils.getAttrBoolean(this, R.attr.dark)));
    recyclerView.setDrawSelectorOnTop(true);
    recyclerView.setOnItemClickListener(this);
    recyclerView.hasFixedSize();
    recyclerView.setClipToPadding(false);
    mOnScrollListener = new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (RecyclerView.SCROLL_STATE_DRAGGING == newState) {
                pauseHolders();
            } else if (RecyclerView.SCROLL_STATE_IDLE == newState) {
                resumeHolders();
            }
        }
    };
    recyclerView.addOnScrollListener(mOnScrollListener);

    int interval = getResources().getDimensionPixelOffset(R.dimen.card_interval);
    if (getResources().getBoolean(R.bool.two_way)) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        MarginItemDecoration decoration = new MarginItemDecoration(interval, interval, interval, interval, interval);
        mRecyclerView.addItemDecoration(decoration);
        decoration.applyPaddings(mRecyclerView);
        mRecyclerView.setItemAnimator(new SlideInUpAnimator());
    } else {
        int halfInterval = interval / 2;
        mRecyclerView.addItemDecoration(new RawMarginItemDecoration(0, halfInterval, 0, halfInterval));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setPadding(0, halfInterval, 0, halfInterval);
    }

    mSearchHelper.firstRefresh();

    Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this);
}
 
Example 23
Source Project: Nimingban   Source File: FeedActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mNMBClient = NMBApplication.getNMBClient(this);

    setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    ToolbarActivityHelper.setContentView(this, R.layout.activity_feed);
    setActionBarUpIndicator(DrawableManager.getDrawable(this, R.drawable.v_arrow_left_dark_x24));

    mContentLayout = (ContentLayout) findViewById(R.id.content_layout);
    mRecyclerView = mContentLayout.getRecyclerView();

    mFeedHelper = new FeedHelper();
    mFeedHelper.setEmptyString(getString(R.string.no_feed));
    mContentLayout.setHelper(mFeedHelper);
    if (Settings.getFastScroller()) {
        mContentLayout.showFastScroll();
    } else {
        mContentLayout.hideFastScroll();
    }

    // Layout Manager
    int interval = getResources().getDimensionPixelOffset(R.dimen.card_interval);
    if (getResources().getBoolean(R.bool.two_way)) {
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        MarginItemDecoration decoration = new MarginItemDecoration(interval, interval, interval, interval, interval);
        mRecyclerView.addItemDecoration(decoration);
        decoration.applyPaddings(mRecyclerView);
        mRecyclerView.setItemAnimator(new SlideInUpAnimator());
    } else {
        int halfInterval = interval / 2;
        mRecyclerView.addItemDecoration(new RawMarginItemDecoration(0, halfInterval, 0, halfInterval));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setPadding(0, halfInterval, 0, halfInterval);
    }

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    mAdapter = new FeedAdapter();
    mAdapter.setHasStableIds(true);
    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mAdapter);      // wrap for swiping

    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.hasFixedSize();
    mRecyclerView.setAdapter(mWrappedAdapter);  // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setOnItemClickListener(this);
    mRecyclerView.setSelector(Ripple.generateRippleDrawable(this, ResourcesUtils.getAttrBoolean(this, R.attr.dark)));
    mRecyclerView.setDrawSelectorOnTop(true);
    mRecyclerView.setClipToPadding(false);
    mRecyclerView.setClipChildren(false);
    mOnScrollListener = new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (RecyclerView.SCROLL_STATE_DRAGGING == newState) {
                pauseHolders();
            } else if (RecyclerView.SCROLL_STATE_IDLE == newState) {
                resumeHolders();
            }
        }
    };
    mRecyclerView.addOnScrollListener(mOnScrollListener);

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);

    mFeedHelper.firstRefresh();

    Messenger.getInstance().register(Constants.MESSENGER_ID_FAST_SCROLLER, this);
}
 
Example 24
Source Project: Nimingban   Source File: UnderLineRelativeLayout.java    License: Apache License 2.0 4 votes vote down vote up
private void init(Context context) {
    mPaint = new Paint();
    mPaint.setColor(ResourcesUtils.getAttrColor(context, R.attr.colorDivider));
    mDividerHeight = context.getResources().getDimensionPixelOffset(R.dimen.divider_height);
}
 
Example 25
Source Project: EhViewer   Source File: GalleryCommentsScene.java    License: 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 26
Source Project: EhViewer   Source File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate2(@Nullable Bundle savedInstanceState) {
    setContentView(R.layout.activity_main);

    mDrawerLayout = (EhDrawerLayout) ViewUtils.$$(this, R.id.draw_view);
    mNavView = (NavigationView) ViewUtils.$$(this, R.id.nav_view);
    mRightDrawer = (FrameLayout) ViewUtils.$$(this, R.id.right_drawer);
    View headerLayout = mNavView.getHeaderView(0);
    mAvatar = (LoadImageView) ViewUtils.$$(headerLayout, R.id.avatar);
    mDisplayName = (TextView) ViewUtils.$$(headerLayout, R.id.display_name);
    mChangeTheme = (Button) ViewUtils.$$(this, R.id.change_theme);

    mDrawerLayout.setStatusBarColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimaryDark));
    // Pre-L need shadow drawable
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_left, Gravity.LEFT);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_right, Gravity.RIGHT);
    }

    updateProfile();

    if (mNavView != null) {
        mNavView.setNavigationItemSelectedListener(this);
    }

    mChangeTheme.setText(getThemeText());
    mChangeTheme.setOnClickListener(v -> {
        Settings.putTheme(getNextTheme());
        ((EhApplication) getApplication()).recreate();
    });

    if (savedInstanceState == null) {
        onInit();
        CommonOperations.checkUpdate(this, false);
        checkDownloadLocation();
        if (Settings.getCellularNetworkWarning()) {
            checkCellularNetwork();
        }
    } else {
        onRestore(savedInstanceState);
    }

    EhTagDatabase.update(this);
}