Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Changing color with different definitions

How do I create one for different labels as well? I have this one for the background but I would also like one for time, date, and a few others. What should I change to do this?

 

Settings

function mySettings(props) {
  return (
    <Page>
         <Select
            label="Theme"
            settingsKey="theme"
            options={[
               {
                 name: "Classic Green",
                 value: {
                   background: "#002200",
                   foreground: "#00ff00"
                 }
               },
               {
                 name: "Classic Red",
                 value: {
                   background: "#220000",
                   foreground: "#ff0000"
                 }
               },
               {
                 name: "Classic Blue",
                 value: {
                   background: "#000022",
                   foreground: "#0000ff"
                 }
               },
               {
                 name: "Classic Yellow",
                 value: {
                   background: "#222200",
                   foreground: "#ffff00"
                 }
               },
               {
                 name: "Classic Pink",
                 value: {
                   background: "#220022",
                   foreground: "#ff00ff"
                 }
               },
               {
                 name: "Classic Cyan",
                 value: {
                   background: "#002222",
                   foreground: "#00ffff"
                 }
               },
               {
                 name: "Orange",
                 value: {
                   background: "#221100",
                   foreground: "#FF8C00"
                 }
               },
               {
                 name: "Cerulean",
                 value: {
                   background: "#191970",
                   foreground: "#5B4CFF"
                 }
               },
               {
                 name: "White and Black",
                 value: {
                   background: "#000000",
                   foreground: "#FFFFFF"
                 }
               }]
            }
          />
               <Section
        title={<Text bold align="center">Demo Settings</Text>}>
        <Toggle
          settingsKey="toggle"
          label="Toggle Switch"
        />
        <ColorSelect
          settingsKey="color"
          colors={[
            {color: 'tomato'},
            {color: 'sandybrown'},
            {color: 'gold'},
            {color: 'aquamarine'},
            {color: 'deepskyblue'},
            {color: 'plum'}
          ]}
        />
      </Section>
    </Page>
  );
}
registerSettingsPage(mySettings);

companion:

import { settingsStorage } from "settings";
import * as messaging from "messaging";

settingsStorage.onchange = function(evt) {
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    if (evt.key === "theme") {
      let data = JSON.parse(evt.newValue);
      messaging.peerSocket.send(data["values"][0].value);
    }
  }
}
import { settingsStorage } from "settings";
import * as messaging from "messaging";
import { me } from "companion";

let KEY_COLOR = "myColor";

// Settings have been changed
settingsStorage.onchange = function(evt1) {
  sendValue(evt1.key, evt.newValue);
}

// Settings were changed while the companion was not running
if (me.launchReasons.settingsChanged) {
  // Send the value of the setting
  sendValue(KEY_COLOR, settingsStorage.getItem(KEY_COLOR));
}

function sendValue(key, val) {
  if (val) {
    sendSettingData({
      key: key,
      value: JSON.parse(val)
    });
  }
}
function sendSettingData(data) {
  // If we have a MessageSocket, send the data to the device
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    messaging.peerSocket.send(data);
  } else {
    console.log("No peerSocket connection");
  }
}

app:

import document from "document";
import clock from "clock";
import { preferences } from "user-settings";
import { goals, today } from "user-activity";

console.log((goals.steps || 0) + " steps");

let myElement = document.getElementById("myElement");
let time = document.getElementById("time");
let steps = document.getElementById("steps");
let arc = document.getElementById("arc-fg");
let txtDate = document.getElementById("date");
let date = new Date();
let month = nameOfMonth(date.getMonth());
let day = date.getDate();
txtDate.text = `${month} ${day}`;
let step = today.local.steps


function update() {
    if (date = new Date()){
      let  step = 0;
    } 
  steps.text = today.local.steps || 0;

    let anglePercentage = (step || 0) / (goals.steps || 0);
    let angle = 360 * anglePercentage;
    arc.sweepAngle = angle;
}
update();

setInterval(update, 3000);
let time12 = document.getElementById("time12");
let myElement = time12;







clock.granularity = "seconds";
clock.ontick = (evt) => {
    let hours = evt.date.getHours();
    let minutes = evt.date.getMinutes();
    let seconds = evt.date.getSeconds();

	if(preferences.clockDisplay === "12h" && hours == 12) {
        hours = 12;
    }
	
    else if(preferences.clockDisplay === "12h" && hours > 12) {
        hours = hours - 12;
    }

    if(minutes < 10) {
        minutes = "0" + minutes;
    }
    let time12 = time;
    time.text = `${hours}:${minutes.toString()}`;
}




