Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ private enum Page { PREPARE, COPY }
// Hotspot/Wi-Fi switch is a natural retry path.
private boolean locationAsked = false;

private TextView tabSend, tabReceive, tabHotspot, tabWifi, caption, subCaption, advance, stop, footer;
private TextView tabSend, tabReceive, tabHotspot, tabWifi, caption, subCaption, footer;
// ADFA-5346: the "Installed? copy the library" advance CTA is a MaterialButton (shape/size from the
// shared style); styleAdvance only toggles fill/emphasis (filled teal vs teal-text), not the shape.
private com.google.android.material.button.MaterialButton advance;
// ADFA-5346: the footer action button morphs across roles (recover/share-anyway/stop/start). It is a
// MaterialButton rebuilt per role via a ThemeOverlay (setStopRole) so the role look stays only in the
// XML styles — no color recipe duplicated here.
private com.google.android.material.button.MaterialButton stop;
// ADFA-4785: intent fork (Send / Receive) replaces the persistent top toggle.
private boolean atFork = true;
private LinearLayout forkBox, tabsRow;
Expand Down Expand Up @@ -676,10 +683,8 @@ private void renderNoSystemSend() {
shareCard.setVisibility(View.GONE);
advance.setVisibility(View.GONE);
actionFooter.setVisibility(View.VISIBLE);
stop.setText(getString(R.string.k2go_home_recover));
stop.setBackgroundResource(R.drawable.k2go_primary_bg);
stop.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_on_teal));
stop.setOnClickListener(v -> SetupLibraryActivity.recover(requireContext()));
setStopRole(R.style.ThemeOverlay_K2Go_Button_Filled, R.string.k2go_home_recover,
v -> SetupLibraryActivity.recover(requireContext()));
footer.setVisibility(View.GONE);
}

Expand Down Expand Up @@ -846,10 +851,8 @@ private void renderStartState(String ip, boolean twoCode) {
subCaption.setText(getString(R.string.k2go_clone_no_library_note));
footer.setText(""); shareCard.setVisibility(View.GONE);
actionFooter.setVisibility(View.VISIBLE);
stop.setText(getString(R.string.k2go_clone_share_anyway));
stop.setBackgroundResource(R.drawable.k2go_getmore_bg);
stop.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_teal));
stop.setOnClickListener(x -> { shareAnyway = true; render(); });
setStopRole(R.style.ThemeOverlay_K2Go_Button_Outlined, R.string.k2go_clone_share_anyway,
x -> { shareAnyway = true; render(); });
return;
}
if (daemonStarting) {
Expand Down Expand Up @@ -924,20 +927,31 @@ private void shareApkViaSheet() {
}
}

/** ADFA-5346: (re)build the footer action button with one of the shared button styles (via a
* ThemeOverlay) plus its text + click. actionFooter holds only this button, so we swap it in place.
* The role look (filled/outlined/destructive) lives only in the XML styles — nothing is spelled here. */
private void setStopRole(int overlayTheme, int textRes, View.OnClickListener onClick) {
com.google.android.material.button.MaterialButton b = new com.google.android.material.button.MaterialButton(
new android.view.ContextThemeWrapper(requireContext(), overlayTheme), null);
b.setId(R.id.k2go_clone_stop); // keep the id stable across rebuilds (a11y / findViewById)
b.setText(getString(textRes));
b.setOnClickListener(onClick);
b.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
actionFooter.removeAllViews();
actionFooter.addView(b);
stop = b;
}

private void showStopButton() {
actionFooter.setVisibility(View.VISIBLE);
stop.setText(getString(R.string.k2go_clone_stop_sharing));
stop.setBackgroundResource(R.drawable.k2go_turnoff_bg);
stop.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_clay));
stop.setOnClickListener(x -> confirmStop());
setStopRole(R.style.ThemeOverlay_K2Go_Button_Destructive, R.string.k2go_clone_stop_sharing, x -> confirmStop());
}

private void showStartButton() {
actionFooter.setVisibility(View.VISIBLE);
stop.setText(getString(R.string.k2go_clone_start_sharing));
stop.setBackgroundResource(R.drawable.k2go_primary_bg);
stop.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_on_teal));
stop.setOnClickListener(x -> { userStopped = false; render(); });
setStopRole(R.style.ThemeOverlay_K2Go_Button_Filled, R.string.k2go_clone_start_sharing,
x -> { userStopped = false; render(); });
}

// ------------------------------------------------------------------ Receive
Expand Down Expand Up @@ -1580,8 +1594,8 @@ private void paintTab(TextView t, boolean on) {
}

private void styleAdvance(boolean filled) {
advance.setBackgroundResource(filled ? R.drawable.k2go_primary_bg : 0);
advance.setTextColor(ContextCompat.getColor(requireContext(), filled ? R.color.k2go_on_teal : R.color.k2go_teal));
// ADFA-5346: shape/size come from the style; only toggle the fill + label emphasis by state.
K2GoButtons.setFilledEmphasis(advance, filled);
}

