跪拜 Guibai
← Back to the summary

Ten Years of Android Open Source: A 167-Star ScrollView and the Discipline to Delete Your Own Backend

In March 2019, I made my last commit to StickScrollView. At that point the repo had 167 stars and 23 forks, the best numbers on my GitHub.

By normal logic, the next step would have been to strike while the iron is hot: extract a few more generic controls, write a few source code analyses, and pile up stars.

But I did the opposite thing: in that project's README, I wrote a paragraph roughly saying: Android's official AppBarLayout + CollapsingToolbarLayout can achieve the same effect with a better experience. If you just need the effect, don't read further.

That paragraph is still there today. Seven years later, I increasingly think it was the most valuable line of documentation I wrote in ten years of open source.

Because from that day on, my criterion for whether something should be written changed from "can I write it" to "should it exist".

This article is a complete account of these ten years: what I did, where I stumbled, how long I stopped, and why in 2025 I went off to write an Electron desktop application. If you are also agonizing over "should I build this wheel", or are planning to move from mobile to AI, this might save you two years.

1. Starting point: a delivery restaurant list page

The story began when I ordered takeout.

I was scrolling the restaurant list page on Ele.me. The header image collapsed, the tab stuck to the top, and the menu list below could switch categories horizontally. The gesture was complex: the outer layer had to follow the scroll, after the sticky header the scroll event dispatch power had to be handed to the inner list, and the inner horizontal swipe had to not be stolen by the vertical swipe.

At that time, my understanding of Android touch event dispatch was only "I know it exists". I had to flip through notes to recall the order of dispatchTouchEvent / onInterceptTouchEvent / onTouchEvent. So I decided to write the effect from scratch: reading source code with a concrete goal is far more useful than reading ten source code analyses.

The result was ScrollViewWithStickHeader. The core was two things:

One was determining the "sticky header" moment. The header height minus the sticky area height is the critical point. If the scroll distance hasn't reached it, events are left to the outer layer; once past the critical point, the MotionEvent has to be dispatched downward.

The second was dual-list linkage. The left category list and right menu list had to follow each other: click the left, the right scrolls over; scroll the right, the left's selected item changes accordingly. The difficulty in this step was not scrolling, but the loop back: A scrolling causes B to follow, B's scrolling callback in turn notifies A to update its selection, and A scrolls again. Without handling, this becomes an endless loop or jitter.

My approach was to add a state flag; whoever initiates, holds it:

// When scrolling is initiated by the left, the right's scroll callback does not drive the left back
private boolean mIsLeftDriving = false;

onLeftScroll() {
    mIsLeftDriving = true;
    rightList.scrollToPosition(pos);
}

onRightScrollChanged(int pos) {
    if (mIsLeftDriving) return;   // don't treat echo as command
    leftList.setSelected(pos);
}

Looking back ten years later, this code and the loop control I use today when writing Agent tool calls — handling "tool results feed back to the model, the model then decides the next step" — is the same problem: in a system with feedback, one party must be able to distinguish "command" from "echo".

After the project was released, stars slowly grew to over a hundred. People filed issues saying a certain device's scrolling was not smooth, some asked whether the sticky area could be made configurable. In the process of fixing these problems, I truly mastered Android's event dispatch.

Then I opened the source code of AppBarLayout.

2. A 167-star project where I discouraged people from using it in the README

The combination of AppBarLayout + CollapsingToolbarLayout + NestedScrollView, together with CoordinatorLayout's Behavior, can achieve the same sticky effect, and its scroll inertia and nested scroll handling are more correct than my handwritten version. Android's design team spent more time on this problem than I, alone, did.

I wrote this discovery into the README and pointed to the official usage in AndroidWidgetActivity.

Honestly, when I wrote it there was a subtle feeling of unwillingness. But more important was another feeling: I took something "already done well by someone else" and made it again, then spent two months maintaining it.

