JustWeTools

repository·master·Indexed 20 days ago

https://github.com/lfkdsk/justwetools

A library of Android-specific custom views and utility classes designed to accelerate development. It includes UI components such as PaintView (drawing tool), CodeView (code editor), MarkDownView (Markdown renderer), ExplorerView (file manager), and ReadView (novel reader), as well as utility classes for network, image processing, SharedPreferences (SpUtils), and alarm events.

Tokens
3.6K
Snippets
11
Records
18
Agent score
71%

What's inside JustWeTools

  1. Overview of JustWeTools modules

    master

    JustWeTools is a collection of Android UI components (View custom controls) and utility classes.

    View Custom Controls

    • PaintView: Drawing tool (includes a refactored version with pressure sensitivity).
    • CodeView: Code viewing and editing tool.
    • ExplorerView: File manager/browser.
    • ReadView: Novel reader.
    • MarkDownView: Text renderer supporting Markdown syntax.
    • VerTextView: TextView supporting vertical layout and underlines.
    • FlashTextView: Flowing/shimmering font (QQ style).
    • Progress: Progress bars and circular progress bars.
    • Clock: Custom view for drawing a clock.
    • CartoonView: Manga/Comic reader.

    Utils (Utility Classes)

    • AlarmUtil: Alarm event utilities.
    • MPUtils: SMS and telephone utilities.
    • NetUtils: Network status utilities.
    • PicUtils: Image processing utilities.
    • ServiceUtils: Service utilities.
    • ImageHelper: Graphic processing.
    • DisplayUtils: Data conversion.
    • SpUtils: Simplified SharedPreferences utility (supports storing List and Map).
    • ToastUtils: Customized Toast utilities.
    • ValidatorsUtils: Regular expression processing.
  2. Use ReadView for novel reading

    master

    ReadView

    ReadView is a Canvas-based novel reader that supports customization of fonts, font sizes, and text colors.

    Usage

    Initialize the view by passing the context and the directory path of the file to be read:

    ReadView readView = new ReadView(this, dir.getPath());
    setContentView(readView);
  3. Install JustWeTools via Gradle

    master

    To use JustWeTools in an Android project using Gradle, follow these two steps:

    1. Add the JitPack repository to your root build.gradle file inside the allprojects block.
    2. Add the dependency to your module-level build.gradle file.
    // Step 1: Add JitPack to root build.gradle
    allprojects {
        repositories {
            ... 
            maven { url "https://jitpack.io" }
        }
    }
    
    // Step 2: Add dependency to module build.gradle
    dependencies {
        compile 'com.github.lfkdsk:JustWeTools:v1.0'
    }
  4. Use PaintView for drawing tools

    master

    PaintView

    PaintView is a drawing tool that supports basic functions like changing colors, switching between pens and erasers, adjusting thickness, clearing the screen, and importing images. It also features advanced capabilities like saving/exporting frame animations and ReDo/UnDo functionality. For custom brushes, you can extend the DrawBase class.

    Basic Setup

    1. Add the view to your XML layout:
    <com.lfk.justwetools.View.PaintIt.PaintView
        android:id="@+id/paintView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    1. Initialize in your Activity:
    paintView = (PaintView)findViewById(R.id.paintView);

    Frame Animation Recording

    To use frame animation features, you must create a PathNode dataset, register it with the PaintView, and implement an OnPathListener to record the drawing path details (coordinates, color, width, etc.).

    // Frame animation setup example
    pathNode = (PathNode)getApplication();
    paintView.setIsRecordPath(true, pathNode);
    paintView.setOnPathListener(new OnPathListener() {
        @Override
        public void AddNodeToPath(float x, float y, int event, boolean IsPaint) {
            PathNode.Node tempnode = pathNode.new Node();
            tempnode.x = x;
            tempnode.y = y;
            if (IsPaint) {
                tempnode.PenColor = UserInfo.PaintColor;
                tempnode.PenWidth = UserInfo.PaintWidth;
            } else {
                tempnode.EraserWidth = UserInfo.EraserWidth;
            }
            tempnode.IsPaint = IsPaint;
            tempnode.TouchEvent = event;
            tempnode.time = System.currentTimeMillis();
            pathNode.AddNode(tempnode);
        }
    });
  5. Use MarkDownView for Markdown rendering

    master

    MarkDownView

    MarkDownView is a WebView-based renderer that supports standard Markdown syntax. Its API is designed to be consistent with CodeView.

    Setup

    1. Add the view to your XML layout:
    <com.lfk.justwetools.View.MarkDown.MarkDownView
        android:id="@+id/markdownview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    1. Provide content via a String or a Directory:
    • Via String: markDownView.setStringSource(String content)
    • Via Directory: markDownView.setDirSource(File dir)
  6. Install JustWeTools via Maven

    master

    To use JustWeTools in a Maven-based project, add the JitPack repository and then the specific dependency to your pom.xml.

    <!-- Step 1: Add JitPack repository -->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    
    <!-- Step 2: Add dependency -->
    <dependency>
        <groupId>com.github.lfkdsk</groupId>
        <artifactId>JustWeTools</artifactId>
        <version>v1.0</version>
    </dependency>
  7. Use ProportionView to analyze file type distribution

    master

    ProportionView

    ProportionView provides a visual analysis of file type ratios within a directory. It is best used in conjunction with ExplorerView.

    Setup

    1. Add the view to your XML layout:
    <com.lfk.justwetools.View.Proportionview.ProportionView
        android:id="@+id/pv"
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:layout_height="30dp" />
    1. Update the data whenever the file explorer path changes:
    fileExplorer.setOnPathChangedListener(new OnPathChangedListener() {
        @Override
        public void onPathChanged(String path) {
            try {
                view.setData(fileExplorer.getPropotionText(path));
            } catch (Exception e) {
                // Handle error (e.g., path inaccessible)
            }
        }
    });
  8. Use VerTextView for vertical text layout

    master

    VerTextView

    VerTextView is a specialized TextView for vertical text layout. It includes built-in support for customizable underlines.

    Setup

    1. Add the view to your XML layout:
    <com.lfk.justwetools.View.VerText.VerTextView
        android:id="@+id/vertextview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    1. Configure properties:
    • setFontSize(int size): Set font size.
    • setIsOpenUnderLine(boolean): Enable/disable underlines.
    • setUnderLineColor(int color): Set underline color.
    • setUnderLineWidth(int width): Set underline thickness.
    • setUnderLineSpacing(int spacing): Set spacing between text and underline.
    • setTextStartAlign(int align): Set alignment (e.g., VerTextView.RIGHT or VerTextView.LEFT).
    • setTextColor(int color): Set text color.
  9. Use CodeView for code viewing and editing

    master

    CodeView

    CodeView is a WebView-based code editor that supports syntax highlighting, dark themes, and real-time editing.

    Basic Setup

    1. Add the view to your XML layout:
    <com.lfk.justwetools.View.CodeView.CodeView
        android:id="@+id/mcodeview"
        android:layerType="hardware"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    1. Set the source directory in your Activity:
    codeView = (CodeView)findViewById(R.id.mcodeview);
    File dir = new File(fileUri.getPath());
    if (dir != null) {
        codeView.setDirSource(dir);
    }

    Enabling Editing

    To toggle editing mode, use setContentEditable(boolean):

    if (!codeView.isEditable()) {
        codeView.setContentEditable(true);
    } else {
        codeView.setContentEditable(false);
    }

    Note: If manually copying code, ensure you include the JS files from the assets folder.

  10. Use Clock for custom clock drawing

    master

    Clock

    Clock is a custom View that draws a clock face.

    Setup

    1. Add the view to your XML layout:
    <com.lfk.justwetools.View.Clock.Clock
        android:id="@+id/clock"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    Configuration Methods

    • setColor(int color): Set clock color.
    • setNeedleColor(int needleColor): Set needle color.
    • setTextColor(int textColor): Set text color.
    • setCircleColor(int circleColor): Set circle color.
    • setUnthehourLineColor(int color): Set color for non-hour lines.
    • setThehourLineColor(int color): Set color for hour lines.
    • setHourSize(int hourSize): Set size for hour markers.
  11. Use PaintView for custom drawing

    master

    PaintView is a custom Android View component designed for drawing and erasing on a canvas. It supports setting brush colors, pen widths, and eraser widths. It also provides functionality to load background images via Uri and save the drawing as a JPEG file.

    // Example initialization in an Activity or Fragment
    PaintView paintView = new PaintView(context);
    // Set up a listener to record paths
    paintView.setOnPathListener(myPathListener);
    // Add to your layout
    layout.addView(paintView);
  12. Record and playback drawing paths with OnPathListener

    master

    To record user strokes for later playback or serialization, implement the OnPathListener interface and register it with setOnPathListener.

    When setIsRecordPath(boolean isRecordPath) is enabled, the view will call addNodeToPath on every touch event (DOWN, MOVE, UP). This allows you to capture the full sequence of coordinates, colors, and widths used during a drawing session.