diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2018-06-21 12:36:02 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2018-06-21 12:36:02 +0000 |
| commit | 4ba6b96471b23008a2d4b6e0dff8fd9f194fb444 (patch) | |
| tree | 0b37815f18b176521b66c26bf3809190b10b43de | |
| parent | a119928455eaa84e87784e34b7b88935fecea4a2 (diff) | |
Android: Teaching FLTK to beep. test/button works.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12955 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx | 165 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.H | 4 | ||||
| -rw-r--r-- | src/drivers/Android/Fl_Android_Screen_Driver.cxx | 41 |
3 files changed, 70 insertions, 140 deletions
diff --git a/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx b/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx index cc3852ba1..06ff0811d 100644 --- a/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx +++ b/ide/AndroidStudio3/app/src/main/cpp/HelloAndroid.cxx @@ -17,158 +17,46 @@ #if 1 -// -// "$Id: color_chooser.cxx 12655 2018-02-09 14:39:42Z AlbrechtS $" -// -// Color chooser test program for the Fast Light Tool Kit (FLTK). -// -// Copyright 1998-2018 by Bill Spitzak and others. -// -// This library is free software. Distribution and use rights are outlined in -// the file "COPYING" which should have been included with this file. If this -// file is missing or damaged, see the license at: -// -// http://www.fltk.org/COPYING.php -// -// Please report all bugs and problems on the following page: -// -// http://www.fltk.org/str.php -// - +#include <stdlib.h> +#include <stdio.h> #include <FL/Fl.H> #include <FL/Fl_Window.H> -#include <FL/Fl_Box.H> #include <FL/Fl_Button.H> -#include <FL/fl_show_colormap.H> -#include <FL/Fl_Color_Chooser.H> -#include <FL/Fl_Image.H> -#include <FL/platform.H> -#include <FL/fl_draw.H> - -#include <stdlib.h> -#include <stdio.h> -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING) && !defined(__ANDROID__) -#include "list_visuals.cxx" -#endif - -int width = 100; -int height = 100; -uchar *image; -Fl_Box *hint; - -void make_image() { - image = new uchar[3*width*height]; - uchar *p = image; - for (int y = 0; y < height; y++) { - double Y = double(y)/(height-1); - for (int x = 0; x < width; x++) { - double X = double(x)/(width-1); - *p++ = uchar(255*((1-X)*(1-Y))); // red in upper-left - *p++ = uchar(255*((1-X)*Y)); // green in lower-left - *p++ = uchar(255*(X*Y)); // blue in lower-right - } - } -} +#include <FL/fl_ask.H> -class Pens : public Fl_Box { - void draw(); -public: - Pens(int X, int Y, int W, int H, const char* L) - : Fl_Box(X,Y,W,H,L) {} -}; -void Pens::draw() { - // use every color in the gray ramp: - for (int i = 0; i < 3*8; i++) { - fl_color((Fl_Color)(FL_GRAY_RAMP+i)); - fl_line(x()+i, y(), x()+i, y()+h()); - } +void beepcb(Fl_Widget *, void *) { + fl_beep(); + fflush(stdout); } -Fl_Color c = FL_GRAY; -#define fullcolor_cell (FL_FREE_COLOR) - -void cb1(Fl_Widget *, void *v) { - c = fl_show_colormap(c); - Fl_Box* b = (Fl_Box*)v; - b->color(c); - hint->labelcolor(fl_contrast(FL_BLACK,c)); - b->parent()->redraw(); +void exitcb(Fl_Widget *, void *) { + exit(0); } -void cb2(Fl_Widget *, void *v) { - uchar r,g,b; - Fl::get_color(c,r,g,b); - if (!fl_color_chooser("New color:",r,g,b,3)) return; - c = fullcolor_cell; - Fl::set_color(fullcolor_cell,r,g,b); - Fl_Box* bx = (Fl_Box*)v; - bx->color(fullcolor_cell); - hint->labelcolor(fl_contrast(FL_BLACK,fullcolor_cell)); - bx->parent()->redraw(); +#if 0 +// test Fl::add_fd()... +void stdin_cb(int, void*) { + char buf[1000]; + fgets(buf, sizeof(buf), stdin); + printf("stdin callback\n"); } +#endif int main(int argc, char ** argv) { - Fl::set_color(fullcolor_cell,145,159,170); - Fl_Window window(400,400); - Fl_Box box(30,30,340,340); - box.box(FL_THIN_DOWN_BOX); - c = fullcolor_cell; - box.color(c); - Fl_Box hintbox(40,40,320,30,"Pick background color with buttons:"); - hintbox.align(FL_ALIGN_INSIDE); - hint = &hintbox; - Fl_Button b1(120,80,180,30,"fl_show_colormap()"); - b1.callback(cb1,&box); - Fl_Button b2(120,120,180,30,"fl_color_chooser()"); - b2.callback(cb2,&box); - Fl_Box image_box(160,190,width,height,0); - make_image(); - (new Fl_RGB_Image(image, width, height))->label(&image_box); - Fl_Box b(160,310,120,30,"Example of fl_draw_image()"); - Pens p(60,180,3*8,120,"lines"); - p.align(FL_ALIGN_TOP); - int i = 1; - if (!Fl::args(argc,argv,i) || i < argc-1) { - printf("usage: %s <switches> visual-number\n" - " - : default visual\n" - " r : call Fl::visual(FL_RGB)\n" - " c : call Fl::own_colormap()\n",argv[0]); -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING) && !defined(__ANDROID__) - printf(" # : use this visual with an empty colormap:\n"); - list_visuals(); + Fl_Window *window = new Fl_Window(320,65); + Fl_Button *b1 = new Fl_Button(20, 20, 80, 25, "&Beep"); + b1->callback(beepcb,0); + /*Fl_Button *b2 =*/ new Fl_Button(120,20, 80, 25, "&no op"); + Fl_Button *b3 = new Fl_Button(220,20, 80, 25, "E&xit"); + b3->callback(exitcb,0); + window->end(); + window->show(argc,argv); +#if 0 + Fl::add_fd(0, stdin_cb); #endif - puts(Fl::help); - exit(1); - } - if (i!=argc) { - if (argv[i][0] == 'r') { - if (!Fl::visual(FL_RGB)) printf("Fl::visual(FL_RGB) returned false.\n"); - } else if (argv[i][0] == 'c') { - Fl::own_colormap(); - } else if (argv[i][0] != '-') { -#if !defined(_WIN32) && !defined(__APPLE__) && !defined(FL_PORTING) && !defined(__ANDROID__) - int visid = atoi(argv[i]); - fl_open_display(); - XVisualInfo templt; int num; - templt.visualid = visid; - fl_visual = XGetVisualInfo(fl_display, VisualIDMask, &templt, &num); - if (!fl_visual) Fl::fatal("No visual with id %d",visid); - fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen), - fl_visual->visual, AllocNone); - fl_xpixel(FL_BLACK); // make sure black is allocated -#else - Fl::fatal("Visual id's not supported on Windows or MacOS."); -#endif - } - } - window.show(argc,argv); return Fl::run(); } -// -// End of "$Id: color_chooser.cxx 12655 2018-02-09 14:39:42Z AlbrechtS $". -// - #else @@ -317,7 +205,8 @@ test/blocks.cxx test/navigation.cxx * test/boxtype.cxx : + 'boxtype' works test/offscreen.cxx test/browser.cxx test/output.cxx -test/button.cxx test/overlay.cxx + * test/button.cxx : + 'button' works, including beep + test/overlay.cxx test/buttons.cxx test/pack.cxx test/cairo_test.cxx test/pixmap.cxx test/checkers.cxx test/pixmap_browser.cxx diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.H b/src/drivers/Android/Fl_Android_Screen_Driver.H index ad9b82d4b..d9054efa5 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.H +++ b/src/drivers/Android/Fl_Android_Screen_Driver.H @@ -109,10 +109,10 @@ public: virtual void screen_dpi(float &h, float &v, int n=0); int screen_num_unscaled(int x, int y); virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n); +#endif // --- audible output - virtual void beep(int type); + virtual void beep(int type) override; // --- global events -#endif virtual void flush() override; virtual double wait(double time_to_wait) override; #if 0 diff --git a/src/drivers/Android/Fl_Android_Screen_Driver.cxx b/src/drivers/Android/Fl_Android_Screen_Driver.cxx index e295f5a1e..060cda304 100644 --- a/src/drivers/Android/Fl_Android_Screen_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Screen_Driver.cxx @@ -442,6 +442,47 @@ void Fl_Android_Screen_Driver::remove_timeout(Fl_Timeout_Handler cb, void *data) } +void Fl_Android_Screen_Driver::beep(int type) +{ + // TODO: map FLTK sounds to Android sounds at https://developer.android.com/reference/android/media/ToneGenerator + int androidSoundID = 93; // TONE_CDMA_ALERT_CALL_GUARD + switch (type) { + case FL_BEEP_DEFAULT: + case FL_BEEP_MESSAGE: + case FL_BEEP_ERROR: + case FL_BEEP_QUESTION: + case FL_BEEP_PASSWORD: + case FL_BEEP_NOTIFICATION: androidSoundID = 93; break; + } + Fl_Android_Java java; + if (java.is_attached()) { + + jclass class_tone_generator = java.env()->FindClass("android/media/ToneGenerator"); + + jmethodID toneGeneratorConstructor = java.env()->GetMethodID( + class_tone_generator, "<init>", + "(II)V"); + + jobject toneGeneratorObj = java.env()->NewObject( + class_tone_generator, toneGeneratorConstructor, + 4, // STREAM_ALARM + 100); // volume + + jmethodID method_start_tone = java.env()->GetMethodID( + class_tone_generator, + "startTone", + "(I)Z"); + + java.env()->CallBooleanMethod( + toneGeneratorObj, method_start_tone, + androidSoundID); + + java.env()->DeleteLocalRef(class_tone_generator); + java.env()->DeleteLocalRef(toneGeneratorObj); + } + +} + // // End of "$Id$". // |