function nameOfMonth(i) {
    switch(i) {
      case 0:
        return "JAN";
      case 1:
        return "FEB";
      case 2:
        return "MAR";
      case 3:
        return "APR";
      case 4:
        return "MAY";
      case 5:
        return "JUN";
      case 6:
        return "JUL";
      case 7:
        return "AUG";
      case 8:
        return "SEP";
      case 9:
        return "OCT";
      case 10:
        return "NOV";
      case 11:
        return "DEC";
    }
  }


import * as messaging from "messaging";
import { me } from "appbit";
import clock from "clock";
import document from "document";
import * as fs from "fs";
import * as messaging from "messaging";
import { preferences } from "user-settings";
import * as util from "./utils";

const SETTINGS_TYPE = "cbor";
const SETTINGS_FILE = "settings.cbor";

let settings = loadSettings();
applyTheme(settings.background, settings.foreground);


function applyTheme(background, foreground) {
  let items = document.getElementsByClassName("background");
  items.forEach(function(item) {
    item.style.fill = background;
  });
  let items = document.getElementsByClassName("foreground");
  items.forEach(function(item) {
    item.style.fill = foreground;
  });
  settings.background = background;
  settings.foreground = foreground;
}
messaging.peerSocket.onmessage = evt => {
  applyTheme(evt.data.background, evt.data.foreground);
}
me.onunload = saveSettings;

function loadSettings() {
  try {
    return fs.readFileSync(SETTINGS_FILE, SETTINGS_TYPE);
  } catch (ex) {
    // Defaults
    return {
      background: "#000000",
      foreground: "#FFFFFF"
    }
  }
}

function saveSettings() {
  fs.writeFileSync(SETTINGS_FILE, settings, SETTINGS_TYPE);
}

import * as messaging from "messaging";
import document from "document";


messaging.peerSocket.onmessage = function(evt1) {
  time12.style.fill = evt1.data.value;
}
Best Answer
0 Votes
3 REPLIES 3

How do I create one for different labels as well? I have this one for the background but I would also like one for time, date, and a few others. What should I change to do this?

function mySettings(props) {
  return (
    <Page>
      <Section
        title={<Text bold align="center">Demo Settings</Text>}>
        <Toggle
          settingsKey="toggle"
          label="Toggle Switch"
        />
        <ColorSelect
          settingsKey="color"
          colors={[
            {color: "#f83c40"},
            {color: "#fc6b3a"},
            {color: "#ffd733"},
            {color: "#e4fa3c"},
            {color: "#f80070"},
            {color: "#f83478"},
            {color: "#a51e7c"},
            {color: "#d828b8"},
            {color: "#bd4efc"},
            {color: "#884cff"},
            {color: "#7898f8"},
            {color: "#7090b5"},
            {color: "#bcd8f8"},
            {color: "#2490dd"},
            {color: "#13d3f5"},
            {color: "#38f8df"},
            {color: "#00a629"},
            {color: "#67e55d"},
            {color: "#b8fc68"}
          ]}
        />
            <ColorSelect
          settingKey="color2"
          colors={[
            {color2: "#f83c40"},
            {color2: "#fc6b3a"},
            {color2: "#ffd733"},
            {color2: "#e4fa3c"},
            {color2: "#f80070"},
            {color2: "#f83478"},
            {color2: "#a51e7c"},
            {color2: "#d828b8"},
            {color2: "#bd4efc"},
            {color2: "#884cff"},
            {color2: "#7898f8"},
            {color2: "#7090b5"},
            {color2: "#bcd8f8"},
            {color2: "#2490dd"},
            {color2: "#13d3f5"},
            {color2: "#38f8df"},
            {color2: "#00a629"},
            {color2: "#67e55d"},
            {color2: "#b8fc68"}
          ]}
        />
      </Section>
    </Page>
  );
}

registerSettingsPage(mySettings);
Best Answer
0 Votes

I'd recommend looking at the Moment clock example.

 

The settings page uses a single array of colors, but renders them multiple times with different settingsKeys:

https://github.com/Fitbit/sdk-moment/blob/master/settings/index.jsx

 

The companion sends all settings to the device when the values change:

https://github.com/Fitbit/sdk-moment/blob/master/companion/simple/companion-settings.js

 

Then the app code receives each color and changes some element:

https://github.com/Fitbit/sdk-moment/tree/master/app

 

 

Best Answer
0 Votes
For some reason it is causing errors however, is there one that only
provides the communication between settings, app, and companion? thats all
i need

--
Thanks,
Everett McLain
Best Answer
0 Votes