Thiemo Melhorn

Hier werde ich immer wieder neuen Code bereitstellen.

ANMERKUNG:
Dieser Code ist nur für die Android App Droidscript Premium verfügbar

Hell- und Dunkelmodus

Beschreibung

Man kann nun mit einem Kippschalter den Hell- und Dunkelmodus ändern.

Code


    // Init variables.
    var lay = null;
    var isLightTheme = false;
    var themeText = null;
    var toggleSwitch = null;
    
    // Called when application is started.
    function OnStart() {
        // Create the layout.
        CreateLayout();
    
        // Load the saved theme status when the app starts.
        var savedTheme = app.LoadText("SavedTheme");
        if (savedTheme === "Light") {
            isLightTheme = true;
        }
        UpdateThemeText(isLightTheme); // Update the theme text.
        ChangeTheme(isLightTheme);
    }
    
    // Create the App's controls.
    function CreateLayout() {
        // Destroy old layout (if exists).
        if (lay) app.DestroyLayout(lay);
    
        // Create a layout with objects vertically centered.
        lay = app.CreateLayout("linear", "VCenter,FillXY");
    
        // Create some text.
        txt = app.CreateText("Theme");
        txt.SetTextSize(16);
        lay.AddChild(txt);
    
        // Create a text element to display the current theme.
        themeText = app.CreateText("Light Theme"); // Initialize with the light theme.
        themeText.SetTextSize(16);
        lay.AddChild(themeText);
    
        // Create the toggle switch.
        toggleSwitch = app.CreateSwitch("");
        toggleSwitch.SetOnTouch(toggleSwitch_OnTouch);
        lay.AddChild(toggleSwitch);
    
        // Add layout to app.
        app.AddLayout(lay);
    
        // Set the initial theme.
        ChangeTheme(isLightTheme);
    }
    
    // Called when the user touches the button to change the theme.
    function button_OnTouch() {
        // Toggle the theme directly in this function.
        isLightTheme = !isLightTheme;
        UpdateThemeText(isLightTheme); // Update the theme text.
        ChangeTheme(isLightTheme);
        // Save the current theme status.
        app.SaveText("SavedTheme", isLightTheme ? "Light" : "Dark");
    }
    
    // Function to change the theme.
    function ChangeTheme(isLightTheme) {
        var theme;
    
        if (isLightTheme) {
            theme = app.CreateTheme("Light");
            // Define a custom background color to make it look closer to white.
            theme.SetBackColor("#ffffff");
        } else {
            theme = app.CreateTheme("Dark");
        }
    
        app.SetTheme(theme);
    }
    
    // Function to update the displayed theme text.
    function UpdateThemeText(isLightTheme) {
        if (isLightTheme) {
            themeText.SetText("Light Theme");
        } else {
            themeText.SetText("Dark Theme");
        }
    }
    
    // Called when the user touches the toggle switch.
    function toggleSwitch_OnTouch(isChecked) {
        // Update the theme when the switch state changes.
        isLightTheme = isChecked;
        UpdateThemeText(isLightTheme);
        ChangeTheme(isLightTheme);
        // Save the current theme status.
        app.SaveText("SavedTheme", isLightTheme ? "Light" : "Dark");
    }
    

Radioplayer

Beschreibung

Dies ist ein Radioplayer, der alle Radiosender erfassen kann bzw. könnte.

Code


        var player;
var currentStationUrl = null; // Variable to store the current station URL
var radioStations = [
    { name: "NAME_DES_SENDERS", url: "URL_DES_SENDERS" },
    { name: "NAME_DES_SENDERS", url: "URL_DES_SENDERS" },
    // Weitere Radiosender hier hinzufügen
];

var currentVolume = 0.5; // Standardlautstärke (0 bis 1)

function OnStart() {
    lay = app.CreateLayout("Linear", "VCenter,FillXY");

    // Create a vertical layout for volume controls on the left side
    var volumeLayout = app.CreateLayout("Linear", "Left");
    volumeLayout.SetMargins(0, 0.3, 0, 0); // Anpassung der Ränder

    var stationSpinner = app.CreateSpinner(radioStations.map(function (station) {
        return station.name;
    }));

    var btnPlay = app.CreateButton("\u25B6", 0.4, 0.1); // Unicode für das Wiedergabesymbol
    var btnStop = app.CreateButton("\u25A0", 0.4, 0.1); // Unicode für das Stoppsymbol
    var btnIncreaseVolume = app.CreateButton("+", 0.2, 0.1);
    var btnDecreaseVolume = app.CreateButton("-", 0.2, 0.1);

    // Textfeld zur Anzeige der aktuellen Lautstärke (links ausgerichtet)
    var volumeText = app.CreateText("Lautstärke: " + (currentVolume * 100).toFixed(0) + "%", 0.8, -1, "Left");

    player = app.CreateMediaPlayer();
    player.SetOnReady(function () {
        app.ShowPopup("Radio Player ist bereit.");
        player.SetVolume(currentVolume, currentVolume); // Lautstärke nach dem Laden einstellen.
    });

    stationSpinner.SetOnTouch(function (item) {
        var selectedStation = radioStations.find(function (station) {
            return station.name === item;
        });

        if (selectedStation) {
            currentStationUrl = selectedStation.url; // Aktuelle Sender-URL aktualisieren
            player.SetFile(currentStationUrl);
            player.Play(); // Autoplay bei Auswahl
        }
    });

    btnPlay.SetOnTouch(function () {
        if (currentStationUrl) {
            player.Play();
        } else {
            app.ShowPopup("Bitte wähle zuerst einen Radiosender aus.");
        }
    });

    btnStop.SetOnTouch(function () {
        player.Stop();
    });

    btnIncreaseVolume.SetOnTouch(function () {
        if (currentVolume < 1.0) {
            currentVolume += 0.01; // Lautstärke um 1 % erhöhen (maximal auf 1.0 begrenzt)
            player.SetVolume(currentVolume, currentVolume);
            updateVolumeText(); // Lautstärkeanzeige aktualisieren
        }
    });

    btnDecreaseVolume.SetOnTouch(function () {
        if (currentVolume > 0.0) {
            currentVolume -= 0.01; // Lautstärke um 1 % verringern (minimal auf 0.0 begrenzt)
            player.SetVolume(currentVolume, currentVolume);
            updateVolumeText(); // Lautstärkeanzeige aktualisieren
        }
    });

    function updateVolumeText() {
        volumeText.SetText("Lautstärke: " + (currentVolume * 100).toFixed(0) + "%");
    }

    lay.AddChild(stationSpinner);
    lay.AddChild(btnPlay);
    lay.AddChild(btnStop);
    volumeLayout.AddChild(volumeText); // Textfeld zum Lautstärke-Layout hinzufügen
    volumeLayout.AddChild(btnIncreaseVolume);
    volumeLayout.AddChild(btnDecreaseVolume);
    lay.AddChild(volumeLayout); // Lautstärke-Layout zur Hauptansicht hinzufügen

    app.AddLayout(lay);
}