<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cuong Le on Medium]]></title>
        <description><![CDATA[Stories by Cuong Le on Medium]]></description>
        <link>https://medium.com/@cuong-le?source=rss-655b3a4cc3aa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0L01s86-MWSgpXsP.jpg</url>
            <title>Stories by Cuong Le on Medium</title>
            <link>https://medium.com/@cuong-le?source=rss-655b3a4cc3aa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 11:28:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cuong-le/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Engineering Smarter Structure Detection: How We Built an Adaptive Support & Resistance Engine]]></title>
            <link>https://cuong-le.medium.com/engineering-smarter-structure-detection-how-we-built-an-adaptive-support-resistance-engine-b7e6a22fc7ee?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7e6a22fc7ee</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Wed, 09 Apr 2025 06:22:51 GMT</pubDate>
            <atom:updated>2025-04-09T06:22:51.873Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TAutoStructure</strong> is the result of years of research focused on one of the most challenging problems in technical analysis: <strong>automatically identifying meaningful support and resistance levels</strong>.</p><p>At its core, it’s powered by a robust algorithm rooted in <strong>Wyckoffian principles</strong> — analyzing waves, volume dynamics, and contextual price behavior to detect moments when market control truly shifts.</p><p>Unlike traditional tools that rely on static highs and lows, TAutoStructure identifies <strong>structural turning points</strong> — zones where supply or demand have clearly asserted themselves — and highlights them precisely.</p><p>These structure levels often become <strong>key inflection points</strong>, offering high-quality trade opportunities when price returns to test them.</p><h3>The Problem with Traditional Support &amp; Resistance Tools</h3><p>Most auto-detection indicators for support and resistance suffer from the same issues:</p><ul><li><strong>Overdrawing:</strong> They paint levels at every swing high and low.</li><li><strong>Repainting:</strong> They change constantly as new bars appear.</li><li><strong>Zero context:</strong> They can’t distinguish between meaningful price action and noise.</li></ul><p>As a result, traders are left with charts that feel chaotic — and structure levels that don’t hold when it matters most.</p><h3>Our Mission: Build a Context-Aware Structure Engine</h3><p>When we built TAutoStructure, we weren’t trying to reinvent the wheel — we were trying to <strong>make it smarter</strong>.</p><p>We wanted an engine that could:</p><ul><li>Understand <strong>directional conviction</strong></li><li>Validate behavior using <strong>volume pressure</strong></li><li>Normalize data to <strong>detect anomalies in context</strong></li><li>Trigger structure <strong>only after real confirmation</strong></li></ul><p>This wasn’t about drawing more lines. It was about <strong>drawing the right ones</strong> — at the right time.</p><h3>The Core Ideas Behind the Algorithm</h3><p>We won’t go into the proprietary mechanics of the engine, but we’ll share some of the ideas that shaped it.</p><h4>1. Directional Conviction, Not Candle Color</h4><p>A single red or green candle doesn’t tell us much. What matters is <em>how price got there</em> — and whether that move shows intent.</p><p>TAutoStructure evaluates sequences of bars to infer directional pressure. We look for <strong>behavioral confirmation</strong>, not just chart patterns.</p><h4>2. Volume Context Matters</h4><p>One of the biggest missing pieces in most auto SR tools is volume.</p><p>We measure <strong>volume response to price moves</strong>, and compare it to prior directional effort. If a reversal occurs on expanding volume, and price fails to continue, that’s a signal that structure has likely formed.</p><h4>3. Contextual Normalization</h4><p>We normalize structure-related metrics using recent behavior. That allows us to ignore noise during low-volatility ranges — and avoid false signals during fast markets.</p><p>This is key to ensuring the structure engine adapts across timeframes and instruments.</p><h4>4. Confirmation Before Commitment</h4><p>TAutoStructure doesn’t draw lines the moment something “looks” like support or resistance. Instead, it waits for confirmation that <strong>control has changed</strong> — that a previous move has failed, and new effort is stepping in.</p><p>This delay often filters out weak zones and keeps the chart clean.</p><h3>Chart Example</h3><p>Here’s a real chart processed with TAutoStructure. The yellow lines show confirmed supply and demand levels based on our internal logic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KdyfMq6fkmKUHAhrQpptDA.jpeg" /><figcaption>BTC — daily chart</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5VUfD0wm3mU3yzXJbo4XaA.jpeg" /><figcaption>TSLA— daily chart</figcaption></figure><h3>The Power of Structure + Flow: Trading with TAutoStructure and TWave</h3><p>When combined, <strong>TAutoStructure</strong> and <strong>TWave</strong> form a complete trading framework that covers both <strong>location</strong> and <strong>timing</strong> — the two most critical elements of any high-quality trade.</p><ul><li><strong>TAutoStructure</strong> tells you <em>where</em> to focus: the levels where price has proven that structure exists.</li><li><strong>TWave</strong> tells you <em>when</em> to act: the exact moment when the market reveals directional conviction or weakness.</li></ul><p>Together, they provide:</p><ul><li>High-probability entries at structure levels with trend confirmation</li><li>Early warnings of exhaustion or reversals near support/resistance</li><li>A context-driven filter that cuts through false signals and noise</li></ul><p>This synergy allows traders to move beyond reactive strategies and into <strong>anticipatory setups</strong> — where edge is defined by insight, not just indicators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D054upIMJF6NqFiAks4IGg.jpeg" /><figcaption>NVDA — daily chart</figcaption></figure><h3>From Visual Indicator to Headless Scanner</h3><p>Once we validated the core logic on charts, we went a step further.</p><p>We built a <strong>headless scanner</strong> that can analyze thousands of symbols in real-time, identifying:</p><ul><li>When a valid support or resistance level has just formed</li><li>When price is returning to test that level on the current candle</li></ul><p>This allows us to flag setups like:</p><blockquote>“Price is currently testing a previously confirmed supply zone from 14 bars ago — on lower volume.”</blockquote><p>It’s like having a Wyckoff-trained assistant watching the entire market.</p><h3>What You See on the Chart</h3><p>When applied to charts, the results are immediately clear:</p><ul><li><strong>Demand zones</strong> form after confirmed downside rejection — usually at the exhaustion of a selling wave.</li><li><strong>Supply zones</strong> appear after upward momentum fails — often just as distribution sets in.</li><li>These levels <strong>do not repaint</strong>. They evolve with the market, and they remain visible until price invalidates them.</li></ul><p>Even better: when price returns to test these lines, they often mark <strong>high-probability trade locations</strong>.</p><h3>Try It Yourself</h3><p>TAutoStructure is already live on at <a href="https://tbchart.xyz/"><strong>TBChart</strong></a>, and it’s available on other charting platforms. You’ll be able to:</p><ul><li>See dynamic support/resistance lines on your charts</li><li>Run real-time scans for “structure touches” across your watchlist</li></ul><p>Whether you’re a price-action trader or a systems builder, we think you’ll immediately feel the difference when you see TAutoStructure in action.</p><h3>Final Thoughts</h3><p>This wasn’t just an academic exercise. TAutoStructure is the tool <strong>we always wanted</strong> as traders: structure detection that’s clean, intelligent, and context-aware.</p><p>We’re proud of what we’ve built — and even more excited to share what’s coming next.</p><p>If you want to trade with real structure — not static zones and guesses — we’d love to show you what we’ve created.</p><p>👉 <a href="https://tbchart.xyz/indicators"><strong>Get early access to the indicators</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7e6a22fc7ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Building the Best Point & Figure Chart Engine — for Every Platform]]></title>
            <link>https://cuong-le.medium.com/building-the-best-point-figure-chart-engine-for-every-platform-667e94d9127f?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/667e94d9127f</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[trading]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Mon, 07 Apr 2025 13:18:44 GMT</pubDate>
            <atom:updated>2025-04-08T14:01:52.221Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building the Best Point &amp; Figure Chart Engine — for Every Platform</h3><p>We built a chart engine that renders Point &amp; Figure (PnF) charts better than anything else on the market — and it runs everywhere: desktop, web, and mobile.</p><p>That wasn’t a lucky accident. It took careful architecture, deep understanding of Compose internals, and relentless attention to polish. This post breaks down the phases of building this engine and the hard-won lessons behind it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*paZIlC4odwQblpwWLSv-oQ.png" /></figure><h3>🧱 Story 1: Laying the foundation — chart layout &amp; scroll logic</h3><p>At first glance, building the layout for a Point &amp; Figure chart seems straightforward: render Xs and Os in a grid, add a price axis, and wrap it in a scrollable container.</p><p>But the first real challenge wasn’t drawing — it was getting <strong>scrolling</strong> to behave correctly.</p><h4>🚫 What didn’t work:</h4><p>We initially thought that setting a fixed height on the Box would define our scrollable area:</p><pre>Box(modifier = Modifier.height(height)) {<br>    Canvas(modifier = Modifier.fillMaxSize()) { ... }<br>}</pre><p>But scrolling didn’t work. Why? Because Canvas didn&#39;t <strong>overflow</strong> its parent — it filled it. So the scroll state had no reason to scroll.</p><h4>✅ What actually worked:</h4><p>We realized the key was to <strong>separate the viewport height from the content height</strong>. So we used:</p><pre>Box(modifier = Modifier.height(visibleHeight)) {<br>    Canvas(modifier = Modifier.height(canvasHeight)) { ... }<br>}</pre><ul><li>visibleHeight = height of the scrollable <strong>viewport</strong></li><li>canvasHeight = height of the actual <strong>rendered content</strong>, based on how many price levels we needed</li></ul><p>Since canvasHeight was typically much taller than visibleHeight, scrolling was now meaningful — and verticalScroll() kicked in.</p><p>This distinction is subtle, but critical in Compose layout:</p><blockquote><em>The outer </em><em>Box defines what you </em>see<em>, the inner </em><em>Canvas defines what </em>exists<em>.</em></blockquote><p>We also applied both vertical and horizontal scroll states directly to the chart region, so that traders could scroll around massive PnF grids intuitively — especially with fine-grained 15M or 1H data.</p><h3>📈 Story 2: Avoid Doing Expensive Work Every Frame</h3><p>Here’s how your code probably looks when rendering volume bars:</p><pre>Canvas {<br>    data.columns.forEachIndexed { index, col -&gt;<br>        drawRect(...) // dozens to hundreds of times<br>    }<br>}</pre><p>Seems simple. But this re-runs on <strong>every frame</strong>, even when the volume data hasn’t changed.</p><p>That means:</p><ul><li>🔁 Looping through all columns</li><li>📐 Calculating bar height/width/position</li><li>🎨 Re-deciding the color</li><li>🧱 Redrawing every single bar</li></ul><p>Even if you’re hitting 60fps, that’s <em>wasted effort</em> if the visual output is unchanged.</p><h4>💡 The Solution: Cache It as an ImageBitmap</h4><p>Instead of redrawing the volume bars each frame, you can <strong>pre-render them once</strong> into an ImageBitmap and re-use it every time.</p><pre>val volumeBitmap = remember(data.columns) {<br>    ImageBitmap(...).apply {<br>        val canvas = Canvas(this)<br>        // draw all bars here ONCE<br>    }<br>}</pre><p>Then, inside your main Canvas:</p><pre>drawImage(volumeBitmap)</pre><p>This approach is known as <strong>retained drawing</strong>, a concept borrowed from game engines and high-performance charting libraries.</p><h4>Performance Comparison</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*USLErkBqcwZaYRuDIK-l1Q.png" /></figure><h4>🧪 When It Matters</h4><p>You’ll feel the performance win especially when:</p><ul><li>📉 You’re rendering <strong>hundreds or thousands of bars</strong></li><li>🖱️ Users are panning or scrolling quickly</li><li>🖼️ Volume data is <strong>static</strong> or changes infrequently</li></ul><p>This is especially noticeable on lower-end devices or when combining multiple overlays in a complex chart UI.</p><h4>🧠 TL;DR</h4><ul><li>❌ <strong>Don’t</strong> redraw volume bars every frame.</li><li>✅ <strong>Do</strong> cache them as a bitmap once, and draw the image instead.</li></ul><blockquote><em>It’s like baking a cake once, and serving slices — instead of baking a whole new cake every time someone wants a bite. 🍰</em></blockquote><h3>🖱️ Story 3: Selection logic that feels right</h3><p>Traders using Point &amp; Figure charts often want to isolate key patterns visually — like consolidations, springs, or breakouts. We needed a way to <strong>select horizontal price ranges</strong> directly on the chart, in a way that was fast, intuitive, and worked with keyboard modifiers.</p><p>We landed on a drag interaction that supports:</p><ul><li>Horizontal box-range selection</li><li>Up to 3 active selections</li><li>Shift + drag to multi-select</li><li>Unique color per selection</li><li>Instant tooltip feedback</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkQTQZU3RpFb-ypblmPMPg.png" /><figcaption>Box count</figcaption></figure><h4>🧠 Behind the drag behavior</h4><p>We implemented all this in a custom hook: rememberSelectionHandler(). It attaches a pointerInput modifier to the chart area, giving us full access to low-level pointer events via awaitPointerEventScope.</p><p>Inside that scope, we use:</p><pre>awaitPointerEventScope {<br>    while (true) {<br>        val event = awaitPointerEvent()<br>        ...<br>    }<br>}</pre><p>💡 Why while (true)?</p><p>Because we need to <strong>continuously listen for pointer state changes</strong> — not just taps or releases, but raw movement, modifier keys, and pressure across the entire drag lifecycle.</p><p>awaitPointerEvent() suspends until a new pointer event arrives (tap, move, release, etc), so this while (true) loop doesn&#39;t spin or block the UI. It&#39;s coroutine-safe and Compose-native.</p><p>This loop lets us:</p><ul><li>Track when the user starts dragging</li><li>Update the current selection as they move</li><li>Detect when the drag ends (pointer released)</li><li>Combine all of that with Shift key state</li></ul><p>Here’s a condensed version of what that logic looks like in action:</p><pre>if (isPressed &amp;&amp; dragStart == null) {<br>    dragStart = row to col<br>    isDragging = true<br>}</pre><pre>if (isPressed &amp;&amp; isDragging) {<br>    currentSelection = ...<br>}</pre><pre>if (!isPressed &amp;&amp; isDragging) {<br>    selections.add(currentSelection)<br>    resetDragState()<br>}</pre><h4>🎨 The result:</h4><ul><li>Color-coded range selections</li><li>Tooltips with Accumulation / Distribution metrics</li><li>A no-button, no-popup interaction model — just <strong>drag and go</strong></li></ul><p>This gave our chart the feel of a precision tool without the complexity of external UI widgets. Everything happens under your pointer, exactly where you’d expect it.</p><h3>🪄 Story 4: Skeleton loading — but make it P&amp;F</h3><p>While waiting for real data to load, we wanted something more thoughtful than a generic spinner. Since this is a chart engine, we leaned into the theme and built a <strong>Point &amp; Figure–inspired skeleton loader</strong>.</p><p>The idea was simple:</p><ul><li>Generate a small grid of fake columns using generateFakePnF(...)</li><li>Mix Xs and Os in each column like real P&amp;F logic</li><li>Animate a left-to-right highlight every 250ms to simulate scan progression</li><li>Fade inactive columns to gray, color the active one using chart themes</li></ul><p>There wasn’t much complexity here — no pulsing or scaling, no shimmer — just a quiet, visual rhythm that keeps the user’s eye engaged while the engine loads.</p><pre>LaunchedEffect(Unit) {<br>    while (true) {<br>        for (i in data.indices) {<br>            selectedColumnIndex.intValue = i<br>            delay(250)<br>        }<br>    }<br>}</pre><p>Sometimes, the best UI polish is the kind that nobody notices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*640FGhMkD8MXrqDtUCFU2A.gif" /><figcaption>Skeleton animation</figcaption></figure><h3>🌍 Story 5: One codebase, every platform</h3><p>Going multiplatform isn’t just about rendering — it’s about making sure core functionality works consistently across desktop, web, and mobile. This phase was about wiring up all the non-UI bits: timekeeping, networking, and image loading.</p><h4>🕒 Time</h4><p>We use <a href="https://github.com/Kotlin/kotlinx-datetime">kotlinx-datetime</a> to get the current time across platforms:</p><pre>Clock.System.now().toEpochMilliseconds()</pre><p>No expect/actual, no messy platform code.</p><h4>🌐 Networking</h4><p>We use <a href="https://ktor.io/">Ktor</a> with different engines per target:</p><ul><li>Desktop: OkHttp</li><li>Web (WASM): Js</li><li>Android: OkHttp or CIO</li><li>iOS: Darwin</li></ul><p>This lets us share our data-fetching code with zero duplication.</p><h4>🖼️ Images</h4><p>We use <a href="https://coil-kt.github.io/coil/compose/">Coil 3 Multiplatform</a>:</p><ul><li>It loads images from resources, URLs, or WASM-friendly paths</li><li>It just works on every platform</li><li>No more painterResource vs AsyncImage drama</li></ul><p>It even loads our watermark logo with the right pixel density and alpha, whether you’re on Android or in a browser tab.</p><h3>🧠 The result</h3><p>We now have a Point &amp; Figure chart engine that:</p><ul><li>Renders real P&amp;F structure — not just boxes, but logic</li><li>Supports smooth horizontal + vertical scrolling</li><li>Lets traders visually mark zones with instant drag gestures</li><li>Shows polished loading states that match the domain</li><li>Runs on <strong>desktop, web, and mobile</strong> from a single codebase</li></ul><p>We didn’t compromise on interactivity. We didn’t cut corners on visuals. And we didn’t stop until the platform differences disappeared.</p><h3>🏁 Final word</h3><p>This is the chart engine we always wished we had — and now it exists. It’s fast. It’s intuitive. And it works anywhere you care about markets.</p><p>If you’re building trading tools, P&amp;F analysis apps, or just want to see how Compose Multiplatform can power real production UI: this is the benchmark.</p><p>At TbChart, we’re proud of it — because it feels like magic, and it’s built on rock-solid engineering. Try now <a href="https://tbchart.xyz/pnf">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=667e94d9127f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Why I Built TBChart — A Modern Charting Platform for Traders]]></title>
            <link>https://cuong-le.medium.com/why-i-built-tbchart-a-modern-charting-platform-for-traders-9d0b41c764b6?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d0b41c764b6</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[technical-analysis]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 15:03:48 GMT</pubDate>
            <atom:updated>2025-03-26T15:03:48.234Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧠 Why I Built TBChart — A Modern Charting Platform for Traders</h3><p>Five years ago, I published a post called <em>“Inside a Trade Alert System”</em>, where I broke down how I hacked together a MetaTrader-based signal system during COVID lockdowns. That side project helped me automate alerts — all while trading from a VPS and stitching together scripts in MQL5. But the MACD indicators are not that good when I learned Wyckoff methodology.</p><p>Fast forward to today: I’ve become a Wyckoffian trader, built my own indicator suite (TSuite), and spent years fighting with charting platforms like <strong>Sierra Chart</strong>, <strong>NinjaTrader 8</strong>, <strong>MetaTrader 5</strong>, and <strong>TradingView</strong>.</p><p>And honestly? <strong>None of them gave me what I needed.</strong><br> So, I built my own — welcome to <strong>TBChart</strong>.</p><h3>💡 The Problem with Existing Platforms</h3><p>I created <strong>TSuite</strong>, a set of order flow-based indicators for:</p><ul><li><strong>Sierra Chart</strong> — high performance, but UI is clunky, log scale is broken, and Point &amp; Figure support is poor.</li><li><strong>NinjaTrader 8</strong> — better than Sierra in some ways, but still hard to configure and not built for speed.</li><li><strong>MetaTrader 5</strong> — by far the worst charting experience. Horrible scaling, outdated UX, but widely used.</li><li><strong>TradingView</strong> — sleek and fast, but its charting model made it impossible for me to make TSuite work. (Also, I suck at PineScript.)</li></ul><p>Worse still, <strong>none</strong> of these platforms allowed me to <strong>screen entire markets</strong> for TSuite signals.</p><p>Then one day, I stumbled on an open-source TypeScript charting library. It had <strong>scrolling and scaling behavior like TradingView</strong>. I plugged TSuite into it. It worked.<br>That was the moment I knew: <strong>I had to build this</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VVDrakWRjoBN7sW_IIynjw.jpeg" /><figcaption>TSuite indicators</figcaption></figure><h3>🖥️ Frontend Overview</h3><p>TBChart has two projects:</p><ul><li><a href="https://tbchart.xyz/"><strong>tbchart.xyz</strong></a> — the main landing page with payments and PnF rendering</li><li><a href="https://app.tbchart.xyz/"><strong>app.tbchart.xyz</strong></a> — the full-featured charting app with the TSuite engine</li></ul><p>Originally, I built a charting site using <strong>React.js + MUI Joy UI</strong>. It worked, but customizing it to TradingView-level quality was too difficult. I gave up and used it for my own trades.</p><p>Later, I experimented with a <strong>Next.js-based blog and finance portal</strong>, but it lacked traction and content. At some point (don’t ask me when), I dusted off the chart project, redesigned the home project using <strong>Tailwind CSS</strong>, and separated the full chart into its own repo again. Why? Too many MUI dependencies and chart submodules to cleanly merge them.</p><p>The upside? <strong>Single sign-on across both sites</strong>.</p><h3>Frontend Tech Stack</h3><ul><li><strong>Next.js + Tailwind CSS</strong> (for tbchart.xyz)</li><li><strong>React.js + Canvas renderer</strong> (for app.tbchart.xyz)</li><li><strong>Firebase Cloud Messaging</strong> for real-time TSuite alerts</li><li><strong>Stripe</strong> integration for payments</li></ul><h3>⚙️ Backend Overview</h3><p>TBChart’s backend is built around Firebase Functions and a Spring Boot app:</p><ol><li><strong>Historical Price Service</strong></li></ol><ul><li>Node.js + Firebase Functions</li><li>Aggregates price data from multiple sources (our secret sauce)</li></ul><p><strong>2. Stock Fundamentals Service</strong></p><ul><li>Node.js + Firebase Functions</li><li>Provides FA data (financial statements, ratios)</li></ul><p><strong>3. AI Analysis Service</strong></p><ul><li>Node.js + Firebase Functions</li><li>Uses FA data for long term investors</li></ul><p><strong>4. PnF Engine</strong></p><ul><li>Python + Firebase Functions</li><li>Generates Point &amp; Figure data with volume columns</li></ul><p><strong>5. API Core (Login, Alerts, Payments)</strong></p><ul><li>Java Spring Boot</li><li>Deployed on DigitalOcean</li></ul><h3>Why This Stack?</h3><ul><li><strong>Firebase</strong> is super easy to deploy, perfect for rapid iterations.</li><li><strong>Spring Boot</strong> fits my background — I’ve worked with Kotlin and Java for years.</li><li><strong>DigitalOcean</strong> makes SSL and deployment easier than AWS.</li><li><strong>Heroku</strong>? It’s great, but not work for crypto APIs.</li></ul><h3>🔧 Key Features Engineered</h3><ul><li><strong>Accurate Point &amp; Figure rendering</strong> with log scale + volume — most platforms fail at this, but it’s essential for Wyckoff traders.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b7gXwSQgK8oxEdIUWKzPSQ.jpeg" /><figcaption>PnF chart</figcaption></figure><ul><li><strong>TSuite goes headless</strong> — alerts and screeners without needing a chart open.</li><li><strong>Multi-source data abstraction</strong> — from crypto to US, HK, and VN stocks.</li><li><strong>Modular architecture</strong> — so we can plug in new data sources, indicators, or exchanges easily.</li></ul><h3>🧪 Challenges &amp; Lessons Learned</h3><ul><li>Budget was tight. So I learned to <strong>stretch free tiers</strong> and <strong>mix-and-match cloud tools</strong> to stay lean.</li><li>The tech stack is wide — I had to <strong>juggle everything from Kotlin and Java</strong>, to <strong>Python</strong>, to <strong>TypeScript</strong>.</li><li>Rendering the PnF chart was make-or-break — if it plotted wrong, my trading was affected.</li><li>I started with DOM rendering, but eventually moved to <strong>canvas</strong> for performance.</li><li>Adding volume support on top of PnF was a complex challenge that took time — but it paid off.</li></ul><h3>🔮 What’s Next</h3><ul><li>A more powerful screener and alert system.</li><li>Support for <strong>more exchanges</strong>, <strong>more asset classes</strong>.</li><li>A full backtesting engine to test TSuite strategies.</li></ul><h3>📣 Closing Thoughts</h3><p>If you’re a Wyckoff trader, you know how important the <strong>right chart</strong> is.<br>Most platforms aren’t built for this style of trading. So I built my own.</p><p>TBChart is still growing — but it already gives you a powerful combo:</p><ul><li><strong>Real Wyckoff charts</strong></li><li><strong>TSuite indicators</strong></li><li><strong>Alerts and screeners</strong></li></ul><p>👉 Try it today at <a href="https://tbchart.xyz/"><strong>tbchart.xyz</strong></a><br> Follow me here for future deep dives into our tech stack, from canvas rendering to real-time alerts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d0b41c764b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inside a trade alert system]]></title>
            <link>https://cuong-le.medium.com/inside-a-trade-alert-system-86eaa4f49728?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/86eaa4f49728</guid>
            <category><![CDATA[forex]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Sun, 13 Dec 2020 13:56:05 GMT</pubDate>
            <atom:updated>2020-12-13T13:56:05.904Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Disclaimer: Trading results in capital loss. Do your own due diligence before taking any action. Trade what you can afford to lose.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wtnfgC_vpUWrEpqPZzOJcw.jpeg" /></figure><h3>Context</h3><p>If we’re not in Vietnam, I think we all still work from home at the moment due to COVID-19. A few months ago, I watched a video on youtube in which the author emphasizes working home is a rare opportunity to improve ourselves, you need to pick up a skill where it helps you through economic downturn. I’ve started learning how to trade Forex since then. Recently, I found a trading method where we just buy at green dot and sell at red dot on enhanced MACD indicator. It’s simple, isn’t it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*tNg6hRbKfDX_yt7uAtCeHw.png" /><figcaption>GBPJPY H4</figcaption></figure><p><strong><em>Note</em></strong>: I’m not covering the detail on the trading method in this article.</p><h3>Problems</h3><p>That trading strategy is not hard. However, whenever there is either a red dot or a green dot, how do I get notified while I’m doing something? MT-based software will beep beep when there is a signal. It means I have to keep the computer on 24/5 (market time). If I’m away from it, I need to check up on the computer whether I miss anything every time. MT-based platform also provides a push functionality to your mobile. Before we continue, look at the image above again, not all dots are reliable entries. So I need to look at the chart to make a decision. Unfortunately, we don’t have the custom indicator on mobile devices.</p><p>I also share my trading journey with my inner circle. They are interested in learning from me. Teaching people learn to read chart, candle sticks seems impossible to me. So how do they can follow me easily at least when to buy or sell? The whole flow is a hassle for me to trade effectively.</p><p>Before jumping into the code, I wrote down all the problems to be solved below</p><h4>1. How do I keep the computer always on?</h4><p>In forex terms, people use VPS (a remote computer) to run a bot trading. Easily, I can use VPS to monitor my signal. I normally shut it down on Friday night to flush stale memory (recommended by VPS provider).</p><h4>2. How do I look at a chart on any devices?</h4><p>The only thing I came up with is just find a way to snapshot a chart and send it as an image. Fortunately, MT-based platform offers what I need</p><p>bool ChartScreenShot(long <em>chart_id</em>, string <em>filename</em>, int <em>width</em>, int <em>height</em>, ENUM_ALIGN_MODE );</p><p>While I worked on this, I realized the indicator can monitor a higher timeframe than the current timeframe. For example, if MT4 is open with a H4 chart, the indicator can monitor on both H4 and D1 chart at the same time. As the API screenshot provided above, it’s only able to snapshot an <strong><em>opening</em></strong> chart. I came up with a small trick. If there is a signal on a specific symbol at any given timeframe, I programmatically open a new chart window with that timeframe, do the screenshot and then close the window.</p><pre>long newChartId = ChartOpen(Symbol(), tf);</pre><pre>ChartNavigate(newChartId,CHART_END,0);</pre><pre>if(ChartScreenShot(newChartId,name,WIDTH,HEIGHT,ALIGN_RIGHT))<br>     {<br>      Print(&quot;We&#39;ve saved the screenshot &quot;,name);<br>      ChartClose(newChartId);<br>     }</pre><h4>3. How do I broadcast my signal?</h4><p>On my initial implementation, I used WebRequest to interact with backend. It doesn’t work on VPS machine for unknown reasons. Plus, it seems hard for me to upload the chart snapshot in C++ I mentioned above. Eventually, I found out that it’s feasible to launch an external program. I quickly wrote a small jvm program to escape from C++ realm.</p><pre>#include &lt;WinUser32.mqh&gt;<br>#import &quot;shell32.dll&quot;</pre><pre>int ShellExecuteW(int hwnd,const string operation,const string file,const string parameters,const string directory,int showCmd);</pre><pre>#import</pre><pre>...</pre><pre>int r = ShellExecuteW(0,&quot;Open&quot;, program_path, params,NULL,5);</pre><p>program_path is location to external program</p><p>params is value you will get in args in jvm program</p><p>I use Cloudinary as a CDN to host chart snapshot image. When upload is completed with an image url, I make a POST request to backend.</p><pre>try {<br>    val url = fileUploader.upload(file)<br>    val updateSignal = signal.copy(chartUrl = url)<br>    signalRepository.create(updateSignal)<br>} catch (e: Exception) {<br>    logger.warn(&quot;error while uploading &quot; + e)<br>}</pre><p>Backend makes record of the signal in CloudStore then broadcasts the alert to messaging apps. The whole flow is visualized below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/1*ABEBpBD8BSywg3FavHJvtg.png" /></figure><h4>4. How do I minimize the maintenance cost?</h4><p>It’s unavoided to pay the VPS fee. However, I want to minimize the cost for this system as much as possible. There are some candidates such as CloudFunction, Heroku. I go with Heroku because of my expertise in Spring Framework. Free Heroku just gives 550 hours a month. If we add a credit card, we have another 450 hours. See more <a href="https://devcenter.heroku.com/articles/free-dyno-hours">here</a>. A basic math</p><p>30*24 = 720h &lt; 550 + 450 = 1000h</p><p>Literally, I have a free backend host. However, it’s not that easy. The free dyno will be in sleep mode every 30 minutes. I simply just ping the server every 25 minutes by another free service which is CloudFunction.</p><pre>exports.scheduledFunction = functions.pubsub.schedule(&#39;every 25 minutes&#39;).onRun((context) =&gt; {</pre><pre>axios<br>        .get(&#39;endpoint&#39;)<br>        .catch((err: any) =&gt; {<br>            if (err !== undefined) {<br>                bot.sendMessage(TELEGRAM_ID, &quot;Server ping error&quot;);<br>            }<br>        });<br>    return null;<br>});</pre><p>If any error while pinging the Heroku server, a message will be sent to my telegram</p><h4>Result</h4><p>It’s always happy to see my code helping me making more money.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*eY9oD1Wm_L2YXshcLCcfGQ.png" /></figure><h3>Closing thought</h3><p>The system is still in its in fancy, there is plenty of room for me to improve in the future. It was kind of hackathon project I had to finish during the weekend before the market opens. The project was intriguing to me after a failure of <a href="https://play.google.com/store/apps/details?id=com.memoir">Memoir</a>. Coding is a problem-solving process in which you walk through your thought and connect pieces to a big puzzle. For new people in MT platform, I suggest to read its documentation instead of asking on forums. It saves you more time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86eaa4f49728" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Phu Quoc Island through the eyes of a Software Engineer]]></title>
            <link>https://cuong-le.medium.com/phu-quoc-island-through-the-eyes-of-a-software-engineer-6164bd280a7?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/6164bd280a7</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[travel]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Sun, 08 Sep 2019 13:34:16 GMT</pubDate>
            <atom:updated>2019-09-08T13:44:50.993Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I had a chance to travel back to Vietnam a few months ago. My family, my best friend and I decided to go to Phu Quoc for our vacations. While visited the island, I came up with an idea of building a new app.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/0*YQwkrVqeI55dlLiw" /><figcaption>Our group arrived at the resort</figcaption></figure><h3>Getting the idea</h3><p>My new app Phu Quoc Island is designed to help you relax, focus and sleep better. You can take a trip to this tropical island anywhere you are, whenever you like and listen to a guided meditation or experience the island by yourself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vIKbDNSF1YUS9-u-.jpg" /><figcaption>The resort where we stayed</figcaption></figure><p>Our group loved walking along the beaches, and enjoy the feeling of the fresh sea wind on our faces. The blue sea is absolutely stunning, the sound of the waves crashing on the rocks amazing. The whole island vibe made me feel so relaxed after the stress of debugging. At night, my friend and I had a fireside chat while the other members were sleeping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*HH9j6vaepX0hD9ki" /><figcaption>Minh and I were having a fireside chat</figcaption></figure><p><strong>Me</strong>: “<em>Hey Minh, I wanted to take this island vibe home.</em>”</p><p><strong>Minh</strong>: “<em>As an ex-Google software engineer, you can build an app about this</em>”</p><p>Wouldn’t it be lovely if we could just get this vibe, this feeling, wherever we were? It would be great if you could just feel like you were on one of Phu Quoc’s beaches for just a while after a busy work day, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s1CILmL04y6vDmqZTmN4Kw.png" /><figcaption>Sketch on Note 9</figcaption></figure><p>We had our discussion throughout the night. We took out our Note 9 to sketch and write down some initial concept. Besides scribbles and quick drawings we took pictures of everything we thought was important; specific color combinations, sunsets, sunrises… We used the hotel where we stayed as a starting point, we just let our imagination run freely. Using all this as a mood board, we started creating our own unique island, unlike any other island. Of course, the next day we were so drowsy while the other members enjoyed the trip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/384/1*pVSYGBN-ligA2FpYMn8nuA.jpeg" /><figcaption>Minh was sleeping on the bus</figcaption></figure><p>Check it out our app at</p><p><a href="https://play.google.com/store/apps/details?id=com.ctech.phuquocisland">PhuQuoc Island - Apps on Google Play</a></p><h4>Note</h4><p>I’d like to thank @Note9, @Chee.Chee to help me bring this project to life</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6164bd280a7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I made $3750 within a week]]></title>
            <link>https://cuong-le.medium.com/how-i-made-3750-within-a-week-eaaf5a58e5cc?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaaf5a58e5cc</guid>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Tue, 30 Jul 2019 15:44:50 GMT</pubDate>
            <atom:updated>2019-07-31T07:14:10.173Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A couple of days ago I completed the sale of <strong>Live Message</strong>. In this article, I wanted to share what I built, why I decided to sell the project.</blockquote><h3>Why I started a side project?</h3><p>When I start a side project, I usually have a clear reason to do so. The reasons can vary, from wanting to learn a new technology or to solve a problem I’m experiencing.</p><p><strong>Live Message</strong> had a bit of an unusual start. Back in 2017, when Samsung released <strong>Note 8</strong>, <strong>Live Message,</strong> which is exclusive for Note series, really caught my attention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*tpq37Sr4l418B_2cTqiBxw.gif" /></figure><p>Aww, that looks so cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/0*37Bo5WK9c6jynn10" /></figure><p>I asked myself as an Android Engineer how did they do it. Till February 2018, when people went on <strong>Tet</strong> holidays, I just stayed home spending 16 hours a day for 2 weeks on bringing a clone of <strong>Live Message</strong> to life. Eventually, I made it. After a few weeks, I left Vietnam with my team. After having settled down in Bangkok, it’s where I first published <strong>Live Message</strong> to Play Store.</p><h3>Reacting to the Launch</h3><p>I built an MVP of the app in 2 weeks, and launched the app in March of 2018. While at work, I randomly checked my Play Store account, I was blown away with the response I received. There were some numbers. That was the first money I ever made by In-App purchase. I was so happy.</p><p>I drew a roadmap for it and tried to achieve it.</p><ul><li>In June 2018, Instant App was added (link <a href="https://medium.com/@Cuong.Le/live-message-goes-instant-7f6fbb199366">https://medium.com/@Cuong.Le/live-message-goes-instant-7f6fbb199366</a> )</li><li>In October 2018, after having moved to Singapore with a new job, I kept it update to Note 9 version (link <a href="https://medium.com/@Cuong.Le/whats-new-in-live-message-872f64549747">https://medium.com/@Cuong.Le/whats-new-in-live-message-872f64549747</a> )</li><li>In March 2019, it stepped out of shadow of the original app, AR was supported</li></ul><h3>Exploring Options</h3><p>While the advertising and IAP revenue were nice in 2018, it tends to drop in early 2019. It wasn’t enough to pay me to work full time. What could I do to expand the app, to add new features that users might want to use, and to pay for.</p><p>I came up with a few ideas, but they are time-consuming, I lacked of resources to optimise on low-end phones and marketing.</p><h3>Looking for Partners</h3><p>There are a lot of Android OEMs but only Samsung Note has a pen to leverage to the app. Although I had a number of promising conversations with companies from all over the world, proving once again but nothing concrete materialised.</p><h3>Deciding to Sell</h3><p>Although I had explored ways to expand the app, I could simply have let it run as it was. The app kept bringing in visitors all by itself, mostly as a result of the great launch I had. Eventually though with no update, no promotion this would have stopped.</p><p>If the app was to continue to be a success it needed to be updated, to be promoted, to grow. If this wasn’t going to happen with me, then it would have to be under new ownership. I just wanted the app to continue to be a success.</p><p>Maintaining the app didn’t take a lot of time, but having a popular app with a lot of potential burns a lot of mental energy. I was constantly thinking about the app, how it could be grown. This played a big part in my decision to sell. I wanted to remove this mental expense, to free up my mind to focus on other projects where my time could be better spent.</p><h3>Making the Sale</h3><p>When it first launched, it started $3000. After a week, there weren’t too much interaction. I listed down to $2500. The second week passed, there was 1 bid. then second, third bid came at $2700. In the third week, somehow <strong>Live Message</strong> was marked as editor choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*nmK3S6zIQnL2pit-OX2Clw.png" /></figure><p>A number of people reached out to me about acquiring the app increased significantly. Ultimately, when all negotiations appeared to have stalled, I did find a buyer willing to buy it at $3750.</p><p>I think I got a fair price, and hope the buyer thinks they did too.</p><p>I know the app will continue to be a success under new management.</p><h3>Final Stats</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/0*4-8gDAhf5cOP2Anh.png" /><figcaption>Revenue for the whole year of 2018</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*pCJNJuZAcXiOceafj46c6Q.png" /><figcaption>Payment received</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaaf5a58e5cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recreating the Facebook Messenger Gradient Effect]]></title>
            <link>https://cuong-le.medium.com/recreating-the-facebook-messenger-gradient-effect-52a1b17c0c3f?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/52a1b17c0c3f</guid>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[messenger]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Tue, 09 Apr 2019 13:07:07 GMT</pubDate>
            <atom:updated>2019-05-06T22:12:01.642Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A few weeks ago, Facebook released a new feature. When I tapped into Messenger, pretty soon my attention went from the actual conversations to the funky gradient effect of the message bubbles containing them. This is a new feature of Messenger, which allows you to choose a gradient instead of a plain color for the background of the chat messages. I was so amazed. Ever since then I have always asked myself how Facebook engineers made that. In this article, I will walk through my thought process as I attempted to recreate it and explain Android API used to make it work.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ig8kDUn0ctPEMIKK.png" /></figure><h3>Analysis</h3><p>First, let’s look at the example again to see what exactly it is that we’re trying to achieve here.</p><p>In general, we have a pretty standard messaging layout: messages are divided into bubbles going from top to bottom, ours on the right and the other people in the chat on the left. The ones on the left all have a gray background color, but the ones on the right look like they’re sharing the same fixed background gradient. Before I figured out it is just fixed background gradient , I have asked around my peers. Most of them suggested to have an algorithm to generate a gradient for each ViewHolder . That sounds hard and not performant to me because when the list is scrolled, the bubble color keeps changing. Then on a beautiful, when I chatted with my friend, I saw a bug from Facebook web</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*4YyMYtDjPzG0KQhhNW_aWg.png" /></figure><p>hmm. Do they just have a gradient in the back and a mask in the front? Off the top of my head I visualized something</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*aHTCcIX5ugVGsPA8PWYqtQ.gif" /></figure><p><strong>(Updated May 1st 2019)</strong></p><p>I added a new gifs. It’s made easier to visualize</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*tJL2nMAKVlWHCv7YXSZhMw.gif" /><figcaption>F8 2019</figcaption></figure><p>Bingo.</p><p>The main idea is the gradient ViewHolder row has a white background and a hole <strong><em>beneath</em></strong> the text content. I will just focus on this particular ViewHolder .</p><h3>Set up the layout</h3><pre>&lt;shape<br>  xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;<br>  &lt;gradient<br>    android:angle=&quot;270&quot;<br>    android:centerColor=&quot;@color/center_color&quot;<br>    android:endColor=&quot;@color/end_color&quot;<br>    android:startColor=&quot;@color/start_color&quot;<br>    android:type=&quot;linear&quot;/&gt;<br>&lt;/shape&gt;<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/215/1*cA5UT7A6DrSHqYHZtKlb-Q.png" /><figcaption><em>chat_background</em><strong><em>.</em></strong><em>xml</em></figcaption></figure><p><strong><em>activity_chat.xml</em></strong></p><pre>&lt;androidx.constraintlayout.widget.ConstraintLayout<br>...&gt;</pre><pre>&lt;ImageView<br>  android:id=&quot;@+id/ivBackground&quot;<br>  android:layout_height=&quot;0dp&quot;<br>  android:layout_width=&quot;match_parent&quot;<br>  app:layout_constraintBottom_toTopOf=&quot;@+id/llInput&quot;<br>  app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>  app:layout_constraintStart_toStartOf=&quot;parent&quot;<br>  app:layout_constraintTop_toBottomOf=&quot;@+id/toolbar&quot;/&gt;</pre><pre>&lt;androidx.constraintlayout.widget.ConstraintLayout/&gt;</pre><p>We will use ConstraintLayout for the chat bubble</p><p><strong><em>item_outgoing_image_message.xml</em></strong></p><pre>&lt;com.ctech.messenger.widget.BackgroundAwareLayout <br>  android:layout_width=&quot;match_parent&quot;<br>  android:layout_height=&quot;wrap_content&quot;<br>  ..<br>  android:background=&quot;@color/white&quot;<br>  app:child_id=&quot;@id/tvContent&quot;<br>  &gt;<br><br>&lt;TextView<br>  android:id=&quot;@id/tvContent&quot;<br>  android:layout_width=&quot;wrap_content&quot;<br>  android:layout_height=&quot;wrap_content&quot;<br>  ...<br>  app:layout_constraintEnd_toEndOf=&quot;parent&quot;<br>  app:layout_constraintTop_toTopOf=&quot;parent&quot;/&gt;</pre><pre>  &lt;TextView<br>    android:id=&quot;@id/tvTimeStamp&quot;<br>    android:layout_width=&quot;wrap_content&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    .../&gt;<br><br>&lt;/com.ctech.messenger.widget.BackgroundAwareLayout&gt;</pre><p>BackgroundAwareLayout is a custom ConstraintLayout . To cut a hole, we need to know the position and the size of the content. It is more reusable when we provide a child reference app:child_idthrough xml attribute than findViewById in the class.</p><p>BackgroundAwareLayout.kt</p><pre>private fun setup(attrs: AttributeSet) {</pre><pre>    val ta = <em>context</em>.obtainStyledAttributes(attrs, R.styleable.<em>BackgroundAwareLayout</em>)<br>    this.childId = ta.getResourceId(R.styleable.<em>BackgroundAwareLayout_child_id</em>, 0)<br> <br>    if (this.childId != 0) {<br>        ta.recycle()<br>        return<br>    }<br>    throw IllegalArgumentException(&quot;unable to find childId to create a hole&quot;)<br>}</pre><pre>override fun onViewAdded(view: View) {<br>    super.onViewAdded(view)<br>    if (view.<em>id </em>== this.childId) {<br>        this.childView = view<br>    }<br>}</pre><p>Next step, we create an eraser to remove a portion of white background where the text context is</p><pre>private fun setupEraser() {<br>    eraser = Paint()<br>    eraser.<em>color </em>= ContextCompat.getColor(<em>context</em>, android.R.color.<em>transparent</em>)<br>    eraser.<em>xfermode </em>= PorterDuffXfermode(PorterDuff.Mode.CLEAR)<br>    eraser.<em>isAntiAlias </em>= true<br>    setLayerType(View.<em>LAYER_TYPE_HARDWARE</em>, null)<br>}</pre><p>It’s straightforward. One thing to note even though hardwareAccelerate is enabled by default, we have to call setLayerType(View.<em>LAYER_TYPE_HARDWARE</em>, null) . Then, we can draw a transparent background to see the gradient background.</p><pre>override fun onDraw(canvas: Canvas) {<br>    super.onDraw(canvas)<br>    childRect.set(childView.<em>left</em>.toFloat(), childView.<em>top</em>.toFloat(),<br>            childView.<em>right</em>.toFloat(), childView.<em>bottom</em>.toFloat())<br>    canvas.drawRoundRect(childRect, radius, radius, eraser)<br>}</pre><p>childRect is just a helper for (left,top,right,bottom) when I tried some testings during the implementation. We’re done!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*VgRx4f0JY_6rcP6dja5TzA.png" /></figure><p>Hold on. The world isn’t so easy. Take a look at Messenger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*f1QSX-xeaGaTgJTUctv9mw.gif" /></figure><p>and ours</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*r8WgeeTKoVI0DbRbzguSCg.gif" /></figure><p>There are two issues:</p><ol><li>The list needs to scroll to the bottom. We can achieve by rvMessages.layoutManager!!.scrollToPosition(adapter.itemCount — 1)</li><li>The color at the bottom is purple not light blue. When the keyboard shows up, the windows is resized to give space to the keyboard. This causes the content of ivBackgroundto scale accordingly.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*eZG_6Wa4s2RPXpevf22P3g.gif" /></figure><p>To solve this problem, the original gradient background has to be cropped by the height of the keyboard.</p><pre>ivBackground.<em>doOnLayout </em><strong>{<br>    </strong>if (!::backgroundBitmap.<em>isInitialized</em>) {<br><em>        </em>val background = ContextCompat.getDrawable(this, R.drawable.<em>chat_background</em>) as GradientDrawable<br>        background.setSize(<strong>it</strong>.<em>width</em>, <strong>it</strong>.<em>height</em>)<br>        backgroundBitmap = background.<em>toBitmap</em>()<br>        ivBackground.setImageBitmap(backgroundBitmap)<br>    }<br><strong>}</strong></pre><p>After the first layout pass, we create a cached bitmap of the background. We change to ImageView to KeyboardAwareImageView</p><pre>ivBackground.setKeyboardListener(object : OnKeyboardShowHideListener {<br>    override fun onToggle(visible: Boolean, height: Int) {</pre><pre>        if (::backgroundBitmap.<em>isInitialized</em>) {<br>            if (visible) {<br>                val cropped = cropBitmap(backgroundBitmap, Rect(0, 0, ivBackground.<em>width</em>, height))<br>                ivBackground.setImageBitmap(cropped)<br>            } else {<br>                ivBackground.setImageBitmap(backgroundBitmap)<br>            }<br>        }<br>    }<br><br>})</pre><p>When the keyboard is visible with the available height of the window, we crop the cached bitmap. Let see our effort 🎉🎉</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*QnlzRhaSPEP-3SRuTY1nLQ.gif" /></figure><p>The source code can be found <a href="https://github.com/dbof10/messenger-theme/tree/master">here</a></p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYxBP_WV7LI6zc-zdUkNqQ.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52a1b17c0c3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open sourcing Bitmp4]]></title>
            <link>https://cuong-le.medium.com/open-sourcing-bitmp4-1e7517e5462f?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e7517e5462f</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Sat, 27 Oct 2018 15:58:13 GMT</pubDate>
            <atom:updated>2018-10-27T16:25:54.364Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the challenge is to reserve image quality when exporting a live message. Due to gif limitation, we planned to adopt APNG, WEBP. However, they are not widely used in most popular messenger apps. The team ended up going with mp4 format.</p><h4>Motivation</h4><p>With an existing infrastructure, we already have an <strong>Encoder</strong>, whose method addFrame(bitmap) gets called every <strong>33ms,</strong> converts a list of bitmaps to a gif backed by a native gif encoder engine. To support video, we only need to add a video encoder engine. Unfortunately, we weren’t able to find a turnkey solution. During our search we got acquainted with some libraries we’d like to tell you about them.</p><h4>Jcodec</h4><p>The library seems fine. However, it is purely Java. When it comes to performance, you’ll mostly have to deal with JNI and C++ code.</p><h4>FFmpeg</h4><p>FFmpeg is well known for processing for video and audio. Looking at its API, it requires a list image files at encoding time. We can’t really rely on ffmpeg because our application generate bitmaps every <strong>33ms</strong>.</p><h4>Grafika</h4><p>This is not a library but a playground with Android media API. It’s quite hard to understand without Android graphic knowledge. We decided to invest time to get insight from <a href="https://github.com/google/grafika/blob/master/app/src/main/java/com/android/grafika/GeneratedMovie.java">this example</a>. Eventually, we managed to get it worked.</p><h4>Conclusion</h4><p>We hope that open-sourcing <strong>Bitmp4</strong> will provide a useful library for other engineers working on mobile applications. We look forward to seeing what the community will create, and over the coming months.</p><p>Check out our source <a href="https://github.com/dbof10/Bitmp4">https://github.com/dbof10/Bitmp4</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e7517e5462f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in Live Message?]]></title>
            <link>https://cuong-le.medium.com/whats-new-in-live-message-872f64549747?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/872f64549747</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[gif]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Sun, 23 Sep 2018 15:12:34 GMT</pubDate>
            <atom:updated>2018-09-24T13:29:48.201Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Our mission is to embellish the way people vent their feelings to the one they care through message. From “LOL” to “I love you,” you can express yourself in countless visual ways when you’re conversing with your friends. Today, we’re introducing the new UI overhaul and new brushes on Live Message.</blockquote><h4>Gradient framework</h4><p>As our engineers have overcome their technical debt, the new render architecture allows us more artistic freedom. With that being said, instead of a lame solid color background previously, we now can replace that with a vibrant background either <strong><em>gradient</em></strong> or <strong><em>animated GIFs</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqhlv9N86RhjXMBHHKbLJg.jpeg" /></figure><h4>Background color, photo chooser</h4><p>We bring background and photo choosers to the front to make it for navigation and reduce context switching between the canvas and the choosers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*R6l1dTyxCa754tghgqI1Vg.jpeg" /><figcaption>Color background chooser</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*dfzvxhxTR3MXhLfntU99yQ.jpeg" /><figcaption>Photo chooser</figcaption></figure><h4>Particle framework</h4><p>As stated earlier, the new technical improvement put your creativity to the next level. We added three new brushes <strong>Heart, Snow, Gradient. </strong>With the first two, your strokes are made to animated within a small of time. Is it amazing, isn’t it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wXdBcoC0qNjHrPsnouHd-g.gif" /><figcaption>Snow brush</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*bxjS3ktKYFa5Y7AQkjauvA.gif" /><figcaption>Gradient brush</figcaption></figure><h4>Color picker</h4><p>At Live Message, we care about our users. We’re open to your feedback. Color picker is one of the top voted requested feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*-LpeHhKaLS2zP8CUhhTrGA.jpeg" /></figure><h4><strong>MP4 video</strong></h4><p>We’re excited to add <strong>MP4</strong> encoder to the platform. This help us stay away from <strong>GIF</strong> 256 colors limitation. In addition, we will allow audio to the background which make your live message really enjoyable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*uE_WrT3Tum0mUukt84d1Hw.jpeg" /><figcaption>MP4 format on the left</figcaption></figure><p>🎉Happy Mid-Autumn Festival 🎉</p><p>Check it out at <a href="https://play.google.com/store/apps/details?id=com.ctech.livemessage">https://play.google.com/store/apps/details?id=com.ctech.livemessage</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=872f64549747" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Live Message goes instant]]></title>
            <link>https://cuong-le.medium.com/live-message-goes-instant-7f6fbb199366?source=rss-655b3a4cc3aa------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f6fbb199366</guid>
            <category><![CDATA[instant-apps]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[dagger]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Cuong Le]]></dc:creator>
            <pubDate>Sat, 23 Jun 2018 03:35:33 GMT</pubDate>
            <atom:updated>2018-06-23T09:29:33.724Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P54PKm2khGzuo4w2zAVDpg.png" /></figure><blockquote>After having watched Google I/O 2018, we decided to invest in supporting Instant App. In this article, we will cover the experience how we went from a monolithic project to multi-modules project and benefits Instant App brings to us.</blockquote><h3>Live Message and our instant app concept</h3><p>Before we take a deep dive, we’ll tell you something about our product. Use Live Message feature to draw your own emojis or write handwritten messages on photos then make animated GIFs. Technically speaking, what drawn on the canvas is recorded and play back. Because we want users to get acquainted and play with the app first, instant app is an opportunity for us to offer users an easy way to install our main app.</p><h3>Structure &amp; plan</h3><p>After deciding to develop an instant app we sat down and started brainstorming how to divide modules. The app at the time mainly had one module. We changed this to a base feature and extracted all necessary code into specific modules. Our modules would look like this:</p><ul><li>base: base feature containing core drawing code</li><li>export: code as an entry point to use base module with export GIFs native library</li><li>preview: another entry point without export engine</li><li>installed: installable app build.gradle</li><li>instant: instant app build.gradle</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s0uhrdf19cMJn7nlcWo_Bw.png" /><figcaption>Pink block is future plan</figcaption></figure><p>It was time-consuming to pull out code and resources out of the base feature. During this whole process of extracting code the project wouldn’t always compile. We were working through different compile errors and runtime errors until we got a stable version. One important thing to note that if you reference to resources from the base module, you have to import R as feature package. So <em>com.example.app.R</em> would become <em>com.example.app_feature.R</em> for example. Importing wrong R package leads to clueless compilation error message.</p><h3>Dagger</h3><p>Getting Dagger to work was most frustrating part. We have to provide a custom ActivityInjector to make this work for Dagger Android. The problem is that the default implementation relies on the Map&lt;Class&lt;? extends T&gt;, Provider&lt;AndroidInjector.Factory&lt;? extends T&gt;&gt;&gt; to be known statically when the application is created. That isn&#39;t the case for InstantApps because not all activities are loaded yet. We found a few feasible solutions. The best one we chose looks like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/757/1*WL1GD5fSD-1mI53Z_ZIBzw.png" /><figcaption>Dagger code for a single feature</figcaption></figure><h3>Unsupported<strong> features</strong></h3><p>We couldn’t find a list of features that AIA doesn’t support. We ran into some cases we noted below</p><ol><li>Access to <a href="https://developer.android.com/reference/android/provider/Settings">Settings</a> class</li></ol><p>java.lang.SecurityException: ContentProvider request not available to instant apps: settings:GET_global</p><p>2. Query from ContentResolver</p><p>java.lang.NullPointerException: Attempt to invoke interface method ‘boolean android.database.Cursor.moveToFirst()’ on a null object reference</p><p>3. Runtime permission</p><p>IActivityManagerProxy : Instant app: com.ctech.livemessage crashed: java.lang.SecurityException: Not allowed to start activity Intent { act=android.settings.APPLICATION_DETAILS_SETTINGS</p><h4>Fabric</h4><p>To enable Crashlytics for all feature modules, we need to set up for the <em>base</em> module.</p><p><strong>base/build.grade:</strong></p><pre>android {<br>  ...<br>}</pre><pre><strong>crashlytics { instantAppSupport true }</strong></pre><pre>dependencies {<br>  ...<br>}</pre><p>You can use Fabric’s <a href="https://docs.fabric.io/android/crashlytics/enhanced-reports.html#custom-keys">custom keys</a> feature to add instant app information to your reports. This information can be very helpful while reading your reports afterwards. To do that, set a boolean value while initializing Fabric:</p><pre>private fun initCrashlytics() {<br>    Fabric.with(this, Crashlytics())<br>    <strong>Crashlytics.setBool(&quot;InstantApp&quot;,     <br>        InstantApps.isInstantApp(this))</strong><br>}</pre><p>One takeaway lesson is that you have to apply plugin: &#39;io.fabric&#39; for <strong>both</strong> base and installed module. We encountered a serious issue with this mistake. Our users emailed us to complain about a new update with constant crash. It stroke us odd that we didn’t receive any warning from Crashlytics. We debugged by enabling Crashlytics for debug build and got an error below</p><pre>Caused by: io.fabric.sdk.android.services.concurrency.UnmetDependencyException: This app relies on Crashlytics. Please sign up for access at <a href="https://fabric.io/sign_up">https://fabric.io/sign_up</a>,<br> install an Android build tool and ask a team member to invite you to this app’s organization.</pre><h3>App Links</h3><p>We thought after fixing above issues, we could be published on Play Store. However, before we actually got to a successful upload we ran into multiple issues with our app.</p><pre>1. You should have at least one active APK that is mapped to site ‘livemessageapp.com’ via a web ‘intent-filter’.</pre><p>It was fixed by adding url for the installable APK. It meant we added an url for export module.</p><p>2. You must provide a default URL for your instant app APKs</p><p>This is a must. Your instant APK must contain a default URL. Adding</p><pre>&lt;meta-data<br> android:name=&quot;default-url&quot;<br> android:value=&quot;https://livemessageapp.com/preview&quot;/&gt;</pre><p>to the preview module solved the problem.</p><pre>3. Your site &#39;www.livemessageapp.com&#39; has not been linked through the Digital Assets Link protocol to your app. Please link your site through the Digital Assets Link protocol to your app.</pre><p>This error was the most annoying. After uploading assetlinks.json to the host, the error still occurred. We didn’t know what went wrong. After a few hours researching, here are the things we learn</p><ul><li>Using app signing key over upload key</li><li>Although we passed the <a href="https://developers.google.com/digital-asset-links/tools/generator">test</a>, it didn’t work still.</li><li>We tried to use web API presented in this <a href="https://developer.android.com/training/app-links/verify-site-associations#web-assoc">link</a> to debug. It threw us a clueless error message which cannot even find in the <a href="https://developers.google.com/digital-asset-links/v1/errors/core_errors">doc</a>. Fortunately, we found a great <a href="https://github.com/google/asset-check">tool</a> for this issue. In our case, our <a href="https://livemessageapp.com/">livemessageapp.com</a> was redirected to www.<a href="https://livemessageapp.com/">livemessageapp.com</a>. If you use Firebase, it’s an easy fix</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*pgrHGUSBXyLpOB8mO4-ZZA.png" /></figure><h3>Proguard</h3><p>We had silence crashes after having made it to Play Store. It failed before reaching to Crashlytics setup. We enabled Proguard for debug build and encounter a log</p><pre>java.lang.RuntimeException: Unable to instantiate activity ComponentInfo: java.lang.ClassNotFoundException: could not find com.xxx.LiveDrawingPreviewActivity in any atom class loader or parent class loader</pre><p>It turned out that Proguard doesn’t work for multi-feature instant app until <strong>Android Studio 3.2 Canary 14. </strong>At the time of this writing, we use AS 3.2 beta 1. Everything works just fine.</p><h4>A side note after upgrading to build tool 3.2 beta 1</h4><p>Previously instant app version was marked by <strong>base and feature module. </strong>It now relies on <strong>installed module </strong>regardless.</p><h3>Conclusion</h3><p>Building instant app was not a one way win for us, it has benefits beyond instant app. Our project structure was expanded to a way that made it more modular and efficiently organized. It would make more senses for us to integrate AR mode as <a href="https://developer.android.com/guide/app-bundle/configure">dynamic feature</a>.</p><p>These changes and improvements did not only make instant app possible, but also brought a lot of value to and refreshed the look of the Live Message app.</p><p>We hope you like our developer story. Please let us know what you think! There are more developer stories coming.</p><p>Try it at</p><p><a href="https://livemessageapp.com/preview">https://livemessageapp.com/preview</a></p><p>References</p><p><a href="https://stackoverflow.com/questions/46231746/multi-feature-instant-apps-cant-be-proguarded">https://stackoverflow.com/questions/46231746/multi-feature-instant-apps-cant-be-proguarded</a></p><ul><li><a href="https://developer.android.com/training/app-links/verify-site-associations">Search results - Android Help</a></li><li><a href="https://stackoverflow.com/questions/50744899/dagger-2-with-instant-app">Dagger 2 with Instant App</a></li><li><a href="https://stackoverflow.com/questions/50776063/instant-app-modularization">Instant App modularization</a></li></ul><p><a href="https://github.com/felipehjcosta/kotlin-rxjava-android">https://github.com/felipehjcosta/kotlin-rxjava-android</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f6fbb199366" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>