private int dp(int v) { return Math.round(v * getResources().getDisplayMetrics().density); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ private enum Mode { HOTSPOT, WIFI }
private final LocalHotspotManager hs = LocalHotspotManager.get();
private ActivityResultLauncher<String> locationPerm;

private TextView tabHotspot, tabWifi, advance, finish, connFooter;
private TextView tabHotspot, tabWifi, finish, connFooter;
// ADFA-5346: advance CTA is a MaterialButton (shape/size from the shared style); styleAdvance only
// toggles fill/emphasis.
private com.google.android.material.button.MaterialButton advance;
private LinearLayout steps, two, single, hint;
private QrSection secJoin, secOpen, secSingle;

Expand Down Expand Up @@ -344,9 +347,8 @@ private void paintTab(TextView t, boolean on) {
}

private void styleAdvance(boolean filled) {
advance.setBackgroundResource(filled ? R.drawable.k2go_primary_bg : 0);
advance.setTextColor(ContextCompat.getColor(requireContext(),
filled ? R.color.k2go_on_teal : R.color.k2go_teal));
// ADFA-5346: shape/size from the style; only toggle the fill + label emphasis by state.
K2GoButtons.setFilledEmphasis(advance, filled);
}

private int dp(int v) { return Math.round(v * getResources().getDisplayMetrics().density); }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* ============================================================================
* Name : K2GoButtons.java
* Author : AppDevForAll
* Copyright : Copyright (c) 2026 AppDevForAll
* Description : ADFA-5346. Shared helpers for the K2Go Material 3 buttons, so the small bits of dynamic
* button styling live in ONE place instead of being copied per fragment. The static look
* (shape, size, colors) belongs to the styles in themes_k2go.xml + the ThemeOverlays; this
* only covers a runtime STATE toggle that a style can't express on its own.
* ============================================================================
*/
package org.iiab.controller.redesign;

import android.content.res.ColorStateList;

import androidx.core.content.ContextCompat;

import com.google.android.material.button.MaterialButton;

import org.iiab.controller.R;

public final class K2GoButtons {

private K2GoButtons() {}

/**
* Toggle a filled CTA between full emphasis (filled teal) and low emphasis (teal text, no fill),
* keeping the button's shape and size from its style. This is a STATE change, not a second style —
* the "advance / continue" buttons in the Clone and Connect flows use it so the same two lines don't
* live in two fragments.
*/
public static void setFilledEmphasis(MaterialButton button, boolean filled) {
int fill = filled ? R.color.k2go_teal : android.R.color.transparent;
int text = filled ? R.color.k2go_on_teal : R.color.k2go_teal;
button.setBackgroundTintList(ColorStateList.valueOf(
ContextCompat.getColor(button.getContext(), fill)));
button.setTextColor(ContextCompat.getColor(button.getContext(), text));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,11 @@ private void buildFooter(Context ctx, LinearLayout footer) {
np.bottomMargin = SettingsUi.dp(ctx, 8);
footer.addView(note, np);

TextView off = new TextView(ctx);
// ADFA-5346: destructive button via the shared M3 style (overlay points at Widget.K2Go.Button.
// Destructive — no color/recipe duplicated in code). Shape/size/clay outline all come from the style.
com.google.android.material.button.MaterialButton off = new com.google.android.material.button.MaterialButton(
new android.view.ContextThemeWrapper(ctx, R.style.ThemeOverlay_K2Go_Button_Destructive), null);
off.setText(getString(R.string.k2go_settings_turn_off));
off.setGravity(Gravity.CENTER);
off.setPadding(SettingsUi.dp(ctx, 16), SettingsUi.dp(ctx, 16), SettingsUi.dp(ctx, 16), SettingsUi.dp(ctx, 16));
off.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_TitleLarge);
off.setTextColor(ContextCompat.getColor(ctx, R.color.k2go_clay));
off.setBackgroundResource(R.drawable.k2go_turnoff_bg);
off.setClickable(true);
off.setOnClickListener(v -> confirmTurnOff());
footer.addView(off, new LinearLayout.LayoutParams(-1, -2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,10 @@ private void buildDns(Context ctx, LinearLayout list) {
final EditText secondary = dnsInput(ctx);
fields.addView(secondary);

final TextView accept = new TextView(ctx);
// ADFA-5346: filled M3 button via the shared style overlay (no drawable / color recipe in code).
final com.google.android.material.button.MaterialButton accept = new com.google.android.material.button.MaterialButton(
new android.view.ContextThemeWrapper(ctx, R.style.ThemeOverlay_K2Go_Button_Filled), null);
accept.setText(getString(R.string.dns_accept));
accept.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_LabelLarge);
accept.setTextColor(ContextCompat.getColor(ctx, R.color.k2go_on_teal));
accept.setGravity(Gravity.CENTER);
accept.setBackgroundResource(R.drawable.k2go_primary_bg);
int ap = SettingsUi.dp(ctx, 14);
accept.setPadding(ap, ap, ap, ap);
accept.setClickable(true);
accept.setFocusable(true);
LinearLayout.LayoutParams aclp = new LinearLayout.LayoutParams(-1, -2);
aclp.topMargin = SettingsUi.dp(ctx, 20);
fields.addView(accept, aclp);
Expand Down Expand Up @@ -550,14 +544,10 @@ private void buildServiceAuth(Context ctx, LinearLayout list, String service) {
eyeHint.setLayoutParams(ehlp);
fields.addView(eyeHint);

final TextView save = new TextView(ctx);
// ADFA-5346: filled M3 button via the shared style overlay.
final com.google.android.material.button.MaterialButton save = new com.google.android.material.button.MaterialButton(
new android.view.ContextThemeWrapper(ctx, R.style.ThemeOverlay_K2Go_Button_Filled), null);
save.setText(getString(R.string.k2go_auth_save));
save.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_LabelLarge);
save.setTextColor(ContextCompat.getColor(ctx, R.color.k2go_on_teal));
save.setGravity(Gravity.CENTER);
save.setBackgroundResource(R.drawable.k2go_primary_bg);
int ap = SettingsUi.dp(ctx, 14);
save.setPadding(ap, ap, ap, ap);
LinearLayout.LayoutParams svlp = new LinearLayout.LayoutParams(-1, -2);
svlp.topMargin = SettingsUi.dp(ctx, 16);
fields.addView(save, svlp);
Expand Down
Loading
Loading