Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.function.Consumer;
- import android.app.Activity;
- import android.content.Context;
- import android.view.ContextThemeWrapper;
- import android.view.ViewGroup;
- import android.view.Gravity;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.LinearLayout;
- import android.widget.ScrollView;
- import android.widget.TextView;
- import android.widget.Button;
- import android.graphics.Color;
- import com.google.android.material.textfield.TextInputLayout;
- import com.google.android.material.textfield.TextInputEditText;
- import com.google.android.material.materialswitch.MaterialSwitch;
- import com.google.android.material.slider.Slider;
- import com.google.android.material.checkbox.MaterialCheckBox;
- import com.google.android.material.appbar.MaterialToolbar;
- import io.reactivex.subjects.SingleSubject;
- import android.content.res.Resources;
- import com.google.android.material.button.MaterialButton;
- import com.google.android.material.color.DynamicColors;
- /*───────────────────────────────────────────────────────────────
- showM3FullScreenSettings(String title)
- **Force Fullscreen Activity UI**
- Uses MATCH_PARENT for the root layout and applies window flags
- to ensure it covers the entire screen, not just a dialog area.
- ───────────────────────────────────────────────────────────────*/
- public String showM3FullScreenSettings(String title) {
- resultSignal = SingleSubject.create();
- uiLogic = new Consumer() {
- accept(Object activityObj) {
- final Activity activity = (Activity) activityObj;
- /* 1. Force Activity Window to Full Size */
- window = activity.getWindow();
- window.requestFeature(Window.FEATURE_NO_TITLE);
- /* Hide status bar and navigation bar for true full screen */
- window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
- /* 2. Resources & Theme Discovery */
- Resources res = activity.getResources();
- String pkg = activity.getPackageName();
- float density = res.getDisplayMetrics().density;
- int padM = (int)(16 * density);
- int themeId = activity.getResources().getIdentifier("Theme.Material3.DynamicColors.Dark", "style", activity.getPackageName());
- activity.setTheme(themeId);
- /* 3. Root Container - Explicitly MATCH_PARENT */
- root = new LinearLayout(activity);
- root.setOrientation(LinearLayout.VERTICAL);
- root.setBackgroundColor(Color.parseColor("#1C1B1F"));
- /* Force the root view to take up the whole screen */
- params = new LinearLayout.LayoutParams(-1, -1);
- root.setLayoutParams(params);
- /* 4. MaterialToolbar */
- toolbar = new MaterialToolbar(activity);
- toolbar.setTitle(title);
- toolbar.setTitleCentered(true);
- toolbar.setElevation(4 * density);
- toolbar.setTitleTextColor(Color.WHITE);
- toolbar.setBackgroundColor(Color.parseColor("#2B2930"));
- root.addView(toolbar);
- /* 5. Scrollable Content Area */
- contentScroll = new ScrollView(activity);
- scrollContent = new LinearLayout(activity);
- scrollContent.setOrientation(LinearLayout.VERTICAL);
- scrollContent.setPadding(padM, padM, padM, padM);
- contentScroll.addView(scrollContent);
- /* Use weight 1.0 to expand and fill available space */
- root.addView(contentScroll, new LinearLayout.LayoutParams(-1, 0, 1.0f));
- /* Profile Name Input */
- nameLayout = new TextInputLayout(activity);
- nameLayout.setHint("Profile Name");
- nameEdit = new TextInputEditText(nameLayout.getContext());
- nameLayout.addView(nameEdit);
- scrollContent.addView(nameLayout);
- /* Toggle Switch Row */
- row = new LinearLayout(activity);
- row.setPadding(0, padM, 0, padM);
- row.setGravity(Gravity.CENTER_VERTICAL);
- label = new TextView(activity);
- label.setText("Enable Analytics");
- label.setTextColor(Color.WHITE);
- label.setLayoutParams(new LinearLayout.LayoutParams(0, -2, 1.0f));
- m3Switch = new MaterialSwitch(activity);
- row.addView(label);
- row.addView(m3Switch);
- scrollContent.addView(row);
- /* Checkbox */
- m3Check = new MaterialCheckBox(activity);
- m3Check.setText("Stay Logged In");
- m3Check.setTextColor(Color.WHITE);
- scrollContent.addView(m3Check);
- /* Slider Section */
- volLabel = new TextView(activity);
- volLabel.setText("Brightness Level");
- volLabel.setTextColor(Color.WHITE);
- volLabel.setPadding(0, padM, 0, 0);
- scrollContent.addView(volLabel);
- m3Slider = new Slider(activity);
- m3Slider.setValueFrom(0.0f);
- m3Slider.setValueTo(100.0f);
- m3Slider.setValue(60.0f);
- scrollContent.addView(m3Slider);
- MaterialButton saveBtn = new MaterialButton(activity);
- saveBtn.setText("SAVE CONFIGURATION");
- saveBtn.setOnClickListener(new android.view.View.OnClickListener() {
- onClick(android.view.View v) {
- java.util.Map results = new java.util.HashMap();
- results.put("name", nameEdit.getText().toString());
- results.put("analytics", m3Switch.isChecked());
- results.put("stayLoggedIn", m3Check.isChecked());
- results.put("brightness", m3Slider.getValue());
- resultSignal.onSuccess(tasker.toJson(results));
- activity.finish();
- }
- });
- scrollContent.addView(saveBtn);
- activity.getWindow().getDecorView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
- onViewAttachedToWindow(v) {}
- onViewDetachedFromWindow(v) {
- activity.finish();
- }
- });
- /* Set the root as content view */
- activity.setContentView(root);
- }
- };
- tasker.doWithActivity(uiLogic);
- return (String) resultSignal.blockingGet();
- }
- return showM3FullScreenSettings("Material Design Settings");
Advertisement
Add Comment
Please, Sign In to add comment