A considerable number of the issues in those two months would not exist at all with the official solution. This is not a technical ability problem, it is a selection problem — I was optimizing my own implementation, not the user's problem.

This gave me a judgment framework I still use today, which I later wrote into the architecture retrospective when building AI products:

Does this component exist for the user, or for "I want to write it"?

In 2019 I used it to convince myself not to reinvent the wheel. In 2025 I used it to delete 21 tables and an entire login system from my AI project.

The same question, six years apart.

3. 2018: the year of taking "reinventing the wheel" to the extreme

After talking about restraint, I need to talk about the counterexample. From 2017 to 2019 were my three most productive years. Ten Android repositories under my account were all created in those three years.

The numbers are real, and you can still click in:

Project star fork Last update One line
StickScrollView 167 23 2019-03 Scroll container with sticky header + dual list linkage
MultiLevelRecyclerView 36 4 2018-08 Single RecyclerView implementing infinite-level tree list
charts 28 9 2019-06 Drawing library for bar, line, stacked, pie charts
ASwipeLayout 21 2 2018-04 Any ViewGroup gets swipe menu in seconds
AnimTextView 17 2 2018-01 TextView with number rolling animation
LineChart 6 — 2019-05 Lighter line chart and ring percentage chart
Android3DWheelView 4 — 2017-06 Fixed original library's wrap_content and custom attributes
AndroidProblem 2 1 2018-10 Collection of weird problems, pure documentation
DataCollectAgent 1 — 2017-07 AOP-based tracking collection
PopupWindowSet 1 — 2018-01 PopupWindow usable on 7.0+ and bottom popup

In total 283 stars. Compared to projects with tens of thousands, it is nothing, but behind every star is a person who actually used it in a real project. I am still a bit proud of that.

Three of them deserve separate mention, because their trade-offs are the same in origin as writing AI applications today.

3.1 MultiLevelRecyclerView: containing infinite levels with one RecyclerView

The conventional solution for multi-level lists (province-city-district, product categories, org structure) is nested RecyclerViews. At three levels it starts to lag; at five levels even scrolling gets messy.

My approach was to use only one RecyclerView, flatten the tree into a line, and distinguish levels by getItemViewType:

public abstract class BaseTreeRVAdapter<T extends RecyclerView.ViewHolder, M extends Tree>
        extends BaseRVAdapterV2<T, M> {

    @Override
    public void onBindViewHolder(T holder, final int position) {
        try {
            getLevel(position, mDatas, new PosBean());  // throw exception when reaching a leaf
        } catch (StopMsgException ex) {
            int type = Integer.parseInt(ex.getMessage());
            onBindViewHolder(type, ex.getTree(), holder);
        }
    }
}

Using exceptions for control flow was a stopgap of that era: in recursive traversal, the simplest way to "stop when found" in Java was to throw an exception. Now I would return Optional or Result, but the trade-off then was: make it run first, don't drag it out for two months for elegance.

But there is one design I think was right: extracting the node capability into a Tree interface. getItemViewType only recognizes the level, not the business type, so any business object implementing Tree can plug in. This structure was later used in several admin systems without modification.

"Constraints on the interface, freedom in the implementation": when writing an Agent tool registry today, I still use the same set.

3.2 charts: three real drawing pitfalls on Android

The chart library was the one I struggled with most, because it was all Canvas-level work.

Pitfall one: control width greater than the screen. When the X-axis of a line chart has many points, the actual width the control needs exceeds the screen. At this point wrap_content must be calculated yourself: maximum width of Y-axis text + number of points × spacing. I wrote all the handling for three MeasureSpec modes in onMeasure, because parent containers behave completely differently under UNSPECIFIED, AT_MOST, and EXACTLY, and this difference is glossed over in most tutorials with one line "call super.onMeasure".

Pitfall two: clipping outside the region. Initially I used a Bitmap as an intermediate layer to limit the drawing region, which was awkward and memory-wasting. After reading the Canvas source, I learned about clipRect:

