Guest User

Untitled

a guest
Mar 14th, 2026
19
0
256 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.93 KB | None | 0 0
  1. import java.util.function.Consumer;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.view.ContextThemeWrapper;
  5. import android.view.ViewGroup;
  6. import android.view.Gravity;
  7. import android.view.View;
  8. import android.view.Window;
  9. import android.view.WindowManager;
  10. import android.widget.LinearLayout;
  11. import android.widget.ScrollView;
  12. import android.widget.TextView;
  13. import android.widget.Button;
  14. import android.graphics.Color;
  15. import com.google.android.material.textfield.TextInputLayout;
  16. import com.google.android.material.textfield.TextInputEditText;
  17. import com.google.android.material.materialswitch.MaterialSwitch;
  18. import com.google.android.material.slider.Slider;
  19. import com.google.android.material.checkbox.MaterialCheckBox;
  20. import com.google.android.material.appbar.MaterialToolbar;
  21. import io.reactivex.subjects.SingleSubject;
  22. import android.content.res.Resources;
  23. import com.google.android.material.button.MaterialButton;
  24. import com.google.android.material.color.DynamicColors;
  25.  
  26. /*───────────────────────────────────────────────────────────────
  27. showM3FullScreenSettings(String title)
  28. **Force Fullscreen Activity UI**
  29. Uses MATCH_PARENT for the root layout and applies window flags
  30. to ensure it covers the entire screen, not just a dialog area.
  31. ───────────────────────────────────────────────────────────────*/
  32. public String showM3FullScreenSettings(String title) {
  33.     resultSignal = SingleSubject.create();
  34.  
  35.  
  36.     uiLogic = new Consumer() {
  37.         accept(Object activityObj) {
  38.             final Activity activity = (Activity) activityObj;
  39.  
  40.             /* 1. Force Activity Window to Full Size */
  41.             window = activity.getWindow();
  42.             window.requestFeature(Window.FEATURE_NO_TITLE);
  43.  
  44.             /* Hide status bar and navigation bar for true full screen */
  45.             window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  46.             window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
  47.  
  48.             /* 2. Resources & Theme Discovery */
  49.             Resources res = activity.getResources();
  50.             String pkg = activity.getPackageName();
  51.             float density = res.getDisplayMetrics().density;
  52.             int padM = (int)(16 * density);
  53.  
  54.             int themeId = activity.getResources().getIdentifier("Theme.Material3.DynamicColors.Dark", "style", activity.getPackageName());
  55.             activity.setTheme(themeId);
  56.  
  57.             /* 3. Root Container - Explicitly MATCH_PARENT */
  58.             root = new LinearLayout(activity);
  59.             root.setOrientation(LinearLayout.VERTICAL);
  60.             root.setBackgroundColor(Color.parseColor("#1C1B1F"));
  61.  
  62.             /* Force the root view to take up the whole screen */
  63.             params = new LinearLayout.LayoutParams(-1, -1);
  64.             root.setLayoutParams(params);
  65.  
  66.             /* 4. MaterialToolbar */
  67.             toolbar = new MaterialToolbar(activity);
  68.             toolbar.setTitle(title);
  69.             toolbar.setTitleCentered(true);
  70.             toolbar.setElevation(4 * density);
  71.             toolbar.setTitleTextColor(Color.WHITE);
  72.             toolbar.setBackgroundColor(Color.parseColor("#2B2930"));
  73.             root.addView(toolbar);
  74.  
  75.             /* 5. Scrollable Content Area */
  76.             contentScroll = new ScrollView(activity);
  77.             scrollContent = new LinearLayout(activity);
  78.             scrollContent.setOrientation(LinearLayout.VERTICAL);
  79.             scrollContent.setPadding(padM, padM, padM, padM);
  80.             contentScroll.addView(scrollContent);
  81.  
  82.             /* Use weight 1.0 to expand and fill available space */
  83.             root.addView(contentScroll, new LinearLayout.LayoutParams(-1, 0, 1.0f));
  84.  
  85.             /* Profile Name Input */
  86.             nameLayout = new TextInputLayout(activity);
  87.             nameLayout.setHint("Profile Name");
  88.             nameEdit = new TextInputEditText(nameLayout.getContext());
  89.             nameLayout.addView(nameEdit);
  90.             scrollContent.addView(nameLayout);
  91.  
  92.             /* Toggle Switch Row */
  93.             row = new LinearLayout(activity);
  94.             row.setPadding(0, padM, 0, padM);
  95.             row.setGravity(Gravity.CENTER_VERTICAL);
  96.  
  97.             label = new TextView(activity);
  98.             label.setText("Enable Analytics");
  99.             label.setTextColor(Color.WHITE);
  100.             label.setLayoutParams(new LinearLayout.LayoutParams(0, -2, 1.0f));
  101.  
  102.             m3Switch = new MaterialSwitch(activity);
  103.  
  104.             row.addView(label);
  105.             row.addView(m3Switch);
  106.             scrollContent.addView(row);
  107.  
  108.             /* Checkbox */
  109.             m3Check = new MaterialCheckBox(activity);
  110.             m3Check.setText("Stay Logged In");
  111.             m3Check.setTextColor(Color.WHITE);
  112.             scrollContent.addView(m3Check);
  113.  
  114.             /* Slider Section */
  115.             volLabel = new TextView(activity);
  116.             volLabel.setText("Brightness Level");
  117.             volLabel.setTextColor(Color.WHITE);
  118.             volLabel.setPadding(0, padM, 0, 0);
  119.             scrollContent.addView(volLabel);
  120.  
  121.             m3Slider = new Slider(activity);
  122.             m3Slider.setValueFrom(0.0f);
  123.             m3Slider.setValueTo(100.0f);
  124.             m3Slider.setValue(60.0f);
  125.             scrollContent.addView(m3Slider);
  126.  
  127.             MaterialButton saveBtn = new MaterialButton(activity);
  128.             saveBtn.setText("SAVE CONFIGURATION");
  129.             saveBtn.setOnClickListener(new android.view.View.OnClickListener() {
  130.                 onClick(android.view.View v) {
  131.                     java.util.Map results = new java.util.HashMap();
  132.                     results.put("name", nameEdit.getText().toString());
  133.                     results.put("analytics", m3Switch.isChecked());
  134.                     results.put("stayLoggedIn", m3Check.isChecked());
  135.                     results.put("brightness", m3Slider.getValue());
  136.  
  137.                     resultSignal.onSuccess(tasker.toJson(results));
  138.                     activity.finish();
  139.                 }
  140.             });
  141.  
  142.             scrollContent.addView(saveBtn);
  143.             activity.getWindow().getDecorView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
  144.                 onViewAttachedToWindow(v) {}
  145.                 onViewDetachedFromWindow(v) {
  146.                     activity.finish();
  147.                 }
  148.             });
  149.             /* Set the root as content view */
  150.             activity.setContentView(root);
  151.         }
  152.     };
  153.  
  154.     tasker.doWithActivity(uiLogic);
  155.  
  156.     return (String) resultSignal.blockingGet();
  157.  
  158.  
  159.  
  160. }
  161.  
  162. return showM3FullScreenSettings("Material Design Settings");
Advertisement
Add Comment
Please, Sign In to add comment