Pebble - change text layer text after delay - pebble-watch

I'm creating a new Pebble watchface. What I need to do is display some text in a text layer, then after a short delay change it to different text. What's the best way to achive this?
I have tried following:
text_layer_set_text(s_status_layer, "updated");
psleep(1000);
text_layer_set_text(s_status_layer, "ok");
The problem with above is that "updated" is never displayed. Pebble simply keeps displaying whatever text was on "s_status_layer" originally and after 1 second changes it to "ok".

Maybe you can use an AppTimer (https://developer.pebble.com/docs/c/Foundation/Timer/) :
AppTimer *updateTimer = app_timer_register(1000, (AppTimerCallback) update_timer_callback, NULL);
void update_timer_callback(void *data) {
text_layer_set_text(s_status_layer, "ok");
}

Related

Koltin low quality images registerForActivityResult

Hi I'm trying to capture a picture using kotlin and registerForActivityResult but I allways get a blur image with no quality I've read several post but I can't understand how to work with my application. I'm using a fragment to call the camera. Any suggestions? Sorry for my bad english I've spent about the full week trying it works. And nothing. Thanks in advance
private var imagenUri: Uri? =null
val startForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
try {
val intent = result.data
intent!!.putExtra(MediaStore.EXTRA_OUTPUT, imagenUri)
val bitMap = intent?.extras?.get("data") as Bitmap
imagenUri= getImageUriFromBitmap(requireContext(),bitMap)
binding.ivImagen.setImageURI(imagenUri)
Toast.makeText(context, "la uri es: $imagenUri", Toast.LENGTH_SHORT).show()
} catch (e: java.lang.Exception){
Toast.makeText(context, "NO SE HA PODIDO ENCONTRAR IMAGEN", Toast.LENGTH_SHORT).show()}
}
}
binding.ibTomarFoto.setOnClickListener(){
startForResult.launch(Intent(MediaStore.ACTION_IMAGE_CAPTURE))
}
From the documentation:
public static final String ACTION_IMAGE_CAPTURE
Standard Intent action that can be sent to have the camera application capture an image and return it.
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.
So you need to add the EXTRA_OUTPUT extra to get a full-size image stored at a URI you supply. Otherwise you get a small image as a data payload in the result Intent (those bundles can't handle large objects).
It looks like you're already trying to do that, you've just added it to the wrong place - you need to add it to the Intent you call launch with, not the result one. It's a configuration option for the task you're launching!
So this should work:
binding.ibTomarFoto.setOnClickListener(){
startForResult.launch(
Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, imagenUri)
)
}
And then remove the same putExtra line from your result-handler code (it doesn't do anything, but there's no point having it there)

Xamarin.Forms: Let Picker show in title something else than what has been picked