int clipRestoreCount = canvas.save();
canvas.clipRect(mContentRect);   // draw only within the content area
doDraw();
canvas.restoreToCount(clipRestoreCount);  // precisely restore to the state before drawing

Note the last line must be restoreToCount(count) instead of restore(). Using restore() in nested drawing will pop the outer save as well, with the symptom being "after drawing the chart, other controls disappear".

Pitfall three: control points of Bezier curves. To make a polyline smooth you need cubic Bezier, and the choice of control points directly determines the appearance. I tried the conventional method of using three points to calculate two control points: within three points it is smooth, but when connecting to a fourth point, the corner is obvious.

Finally I switched to a distance-weighted algorithm:

public static ControlPonits getControlPoints(double x0, double y0, double x1, double y1,
                                             double x2, double y2, double paramCoefficient) {
    double d01 = Math.sqrt(Math.pow(x1 - x0, 2) + Math.pow(y1 - y0, 2));
    double d12 = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
    double fa = paramCoefficient * d01 / (d01 + d12);
    double fb = paramCoefficient * d12 / (d01 + d12);
    double p1x = x1 - fa * (x2 - x0);
    double p1y = y1 - fa * (y2 - y0);
    double p2x = x1 + fb * (x2 - x0);
    double p2y = y1 + fb * (y2 - y0);
    // ...
}

The math itself is not complex; the key is the adjustable paramCoefficient. Smoothness is not a correctness problem, it is an aesthetic problem, and you must leave a knob for the user.

This understanding saved me later: when doing layout for AI-generated PPT, I agonized over whether the spacing of auto-layout drafts should be nailed down by an algorithm. The answer was no; you need a coefficient for the user to adjust. Subjective judgments that can be expressed as parameters should not be hard-coded.

3.3 ASwipeLayout: reuse-induced disorder is the root of all list problems

ASwipeLayout has only 21 stars, but it was asked about most closely. Because it solved a problem that everyone who has done list swipe menus has hit: Item reuse.

Swipe open the menu of item 2, scroll up and down, item 9 is also open.

The root cause is that RecyclerView reuses Views, not states. My approach was not to save states internally (that would increase memory), but to expose a listener and let the business decide:

holder.scrollDelLl.setOnSwipeStateChangeListener(open -> person.setOpen(open));
// in onBindViewHolder
holder.scrollDelLl.setOpen(person.isOpen());

The control's responsibility is to tell you about state changes, not to remember state for you. This sense of boundary is more important than the implementation itself. Later I saw many libraries choose "I will remember it for you", and the result was worse memory and performance, and they were criticized as hard to use — not because they did it wrong, but because they made a decision on behalf of the user that the business should make.

4. After 2019, I stopped

The last commit to charts was in June 2019. After that, my GitHub was quiet for nearly four years.

The reason was ordinary: work got busy, my role shifted from "writing controls" to "carrying business". Writing business code does not require stars and does not produce presentable repositories. In between, a few small things are worth noting:

One is Arctic Code Vault Contributor. In 2020 GitHub engraved open source code on film and stored it in an abandoned mine in the Arctic. StickScrollView and my other repositories were in that batch of snapshots. The practical significance is small, but when I saw that badge, I was genuinely stunned for a moment — a pile of unused Android controls buried in the coldest place on Earth. That was the first time I realized the word "open source" contains the meaning of "archive".

Second, the Starstruck badge lit up twice (once at 16 stars, once at 128 stars). When the system reminded me, I had long stopped writing controls.

Third, AndroidProblem, a pure documentation repository, I always felt was more valuable than the control libraries. Inside are the problems that documentation never answers:

These still hold today, because these Android behaviors are not bugs; they are design. Debugging experience that can be turned into documentation lives longer than code that can be merged into a repo.

5. Four silent years, watching how others write

From 2019 to 2023 I basically produced nothing, but I kept reading. My fork list explains this transition better than my code:

