Skip to content

Commit c6f36eb

Browse files
committed
Add tabbed Settings layout (General / Network / System)
1 parent df4a518 commit c6f36eb

1 file changed

Lines changed: 90 additions & 29 deletions

File tree

src/com/bpmct/trmnl_nook_simple_touch/SettingsActivity.java

Lines changed: 90 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,38 @@ protected void onCreate(Bundle savedInstanceState) {
6060
title.setTextColor(0xFF000000);
6161
main.addView(title);
6262

63-
// Credentials
64-
main.addView(createSectionLabel("Credentials"));
63+
// ── Tab bar ──────────────────────────────────────────────────────────
64+
final LinearLayout tabBar = new LinearLayout(this);
65+
tabBar.setOrientation(LinearLayout.HORIZONTAL);
66+
LinearLayout.LayoutParams tabBarParams = new LinearLayout.LayoutParams(
67+
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
68+
tabBarParams.topMargin = 12;
69+
70+
final Button tabGeneral = createTabButton("General");
71+
final Button tabNetwork = createTabButton("Network");
72+
final Button tabSystem = createTabButton("System");
73+
74+
LinearLayout.LayoutParams tabParams = new LinearLayout.LayoutParams(
75+
0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f);
76+
tabBar.addView(tabGeneral, tabParams);
77+
tabBar.addView(tabNetwork, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
78+
tabBar.addView(tabSystem, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
79+
main.addView(tabBar, tabBarParams);
80+
81+
// ── Panel: General ───────────────────────────────────────────────────
82+
final LinearLayout panelGeneral = new LinearLayout(this);
83+
panelGeneral.setOrientation(LinearLayout.VERTICAL);
84+
85+
panelGeneral.addView(createSectionLabel("Credentials"));
6586
statusView = new TextView(this);
6687
statusView.setTextSize(12);
6788
statusView.setTextColor(0xFF444444);
6889
statusView.setText(ApiPrefs.hasCredentials(this) ? "Configured" : "Not set");
6990
LinearLayout.LayoutParams statusParams = new LinearLayout.LayoutParams(
7091
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
7192
statusParams.topMargin = 6;
72-
main.addView(statusView, statusParams);
93+
panelGeneral.addView(statusView, statusParams);
94+
7395
Button editButton = createGreyButton("Edit Credentials");
7496
editButton.setOnClickListener(new View.OnClickListener() {
7597
public void onClick(View v) {
@@ -79,23 +101,22 @@ public void onClick(View v) {
79101
LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(
80102
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
81103
editParams.topMargin = 8;
82-
main.addView(editButton, editParams);
104+
panelGeneral.addView(editButton, editParams);
83105

84-
// Display
85-
main.addView(createSectionLabel("Display"));
106+
panelGeneral.addView(createSectionLabel("Display"));
86107
allowSleepCheck = new CheckBox(this);
87108
allowSleepCheck.setText("Sleep between updates");
88109
allowSleepCheck.setTextColor(0xFF000000);
89110
allowSleepCheck.setChecked(ApiPrefs.isAllowSleep(this));
90-
main.addView(allowSleepCheck);
111+
panelGeneral.addView(allowSleepCheck);
91112

92113
sleepHint = new TextView(this);
93114
sleepHint.setText("Set screensaver to TRMNL, sleep after 2 min");
94115
sleepHint.setTextSize(11);
95116
sleepHint.setTextColor(0xFF888888);
96117
sleepHint.setPadding(40, 0, 0, 0);
97118
sleepHint.setVisibility(allowSleepCheck.isChecked() ? View.VISIBLE : View.GONE);
98-
main.addView(sleepHint);
119+
panelGeneral.addView(sleepHint);
99120

100121
allowSleepCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
101122
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -104,8 +125,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
104125
}
105126
});
106127

107-
// Gift Mode
108-
main.addView(createSectionLabel("Gift Mode"));
128+
panelGeneral.addView(createSectionLabel("Gift Mode"));
109129
giftModeCheck = new CheckBox(this);
110130
giftModeCheck.setText("Enable gift mode");
111131
giftModeCheck.setTextColor(0xFF000000);
@@ -118,7 +138,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
118138
}
119139
}
120140
});
121-
main.addView(giftModeCheck);
141+
panelGeneral.addView(giftModeCheck);
122142

123143
giftSettingsButton = createGreyButton("Configure Gift Mode");
124144
giftSettingsButton.setOnClickListener(new View.OnClickListener() {
@@ -129,23 +149,29 @@ public void onClick(View v) {
129149
LinearLayout.LayoutParams giftBtnParams = new LinearLayout.LayoutParams(
130150
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
131151
giftBtnParams.topMargin = 6;
132-
main.addView(giftSettingsButton, giftBtnParams);
152+
panelGeneral.addView(giftSettingsButton, giftBtnParams);
133153
updateGiftSettingsVisibility();
134154

135-
// Network (for self-hosted/BYOS setups)
136-
main.addView(createSectionLabel("Network"));
155+
main.addView(panelGeneral);
156+
157+
// ── Panel: Network ───────────────────────────────────────────────────
158+
final LinearLayout panelNetwork = new LinearLayout(this);
159+
panelNetwork.setOrientation(LinearLayout.VERTICAL);
160+
panelNetwork.setVisibility(View.GONE);
161+
162+
panelNetwork.addView(createSectionLabel("Network"));
137163
allowHttpCheck = new CheckBox(this);
138164
allowHttpCheck.setText("Allow HTTP (insecure)");
139165
allowHttpCheck.setTextColor(0xFF000000);
140166
allowHttpCheck.setChecked(ApiPrefs.isAllowHttp(this));
141-
main.addView(allowHttpCheck);
167+
panelNetwork.addView(allowHttpCheck);
142168

143169
TextView httpHint = new TextView(this);
144170
httpHint.setText("Enable for local/BYOS servers without HTTPS");
145171
httpHint.setTextSize(11);
146172
httpHint.setTextColor(0xFF888888);
147173
httpHint.setPadding(40, 0, 0, 0);
148-
main.addView(httpHint);
174+
panelNetwork.addView(httpHint);
149175

150176
allowSelfSignedCheck = new CheckBox(this);
151177
allowSelfSignedCheck.setText("Allow self-signed certificates");
@@ -154,14 +180,14 @@ public void onClick(View v) {
154180
LinearLayout.LayoutParams selfSignedParams = new LinearLayout.LayoutParams(
155181
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
156182
selfSignedParams.topMargin = 8;
157-
main.addView(allowSelfSignedCheck, selfSignedParams);
183+
panelNetwork.addView(allowSelfSignedCheck, selfSignedParams);
158184

159185
TextView selfSignedHint = new TextView(this);
160186
selfSignedHint.setText("Trust HTTPS servers with self-signed certs");
161187
selfSignedHint.setTextSize(11);
162188
selfSignedHint.setTextColor(0xFF888888);
163189
selfSignedHint.setPadding(40, 0, 0, 0);
164-
main.addView(selfSignedHint);
190+
panelNetwork.addView(selfSignedHint);
165191

166192
autoDisableWifiCheck = new CheckBox(this);
167193
autoDisableWifiCheck.setText("Auto-disable WiFi");
@@ -170,41 +196,46 @@ public void onClick(View v) {
170196
LinearLayout.LayoutParams wifiParams = new LinearLayout.LayoutParams(
171197
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
172198
wifiParams.topMargin = 8;
173-
main.addView(autoDisableWifiCheck, wifiParams);
199+
panelNetwork.addView(autoDisableWifiCheck, wifiParams);
174200

175201
TextView wifiHint = new TextView(this);
176202
wifiHint.setText("Turn off WiFi between fetches to save battery");
177203
wifiHint.setTextSize(11);
178204
wifiHint.setTextColor(0xFF888888);
179205
wifiHint.setPadding(40, 0, 0, 0);
180-
main.addView(wifiHint);
206+
panelNetwork.addView(wifiHint);
207+
208+
main.addView(panelNetwork);
209+
210+
// ── Panel: System ────────────────────────────────────────────────────
211+
final LinearLayout panelSystem = new LinearLayout(this);
212+
panelSystem.setOrientation(LinearLayout.VERTICAL);
213+
panelSystem.setVisibility(View.GONE);
181214

182-
// Debug & Device
183-
main.addView(createSectionLabel("Debug & Device"));
215+
panelSystem.addView(createSectionLabel("Debug Logs"));
184216
fileLoggingCheck = new CheckBox(this);
185217
fileLoggingCheck.setText("Save logs to file");
186218
fileLoggingCheck.setTextColor(0xFF000000);
187219
fileLoggingCheck.setChecked(ApiPrefs.isFileLoggingEnabled(this));
188-
main.addView(fileLoggingCheck);
220+
panelSystem.addView(fileLoggingCheck);
189221

190222
TextView logHint = new TextView(this);
191223
logHint.setText("/media/My Files/trmnl.log");
192224
logHint.setTextSize(11);
193225
logHint.setTextColor(0xFF888888);
194226
logHint.setPadding(40, 0, 0, 0);
195-
main.addView(logHint);
227+
panelSystem.addView(logHint);
196228

197229
Button clearLogsButton = createGreyButton("Clear Logs");
198230
clearLogsButton.setOnClickListener(new View.OnClickListener() {
199-
public void onClick(View v) {
200-
FileLogger.clear();
201-
}
231+
public void onClick(View v) { FileLogger.clear(); }
202232
});
203233
LinearLayout.LayoutParams clearParams = new LinearLayout.LayoutParams(
204234
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
205235
clearParams.topMargin = 6;
206-
main.addView(clearLogsButton, clearParams);
236+
panelSystem.addView(clearLogsButton, clearParams);
207237

238+
panelSystem.addView(createSectionLabel("Device"));
208239
LinearLayout deviceRow = new LinearLayout(this);
209240
deviceRow.setOrientation(LinearLayout.HORIZONTAL);
210241
LinearLayout.LayoutParams deviceRowParams = new LinearLayout.LayoutParams(
@@ -240,8 +271,30 @@ public void onClick(View v) {
240271
}
241272
});
242273
deviceRow.addView(appsDrawerButton, appsParams);
274+
panelSystem.addView(deviceRow, deviceRowParams);
275+
276+
main.addView(panelSystem);
243277

244-
main.addView(deviceRow, deviceRowParams);
278+
// ── Tab switching logic ───────────────────────────────────────────────
279+
final LinearLayout[] panels = { panelGeneral, panelNetwork, panelSystem };
280+
final Button[] tabs = { tabGeneral, tabNetwork, tabSystem };
281+
282+
View.OnClickListener tabClick = new View.OnClickListener() {
283+
public void onClick(View v) {
284+
for (int i = 0; i < tabs.length; i++) {
285+
boolean active = tabs[i] == v;
286+
panels[i].setVisibility(active ? View.VISIBLE : View.GONE);
287+
tabs[i].setBackgroundColor(active ? 0xFF000000 : 0xFFDDDDDD);
288+
tabs[i].setTextColor(active ? 0xFFFFFFFF : 0xFF444444);
289+
}
290+
}
291+
};
292+
tabGeneral.setOnClickListener(tabClick);
293+
tabNetwork.setOnClickListener(tabClick);
294+
tabSystem.setOnClickListener(tabClick);
295+
// start on General (already active styling)
296+
tabGeneral.setBackgroundColor(0xFF000000);
297+
tabGeneral.setTextColor(0xFFFFFFFF);
245298

246299
scroll.addView(main);
247300
rootLayout.addView(scroll, new FrameLayout.LayoutParams(
@@ -289,6 +342,14 @@ private TextView createSectionLabel(String text) {
289342
return label;
290343
}
291344

345+
private Button createTabButton(String text) {
346+
Button btn = new Button(this);
347+
btn.setText(text);
348+
btn.setTextColor(0xFF444444);
349+
btn.setBackgroundColor(0xFFDDDDDD);
350+
return btn;
351+
}
352+
292353
private Button createGreyButton(String text) {
293354
Button btn = new Button(this);
294355
btn.setText(text);

0 commit comments

Comments
 (0)