This sounds like a stupid idea, but hear me out:
My custom picker has a list with the top item being: "no filtering". If someone picks this item, I dont want the picker to say "no filtering" as it does atm, I want it to display its title again which is "region".
I mean, it does this from the beginning, only when you change the list to something else, it always shows what has been picked (which is fine) but in this one case, I want it to display "Region" again and not just "no filtering" (since it is a picker to chose a certain region.
I tried to set the picker to its title again:
picker_subcat1_mainmenu.Title = "Region";
But this doenst change anything, since the title hasnt changed, only what is displayed has.
Can u help me out here?
THank you!
Xamarin.Forms picker has it's default value which is -1 when nothing selected. Picker's items start from 0. So as far as i got your problem, here is one solution which i'll suggest:
when pickers index change, an event called picker_SelectedIndexChanged fired. Change placeholder(Title) of picker when select "no filtering" which has 0 index in picker.
private void picker_SelectedIndexChanged(object sender, EventArgs e)
{
var picker = sender as Picker;
if (picker.SelectedIndex == 0)
{
picker_subcat1_mainmenu.Title = "Region";
}
else{
return;
//or set e.selectedItem
}
}
Let me know if you have any query. Hope this will help you.
Thank you.

Xamarin Android : Retain data on activity change and come back

I'm developing an app in Xamarin.android where in I want to retain the data of Edit Text, spinners etc. whenever i revisit to that activity. E.g.
Activity A contains Edit Text, Spinners.
I navigate to Activity B from Activity A, and whenever I come back to Activity A from B I want to retain those values of Edit Text and Spinners.
I tried using Put Extra and Get Extra, but as there are multiple values this approach seems to be wrong.
var activity2 = new Intent (this, typeof(Activity2));
activity2.PutExtra ("MyData", "Data from Activity1");
StartActivity (activity2);
Also OnSaveInstanceState and OnRestoreInstanceState is not working out for me as I'm using Fragments in my Activity A
Please Guide
Can't your fragments save their own data using Fragment.onSaveInstanceState ?
in your case you need to save this temp data in Shared Preference
here is example
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor editor = prefs.Edit();
editor.PutInt(("number_of_times_accessed", accessCount++);
editor.PutString("date_last_accessed", DateTime.Now.ToString("yyyy-MMM-dd"));
editor.Apply();
save what ever you want int or string
and when you load you activity retrieve this data and set it to your views
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
string passedString = prefs.GetString(key, defValue);
// here set retured data to your view
// Ex : YourEditText.Text = passedString
hope this help

IUP, menu, webbrowser, tree, tabs

I have such menu situation:
int menu_create(Ihandle *menu)
{
hamburger = IupItem("&Hamburger", "hamburger");
IupSetAttributes(hamburger, "AUTOTOGGLE=YES, RADIO=YES");
char* ce = "Ćev&apčići";
cevapcici = IupItem(utf8_to_cp1250(ce), "cevapcici");
IupSetAttributes(cevapcici, "AUTOTOGGLE=YES, RADIO=YES");
exit = IupItem("Exit\tAlt+F4", "exit");
img4 = IupLoadImage("icons\\delete_16x16.ico");
IupSetAttributeHandle(exit, "TITLEIMAGE", img4);
menu = IupMenu(
IupSubmenu("File",
IupMenu(
hamburger,
cevapcici,
IupSeparator(),
IupItem("Carro&t", "carrot"),
IupSeparator(),
exit,
NULL)),
NULL);
IupSetFunction("exit", (Icallback)mnu_exit);
... etc...
IupSetHandle("menu", menu);
return IUP_DEFAULT;
}
How to get "radio toggle group" functionality with items hamburger and cevapcici so first turns off a second checkmark and opposite. This is my try but it don't work.
2) I try webbrowser example from IUP suite on my windows 7. Problem is that bad black flickering appear's during resize (increase). Also, background of webbrowser flicker black during showing.
I try a same example on Ubuntu and there flickering appear's too but it is not so much visible since background is there white.
Is here any way to get rid of those flickering or if not to get white background of webbrowser window on windows?
3) Since webbrowser is ole object (on windows) is it possible to use say "print preview" or "zoom" function by reference from IUP handle or at any other way like we used to do from MS programming tools?
wbInstance.ExecWB(Exec.OLECMDID_OPTICAL_ZOOM, ExecOpt.OLECMDEXECOPT_DONTPROMPTUSER, 150, DBNull.Value)
4) How can I get key_up event fired from IupTree?
5) Interesting situation with IupTabs:
frame3 = IupHbox(mat, val, NULL);
vboxt1 = IupVbox(frame3, NULL);
vboxt2 = IupVbox(frame3, NULL);
IupSetAttribute(vboxt1, "TABTITLE", "First documents... ");
IupSetAttribute(vboxt2, "TABTITLE", "Second documents... ");
tabs = IupTabs(vboxt1, vboxt2, NULL);
hbox1 = IupHbox(tabs, IupVbox(frame, tree, frame2, NULL), NULL);
dlg = IupDialog(hbox1);
When I set frame3 which should be a same for both tabs my GUI frozes.
However, I have to got same "mat" (IupMatrix) in both tabs because by changing tabs other data load in matrix but similar enough to use same matrix and related functions.
What to do here?
1) The RADIO attribute belongs to the IupMenu, not to the IupItem. This also means that all the IupItems inside that menu will be part of the radio.
A workaround would be to manually unset the other toggle inside the action callback.
2) That flicker is not caused by IUP. Don't know why the native controls are doing it.
3) Yes, but you will have to program that using the OLE API. If you take a look at the IupOleControl and IupWebBrower source code and send me the code to do it, I will be happy to add it to IUP.
4) You don't. Use the K_ANY callbacks.
5) You can not reuse a control in different places in any dialog. So you must have two different frames, with two different matrices. What you can do is to encapsulate your matrix, so the same function will create a matrix with the same attributes and callbacks any time you want one.

In Win32, how can a Change Color dialog be used to change STATIC text?

I am relatively new to the Win32/Windows API (non-MFC), and am trying to change the text colour of a static text control. It is already drawn to the screen in black, but I want to change it to another colour using the Windows Colour Chooser dialog, which is opened on clicking a button. Is this possible?
For the button, the WM_COMMAND message is handled on clicking. So far, I have written:
CHOOSECOLOR ccColour;
ccColour.lStructSize = sizeof(ccColour);
ccColour.hwndOwner = hWnd;
ccColour.rgbResult = crLabelTextColour;
ccColour.Flags = CC_FULLOPEN | CC_RGBINIT;
if (ChooseColor(&ccColour) == TRUE)
{
// crLabelTextColour is a COLORREF global variable assigned on loading the program
crLabelTextColour = ccColour.rgbResult;
}
This code, however, fails with an unhandled exception at the if statement, and I'm not sure why! Other examples seem to write code like this.
ChooseColor() crashes because you are not initializing the CHOOSECOLOR structure completely. You are only setting 3 fields, the rest will contain garbage. You'll need to zero-initialize everything, simple to do:
CHOOSECOLOR ccColour = {0};

Resources