Skip to content

Commit a92b038

Browse files
committed
Stub: Splash pic, fix class u won't flush()
1 parent 017c861 commit a92b038

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//Shows welcome anim

app/src/main/assets/libs/fetchFortune.bshL

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,30 @@ nfzurl = "https://api.nfz.moe/paranoia/";
55

66
import java.net.URL;
77

8+
me.Import("libs/getAssets");
9+
810
//don't forget to set fortune var !
911
String fetchFortune(int type) {
1012
if (type == lwl) {
1113
fortune = lwlFortune();
12-
return fortune;
1314
}
1415
else {
1516
fortune = nfzFortune();
16-
return fortune;
1717
}
18+
saveFortune(fortune);
19+
return fortune;
20+
}
21+
22+
void saveFortune(String txt) {
23+
try {
24+
FileWriter fw = new FileWriter(assetPath("fortune"), true);
25+
BufferedWriter bw = new BufferedWriter(fw);
26+
PrintWriter out = new PrintWriter(bw);
27+
out.println(txt);
28+
//complain: WTF StackOverFlow gives... I think and think.... emmmm, I haven't call flush().......
29+
out.flush();
30+
out.close();
31+
} catch (Exception e) { e.printStackTrace(); }
1832
}
1933

2034
String performGET(String url) {

app/src/main/assets/libs/fetchSplash.bshL

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,31 @@ import android.os.*;
33
import android.graphics.*;
44
import android.graphics.drawable.*;
55

6-
String SplashPicDir = me.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getPath();
6+
SplashPicDir = me.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
77
//sets background var when finished
88
void fetchSplash() {
9-
loadSplash("welcome.png");
9+
String[] files = SplashPicDir.list();
10+
if (files.length == 0) {
11+
init();
12+
return;
13+
}
14+
selected_splash = files[randInt(0, files.length - 1)];
15+
loadSplash(selected_splash);
1016
}
1117

1218
void loadSplash(nvme) {
13-
InputStream input = new FileInputStream(SplashPicDir + "/" + nvme);
19+
InputStream input = new FileInputStream(SplashPicDir.getPath() + "/" + nvme);
1420
bit = BitmapFactory.decodeStream(input);
1521
background = new BitmapDrawable(bit);
22+
app_name = nvme;
1623
}
1724

1825
void init() {
19-
26+
me.Import("libs/SplashWelcome");
2027
}
28+
29+
int randInt(int min, int max) {
30+
Random rand = new Random();
31+
int randomNum = rand.nextInt((max - min) + 1) + min;
32+
return randomNum;
33+
}

app/src/main/assets/splash.bshA

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ written = false;
7272
String fortune = null;
7373
BitmapDrawable background = null;
7474
void try_draw() {
75+
upper_tv.animateText(app_name);
7576
if (!drawen||!written) {
7677
if (background != null&&!drawen)
7778
v.setBackgroundDrawable(background);

app/src/main/java/org/duangsuse/u.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ public static void wrt(String loc, String txt) throws IOException {
3838
FileWriter fw = new FileWriter(loc);
3939
BufferedWriter writer = new BufferedWriter(fw);
4040
writer.write(txt);
41+
writer.flush();
42+
writer.close();
4143
}
4244

4345
// append text to special file (newline)
4446
public static void append(String loc, String txt, String charset) throws IOException {
4547
PrintWriter pwrt = new PrintWriter(loc, charset);
4648
pwrt.println(txt);
49+
pwrt.flush();
50+
pwrt.close();
4751
}
4852

4953
public static void append(String l, String t) throws IOException {

0 commit comments

Comments
 (0)