forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'tonykakuuu/master' into app-loader
- Loading branch information
Showing
8 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.01: New App! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# txtreader | ||
|
||
Very basic text reader with an integrated file selector. | ||
|
||
## Features | ||
|
||
- select files from storage (.txt) | ||
- display their contents | ||
- browse pages | ||
|
||
## Controls | ||
|
||
Bangle.js 2 | ||
- tap the right side of the screen to flip to the next page | ||
- tap the left side of the screen to flip to the previous page | ||
- exit by pressing the physical button | ||
|
||
## Creator | ||
|
||
<https://topkekker.rip/> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
function showFileSelector() { | ||
let files = require("Storage").list().filter(f => f.endsWith('.txt')); | ||
|
||
let menuItems = {}; | ||
files.forEach(file => { | ||
menuItems[file] = () => { | ||
E.showPrompt(`Select ${file}?`).then(confirm => { | ||
if (confirm) { | ||
onFileSelected(file); | ||
} else { | ||
showFileSelector(); | ||
} | ||
}); | ||
}; | ||
}); | ||
|
||
menuItems['< Back'] = () => { load(); }; | ||
E.showMenu(menuItems); | ||
} | ||
|
||
function onFileSelected(file) { | ||
const chunkSize = 1024; | ||
let currentOffset = 0; | ||
let currentPage = 1; | ||
let history = []; | ||
|
||
function displayText(offset, pageNumber) { | ||
g.clear(); | ||
g.setFont("6x8", 1); | ||
g.setColor(1); | ||
g.drawString("Page " + pageNumber, 10, 2); | ||
//g.drawString("Offset " + offset, 60, 2); | ||
g.drawString(file, g.getWidth() - file.length * 6, 2); | ||
|
||
var text = require("Storage").read(file, offset, chunkSize); | ||
var lines = text.split("\n"); | ||
var y = 15; // Text start, top row reserved for page number | ||
var linesDisplayed = 0; // Lines per page | ||
var totalCharsDisplayed = 0; // Total characters per page | ||
|
||
for (var i = 0; i < lines.length; i++) { | ||
var wrappedLines = g.wrapString(lines[i], g.getWidth() - 20); | ||
for (var j = 0; j < wrappedLines.length; j++) { | ||
g.drawString(wrappedLines[j], 10, y); | ||
y += 10; // Move down for the next line | ||
linesDisplayed++; | ||
totalCharsDisplayed += wrappedLines[j].length + (j < wrappedLines.length - 1 ? 0 : 1); // Add newline character for the last wrapped line | ||
if (y >= g.getHeight() - 10) { | ||
// If we run out of space, stop drawing | ||
return { nextOffset: offset + totalCharsDisplayed, linesDisplayed: linesDisplayed }; | ||
} | ||
} | ||
} | ||
return null; // No more lines to display | ||
} | ||
|
||
// Initial display | ||
var result = displayText(currentOffset, currentPage); | ||
history.push({ offset: currentOffset, linesDisplayed: result.linesDisplayed }); | ||
|
||
// Handle touch events | ||
Bangle.on('touch', function(button) { | ||
if (button === 2) { // Right side of the screen (next page) | ||
var nextOffset = displayText(currentOffset, currentPage + 1); | ||
if (nextOffset !== null) { | ||
currentOffset = nextOffset.nextOffset; | ||
currentPage++; | ||
history.push({ offset: currentOffset, linesDisplayed: nextOffset.linesDisplayed }); | ||
displayText(currentOffset, currentPage); | ||
} else { | ||
currentOffset = 0; | ||
currentPage = 1; | ||
history = [{ offset: currentOffset, linesDisplayed: result.linesDisplayed }]; | ||
displayText(currentOffset, currentPage); | ||
} | ||
} else if (button === 1) { // Left side of the screen (previous page) | ||
if (currentPage > 1) { | ||
history.pop(); // Remove current page from history | ||
var previousPage = history[history.length - 1]; | ||
currentOffset = previousPage.offset; | ||
currentPage--; | ||
displayText(currentOffset, currentPage); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
showFileSelector(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"id": "txtreader", | ||
"name": "txtreader", | ||
"shortName": "txtreader", | ||
"version": "0.01", | ||
"description": "Basic text reader with pages and a file selector.", | ||
"icon": "txtreader.png", | ||
"screenshots": [{"url":"screenshot_txtreader.png"}], | ||
"tags": "app,tool", | ||
"supports": ["BANGLEJS2"], | ||
"readme": "README.md", | ||
"storage": [ | ||
{"name":"txtreader.app.js","url":"app.js"}, | ||
{"name":"txtreader.img","url":"app-icon.js","evaluate":true} | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.