Forked repo Upstream What I was looking at
dify langgenius How workflow orchestration and Agent nodes are organized
ragflow infiniflow Real engineering of document splitting and retrieval recall
himarket higress-group AI capability marketplace, enterprise API governance
ruoyi-ai ageerle Full-stack implementation of domestic AI platforms
OCRmyPDF ocrmypdf Complete pipeline for adding text layer to scanned files
human-eval openai How to evaluate code generation without self-deception
Transformer SamLynnEvans seq2seq from scratch, to understand attention
unioffice-examples unidoc How to generate Office files server-side

What I was doing in those years, in essence, was replacing the effort of "building wheels" with "reading wheels". The set of things Android custom Views taught me — measurement, drawing, events, state — turns out to apply to AI applications:

This is not a forced analogy. People who do UI have muscle memory for "when does a state belong to whom", and that happens to be the most error-prone place in Agent development.

6. 2025: why an Android person went off to write Electron

Last year I started making my own AI office tool, called AI Mate. The first version was very "standard", standard enough to be a teaching case: Spring Boot backend, JWT login, 21 MySQL tables, Redis for sessions, Vue admin console, server-side knowledge base.

All features worked. Then I deleted all of it.

I wrote the process and reasoning in detail in another post; here I will only say the part relevant to this article's theme.

During the retrospective I made a table and forced myself to answer: does each component exist for the user, or for my business model? The result revealed one thing: my Electron client already had a complete set of offline capabilities: local vector database, Ollama client, four-level degradation, task scheduling, eleven files, code quality not bad, but none of it was connected to any interface.

Why not connect it? Because the product logic was "must log in, must go through the gateway". Once local capabilities get a UI, it would be equivalent to admitting "you can use it without logging in".

Capability was held down by my own business model.

This is the same thing as the self-denial in that 2019 README, two sides of the same coin. That time I admitted "the official does it better than me"; this time I admitted "what I added, users don't need". Both were uncomfortable, both were right.

After deleting: zero login, zero backend process, data stays on the machine, model keys are filled in by the user (safeStorage uses the system keychain, 0600 permissions, plaintext never passes through contextBridge to the renderer layer). Mac and Windows share the same source build; three versions released in one day.

An Android person writing Electron + React 19 has no romantic story technically; there are just a few hard rules:

The tech stack is React 19 + Electron 45 + TypeScript, Node ≥ 22.12, the gateway becomes optional (a stateless proxy, no database, no login, only OpenAI-compatible forwarding). Open source license Apache 2.0.

7. Ten years only taught me one thing

If I can leave only one sentence for the next ten years, it is this:

First ask "should this thing exist", then ask "can I write it".

It has three concrete forms, and I run into one every few years:

First, when someone else's wheel is already sufficient (2019, StickScrollView). I spent two months maintaining a control for which the official version already had a better implementation. The judgment standard is not code quality, but "has the user's problem been solved".

Second, when a wheel's decisions should be left to the user, don't make them for him (2018, ASwipeLayout). I restrained myself from storing state inside the library and handed the decision back to the business. That restraint is why it is still usable today.

Third, when what you add serves the business model, not the user (2025, AI Mate). The 21-table login system did not block malicious users; it blocked my own product's usability.

In ten years I collected 283 stars, 21 followers, and an Arctic archive badge. Those numbers will stay where they are, but the three judgments above will keep updating.

In the years I wrote controls, I thought I was learning Canvas and MotionEvent. Now I know I was learning boundaries — which part should I write, which part should the official write, which part should be handed to the user.

In the Agent era, the version of that question becomes: which part should the model decide, which part should code constrain, which part should the user decide. Change the language and framework; the question is exactly the same.


If you also came from mobile, or are agonizing over whether to build a wheel, leave a comment. I am especially curious whether anyone else, like me, has personally discouraged users of their own project in a README.

Entry points

AI Mate is still a private repository and not open sourced, so no repo link is provided here. Once it is cleaned up, I will write a separate post about its architecture.