├── icons ├── Contacts.psd ├── MissedCall.psd ├── RecentCalls.psd ├── IncomingCall.psd └── OutgoingCall.psd ├── resources ├── call.png ├── icon.png ├── mic_off.png ├── micon.png ├── answer~bw.png ├── speakeron.png ├── volumeup.png ├── answer~color.png ├── contacts~bw.png ├── endcall~bw.png ├── message~bw.png ├── speakeroff.png ├── volumedown.png ├── callhistory~bw.png ├── contacts~color.png ├── endcall~color.png ├── message~color.png ├── missedcall~bw.png ├── callhistory~color.png ├── contactgroup~bw.png ├── incomingcall~bw.png ├── missedcall~color.png ├── outgoingcall~bw.png ├── contactgroup~color.png ├── incomingcall~color.png └── outgoingcall~color.png ├── .gitignore ├── src ├── util.h ├── CallWindow.h ├── CallLogWindow.h ├── NumberPickerWindow.h ├── ContactsWindow.h ├── MainMenuWindow.h ├── util.c ├── ActionsMenu.h ├── tertiary_text.h ├── CircularBuffer.h ├── PebbleDialer.h ├── CircularBuffer.c ├── ActionsMenu.c ├── NumberPickerWindow.c ├── CallLogWindow.c ├── PebbleDialer.c ├── MainMenuWindow.c ├── ContactsWindow.c ├── tertiary_text.c └── CallWindow.c ├── README.md ├── wscript ├── package.json └── COPYING /icons/Contacts.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/icons/Contacts.psd -------------------------------------------------------------------------------- /resources/call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/call.png -------------------------------------------------------------------------------- /resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/icon.png -------------------------------------------------------------------------------- /icons/MissedCall.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/icons/MissedCall.psd -------------------------------------------------------------------------------- /icons/RecentCalls.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/icons/RecentCalls.psd -------------------------------------------------------------------------------- /resources/mic_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/mic_off.png -------------------------------------------------------------------------------- /resources/micon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/micon.png -------------------------------------------------------------------------------- /icons/IncomingCall.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/icons/IncomingCall.psd -------------------------------------------------------------------------------- /icons/OutgoingCall.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/icons/OutgoingCall.psd -------------------------------------------------------------------------------- /resources/answer~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/answer~bw.png -------------------------------------------------------------------------------- /resources/speakeron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/speakeron.png -------------------------------------------------------------------------------- /resources/volumeup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/volumeup.png -------------------------------------------------------------------------------- /resources/answer~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/answer~color.png -------------------------------------------------------------------------------- /resources/contacts~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/contacts~bw.png -------------------------------------------------------------------------------- /resources/endcall~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/endcall~bw.png -------------------------------------------------------------------------------- /resources/message~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/message~bw.png -------------------------------------------------------------------------------- /resources/speakeroff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/speakeroff.png -------------------------------------------------------------------------------- /resources/volumedown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/volumedown.png -------------------------------------------------------------------------------- /resources/callhistory~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/callhistory~bw.png -------------------------------------------------------------------------------- /resources/contacts~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/contacts~color.png -------------------------------------------------------------------------------- /resources/endcall~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/endcall~color.png -------------------------------------------------------------------------------- /resources/message~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/message~color.png -------------------------------------------------------------------------------- /resources/missedcall~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/missedcall~bw.png -------------------------------------------------------------------------------- /resources/callhistory~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/callhistory~color.png -------------------------------------------------------------------------------- /resources/contactgroup~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/contactgroup~bw.png -------------------------------------------------------------------------------- /resources/incomingcall~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/incomingcall~bw.png -------------------------------------------------------------------------------- /resources/missedcall~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/missedcall~color.png -------------------------------------------------------------------------------- /resources/outgoingcall~bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/outgoingcall~bw.png -------------------------------------------------------------------------------- /resources/contactgroup~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/contactgroup~color.png -------------------------------------------------------------------------------- /resources/incomingcall~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/incomingcall~color.png -------------------------------------------------------------------------------- /resources/outgoingcall~color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matejdro/PebbleDialer-Watchapp/HEAD/resources/outgoingcall~color.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Ignore build generated files 3 | build 4 | PebbleDialer 5 | 6 | waf* 7 | .lock* 8 | 9 | CMakeLists.txt 10 | .idea 11 | node_modules/ 12 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util.h 3 | * 4 | * Created on: May 26, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef UTIL_H_ 9 | #define UTIL_H_ 10 | 11 | char* itoa(int num); 12 | 13 | #endif /* UTIL_H_ */ 14 | -------------------------------------------------------------------------------- /src/CallWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * callscreen.h 3 | * 4 | * Created on: May 31, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef CALLWINDOW_H_ 9 | #define CALLWINDOW_H_ 10 | 11 | void call_window_init(); 12 | void call_window_data_received(uint8_t module, uint8_t packet, DictionaryIterator *received); 13 | 14 | #endif /* CALLWINDOW_H_ */ 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PebbleDialer-Watchapp 2 | ===================== 3 | 4 | Watchapp part of the Dialer for Pebble 5 | 6 | Phone counterpart: https://github.com/matejdro/PebbleDialer-Android 7 | Pebble App Store entry: https://apps.getpebble.com/en_US/application/532323bf60c773c1420000a8 8 | Discussion forums: https://plus.google.com/communities/105292167808840816317 -------------------------------------------------------------------------------- /src/CallLogWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CallLog.h 3 | * 4 | * Created on: Aug 20, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef CALLLOGWINDOW_H_ 9 | #define CALLLOGWINDOW_H_ 10 | 11 | void call_log_window_init(void); 12 | void call_log_window_data_received(int packetId, DictionaryIterator* data); 13 | void call_log_window_data_sent(void); 14 | 15 | #endif /* CALLLOGWINDOW_H_ */ 16 | -------------------------------------------------------------------------------- /src/NumberPickerWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NumberPicker.h 3 | * 4 | * Created on: Aug 19, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef NUMBERPICKERWINDOW_H_ 9 | #define NUMBERPICKERWINDOW_H_ 10 | 11 | void number_picker_window_data_received(int packetId, DictionaryIterator* data); 12 | void number_picker_window_data_sent(void); 13 | 14 | void number_picker_window_init(void); 15 | 16 | #endif /* NUMBERPICKERWINDOW_H_ */ 17 | -------------------------------------------------------------------------------- /src/ContactsWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ContactsWindow.h 3 | * 4 | * Created on: Aug 13, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef CONTACTSWINDOW_H_ 9 | #define CONTACTSWINDOW_H_ 10 | 11 | void contacts_window_data_received(int packetId, DictionaryIterator* data); 12 | void contacts_window_data_delivered(void); 13 | void contacts_window_init(void); 14 | void contacts_window_stop_filtering(void); 15 | 16 | #endif /* CONTACTSWINDOW_H_ */ 17 | -------------------------------------------------------------------------------- /src/MainMenuWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * DialerMenu.h 3 | * 4 | * Created on: Aug 12, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef MAINMENUWINDOW_H_ 9 | #define MAINMENUWINDOW_H_ 10 | 11 | void main_menu_init(void); 12 | void main_menu_close(void); 13 | void main_menu_data_received(int packetId, DictionaryIterator* data); 14 | void main_menu_show_menu(void); 15 | void main_menu_show_closing(void); 16 | void main_menu_show_old_watchapp(void); 17 | void main_menu_show_old_android(void); 18 | void main_menu_show_no_connection(void); 19 | 20 | #endif /* MAINMENUWINDOW_H_ */ 21 | -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | char *itoa(int num) 2 | { 3 | static char buff[20] = {}; 4 | int i = 0, temp_num = num, length = 0; 5 | char *string = buff; 6 | if(num >= 0) { 7 | // count how many characters in the number 8 | while(temp_num) { 9 | temp_num /= 10; 10 | length++; 11 | } 12 | // assign the number to the buffer starting at the end of the 13 | // number and going to the begining since we are doing the 14 | // integer to character conversion on the last number in the 15 | // sequence 16 | for(i = 0; i < length; i++) { 17 | buff[(length-1)-i] = '0' + (num % 10); 18 | num /= 10; 19 | } 20 | buff[i] = '\0'; // can't forget the null byte to properly end our string 21 | return string; 22 | } 23 | else 24 | return "Unsupported Number"; 25 | } 26 | -------------------------------------------------------------------------------- /src/ActionsMenu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ActionMenu.h 3 | * 4 | * Created on: Dec 19, 2014 5 | * Author: matej 6 | */ 7 | 8 | #ifndef ACTIONMENU_H_ 9 | #define ACTIONMENU_H_ 10 | 11 | bool actions_menu_is_displayed(void); 12 | int16_t actions_menu_get_selected_index(void); 13 | char* actions_menu_get_action_text(int action); 14 | void actions_menu_set_number_of_items(int items); 15 | void actions_menu_reset_text(void); 16 | void actions_menu_show(void); 17 | void actions_menu_hide(void); 18 | void actions_menu_move_up(void); 19 | void actions_menu_move_down(void); 20 | bool actions_menu_got_data(uint8_t packetId, DictionaryIterator* dictionary); 21 | void actions_menu_deinit(void); 22 | void actions_menu_attach(Layer* layer); 23 | void actions_menu_init(void); 24 | 25 | #endif /* ACTIONMENU_H_ */ 26 | -------------------------------------------------------------------------------- /src/tertiary_text.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // A callback which is called when a user submits data 4 | // 5 | // Params: 6 | // result - The data the user typed. Memory is shared across calls to tertiary_text_prompt, so copy it before calling again 7 | // result_lengh - Number of characters in result 8 | // extra - The extra data passed to tertiary_text_prompt 9 | // 10 | typedef void(* TertiaryTextCallback)( const char* result, size_t result_length, void* extra ); 11 | 12 | // Opens a tertiary text window and gets user input 13 | // 14 | // Params: 15 | // title - Some text to display on the top of the input screen 16 | // callback - The function to call when input is complete 17 | // extra - Some extra data to pass to the callback 18 | // 19 | void tertiary_text_prompt( const char* title, TertiaryTextCallback callback, void* extra ); 20 | 21 | void tertiary_text_window_close(); -------------------------------------------------------------------------------- /src/CircularBuffer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Matej on 18.12.2015. 3 | // 4 | 5 | #ifndef DIALER2_CIRCULARBUFFER_H 6 | #define DIALER2_CIRCULARBUFFER_H 7 | 8 | #include 9 | 10 | typedef struct 11 | { 12 | bool* loaded; 13 | char* data; 14 | int8_t bufferCenterPos; 15 | uint16_t centerIndex; 16 | 17 | uint8_t bufferSize; 18 | size_t singleEntrySize; 19 | 20 | } CircularBuffer; 21 | 22 | CircularBuffer* cb_create(size_t singleEntrySize, uint8_t bufferSize); 23 | void* cb_getEntry(CircularBuffer* buffer, uint16_t index); 24 | void* cb_getEntryForFilling(CircularBuffer* buffer, uint16_t index); 25 | bool cb_isLoaded(CircularBuffer* buffer, uint16_t index); 26 | void cb_destroy(CircularBuffer* buffer); 27 | void cb_shift(CircularBuffer* buffer, uint16_t newIndex); 28 | uint8_t cb_getNumOfLoadedSpacesDownFromCenter(CircularBuffer* buffer, uint16_t limit); 29 | uint8_t cb_getNumOfLoadedSpacesUpFromCenter(CircularBuffer* buffer); 30 | void cb_clear(CircularBuffer* buffer); 31 | 32 | 33 | #endif //DIALER2_CIRCULARBUFFER_H 34 | -------------------------------------------------------------------------------- /src/PebbleDialer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dialer2.h 3 | * 4 | * Created on: Aug 13, 2013 5 | * Author: matej 6 | */ 7 | 8 | #ifndef PEBBLEDIALER_H_ 9 | #define PEBBLEDIALER_H_ 10 | 11 | 12 | #define SCREEN_WIDTH (PBL_IF_RECT_ELSE(144, 180)) 13 | #define SCREEN_HEIGHT (PBL_IF_RECT_ELSE(168, 180)) 14 | 15 | #define HEIGHT_BELOW_STATUSBAR (SCREEN_HEIGHT - STATUS_BAR_LAYER_HEIGHT) 16 | 17 | #ifdef PBL_PLATFORM_APLITE 18 | #define PBL_LOW_MEMORY 19 | #endif 20 | 21 | extern bool config_dontClose; 22 | extern uint8_t config_numOfGroups; 23 | extern bool config_noMenu; 24 | extern bool config_noFilterGroups; 25 | extern bool config_lightCallWindow; 26 | extern bool config_dontVibrateWhenCharging; 27 | extern bool config_enableCallTimer; 28 | extern bool config_enableOutgoingCallPopup; 29 | extern uint8_t config_fontTimer; 30 | extern uint8_t config_fontName; 31 | extern uint8_t config_fontNumberType; 32 | extern uint8_t config_fontNumber; 33 | 34 | const char* config_getFontResource(int id); 35 | 36 | extern bool closingMode; 37 | extern bool exitOnDataDelivered; 38 | 39 | 40 | void setCurWindow(int window); 41 | void switchWindow(int window); 42 | void closeApp(void); 43 | bool canVibrate(void); 44 | void onOutgoingCallEstablished(); 45 | 46 | #endif /* PEBBLEDIALER_H_ */ 47 | -------------------------------------------------------------------------------- /wscript: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This file is the default set of rules to compile a Pebble project. 4 | # 5 | # Feel free to customize this to your needs. 6 | # 7 | 8 | import os.path 9 | 10 | top = '.' 11 | out = 'build' 12 | 13 | def options(ctx): 14 | ctx.load('pebble_sdk') 15 | 16 | def configure(ctx): 17 | ctx.load('pebble_sdk') 18 | 19 | def build(ctx): 20 | ctx.load('pebble_sdk') 21 | 22 | build_worker = os.path.exists('worker_src') 23 | binaries = [] 24 | 25 | for p in ctx.env.TARGET_PLATFORMS: 26 | ctx.set_env(ctx.all_envs[p]) 27 | ctx.set_group(ctx.env.PLATFORM_NAME) 28 | app_elf='{}/pebble-app.elf'.format(ctx.env.BUILD_DIR) 29 | ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), 30 | target=app_elf) 31 | 32 | if build_worker: 33 | worker_elf='{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR) 34 | binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf}) 35 | ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), 36 | target=worker_elf) 37 | else: 38 | binaries.append({'platform': p, 'app_elf': app_elf}) 39 | 40 | ctx.set_group('bundle') 41 | ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/**/*.js')) 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "3.4.0", 3 | "author": "matejdro", 4 | "private": true, 5 | "dependencies": { 6 | "pebble-activity-indicator-layer": "1.0.3", 7 | "pebble-rtltr": "^0.3.5" 8 | }, 9 | "keywords": [ 10 | "pebble-app","pebble-rtltr","elbbeP" 11 | ], 12 | "pebble": { 13 | "sdkVersion": "3", 14 | "resources": { 15 | "media": [ 16 | { 17 | "menuIcon": true, 18 | "type": "bitmap", 19 | "name": "ICON", 20 | "file": "icon.png" 21 | }, 22 | { 23 | "type": "bitmap", 24 | "name": "ANSWER", 25 | "file": "answer.png" 26 | }, 27 | { 28 | "type": "bitmap", 29 | "name": "ENDCALL", 30 | "file": "endcall.png" 31 | }, 32 | { 33 | "type": "bitmap", 34 | "name": "MIC_OFF", 35 | "file": "mic_off.png" 36 | }, 37 | { 38 | "type": "bitmap", 39 | "name": "MIC_ON", 40 | "file": "micon.png" 41 | }, 42 | { 43 | "type": "bitmap", 44 | "name": "SPEAKER_ON", 45 | "file": "speakeron.png" 46 | }, 47 | { 48 | "type": "bitmap", 49 | "name": "SPEAKER_OFF", 50 | "file": "speakeroff.png" 51 | }, 52 | { 53 | "type": "bitmap", 54 | "name": "VOLUME_UP", 55 | "file": "volumeup.png" 56 | }, 57 | { 58 | "type": "bitmap", 59 | "name": "VOLUME_DOWN", 60 | "file": "volumedown.png" 61 | }, 62 | { 63 | "type": "bitmap", 64 | "name": "CALL_HISTORY", 65 | "file": "callhistory.png" 66 | }, 67 | { 68 | "type": "bitmap", 69 | "name": "CONTACTS", 70 | "file": "contacts.png" 71 | }, 72 | { 73 | "type": "bitmap", 74 | "name": "CONTACT_GROUP", 75 | "file": "contactgroup.png" 76 | }, 77 | { 78 | "type": "bitmap", 79 | "name": "INCOMING_CALL", 80 | "file": "incomingcall.png" 81 | }, 82 | { 83 | "type": "bitmap", 84 | "name": "OUTGOING_CALL", 85 | "file": "outgoingcall.png" 86 | }, 87 | { 88 | "type": "bitmap", 89 | "name": "MISSED_CALL", 90 | "file": "missedcall.png" 91 | }, 92 | { 93 | "type": "bitmap", 94 | "name": "MESSAGE", 95 | "file": "message.png" 96 | }, 97 | { 98 | "type": "bitmap", 99 | "name": "CALL", 100 | "file": "call.png" 101 | } 102 | ] 103 | }, 104 | "projectType": "native", 105 | "uuid": "158a074d-85ce-43d2-ab7d-14416ddc1058", 106 | "messageKeys": {}, 107 | "enableMultiJS": false, 108 | "displayName": "Dialer", 109 | "watchapp": { 110 | "onlyShownOnCommunication": false, 111 | "hiddenApp": false, 112 | "watchface": false 113 | }, 114 | "targetPlatforms": [ 115 | "aplite", 116 | "basalt", 117 | "chalk" 118 | ], 119 | "capabilities": [] 120 | }, 121 | "name": "Dialer" 122 | } -------------------------------------------------------------------------------- /src/CircularBuffer.c: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Matej on 18.12.2015. 3 | // 4 | 5 | #include "CircularBuffer.h" 6 | 7 | void cb_clear(CircularBuffer* buffer) 8 | { 9 | for (int i = 0; i < buffer->bufferSize; i++) 10 | buffer->loaded[i] = false; 11 | } 12 | 13 | CircularBuffer* cb_create(size_t singleEntrySize, uint8_t bufferSize) 14 | { 15 | CircularBuffer* circularBuffer = (CircularBuffer*) malloc(sizeof(CircularBuffer)); 16 | circularBuffer->data = malloc(singleEntrySize * bufferSize); 17 | circularBuffer->loaded = malloc(sizeof(bool) * bufferSize); 18 | circularBuffer->singleEntrySize = singleEntrySize; 19 | circularBuffer->bufferSize = bufferSize; 20 | circularBuffer->bufferCenterPos = 0; 21 | circularBuffer->centerIndex = 0; 22 | 23 | cb_clear(circularBuffer); 24 | 25 | return circularBuffer; 26 | } 27 | 28 | void cb_destroy(CircularBuffer* buffer) 29 | { 30 | free(buffer->loaded); 31 | free(buffer->data); 32 | free(buffer); 33 | } 34 | 35 | 36 | void cb_shift(CircularBuffer* circularBuffer, uint16_t newIndex) 37 | { 38 | int8_t clearIndex; 39 | 40 | int16_t diff = newIndex - circularBuffer->centerIndex; 41 | if (diff == 0) 42 | return; 43 | 44 | circularBuffer->centerIndex += diff; 45 | circularBuffer->bufferCenterPos += diff; 46 | 47 | if (diff > 0) 48 | { 49 | if (circularBuffer->bufferCenterPos >= circularBuffer->bufferSize) 50 | circularBuffer->bufferCenterPos -= circularBuffer->bufferSize; 51 | 52 | clearIndex = (int8_t) (circularBuffer->bufferCenterPos - circularBuffer->bufferSize / 2); 53 | if (clearIndex < 0) 54 | clearIndex += circularBuffer->bufferSize; 55 | } 56 | else 57 | { 58 | if (circularBuffer->bufferCenterPos < 0) 59 | circularBuffer->bufferCenterPos += circularBuffer->bufferSize; 60 | 61 | clearIndex = (int8_t) (circularBuffer->bufferCenterPos + circularBuffer->bufferSize / 2); 62 | if (clearIndex >= circularBuffer->bufferSize) 63 | clearIndex -= circularBuffer->bufferSize; 64 | } 65 | 66 | circularBuffer->loaded[clearIndex] = false; 67 | } 68 | 69 | 70 | static int8_t convertToArrayPos(CircularBuffer* buffer, uint16_t index) 71 | { 72 | int16_t indexDiff = index - buffer->centerIndex; 73 | if (indexDiff >= buffer->bufferSize / 2 || indexDiff <= -buffer->bufferSize / 2) 74 | return -1; 75 | 76 | int8_t arrayPos = (int8_t) (buffer->bufferCenterPos + indexDiff); 77 | if (arrayPos < 0) 78 | arrayPos += buffer->bufferSize; 79 | if (arrayPos >= buffer->bufferSize) 80 | arrayPos -= buffer->bufferSize; 81 | 82 | return arrayPos; 83 | } 84 | 85 | void* cb_getEntry(CircularBuffer* buffer, uint16_t index) 86 | { 87 | int8_t bufferPosition = convertToArrayPos(buffer, index); 88 | if (bufferPosition < 0) 89 | return NULL; 90 | 91 | if (!buffer->loaded[bufferPosition]) 92 | return NULL; 93 | 94 | return (void*) &buffer->data[buffer->singleEntrySize * bufferPosition]; 95 | 96 | } 97 | 98 | bool cb_isLoaded(CircularBuffer* buffer, uint16_t index) 99 | { 100 | int8_t bufferPosition = convertToArrayPos(buffer, index); 101 | if (bufferPosition < 0) 102 | return false; 103 | 104 | return buffer->loaded[bufferPosition]; 105 | } 106 | 107 | void* cb_getEntryForFilling(CircularBuffer* buffer, uint16_t index) 108 | { 109 | int8_t bufferPosition = convertToArrayPos(buffer, index); 110 | if (bufferPosition < 0) 111 | return NULL; 112 | 113 | buffer->loaded[bufferPosition] = true; 114 | 115 | return (void*) &buffer->data[buffer->singleEntrySize * bufferPosition]; 116 | } 117 | 118 | uint8_t cb_getNumOfLoadedSpacesDownFromCenter(CircularBuffer* buffer, uint16_t limit) 119 | { 120 | uint8_t spaces = 0; 121 | for (int16_t i = buffer->centerIndex; i < buffer->centerIndex + buffer->bufferSize / 2; i++) 122 | { 123 | if (i >= limit) 124 | return buffer->bufferSize / 2; //Everything up to limit is loaded. Lets pretend everything beyond is already loaded. 125 | 126 | if (!cb_isLoaded(buffer, (uint8_t) i)) 127 | { 128 | break; 129 | } 130 | 131 | spaces++; 132 | } 133 | 134 | return spaces; 135 | } 136 | 137 | uint8_t cb_getNumOfLoadedSpacesUpFromCenter(CircularBuffer* buffer) 138 | { 139 | uint8_t spaces = 0; 140 | for (int16_t i = buffer->centerIndex; i > buffer->centerIndex - buffer->bufferSize / 2; i--) 141 | { 142 | if (i < 0) 143 | return buffer->bufferSize / 2; //Everything up to first entry is loaded. Lets pretend everything beyond is already loaded. 144 | 145 | if (!cb_isLoaded(buffer, (uint8_t) i)) 146 | { 147 | break; 148 | } 149 | 150 | spaces++; 151 | } 152 | 153 | return spaces; 154 | 155 | } 156 | 157 | -------------------------------------------------------------------------------- /src/ActionsMenu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ActionMenu.c 3 | * 4 | * Created on: Dec 19, 2014 5 | * Author: matej 6 | */ 7 | 8 | #include 9 | #include "tertiary_text.h" 10 | #include "PebbleDialer.h" 11 | 12 | #define MENU_X_OFFSET (PBL_IF_RECT_ELSE(9, 27)) 13 | #define MENU_Y_OFFSET (PBL_IF_RECT_ELSE(9 + STATUS_BAR_LAYER_HEIGHT, 27)) 14 | #define MENU_WIDTH (144 - 18) 15 | #define MENU_HEIGHT (PBL_IF_RECT_ELSE(168 - 34, 126)) 16 | 17 | static Layer* menuBackground; 18 | static MenuLayer* menu; 19 | static bool actionsMenuDisplayed = false; 20 | static char actions[20][20]; 21 | static uint8_t numOfActions = 0; 22 | 23 | static uint8_t initCounter = 0; 24 | 25 | 26 | static void menu_paint_background(Layer *layer, GContext *ctx) 27 | { 28 | graphics_context_set_fill_color(ctx, GColorBlack); 29 | graphics_fill_rect(ctx, GRect(0, 0, MENU_WIDTH, MENU_HEIGHT), 0, GCornerNone); 30 | graphics_context_set_fill_color(ctx, GColorWhite); 31 | graphics_fill_rect(ctx, GRect(1, 1, MENU_WIDTH - 2, MENU_HEIGHT - 2), 0, GCornerNone); 32 | } 33 | 34 | static uint16_t menu_get_num_sections_callback(MenuLayer *me, void *data) { 35 | return 1; 36 | } 37 | 38 | static uint16_t menu_get_num_rows_callback(MenuLayer *me, uint16_t section_index, void *data) { 39 | return numOfActions; 40 | } 41 | 42 | 43 | static int16_t menu_get_row_height_callback(MenuLayer *me, MenuIndex *cell_index, void *data) { 44 | return 30; 45 | } 46 | 47 | static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { 48 | graphics_context_set_text_color(ctx, PBL_IF_COLOR_ELSE(GColorBlack, menu_cell_layer_is_highlighted(cell_layer) ? GColorWhite : GColorBlack)); 49 | graphics_draw_text(ctx, actions[cell_index->row], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(5, 0, MENU_WIDTH - 12, 27), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); 50 | } 51 | 52 | 53 | void actions_menu_reset_text(void) 54 | { 55 | for (int i = 0; i < 20; i++) 56 | { 57 | actions[i][0] = 0; 58 | } 59 | } 60 | 61 | bool actions_menu_is_displayed(void) 62 | { 63 | return actionsMenuDisplayed; 64 | } 65 | 66 | int16_t actions_menu_get_selected_index(void) 67 | { 68 | return menu_layer_get_selected_index(menu).row; 69 | } 70 | 71 | char* actions_menu_get_action_text(int action) 72 | { 73 | return actions[action]; 74 | } 75 | 76 | void actions_menu_set_number_of_items(int items) 77 | { 78 | numOfActions = items; 79 | } 80 | 81 | void actions_menu_move_up(void) 82 | { 83 | MenuIndex index = menu_layer_get_selected_index(menu); 84 | if (index.row == 0) 85 | { 86 | menu_layer_set_selected_index(menu, MenuIndex(0,numOfActions - 1), MenuRowAlignCenter, true); 87 | return; 88 | } 89 | 90 | menu_layer_set_selected_next(menu, true, MenuRowAlignCenter, true); 91 | } 92 | 93 | void actions_menu_move_down(void) 94 | { 95 | MenuIndex index = menu_layer_get_selected_index(menu); 96 | if (index.row == numOfActions - 1) 97 | { 98 | menu_layer_set_selected_index(menu, MenuIndex(0, 0), MenuRowAlignCenter, true); 99 | return; 100 | } 101 | 102 | menu_layer_set_selected_next(menu, false, MenuRowAlignCenter, true); 103 | } 104 | 105 | void actions_menu_show(void) 106 | { 107 | menu_layer_reload_data(menu); 108 | MenuIndex firstItem; 109 | firstItem.row = 0; 110 | firstItem.section = 0; 111 | menu_layer_set_selected_index(menu, firstItem, MenuRowAlignTop, false); 112 | actionsMenuDisplayed = true; 113 | layer_set_hidden((Layer*) menuBackground, false); 114 | } 115 | 116 | void actions_menu_hide(void) 117 | { 118 | actionsMenuDisplayed = false; 119 | layer_set_hidden((Layer*) menuBackground, true); 120 | } 121 | 122 | bool actions_menu_got_data(uint8_t packetId, DictionaryIterator* dictionary) 123 | { 124 | if (packetId != 0) 125 | return false; 126 | 127 | bool menuPoppedUp = false; 128 | 129 | uint8_t* data = dict_find(dictionary, 2)->value->data; 130 | uint8_t* text = dict_find(dictionary, 3)->value->data; 131 | 132 | uint8_t firstId = data[0]; 133 | numOfActions = data[1]; 134 | bool displayTertiaryText = data[2] != 0; 135 | 136 | uint8_t packetSize = numOfActions - firstId; 137 | 138 | if (firstId == 0) 139 | { 140 | if (displayTertiaryText) 141 | { 142 | actions_menu_hide(); 143 | tertiary_text_prompt("Enter SMS:", NULL, NULL); 144 | } 145 | else if (!actions_menu_is_displayed()) 146 | { 147 | actions_menu_reset_text(); 148 | actions_menu_show(); 149 | } 150 | 151 | menuPoppedUp = true; 152 | } 153 | 154 | if (packetSize > 4) 155 | packetSize = 4; 156 | 157 | for (int i = 0; i < packetSize; i++) 158 | { 159 | memcpy(actions[i + firstId], &text[i*19], 19); 160 | } 161 | 162 | if (actionsMenuDisplayed) 163 | menu_layer_reload_data(menu); 164 | 165 | return menuPoppedUp; 166 | } 167 | 168 | void actions_menu_init(void) 169 | { 170 | initCounter++; 171 | if (initCounter > 1) 172 | return; 173 | 174 | menuBackground = layer_create(GRect(MENU_X_OFFSET, MENU_Y_OFFSET, MENU_WIDTH, MENU_HEIGHT)); 175 | layer_set_update_proc(menuBackground, menu_paint_background); 176 | layer_set_hidden((Layer*) menuBackground, true); 177 | 178 | menu = menu_layer_create(GRect(1, 1, MENU_WIDTH - 2, MENU_HEIGHT - 2)); 179 | 180 | menu_layer_set_callbacks(menu, NULL, (MenuLayerCallbacks) { 181 | .get_num_sections = menu_get_num_sections_callback, 182 | .get_num_rows = menu_get_num_rows_callback, 183 | .get_cell_height = menu_get_row_height_callback, 184 | .draw_row = menu_draw_row_callback, 185 | }); 186 | 187 | layer_add_child(menuBackground, (Layer*) menu); 188 | 189 | #ifdef PBL_COLOR 190 | menu_layer_set_highlight_colors(menu, GColorJaegerGreen, GColorBlack); 191 | #endif 192 | } 193 | 194 | void actions_menu_attach(Layer* layer) 195 | { 196 | layer_add_child(layer, menuBackground); 197 | } 198 | 199 | void actions_menu_deinit(void) 200 | { 201 | if (initCounter > 0) 202 | initCounter--; 203 | 204 | if (initCounter > 0) 205 | return; 206 | 207 | layer_destroy(menuBackground); 208 | menu_layer_destroy(menu); 209 | 210 | actionsMenuDisplayed = false; 211 | } 212 | -------------------------------------------------------------------------------- /src/NumberPickerWindow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pebble.h" 3 | #include "pebble_fonts.h" 4 | 5 | #include "PebbleDialer.h" 6 | #include "util.h" 7 | #include "ActionsMenu.h" 8 | #include "CircularBuffer.h" 9 | #include "pebble-rtltr/rtltr.h" 10 | 11 | static Window* window; 12 | 13 | static uint16_t numMaxNumbers = 10; 14 | 15 | static int16_t pickedNumber = -1; 16 | 17 | static GBitmap* callIcon; 18 | static GBitmap* messageIcon; 19 | 20 | typedef struct 21 | { 22 | uint8_t actionType; 23 | char numberType[21]; 24 | char number[21]; 25 | 26 | } ContactAction; 27 | 28 | static CircularBuffer* contactActions; 29 | 30 | MenuLayer* menuLayer; 31 | 32 | StatusBarLayer* statusBar; 33 | 34 | static void sendMenuPick(uint8_t buttonId); 35 | static void sendPickedNumber(int16_t pos); 36 | 37 | static void button_up_press(ClickRecognizerRef recognizer, Window *window) 38 | { 39 | if (actions_menu_is_displayed()) 40 | { 41 | actions_menu_move_up(); 42 | return; 43 | } 44 | 45 | menu_layer_set_selected_next(menuLayer, true, MenuRowAlignCenter, true); 46 | } 47 | 48 | static void button_select_press(ClickRecognizerRef recognizer, Window *window) 49 | { 50 | if (actions_menu_is_displayed()) 51 | { 52 | sendMenuPick(actions_menu_get_selected_index()); 53 | actions_menu_hide(); 54 | return; 55 | } 56 | 57 | sendPickedNumber(menu_layer_get_selected_index(menuLayer).row); 58 | } 59 | 60 | static void button_down_press(ClickRecognizerRef recognizer, Window *window) 61 | { 62 | if (actions_menu_is_displayed()) 63 | { 64 | actions_menu_move_down(); 65 | return; 66 | } 67 | 68 | menu_layer_set_selected_next(menuLayer, false, MenuRowAlignCenter, false); 69 | } 70 | 71 | static void sendMenuPick(uint8_t buttonId) 72 | { 73 | DictionaryIterator *iterator; 74 | app_message_outbox_begin(&iterator); 75 | 76 | dict_write_uint8(iterator, 0, 5); 77 | dict_write_uint8(iterator, 1, 0); 78 | dict_write_uint8(iterator, 2, buttonId); 79 | 80 | app_message_outbox_send(); 81 | } 82 | 83 | static void requestNumbers(uint16_t pos) 84 | { 85 | DictionaryIterator *iterator; 86 | app_message_outbox_begin(&iterator); 87 | dict_write_uint8(iterator, 0, 4); 88 | dict_write_uint8(iterator, 1, 0); 89 | dict_write_uint16(iterator, 2, pos); 90 | app_message_outbox_send(); 91 | 92 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 93 | } 94 | 95 | static void sendPickedNumber(int16_t pos) 96 | { 97 | DictionaryIterator *iterator; 98 | AppMessageResult result = app_message_outbox_begin(&iterator); 99 | if (result != APP_MSG_OK) { 100 | pickedNumber = pos; 101 | return; 102 | } 103 | 104 | dict_write_uint8(iterator, 0, 4); 105 | dict_write_uint8(iterator, 1, 1); 106 | dict_write_int16(iterator, 2, pos); 107 | app_message_outbox_send(); 108 | 109 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 110 | 111 | pickedNumber = -1; 112 | onOutgoingCallEstablished(); 113 | } 114 | 115 | static void requestAdditionalNumbers(void) 116 | { 117 | uint8_t filledDown = cb_getNumOfLoadedSpacesDownFromCenter(contactActions, numMaxNumbers); 118 | uint8_t filledUp = cb_getNumOfLoadedSpacesUpFromCenter(contactActions); 119 | 120 | if (filledDown < 4 && filledDown <= filledUp) 121 | { 122 | uint16_t startingIndex = contactActions->centerIndex + filledDown; 123 | requestNumbers(startingIndex); 124 | } 125 | else if (filledUp < 4) 126 | { 127 | uint16_t startingIndex = contactActions->centerIndex - 1 - filledUp; 128 | requestNumbers(startingIndex); 129 | } 130 | } 131 | 132 | static uint16_t menu_get_num_sections_callback(MenuLayer *me, void *data) { 133 | return 1; 134 | } 135 | 136 | static uint16_t menu_get_num_rows_callback(MenuLayer *me, uint16_t section_index, void *data) { 137 | return numMaxNumbers; 138 | } 139 | 140 | 141 | static int16_t menu_get_row_height_callback(MenuLayer *me, MenuIndex *cell_index, void *data) { 142 | return 44; 143 | } 144 | 145 | static void menu_pos_changed(struct MenuLayer *menu_layer, MenuIndex new_index, MenuIndex old_index, void *callback_context) 146 | { 147 | cb_shift(contactActions, new_index.row); 148 | requestAdditionalNumbers(); 149 | } 150 | 151 | 152 | static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { 153 | ContactAction* action = cb_getEntry(contactActions, cell_index->row); 154 | if (action == NULL) 155 | return; 156 | 157 | GBitmap* icon = action->actionType == 0 ? callIcon : messageIcon; 158 | 159 | #ifdef PBL_ROUND 160 | char title[32]; 161 | strncpy(title, icon == callIcon ? "[Call] " : "[Msg] ", sizeof title - 1); 162 | strncat(title, action->numberType, sizeof title - 1 - strlen(title)); 163 | menu_cell_basic_draw(ctx, cell_layer, title, action->number, icon); 164 | #else 165 | menu_cell_basic_draw(ctx, cell_layer, action->numberType, action->number, icon); 166 | #endif 167 | } 168 | 169 | 170 | static void receivedNumbers(DictionaryIterator* data) 171 | { 172 | uint16_t offset = dict_find(data, 2)->value->uint16; 173 | numMaxNumbers = dict_find(data, 3)->value->uint16; 174 | uint8_t* actions = dict_find(data, 8)->value->data; 175 | for (int i = 0; i < 2; i++) 176 | { 177 | uint16_t groupPos = offset + i; 178 | 179 | if (groupPos >= numMaxNumbers) 180 | continue; 181 | 182 | ContactAction* action = cb_getEntryForFilling(contactActions, groupPos); 183 | if (action == NULL) 184 | continue; 185 | 186 | #ifndef PBL_LOW_MEMORY 187 | rtltr_strcpy(action->numberType, dict_find(data, 4 + i)->value->cstring); 188 | #else 189 | strcpy(action->numberType, dict_find(data, 4 + i)->value->cstring); 190 | #endif 191 | strcpy(action->number, dict_find(data, 6 + i)->value->cstring); 192 | action->actionType = actions[i]; 193 | } 194 | 195 | menu_layer_reload_data(menuLayer); 196 | 197 | requestAdditionalNumbers(); 198 | } 199 | 200 | void number_picker_window_data_received(int packetId, DictionaryIterator* data) 201 | { 202 | switch (packetId) 203 | { 204 | case 0: 205 | receivedNumbers(data); 206 | break; 207 | 208 | } 209 | 210 | } 211 | 212 | void number_picker_window_data_sent(void) 213 | { 214 | if (pickedNumber >= 0) 215 | { 216 | sendPickedNumber(pickedNumber); 217 | } 218 | } 219 | 220 | static void config_provider(void* context) { 221 | window_single_repeating_click_subscribe(BUTTON_ID_UP, 200, (ClickHandler) button_up_press); 222 | window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 200, (ClickHandler) button_down_press); 223 | window_single_click_subscribe(BUTTON_ID_SELECT, (ClickHandler) button_select_press); 224 | } 225 | 226 | 227 | static void window_load(Window* me) { 228 | contactActions = cb_create(sizeof(ContactAction), 8); 229 | 230 | Layer* topLayer = window_get_root_layer(window); 231 | 232 | menuLayer = menu_layer_create(GRect(0, STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, HEIGHT_BELOW_STATUSBAR)); 233 | 234 | // Set all the callbacks for the menu layer 235 | menu_layer_set_callbacks(menuLayer, NULL, (MenuLayerCallbacks){ 236 | .get_num_sections = menu_get_num_sections_callback, 237 | .get_num_rows = menu_get_num_rows_callback, 238 | .get_cell_height = menu_get_row_height_callback, 239 | .draw_row = menu_draw_row_callback, 240 | .selection_changed = menu_pos_changed 241 | }); 242 | 243 | menu_layer_set_click_config_onto_window(menuLayer, window); 244 | window_set_click_config_provider(window, config_provider); 245 | 246 | layer_add_child(topLayer, (Layer*) menuLayer); 247 | 248 | #ifdef PBL_COLOR 249 | menu_layer_set_highlight_colors(menuLayer, GColorJaegerGreen, GColorBlack); 250 | #endif 251 | 252 | statusBar = status_bar_layer_create(); 253 | layer_add_child(topLayer, status_bar_layer_get_layer(statusBar)); 254 | 255 | callIcon = gbitmap_create_with_resource(RESOURCE_ID_CALL); 256 | messageIcon = gbitmap_create_with_resource(RESOURCE_ID_MESSAGE); 257 | 258 | actions_menu_init(); 259 | actions_menu_attach(topLayer); 260 | } 261 | 262 | static void window_appear(Window* me) 263 | { 264 | setCurWindow(4); 265 | } 266 | 267 | static void window_unload(Window* me) 268 | { 269 | menu_layer_destroy(menuLayer); 270 | status_bar_layer_destroy(statusBar); 271 | 272 | gbitmap_destroy(callIcon); 273 | gbitmap_destroy(messageIcon); 274 | 275 | actions_menu_deinit(); 276 | 277 | window_destroy(me); 278 | cb_destroy(contactActions); 279 | } 280 | 281 | void number_picker_window_init(void) 282 | { 283 | window = window_create(); 284 | 285 | window_set_window_handlers(window, (WindowHandlers){ 286 | .load = window_load, 287 | .appear = window_appear, 288 | .unload = window_unload 289 | }); 290 | 291 | window_stack_push(window, true /* Animated */); 292 | } 293 | 294 | -------------------------------------------------------------------------------- /src/CallLogWindow.c: -------------------------------------------------------------------------------- 1 | #include "pebble.h" 2 | #include "pebble_fonts.h" 3 | 4 | #include "PebbleDialer.h" 5 | #include "util.h" 6 | #include "CircularBuffer.h" 7 | #include "pebble-rtltr/rtltr.h" 8 | 9 | static Window* window; 10 | 11 | static uint16_t numEntries = 10; 12 | 13 | static int16_t pickedEntry = -1; 14 | static uint8_t pickedMode = 0; 15 | 16 | typedef struct 17 | { 18 | char name[21]; 19 | char date[21]; 20 | uint8_t type; 21 | char number[21]; 22 | } CallLogEntry; 23 | 24 | static CircularBuffer* callLogData; 25 | 26 | static MenuLayer* menuLayer; 27 | 28 | static GBitmap* incomingCall; 29 | static GBitmap* outgoingCall; 30 | static GBitmap* missedCall; 31 | 32 | static StatusBarLayer* statusBar; 33 | 34 | static uint16_t scrollPosition = 0; 35 | 36 | static void requestNumbers(uint16_t pos) 37 | { 38 | DictionaryIterator *iterator; 39 | app_message_outbox_begin(&iterator); 40 | dict_write_uint8(iterator, 0, 2); 41 | dict_write_uint8(iterator, 1, 0); 42 | dict_write_uint16(iterator, 2, pos); 43 | 44 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 45 | app_message_outbox_send(); 46 | } 47 | 48 | static void sendpickedEntry(int16_t pos, uint8_t mode) 49 | { 50 | DictionaryIterator *iterator; 51 | AppMessageResult result = app_message_outbox_begin(&iterator); 52 | if (result != APP_MSG_OK) 53 | { 54 | pickedEntry = pos; 55 | pickedMode = mode; 56 | return; 57 | } 58 | 59 | dict_write_uint8(iterator, 0, 2); 60 | dict_write_uint8(iterator, 1, 1); 61 | dict_write_int16(iterator, 2, pos); 62 | dict_write_uint8(iterator, 3, mode); 63 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 64 | app_message_outbox_send(); 65 | 66 | pickedEntry = -1; 67 | if (mode == 0) 68 | onOutgoingCallEstablished(); 69 | } 70 | 71 | static void requestAdditionalEntries(void) 72 | { 73 | uint16_t filledDown = cb_getNumOfLoadedSpacesDownFromCenter(callLogData, numEntries); 74 | uint16_t filledUp = cb_getNumOfLoadedSpacesUpFromCenter(callLogData); 75 | 76 | 77 | if (filledDown < 4 && filledDown <= filledUp) 78 | { 79 | uint16_t startingIndex = callLogData->centerIndex + filledDown; 80 | requestNumbers(startingIndex); 81 | } 82 | else if (filledUp < 4) 83 | { 84 | uint16_t startingIndex = callLogData->centerIndex - filledUp; 85 | requestNumbers(startingIndex); 86 | } 87 | } 88 | 89 | static uint16_t menu_get_num_sections_callback(MenuLayer *me, void *data) { 90 | return 1; 91 | } 92 | 93 | static uint16_t menu_get_num_rows_callback(MenuLayer *me, uint16_t section_index, void *data) { 94 | return numEntries; 95 | } 96 | 97 | 98 | static int16_t menu_get_row_height_callback(MenuLayer *me, MenuIndex *cell_index, void *data) { 99 | CallLogEntry* entry = cb_getEntry(callLogData, cell_index->row); 100 | if (entry == NULL || entry->number[0] == 0) 101 | return 40; //Return smaller window if there is no number (third row) to display 102 | else 103 | return 55; 104 | } 105 | 106 | static void menu_pos_changed(struct MenuLayer *menu_layer, MenuIndex new_index, MenuIndex old_index, void *callback_context) 107 | { 108 | cb_shift(callLogData, new_index.row); 109 | requestAdditionalEntries(); 110 | 111 | menu_layer_set_selected_index(menuLayer, new_index, MenuRowAlignCenter, false); 112 | } 113 | 114 | 115 | static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) 116 | { 117 | CallLogEntry* callLogEntry = cb_getEntry(callLogData, cell_index->row); 118 | if (callLogEntry == NULL) 119 | return; 120 | 121 | bool hasNumberType = callLogEntry->number[0] != 0; 122 | 123 | graphics_context_set_text_color(ctx, PBL_IF_COLOR_ELSE(GColorBlack, menu_cell_layer_is_highlighted(cell_layer) ? GColorWhite : GColorBlack)); 124 | 125 | graphics_draw_text(ctx, callLogEntry->name, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(35, 0, SCREEN_WIDTH - 30, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); 126 | graphics_draw_text(ctx, callLogEntry->date, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(35, 20, SCREEN_WIDTH - 30, 15), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); 127 | if (hasNumberType) 128 | graphics_draw_text(ctx, callLogEntry->number, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), GRect(35, 35, SCREEN_WIDTH - 30, 20), GTextOverflowModeTrailingEllipsis, GTextAlignmentLeft, NULL); 129 | 130 | GBitmap* image; 131 | switch (callLogEntry->type) 132 | { 133 | case 1: 134 | image = incomingCall; 135 | break; 136 | case 2: 137 | image = outgoingCall; 138 | break; 139 | default: 140 | image = missedCall; 141 | break; 142 | } 143 | 144 | graphics_context_set_compositing_mode(ctx, GCompOpSet); 145 | graphics_draw_bitmap_in_rect(ctx, image, GRect(3, hasNumberType ? 14 : 5, 28, 28)); 146 | } 147 | 148 | 149 | static void menu_select_callback(MenuLayer *me, MenuIndex *cell_index, void *data) { 150 | sendpickedEntry(cell_index->row, 0); 151 | } 152 | 153 | static void menu_long_select_callback(MenuLayer *me, MenuIndex *cell_index, void *data) { 154 | sendpickedEntry(cell_index->row, 1); 155 | } 156 | 157 | static void receivedEntries(DictionaryIterator* data) 158 | { 159 | uint16_t offset = dict_find(data, 2)->value->uint16; 160 | numEntries = dict_find(data, 3)->value->uint16; 161 | 162 | CallLogEntry* entry = cb_getEntryForFilling(callLogData, offset); 163 | if (entry != NULL) 164 | { 165 | entry->type = dict_find(data, 4)->value->uint8; 166 | #ifndef PBL_LOW_MEMORY 167 | rtltr_strcpy(entry->name, dict_find(data, 5)->value->cstring); 168 | rtltr_strcpy(entry->number, dict_find(data, 7)->value->cstring); 169 | #else 170 | strcpy(entry->name, dict_find(data, 5)->value->cstring); 171 | strcpy(entry->number, dict_find(data, 7)->value->cstring); 172 | #endif 173 | strcpy(entry->date, dict_find(data, 6)->value->cstring); 174 | } 175 | 176 | menu_layer_reload_data(menuLayer); 177 | 178 | if (pickedEntry >= 0) 179 | { 180 | sendpickedEntry(pickedEntry, pickedMode); 181 | return; 182 | } 183 | 184 | requestAdditionalEntries(); 185 | } 186 | 187 | void call_log_window_data_received(int packetId, DictionaryIterator* data) 188 | { 189 | switch (packetId) 190 | { 191 | case 0: 192 | receivedEntries(data); 193 | break; 194 | 195 | } 196 | } 197 | 198 | void call_log_window_data_sent(void) 199 | { 200 | if (pickedEntry >= 0) 201 | { 202 | sendpickedEntry(pickedEntry, pickedMode); 203 | } 204 | } 205 | 206 | static void window_appear(Window *me) { 207 | callLogData = cb_create(sizeof(CallLogEntry), 8); 208 | 209 | Layer* topLayer = window_get_root_layer(window); 210 | 211 | menuLayer = menu_layer_create(GRect(0, STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, HEIGHT_BELOW_STATUSBAR)); 212 | 213 | // Set all the callbacks for the menu layer 214 | menu_layer_set_callbacks(menuLayer, NULL, (MenuLayerCallbacks){ 215 | .get_num_sections = menu_get_num_sections_callback, 216 | .get_num_rows = menu_get_num_rows_callback, 217 | .get_cell_height = menu_get_row_height_callback, 218 | .draw_row = menu_draw_row_callback, 219 | .select_click = menu_select_callback, 220 | .select_long_click = menu_long_select_callback, 221 | .selection_changed = menu_pos_changed, 222 | 223 | 224 | }); 225 | 226 | #ifdef PBL_COLOR 227 | menu_layer_set_highlight_colors(menuLayer, GColorJaegerGreen, GColorBlack); 228 | #endif 229 | 230 | menu_layer_set_click_config_onto_window(menuLayer, window); 231 | 232 | incomingCall = gbitmap_create_with_resource(RESOURCE_ID_INCOMING_CALL); 233 | outgoingCall = gbitmap_create_with_resource(RESOURCE_ID_OUTGOING_CALL); 234 | missedCall = gbitmap_create_with_resource(RESOURCE_ID_MISSED_CALL); 235 | 236 | layer_add_child(topLayer, (Layer*) menuLayer); 237 | 238 | statusBar = status_bar_layer_create(); 239 | layer_add_child(topLayer, status_bar_layer_get_layer(statusBar)); 240 | 241 | menu_layer_set_selected_index(menuLayer, MenuIndex(0, scrollPosition), MenuRowAlignCenter, false); 242 | requestAdditionalEntries(); 243 | 244 | setCurWindow(2); 245 | } 246 | 247 | static void window_disappear(Window* me) 248 | { 249 | layer_remove_child_layers(window_get_root_layer(me)); 250 | 251 | scrollPosition = menu_layer_get_selected_index(menuLayer).row; 252 | 253 | gbitmap_destroy(incomingCall); 254 | gbitmap_destroy(outgoingCall); 255 | gbitmap_destroy(missedCall); 256 | 257 | menu_layer_destroy(menuLayer); 258 | status_bar_layer_destroy(statusBar); 259 | 260 | cb_destroy(callLogData); 261 | } 262 | 263 | static void window_load(Window *me) { 264 | scrollPosition = 0; 265 | } 266 | 267 | static void window_unload(Window *me) { 268 | window_destroy(me); 269 | } 270 | 271 | void call_log_window_init(void) 272 | { 273 | window = window_create(); 274 | 275 | window_set_window_handlers(window, (WindowHandlers){ 276 | .appear = window_appear, 277 | .load = window_load, 278 | .unload = window_unload, 279 | .disappear = window_disappear 280 | 281 | }); 282 | 283 | window_stack_push(window, true /* Animated */); 284 | } 285 | 286 | -------------------------------------------------------------------------------- /src/PebbleDialer.c: -------------------------------------------------------------------------------- 1 | #include "pebble.h" 2 | #include "pebble_fonts.h" 3 | 4 | #include "CallLogWindow.h" 5 | #include "ContactsWindow.h" 6 | #include "CallWindow.h" 7 | #include "MainMenuWindow.h" 8 | #include "NumberPickerWindow.h" 9 | #include "ActionsMenu.h" 10 | #include "PebbleDialer.h" 11 | 12 | const uint16_t PROTOCOL_VERSION = 11; 13 | 14 | static uint8_t curWindow = 0; 15 | static bool gotConfig = false; 16 | static bool loadingMode; 17 | static uint16_t appmessage_max_size; 18 | 19 | bool config_dontClose; 20 | bool config_noMenu; 21 | uint8_t config_numOfGroups; 22 | bool config_noFilterGroups; 23 | bool config_lightCallWindow; 24 | bool config_dontVibrateWhenCharging; 25 | bool config_enableCallTimer; 26 | bool config_enableOutgoingCallPopup; 27 | uint8_t config_fontTimer; 28 | uint8_t config_fontName; 29 | uint8_t config_fontNumberType; 30 | uint8_t config_fontNumber; 31 | 32 | bool closingMode; 33 | bool exitOnDataDelivered; 34 | 35 | static const char* fonts[] = { 36 | FONT_KEY_GOTHIC_14, 37 | FONT_KEY_GOTHIC_14_BOLD, 38 | FONT_KEY_GOTHIC_18, 39 | FONT_KEY_GOTHIC_18_BOLD, 40 | FONT_KEY_GOTHIC_24, 41 | FONT_KEY_GOTHIC_24_BOLD, 42 | FONT_KEY_GOTHIC_28, 43 | FONT_KEY_GOTHIC_28_BOLD, 44 | FONT_KEY_BITHAM_30_BLACK, 45 | FONT_KEY_BITHAM_42_BOLD, 46 | FONT_KEY_BITHAM_42_LIGHT, 47 | FONT_KEY_BITHAM_42_MEDIUM_NUMBERS, 48 | FONT_KEY_BITHAM_34_MEDIUM_NUMBERS, 49 | FONT_KEY_BITHAM_34_LIGHT_SUBSET, 50 | FONT_KEY_BITHAM_18_LIGHT_SUBSET, 51 | FONT_KEY_ROBOTO_CONDENSED_21, 52 | FONT_KEY_ROBOTO_BOLD_SUBSET_49, 53 | FONT_KEY_DROID_SERIF_28_BOLD 54 | }; 55 | 56 | static void send_initial_packet(); 57 | 58 | const char* config_getFontResource(int id) 59 | { 60 | return fonts[id]; 61 | } 62 | 63 | void setCurWindow(int window) 64 | { 65 | curWindow = window; 66 | } 67 | 68 | void switchWindow(int window) 69 | { 70 | switch (window) 71 | { 72 | case 0: 73 | main_menu_init(); 74 | break; 75 | case 1: 76 | call_window_init(); 77 | break; 78 | case 2: 79 | call_log_window_init(); 80 | break; 81 | case 3: 82 | contacts_window_init(); 83 | break; 84 | case 4: 85 | number_picker_window_init(); 86 | break; 87 | } 88 | } 89 | 90 | void closeApp(void) 91 | { 92 | DictionaryIterator *iterator; 93 | app_message_outbox_begin(&iterator); 94 | dict_write_uint8(iterator, 0, 0); 95 | dict_write_uint8(iterator, 1, 2); 96 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 97 | app_message_outbox_send(); 98 | 99 | closingMode = true; 100 | } 101 | 102 | static void received_config(DictionaryIterator *received) 103 | { 104 | loadingMode = false; 105 | 106 | uint8_t* data = dict_find(received, 2)->value->data; 107 | 108 | uint16_t supportedVersion = (data[0] << 8) | (data[1]); 109 | if (supportedVersion > PROTOCOL_VERSION) 110 | { 111 | main_menu_show_old_watchapp(); 112 | return; 113 | } 114 | else if (supportedVersion < PROTOCOL_VERSION) 115 | { 116 | main_menu_show_old_android(); 117 | return; 118 | } 119 | 120 | config_noMenu = (data[2] & 0x01) != 0; 121 | config_dontClose = (data[2] & 0x02) != 0; 122 | config_noFilterGroups = (data[2] & 0x04) != 0; 123 | config_lightCallWindow = (data[2] & 0x08) != 0; 124 | config_dontVibrateWhenCharging = (data[2] & 0x10) != 0; 125 | config_enableCallTimer = (data[2] & 0x20) != 0; 126 | config_enableOutgoingCallPopup = (data[2] & 0x40) != 0; 127 | 128 | config_numOfGroups = data[3]; 129 | config_fontTimer = data[4]; 130 | config_fontName = data[5]; 131 | config_fontNumberType = data[6]; 132 | config_fontNumber = data[7]; 133 | 134 | gotConfig = true; 135 | 136 | if (!config_noMenu) 137 | main_menu_show_menu(); 138 | 139 | } 140 | 141 | bool canVibrate(void) 142 | { 143 | return !config_dontVibrateWhenCharging || !battery_state_service_peek().is_plugged; 144 | } 145 | 146 | void onOutgoingCallEstablished() 147 | { 148 | if (!config_enableOutgoingCallPopup) 149 | exitOnDataDelivered = true; 150 | } 151 | 152 | static void received_data(DictionaryIterator *received, void *context) { 153 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 154 | 155 | uint8_t destModule = dict_find(received, 0)->value->uint8; 156 | uint8_t packetId = dict_find(received, 1)->value->uint8; 157 | bool autoSwitch = dict_find(received, 999) != NULL; 158 | 159 | if (destModule == 0 && packetId == 0) 160 | { 161 | received_config(received); 162 | return; 163 | } 164 | 165 | if (!gotConfig) //Do not react to anything until we got config 166 | return; 167 | 168 | if (destModule == 0) 169 | { 170 | if (packetId == 1) 171 | { 172 | closingMode = true; 173 | window_stack_pop_all(false); 174 | switchWindow(0); 175 | 176 | return; 177 | } 178 | if (curWindow != 0) 179 | { 180 | if (autoSwitch) 181 | switchWindow(0); 182 | else 183 | return; 184 | } 185 | 186 | main_menu_data_received(packetId, received); 187 | } 188 | else if (destModule == 1) 189 | { 190 | if (curWindow != 1) 191 | { 192 | if (autoSwitch) 193 | switchWindow(1); 194 | else 195 | return; 196 | } 197 | 198 | call_window_data_received(destModule, packetId, received); 199 | } 200 | else if (destModule == 2) 201 | { 202 | if (curWindow != 2) 203 | { 204 | if (autoSwitch) 205 | switchWindow(2); 206 | else 207 | return; 208 | } 209 | 210 | call_log_window_data_received(packetId, received); 211 | } 212 | else if (destModule == 3) 213 | { 214 | if (curWindow != 3) 215 | { 216 | if (autoSwitch) 217 | switchWindow(3); 218 | else 219 | return; 220 | } 221 | 222 | contacts_window_data_received(packetId, received); 223 | } 224 | else if (destModule == 4) 225 | { 226 | if (curWindow != 4) 227 | { 228 | if (autoSwitch) 229 | switchWindow(4); 230 | else 231 | return; 232 | } 233 | 234 | number_picker_window_data_received(packetId, received); 235 | } 236 | else if (destModule == 5) 237 | { 238 | actions_menu_got_data(packetId, received); 239 | } 240 | } 241 | 242 | static void data_delivered(DictionaryIterator *sent, void *context) { 243 | switch (curWindow) 244 | { 245 | case 2: 246 | call_log_window_data_sent(); 247 | break; 248 | case 3: 249 | contacts_window_data_delivered(); 250 | break; 251 | case 4: 252 | number_picker_window_data_sent(); 253 | break; 254 | } 255 | 256 | if (exitOnDataDelivered) 257 | window_stack_pop_all(true); 258 | } 259 | 260 | static uint32_t getCapabilities(uint16_t maxInboxSize) 261 | { 262 | uint32_t serializedCapabilities = 0; 263 | 264 | serializedCapabilities |= PBL_IF_MICROPHONE_ELSE(0x01, 0x00); 265 | serializedCapabilities |= PBL_IF_COLOR_ELSE(0x02, 0x00); 266 | serializedCapabilities |= PBL_IF_ROUND_ELSE(0x04, 0x00); 267 | serializedCapabilities |= PBL_IF_SMARTSTRAP_ELSE(0x08, 0x00); 268 | serializedCapabilities |= PBL_IF_HEALTH_ELSE(0x10, 0x00); 269 | serializedCapabilities |= maxInboxSize << 16; 270 | 271 | return serializedCapabilities; 272 | } 273 | 274 | 275 | static void send_initial_packet_and_start_timer(void *data) 276 | { 277 | if (!loadingMode) 278 | return; 279 | 280 | if (!connection_service_peek_pebble_app_connection()) 281 | { 282 | main_menu_show_no_connection(); 283 | return; 284 | } 285 | send_initial_packet(); 286 | app_timer_register(3000, send_initial_packet_and_start_timer, NULL); 287 | } 288 | 289 | 290 | static void send_initial_packet() { 291 | uint16_t fullscreenImageWidth = SCREEN_WIDTH - PBL_IF_ROUND_ELSE(ACTION_BAR_WIDTH / 2, ACTION_BAR_WIDTH); 292 | uint16_t fullscreenImageHeight = HEIGHT_BELOW_STATUSBAR; 293 | 294 | DictionaryIterator *iterator; 295 | app_message_outbox_begin(&iterator); 296 | dict_write_uint8(iterator, 0, 0); 297 | dict_write_uint8(iterator, 1, 0); 298 | dict_write_uint16(iterator, 2, PROTOCOL_VERSION); 299 | dict_write_uint32(iterator, 3, getCapabilities(appmessage_max_size)); 300 | dict_write_uint16(iterator, 4, fullscreenImageWidth); 301 | dict_write_uint16(iterator, 5, fullscreenImageHeight); 302 | 303 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 304 | app_message_outbox_send(); 305 | } 306 | 307 | int main() { 308 | if (quiet_time_is_active()) 309 | { 310 | AppLaunchReason launchReason = launch_reason(); 311 | if (launchReason == APP_LAUNCH_PHONE) 312 | { 313 | // Incoming call popup was launched by phone, but quiet time is active. Lets bail out. 314 | return 0; 315 | } 316 | } 317 | 318 | app_message_register_outbox_sent(data_delivered); 319 | app_message_register_inbox_received(received_data); 320 | 321 | appmessage_max_size = app_message_inbox_size_maximum(); 322 | if (appmessage_max_size > 4096) 323 | appmessage_max_size = 4096; //Limit inbox size to conserve RAM. 324 | 325 | #ifdef PBL_PLATFORM_APLITE 326 | //Aplite has so little memory, we can't squeeze much more than that out of appmessage buffer. 327 | appmessage_max_size = 124; 328 | #endif 329 | 330 | 331 | app_message_open(appmessage_max_size, 124); 332 | 333 | loadingMode = true; 334 | send_initial_packet_and_start_timer(NULL); 335 | 336 | switchWindow(0); 337 | app_event_loop(); 338 | window_stack_pop_all(false); 339 | 340 | AppLaunchReason appLaunchReason = launch_reason(); 341 | if (appLaunchReason == APP_LAUNCH_PHONE && !config_dontClose) { 342 | // If app was launched by phone and close to last app is disabled, always exit to the watchface instead of to the menu 343 | exit_reason_set(APP_EXIT_ACTION_PERFORMED_SUCCESSFULLY); 344 | } 345 | 346 | return 0; 347 | } 348 | -------------------------------------------------------------------------------- /src/MainMenuWindow.c: -------------------------------------------------------------------------------- 1 | #include "pebble.h" 2 | #include "pebble_fonts.h" 3 | #include 4 | 5 | #include "PebbleDialer.h" 6 | #include "ContactsWindow.h" 7 | #include "MainMenuWindow.h" 8 | 9 | static Window* window = NULL; 10 | 11 | static char groupNames[20][21] = {}; 12 | 13 | static GBitmap* callHistoryIcon; 14 | static GBitmap* contactsIcon; 15 | static GBitmap* contactGroupIcon; 16 | 17 | static TextLayer* loadingLayer; 18 | 19 | #ifndef PBL_LOW_MEMORY 20 | static const uint16_t ACTIVITY_INDICATOR_SIZE = 50; 21 | static const uint16_t ACTIVITY_INDICATOR_THICKNESS = 5; 22 | static ActivityIndicatorLayer *loadingIndicator; 23 | #endif 24 | 25 | static TextLayer* quitTitle; 26 | static TextLayer* quitText; 27 | 28 | static MenuLayer* menuLayer; 29 | 30 | static StatusBarLayer* statusBar; 31 | 32 | static bool menuLoaded = false; 33 | 34 | static void show_error_base(void); 35 | 36 | static void show_loading(void) 37 | { 38 | layer_set_hidden((Layer *) loadingLayer, false); 39 | layer_set_hidden((Layer *) quitTitle, true); 40 | layer_set_hidden((Layer *) quitText, true); 41 | layer_set_hidden((Layer *) menuLayer, true); 42 | 43 | #ifndef PBL_LOW_MEMORY 44 | activity_indicator_layer_set_animating(loadingIndicator, true); 45 | layer_set_hidden(activity_indicator_layer_get_layer(loadingIndicator), false); 46 | #endif 47 | } 48 | 49 | void main_menu_show_closing(void) 50 | { 51 | if (!window_stack_contains_window(window)) 52 | main_menu_init(); 53 | layer_set_hidden((Layer *) loadingLayer, true); 54 | layer_set_hidden((Layer *) menuLayer, true); 55 | layer_set_hidden((Layer *) quitTitle, false); 56 | layer_set_hidden((Layer *) quitText, false); 57 | 58 | closingMode = true; 59 | } 60 | 61 | void main_menu_show_old_watchapp(void) 62 | { 63 | show_error_base(); 64 | text_layer_set_text(loadingLayer, "Dialer\nOutdated Watchapp \n\n Check your phone"); 65 | 66 | } 67 | 68 | void main_menu_show_old_android(void) 69 | { 70 | show_error_base(); 71 | text_layer_set_text(loadingLayer, "Dialer\nUpdate Android App \n\n Open link:\n bit.ly/1KhZCog"); 72 | } 73 | 74 | void main_menu_show_no_connection(void) 75 | { 76 | if (window == NULL) 77 | return; 78 | 79 | show_error_base(); 80 | text_layer_set_text(loadingLayer, "Dialer\n\nPhone is not connected."); 81 | } 82 | 83 | static void show_error_base(void) 84 | { 85 | layer_set_hidden((Layer *) loadingLayer, false); 86 | layer_set_hidden((Layer *) quitTitle, true); 87 | layer_set_hidden((Layer *) quitText, true); 88 | layer_set_hidden((Layer *) menuLayer, true); 89 | 90 | #ifndef PBL_LOW_MEMORY 91 | activity_indicator_layer_set_animating(loadingIndicator, false); 92 | layer_set_hidden(activity_indicator_layer_get_layer(loadingIndicator), true); 93 | #endif 94 | 95 | text_layer_set_font(loadingLayer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); 96 | } 97 | 98 | static uint16_t menu_get_num_sections_callback(MenuLayer *me, void *data) { 99 | return 1; 100 | } 101 | 102 | static uint16_t menu_get_num_rows_callback(MenuLayer *me, uint16_t section_index, void *data) { 103 | return config_numOfGroups + 2; 104 | } 105 | 106 | static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { 107 | char* text; 108 | GBitmap* icon; 109 | 110 | int16_t index = cell_index->row; 111 | 112 | if (index == 0) 113 | { 114 | text = "Call History"; 115 | icon = callHistoryIcon; 116 | } 117 | else if (index == 1) 118 | { 119 | text = "All contacts"; 120 | icon = contactsIcon; 121 | } 122 | else 123 | { 124 | text = groupNames[index - 2]; 125 | icon = contactGroupIcon; 126 | } 127 | 128 | 129 | graphics_context_set_compositing_mode(ctx, GCompOpSet); 130 | menu_cell_basic_draw(ctx, cell_layer, text, NULL, icon); 131 | } 132 | 133 | void main_menu_show_menu(void) 134 | { 135 | menuLoaded = true; 136 | 137 | layer_set_hidden((Layer *) loadingLayer, true); 138 | layer_set_hidden((Layer *) menuLayer, false); 139 | layer_set_hidden((Layer *) quitTitle, true); 140 | layer_set_hidden((Layer *) quitText, true); 141 | 142 | #ifndef PBL_LOW_MEMORY 143 | activity_indicator_layer_set_animating(loadingIndicator, false); 144 | layer_set_hidden(activity_indicator_layer_get_layer(loadingIndicator), true); 145 | #endif 146 | } 147 | 148 | void main_menu_close(void) 149 | { 150 | if (window != NULL) 151 | { 152 | window_stack_remove(window, false); 153 | window = NULL; 154 | } 155 | } 156 | 157 | static void closing_timer(void* data) 158 | { 159 | if (!closingMode) 160 | return; 161 | 162 | closeApp(); 163 | app_timer_register(3000, closing_timer, NULL); 164 | } 165 | 166 | static void menu_select_callback(MenuLayer *me, MenuIndex *cell_index, void *data) 167 | { 168 | DictionaryIterator *iterator; 169 | app_message_outbox_begin(&iterator); 170 | 171 | int16_t index = cell_index->row; 172 | 173 | dict_write_uint8(iterator, 0, 0); 174 | dict_write_uint8(iterator, 1, 1); 175 | dict_write_uint8(iterator, 2, index); 176 | 177 | app_message_outbox_send(); 178 | 179 | int newWindow = index > 0 ? 3 : 2; 180 | switchWindow(newWindow); 181 | if (index > 1 && config_noFilterGroups) 182 | contacts_window_stop_filtering(); 183 | } 184 | 185 | 186 | static void receivedGroupNames(DictionaryIterator* data) 187 | { 188 | uint8_t offset = dict_find(data, 2)->value->uint8; 189 | 190 | for (int i = 0; i < 3; i++) 191 | { 192 | 193 | int groupPos = offset + i; 194 | if (groupPos >= config_numOfGroups) 195 | break; 196 | 197 | strcpy(groupNames[groupPos], dict_find(data, 3 + i)->value->cstring); 198 | } 199 | 200 | menu_layer_reload_data(menuLayer); 201 | } 202 | 203 | void main_menu_data_received(int packetId, DictionaryIterator* data) 204 | { 205 | 206 | switch (packetId) 207 | { 208 | case 2: 209 | receivedGroupNames(data); 210 | break; 211 | 212 | } 213 | 214 | } 215 | 216 | static void window_appears(Window *me) 217 | { 218 | callHistoryIcon = gbitmap_create_with_resource(RESOURCE_ID_CALL_HISTORY); 219 | contactsIcon = gbitmap_create_with_resource(RESOURCE_ID_CONTACTS); 220 | contactGroupIcon = gbitmap_create_with_resource(RESOURCE_ID_CONTACT_GROUP); 221 | 222 | Layer* topLayer = window_get_root_layer(me); 223 | loadingLayer = text_layer_create(GRect(0, STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, HEIGHT_BELOW_STATUSBAR)); 224 | text_layer_set_text_alignment(loadingLayer, GTextAlignmentCenter); 225 | text_layer_set_text(loadingLayer, "Dialer"); 226 | text_layer_set_font(loadingLayer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); 227 | layer_add_child(topLayer, (Layer*) loadingLayer); 228 | 229 | quitTitle = text_layer_create(GRect(0, 70 + STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, 50)); 230 | text_layer_set_text_alignment(quitTitle, GTextAlignmentCenter); 231 | text_layer_set_text(quitTitle, "Press back again if app does not close in several seconds"); 232 | layer_add_child(topLayer, (Layer*) quitTitle); 233 | 234 | quitText = text_layer_create(GRect(0, 10 + STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, 50)); 235 | text_layer_set_text_alignment(quitText, GTextAlignmentCenter); 236 | text_layer_set_text(quitText, "Quitting...\n Please wait"); 237 | text_layer_set_font(quitText, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); 238 | layer_add_child(topLayer, (Layer*) quitText); 239 | 240 | #ifndef PBL_LOW_MEMORY 241 | loadingIndicator = activity_indicator_layer_create(GRect(SCREEN_WIDTH / 2 - ACTIVITY_INDICATOR_SIZE / 2, HEIGHT_BELOW_STATUSBAR / 2 - ACTIVITY_INDICATOR_SIZE / 2 + STATUS_BAR_LAYER_HEIGHT, ACTIVITY_INDICATOR_SIZE, ACTIVITY_INDICATOR_SIZE)); 242 | activity_indicator_layer_set_thickness(loadingIndicator, ACTIVITY_INDICATOR_THICKNESS); 243 | layer_add_child(topLayer, activity_indicator_layer_get_layer(loadingIndicator)); 244 | 245 | text_layer_set_text(loadingLayer, "Dialer"); 246 | #else 247 | text_layer_set_text(loadingLayer, "Dialer\n\nLoading"); 248 | #endif 249 | 250 | menuLayer = menu_layer_create(GRect(0, STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, HEIGHT_BELOW_STATUSBAR)); 251 | 252 | // Set all the callbacks for the menu layer 253 | menu_layer_set_callbacks(menuLayer, NULL, (MenuLayerCallbacks){ 254 | .get_num_sections = menu_get_num_sections_callback, 255 | .get_num_rows = menu_get_num_rows_callback, 256 | .draw_row = menu_draw_row_callback, 257 | .select_click = menu_select_callback, 258 | }); 259 | 260 | #ifdef PBL_COLOR 261 | menu_layer_set_highlight_colors(menuLayer, GColorJaegerGreen, GColorBlack); 262 | #endif 263 | 264 | menu_layer_set_click_config_onto_window(menuLayer, window); 265 | layer_add_child(topLayer, (Layer*) menuLayer); 266 | 267 | statusBar = status_bar_layer_create(); 268 | layer_add_child(topLayer, status_bar_layer_get_layer(statusBar)); 269 | 270 | if (closingMode) 271 | { 272 | main_menu_show_closing(); 273 | closeApp(); 274 | app_timer_register(3000, closing_timer, NULL); 275 | } 276 | else if (menuLoaded) 277 | { 278 | main_menu_show_menu(); 279 | } 280 | else if (!connection_service_peek_pebble_app_connection()) 281 | { 282 | main_menu_show_no_connection(); 283 | } 284 | else 285 | { 286 | show_loading(); 287 | } 288 | 289 | setCurWindow(0); 290 | } 291 | 292 | static void window_disappears(Window* me) 293 | { 294 | gbitmap_destroy(callHistoryIcon); 295 | gbitmap_destroy(contactsIcon); 296 | gbitmap_destroy(contactGroupIcon); 297 | 298 | text_layer_destroy(loadingLayer); 299 | text_layer_destroy(quitTitle); 300 | text_layer_destroy(quitText); 301 | 302 | menu_layer_destroy(menuLayer); 303 | status_bar_layer_destroy(statusBar); 304 | #ifndef PBL_LOW_MEMORY 305 | activity_indicator_layer_destroy(loadingIndicator); 306 | #endif 307 | } 308 | 309 | static void window_unload(Window* me) 310 | { 311 | window_destroy(me); 312 | } 313 | 314 | 315 | void main_menu_init(void) 316 | { 317 | window = window_create(); 318 | 319 | window_set_window_handlers(window, (WindowHandlers){ 320 | .appear = window_appears, 321 | .disappear = window_disappears, 322 | .unload = window_unload 323 | }); 324 | 325 | window_stack_push(window, true /* Animated */); 326 | setCurWindow(0); 327 | } 328 | 329 | -------------------------------------------------------------------------------- /src/ContactsWindow.c: -------------------------------------------------------------------------------- 1 | #include "pebble.h" 2 | #include "pebble_fonts.h" 3 | 4 | #include "PebbleDialer.h" 5 | #include "util.h" 6 | #include "CircularBuffer.h" 7 | #include "pebble-rtltr/rtltr.h" 8 | 9 | static Window* window; 10 | 11 | static uint16_t numMaxContacts = 7; 12 | 13 | static int16_t pickedContact = -1; 14 | static int8_t pickedFilterButton = -1; 15 | 16 | static CircularBuffer* contacts; 17 | 18 | static MenuLayer* contactsMenuLayer; 19 | 20 | static StatusBarLayer* statusBar; 21 | 22 | static bool filterMode; 23 | static bool nothingFiltered; 24 | static bool firstAppear; 25 | static uint16_t scrollPosition; 26 | 27 | static void menu_config_provider(void* context); 28 | 29 | static void requestContacts(uint16_t pos) 30 | { 31 | DictionaryIterator *iterator; 32 | app_message_outbox_begin(&iterator); 33 | dict_write_uint8(iterator, 0, 3); 34 | dict_write_uint8(iterator, 1, 1); 35 | dict_write_uint16(iterator, 2, pos); 36 | app_message_outbox_send(); 37 | 38 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 39 | } 40 | 41 | static void sendPickedContact(int16_t pos) 42 | { 43 | DictionaryIterator *iterator; 44 | AppMessageResult result = app_message_outbox_begin(&iterator); 45 | if (result != APP_MSG_OK) 46 | { 47 | pickedContact = pos; 48 | return; 49 | } 50 | 51 | dict_write_uint8(iterator, 0, 3); 52 | dict_write_uint8(iterator, 1, 2); 53 | dict_write_int16(iterator, 2, pos); 54 | app_message_outbox_send(); 55 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 56 | 57 | pickedContact = -1; 58 | } 59 | 60 | static void requestAdditionalContacts(void) 61 | { 62 | uint16_t filledDown = cb_getNumOfLoadedSpacesDownFromCenter(contacts, numMaxContacts); 63 | uint16_t filledUp = cb_getNumOfLoadedSpacesUpFromCenter(contacts); 64 | 65 | if (filledDown < 6 && filledDown <= filledUp) 66 | { 67 | uint16_t startingIndex = contacts->centerIndex + filledDown; 68 | requestContacts(startingIndex); 69 | } 70 | else if (filledUp < 6) 71 | { 72 | uint16_t startingIndex = contacts->centerIndex - filledUp; 73 | requestContacts(startingIndex); 74 | } 75 | } 76 | 77 | static uint16_t menu_get_num_sections_callback(MenuLayer *me, void *data) { 78 | if (filterMode) 79 | return 2; //Second section is dummy section to hold selection when filtering is active 80 | 81 | return 1; 82 | } 83 | 84 | static uint16_t menu_get_num_rows_callback(MenuLayer *me, uint16_t section_index, void *data) { 85 | if (section_index != 0) 86 | return 1; 87 | 88 | return numMaxContacts; 89 | } 90 | 91 | 92 | static int16_t menu_get_row_height_callback(MenuLayer *me, MenuIndex *cell_index, void *data) { 93 | if (cell_index->section != 0) 94 | return 0; 95 | 96 | return 27; 97 | } 98 | 99 | static void menu_pos_changed(struct MenuLayer *menu_layer, MenuIndex new_index, MenuIndex old_index, void *callback_context) 100 | { 101 | cb_shift(contacts, new_index.row); 102 | requestAdditionalContacts(); 103 | } 104 | 105 | 106 | static void menu_draw_row_callback(GContext* ctx, const Layer *cell_layer, MenuIndex *cell_index, void *data) { 107 | if (cell_index->section != 0) 108 | return; 109 | 110 | char* contact = cb_getEntry(contacts, cell_index->row); 111 | if (contact == NULL) 112 | return; 113 | 114 | graphics_context_set_text_color(ctx, PBL_IF_COLOR_ELSE(GColorBlack, menu_cell_layer_is_highlighted(cell_layer) ? GColorWhite : GColorBlack)); 115 | 116 | graphics_draw_text(ctx, contact, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD), GRect(3, 3, SCREEN_WIDTH - 3, 23), GTextOverflowModeTrailingEllipsis, PBL_IF_RECT_ELSE(GTextAlignmentLeft, GTextAlignmentCenter), NULL); 117 | } 118 | 119 | static void filter(int button) 120 | { 121 | DictionaryIterator *iterator; 122 | AppMessageResult result = app_message_outbox_begin(&iterator); 123 | if (result != APP_MSG_OK) 124 | { 125 | pickedFilterButton = button; 126 | return; 127 | } 128 | 129 | dict_write_uint8(iterator, 0, 3); 130 | dict_write_uint8(iterator, 1, 0); 131 | dict_write_uint8(iterator, 2, button); 132 | app_message_outbox_send(); 133 | app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED); 134 | 135 | cb_clear(contacts); 136 | nothingFiltered = button == 3; 137 | menu_layer_reload_data(contactsMenuLayer); 138 | pickedFilterButton = -1; 139 | } 140 | 141 | 142 | void contacts_window_stop_filtering(void) 143 | { 144 | filterMode = false; 145 | menu_layer_set_selected_index(contactsMenuLayer, MenuIndex(0, 0), MenuRowAlignCenter, false); 146 | menu_layer_set_click_config_onto_window(contactsMenuLayer, window); 147 | 148 | window_set_click_config_provider(window, menu_config_provider); 149 | 150 | } 151 | 152 | static void filter_up_button(ClickRecognizerRef recognizer, Window *window) { 153 | filter(0); 154 | } 155 | 156 | static void filter_down_button(ClickRecognizerRef recognizer, Window *window) { 157 | 158 | filter(2); 159 | } 160 | 161 | static void filter_center_button(ClickRecognizerRef recognizer, Window *window) 162 | { 163 | filter(1); 164 | } 165 | 166 | static void filter_back_button(ClickRecognizerRef recognizer, Window *window) 167 | { 168 | if (nothingFiltered || !filterMode) 169 | window_stack_pop(true); 170 | else 171 | filter(3); 172 | } 173 | 174 | static void filter_center_long(ClickRecognizerRef recognizer, Window *window) 175 | { 176 | requestContacts(8); 177 | contacts_window_stop_filtering(); 178 | } 179 | 180 | static void menu_up_button(ClickRecognizerRef recognizer, Window *window) { 181 | menu_layer_set_selected_next(contactsMenuLayer, true, MenuRowAlignCenter, true); 182 | } 183 | 184 | static void menu_center_button(ClickRecognizerRef recognizer, Window *window) 185 | { 186 | MenuIndex cell_index = menu_layer_get_selected_index(contactsMenuLayer); 187 | sendPickedContact(cell_index.row); 188 | 189 | } 190 | 191 | 192 | static void menu_down_button(ClickRecognizerRef recognizer, Window *window) { 193 | menu_layer_set_selected_next(contactsMenuLayer, false, MenuRowAlignCenter, true); 194 | } 195 | 196 | static void filter_config_provider(void* context) { 197 | window_single_click_subscribe(BUTTON_ID_UP, (ClickHandler) filter_up_button); 198 | window_single_click_subscribe(BUTTON_ID_DOWN, (ClickHandler) filter_down_button); 199 | window_single_click_subscribe(BUTTON_ID_SELECT, (ClickHandler) filter_center_button); 200 | window_single_click_subscribe(BUTTON_ID_BACK, (ClickHandler) filter_back_button); 201 | 202 | window_long_click_subscribe(BUTTON_ID_SELECT, 500, (ClickHandler) filter_center_long, NULL); 203 | } 204 | 205 | static void menu_config_provider(void* context) 206 | { 207 | window_single_repeating_click_subscribe(BUTTON_ID_UP, 100, (ClickHandler) menu_up_button); 208 | window_single_repeating_click_subscribe(BUTTON_ID_DOWN, 100, (ClickHandler) menu_down_button); 209 | 210 | window_single_click_subscribe(BUTTON_ID_SELECT, (ClickHandler) menu_center_button); 211 | window_single_click_subscribe(BUTTON_ID_BACK, (ClickHandler) filter_back_button); 212 | } 213 | 214 | 215 | static void receivedContactNames(DictionaryIterator* data) 216 | { 217 | uint16_t offset = dict_find(data, 2)->value->uint16; 218 | numMaxContacts = dict_find(data, 3)->value->uint16; 219 | for (int i = 0; i < 3; i++) 220 | { 221 | uint16_t groupPos = offset + i; 222 | if (groupPos >= numMaxContacts) 223 | break; 224 | 225 | char* contact = cb_getEntryForFilling(contacts, groupPos); 226 | if (contact != NULL) { 227 | #ifndef PBL_LOW_MEMORY 228 | rtltr_strcpy(contact, dict_find(data, 4 + i)->value->cstring); 229 | #else 230 | strcpy(contact, dict_find(data, 4 + i)->value->cstring); 231 | #endif 232 | } 233 | } 234 | 235 | if (numMaxContacts == 0) 236 | { 237 | cb_clear(contacts); 238 | char* contact = cb_getEntryForFilling(contacts, 0); 239 | if (contact != NULL) 240 | strcpy(contact, "No contacts"); 241 | numMaxContacts = 1; 242 | } 243 | 244 | menu_layer_reload_data(contactsMenuLayer); 245 | 246 | requestAdditionalContacts(); 247 | } 248 | 249 | void contacts_window_data_received(int packetId, DictionaryIterator* data) 250 | { 251 | switch (packetId) 252 | { 253 | case 0: 254 | receivedContactNames(data); 255 | break; 256 | 257 | } 258 | } 259 | 260 | void contacts_window_data_delivered(void) 261 | { 262 | if (pickedContact != -1) 263 | sendPickedContact(pickedContact); 264 | } 265 | 266 | static void window_load(Window* me) 267 | { 268 | filterMode = true; 269 | nothingFiltered = true; 270 | firstAppear = true; 271 | } 272 | 273 | static void window_unload(Window* me) 274 | { 275 | window_destroy(me); 276 | } 277 | 278 | static void window_appear(Window *me) { 279 | contacts = cb_create(sizeof(char) * 21, 13); 280 | 281 | Layer* topLayer = window_get_root_layer(window); 282 | 283 | contactsMenuLayer = menu_layer_create(GRect(0, STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH, HEIGHT_BELOW_STATUSBAR)); 284 | 285 | // Set all the callbacks for the menu layer 286 | menu_layer_set_callbacks(contactsMenuLayer, NULL, (MenuLayerCallbacks){ 287 | .get_num_sections = menu_get_num_sections_callback, 288 | .get_num_rows = menu_get_num_rows_callback, 289 | .get_cell_height = menu_get_row_height_callback, 290 | .draw_row = menu_draw_row_callback, 291 | .selection_changed = menu_pos_changed 292 | }); 293 | 294 | menu_layer_set_center_focused(contactsMenuLayer, false); 295 | 296 | layer_add_child(topLayer, (Layer*) contactsMenuLayer); 297 | 298 | if (filterMode) 299 | { 300 | window_set_click_config_provider(window, filter_config_provider); 301 | 302 | menu_layer_set_selected_index(contactsMenuLayer, MenuIndex(0, 0), MenuRowAlignCenter, false); 303 | menu_layer_set_selected_index(contactsMenuLayer, MenuIndex(-1, -1), MenuRowAlignNone, false); 304 | } 305 | else 306 | { 307 | contacts_window_stop_filtering(); 308 | } 309 | 310 | #ifdef PBL_COLOR 311 | menu_layer_set_highlight_colors(contactsMenuLayer, GColorJaegerGreen, GColorBlack); 312 | #endif 313 | 314 | statusBar = status_bar_layer_create(); 315 | layer_add_child(topLayer, status_bar_layer_get_layer(statusBar)); 316 | 317 | setCurWindow(3); 318 | 319 | if (firstAppear) 320 | firstAppear = false; 321 | else 322 | { 323 | menu_layer_set_selected_index(contactsMenuLayer, MenuIndex(0, scrollPosition), MenuRowAlignCenter, false); 324 | requestContacts(scrollPosition); 325 | } 326 | } 327 | 328 | static void window_disappear(Window* me) 329 | { 330 | layer_remove_child_layers(window_get_root_layer(me)); 331 | 332 | scrollPosition = menu_layer_get_selected_index(contactsMenuLayer).row; 333 | menu_layer_destroy(contactsMenuLayer); 334 | 335 | status_bar_layer_destroy(statusBar); 336 | 337 | cb_destroy(contacts); 338 | } 339 | 340 | 341 | void contacts_window_init() 342 | { 343 | window = window_create(); 344 | 345 | window_set_window_handlers(window, (WindowHandlers){ 346 | .load = window_load, 347 | .unload = window_unload, 348 | .appear = window_appear, 349 | .disappear = window_disappear 350 | }); 351 | 352 | window_stack_push(window, true /* Animated */); 353 | } 354 | 355 | -------------------------------------------------------------------------------- /src/tertiary_text.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Tertiary Text, originally by vgmoose and PeterSumm 3 | * https://github.com/PeterSumm/tertiary_text 4 | */ 5 | 6 | #include "tertiary_text.h" 7 | #include "ActionsMenu.h" 8 | 9 | // Max text limit in characters 10 | // You may adjust this to allow longer messages 11 | #define MAX_CHARS 60 12 | 13 | #define TOP 0 14 | #define MID 1 15 | #define BOT 2 16 | 17 | static Window* window; 18 | 19 | static TextLayer* text_title; 20 | // static TextLayer* text_layer; 21 | static TextLayer* text_input; 22 | 23 | static TextLayer* buttons1[3]; 24 | static TextLayer* buttons2[3]; 25 | static TextLayer* buttons3[3]; 26 | static TextLayer** bbuttons[3]; 27 | 28 | static bool menu = false; 29 | 30 | // Here are the three cases, or sets 31 | static char caps[] = "ABCDEFGHIJKLM NOPQRSTUVWXYZ"; 32 | static char letters[] = "abcdefghijklm nopqrstuvwxyz"; 33 | static char numsym[] = "1234567890!?-'\"$()&*+#:@/,."; 34 | 35 | // the below three strings just have to be unique, abc - xyz will be overwritten with the long strings above 36 | static char* btext1[] = {"abc", "def", "ghi"}; 37 | static char* btext2[] = {"jkl", "m n", "opq"}; 38 | static char* btext3[] = {"rst", "uvw", "xyz"}; 39 | static char** btexts[] = {btext1, btext2, btext3}; 40 | 41 | // These are the actual sets that are displayed on each button, also need to be unique 42 | static char set1[4] = " a"; 43 | static char set2[4] = " b"; 44 | static char set3[4] = " c"; 45 | static char* setlist[] = {set1, set2, set3}; 46 | 47 | static char* cases[] = {"CAP", "low", "#@1"}; 48 | 49 | static int cur_set = 1; 50 | 51 | static void drawSides(); 52 | static void drawMenu(); 53 | static void set_menu(); 54 | static void drawNotepadText(); 55 | 56 | static char* rotate_text[] = {caps, letters, numsym}; 57 | static void next(); 58 | 59 | static char* master = letters; 60 | 61 | static char text_buffer[MAX_CHARS]; 62 | static int pos = 0; 63 | static int top, end, size; 64 | 65 | static const char* title; 66 | static void* extra; 67 | static TertiaryTextCallback callback; 68 | 69 | static const bool animated = true; 70 | 71 | // This function changes the next case/symbol set. 72 | static void change_set(int s, bool lock) 73 | { 74 | int count = 0; 75 | master = rotate_text[s]; 76 | for (int i=0; i<3; i++) 77 | { 78 | for (int j=0; j<3; j++) 79 | { 80 | for (int k=0; k<3; k++) 81 | { 82 | btexts[i][j][k] = master[count]; 83 | count++; 84 | } 85 | } 86 | } 87 | 88 | menu = false; 89 | if (lock) cur_set = s; 90 | 91 | drawSides(); 92 | } 93 | 94 | static void next() 95 | { 96 | top = 0; 97 | end = 26; 98 | size = 27; 99 | } 100 | 101 | static void clickButton(int b) 102 | { 103 | if (menu) 104 | { 105 | change_set(b, false); 106 | return; 107 | } 108 | 109 | if (size > 3) 110 | { 111 | size /= 3; 112 | if (b == TOP) 113 | end -= 2*size; 114 | else if (b == MID) 115 | { 116 | top += size; 117 | end -= size; 118 | } 119 | else if (b == BOT) 120 | top += 2*size; 121 | } 122 | else 123 | { 124 | // Prevent overflowing 125 | if (pos == MAX_CHARS-1) 126 | pos--; 127 | 128 | // Type the character 129 | text_buffer[pos++] = master[top+b]; 130 | drawNotepadText(); 131 | change_set(cur_set, false); 132 | next(); 133 | } 134 | 135 | drawSides(); 136 | } 137 | 138 | static void up_single_click_handler(ClickRecognizerRef recognizer, void* context) 139 | { 140 | if (actions_menu_is_displayed()) 141 | { 142 | actions_menu_move_up(); 143 | return; 144 | } 145 | 146 | clickButton(TOP); 147 | } 148 | 149 | static void send_message_reply_writing_result(void) 150 | { 151 | DictionaryIterator *iterator; 152 | app_message_outbox_begin(&iterator); 153 | dict_write_uint8(iterator, 0, 5); 154 | dict_write_uint8(iterator, 1, 1); 155 | dict_write_cstring(iterator, 2, text_buffer); 156 | app_message_outbox_send(); 157 | } 158 | 159 | static void select_single_click_handler(ClickRecognizerRef recognizer, void* context) 160 | { 161 | if (actions_menu_is_displayed()) 162 | { 163 | int16_t pickedItem = actions_menu_get_selected_index(); 164 | if (pickedItem == 0) 165 | { 166 | send_message_reply_writing_result(); 167 | actions_menu_hide(); 168 | window_stack_pop(true); 169 | } 170 | else 171 | { 172 | char* copySource = actions_menu_get_action_text(pickedItem); 173 | int sourceLength = strlen(copySource); 174 | 175 | if (sourceLength + pos < MAX_CHARS) 176 | { 177 | strcpy(&text_buffer[pos], copySource); 178 | pos += sourceLength; 179 | drawNotepadText(); 180 | actions_menu_hide(); 181 | } 182 | } 183 | 184 | return; 185 | } 186 | 187 | clickButton(MID); 188 | } 189 | 190 | static void down_single_click_handler(ClickRecognizerRef recognizer, void* context) 191 | { 192 | if (actions_menu_is_displayed()) 193 | { 194 | actions_menu_move_down(); 195 | return; 196 | } 197 | 198 | clickButton(BOT); 199 | } 200 | 201 | static bool common_long(int b) 202 | { 203 | if (menu) 204 | { 205 | change_set(b, true); 206 | return true; 207 | } 208 | return false; 209 | } 210 | 211 | static void up_long_click_handler(ClickRecognizerRef recognizer, void* context) 212 | { 213 | if (common_long(TOP)) return; 214 | 215 | set_menu(); 216 | } 217 | 218 | static void select_long_click_handler(ClickRecognizerRef recognizer, void* context) 219 | { 220 | if (common_long(MID)) return; 221 | 222 | // Close this window 223 | 224 | actions_menu_show(); 225 | } 226 | 227 | 228 | static void down_long_click_handler(ClickRecognizerRef recognizer, void* context) { 229 | 230 | if (common_long(BOT)) return; 231 | 232 | // delete or cancel when back is held 233 | if (size==27 && pos>0 ) 234 | { 235 | text_buffer[--pos] = ' '; 236 | drawNotepadText(); 237 | } 238 | else 239 | { 240 | next(); 241 | drawSides(); 242 | } 243 | 244 | } 245 | 246 | static void back_single_click_handler(ClickRecognizerRef recognizer, void* context) { 247 | 248 | if (actions_menu_is_displayed()) 249 | actions_menu_hide(); 250 | else 251 | window_stack_pop(true); 252 | } 253 | 254 | static void set_menu() 255 | { 256 | menu = true; 257 | drawMenu(); 258 | } 259 | 260 | static void click_config_provider(void* context) 261 | { 262 | window_single_click_subscribe(BUTTON_ID_UP, up_single_click_handler); 263 | window_long_click_subscribe(BUTTON_ID_UP, 1000, up_long_click_handler, NULL); 264 | 265 | window_single_click_subscribe(BUTTON_ID_SELECT, select_single_click_handler); 266 | window_long_click_subscribe(BUTTON_ID_SELECT, 1000, select_long_click_handler, NULL); 267 | 268 | window_single_click_subscribe(BUTTON_ID_DOWN, down_single_click_handler); 269 | window_long_click_subscribe(BUTTON_ID_DOWN, 1000, down_long_click_handler, NULL); 270 | 271 | window_single_click_subscribe(BUTTON_ID_BACK, back_single_click_handler); 272 | } 273 | 274 | static void drawMenu() 275 | { 276 | for (int i=0; i<3; i++) 277 | { 278 | text_layer_set_text(bbuttons[i][i!=2], " "); 279 | text_layer_set_text(bbuttons[i][2], " "); 280 | 281 | text_layer_set_text(bbuttons[i][i==2], cases[i]); 282 | text_layer_set_font(bbuttons[i][0], fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); 283 | } 284 | } 285 | 286 | 287 | // This method draws the characters on the right side near the buttons 288 | static void drawSides() 289 | { 290 | if (size==27) // first click (full size) 291 | { 292 | // update all 9 labels to their proper values 293 | for (int h=0; h<3; h++) 294 | { 295 | for (int i=0; i<3; i++) 296 | { 297 | text_layer_set_text(bbuttons[h][i], btexts[h][i]); 298 | text_layer_set_background_color(bbuttons[h][i], GColorClear); 299 | text_layer_set_font(bbuttons[h][i], fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); 300 | } 301 | 302 | } 303 | } 304 | else if (size==9) // second click 305 | { 306 | for (int i=0; i<3; i++) 307 | { 308 | text_layer_set_text(bbuttons[i][i!=2], " "); 309 | text_layer_set_text(bbuttons[i][2], " "); 310 | 311 | text_layer_set_text(bbuttons[i][i==2], btexts[top/9][i]); 312 | text_layer_set_font(bbuttons[i][i==2], fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); 313 | } 314 | 315 | } 316 | else if (size == 3) 317 | { 318 | for (int i=0; i<3; i++) 319 | { 320 | setlist[i][2] = master[top+i]; 321 | text_layer_set_text(bbuttons[i][i==2], setlist[i]); 322 | text_layer_set_font(bbuttons[i][i==2], fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); 323 | } 324 | } 325 | } 326 | 327 | static void clearText() 328 | { 329 | for (int i=0; i 2 | #include "pebble_fonts.h" 3 | #include "pebble.h" 4 | #include "util.h" 5 | #include "PebbleDialer.h" 6 | #include "MainMenuWindow.h" 7 | #include "ActionsMenu.h" 8 | #include "pebble-rtltr/rtltr.h" 9 | 10 | static Window* window; 11 | 12 | static TextLayer* title; 13 | static char timerText[10]; 14 | 15 | static GSize windowFrame; 16 | static TextLayer* callerName; 17 | static TextLayer* callerNumType; 18 | static TextLayer* callerNumber; 19 | 20 | static GBitmap* iconTop = NULL; 21 | static GBitmap* iconMiddle = NULL; 22 | static GBitmap* iconBottom = NULL; 23 | 24 | #ifdef PBL_COLOR 25 | static uint16_t callerImageSize; 26 | static uint8_t* bitmapReceivingBuffer = NULL; 27 | static uint16_t bitmapReceivingBufferHead; 28 | static GBitmap* callerBitmap = NULL; 29 | static BitmapLayer* callerBitmapLayer; 30 | #endif 31 | 32 | static uint32_t iconResources[8] = {RESOURCE_ID_ANSWER, RESOURCE_ID_ENDCALL, RESOURCE_ID_MIC_ON, RESOURCE_ID_MIC_OFF, RESOURCE_ID_SPEAKER_OFF, RESOURCE_ID_SPEAKER_ON, RESOURCE_ID_VOLUME_DOWN, RESOURCE_ID_VOLUME_UP }; 33 | 34 | static ActionBarLayer* actionBar; 35 | 36 | static StatusBarLayer* statusBar; 37 | 38 | static bool callEstablished; 39 | static uint16_t elapsedTime = 0; 40 | static bool vibrate; 41 | 42 | static bool vibratingNow = false; 43 | static uint32_t vibrationPatternSegments[20]; 44 | static VibePattern vibrationPattern; 45 | static uint32_t totalVibePatternLength; 46 | static uint32_t vibrationCycleDelay; 47 | 48 | static char callerNameText[101]; 49 | static char callerNumTypeText[31]; 50 | static char callerNumberText[31]; 51 | static bool nameAtBottom; 52 | 53 | static void vibrate_cycle_finished(void* data); 54 | 55 | static void convertTwoNumber(int number, char* string, int offset) 56 | { 57 | if (number == 0) 58 | { 59 | string[offset] = '0'; 60 | string[offset + 1] = '0'; 61 | return; 62 | } 63 | 64 | char* iConvert = itoa(number); 65 | 66 | if (number < 10) 67 | { 68 | string[offset] = '0'; 69 | string[offset + 1] = iConvert[0]; 70 | } 71 | else if (number < 100) 72 | { 73 | string[offset] = iConvert[0]; 74 | string[offset + 1] = iConvert[1]; 75 | } 76 | else 77 | { 78 | string[offset] = iConvert[0]; 79 | string[offset + 1] = iConvert[1]; 80 | string[offset + 2] = iConvert[2]; 81 | } 82 | } 83 | 84 | static void updateTimer(void) 85 | { 86 | if (!callEstablished) 87 | { 88 | text_layer_set_text(title, "Incoming Call"); 89 | return; 90 | } 91 | 92 | if (!config_enableCallTimer) 93 | { 94 | text_layer_set_text(title, ""); 95 | return; 96 | } 97 | 98 | 99 | uint16_t minutes = elapsedTime / 60; 100 | uint16_t seconds = elapsedTime % 60; 101 | 102 | uint8_t extraOffset = minutes > 99 ? 1 : 0; 103 | 104 | convertTwoNumber(minutes, timerText, 0); 105 | timerText[2 + extraOffset] = ':'; 106 | convertTwoNumber(seconds, timerText, 3 + extraOffset); 107 | 108 | text_layer_set_text(title, timerText); 109 | } 110 | 111 | static GRect moveAndCalculateTextSize(TextLayer* textLayer, int16_t yPosition, bool centerY, bool moveUp) 112 | { 113 | uint16_t startX = layer_get_frame(text_layer_get_layer(textLayer)).origin.x; 114 | 115 | layer_set_frame(text_layer_get_layer(textLayer), GRect(startX, yPosition, windowFrame.w - startX, 1000)); 116 | GSize size = text_layer_get_content_size(textLayer); 117 | size.h += 3; 118 | 119 | if (centerY) 120 | yPosition -= size.h / 2; 121 | if (moveUp) 122 | yPosition -= size.h; 123 | 124 | GRect frame = GRect(startX, yPosition, windowFrame.w - startX, size.h); 125 | layer_set_frame(text_layer_get_layer(textLayer), frame); 126 | return frame; 127 | } 128 | 129 | static void updateTextFields(void) 130 | { 131 | //Timer at the top 132 | updateTimer(); 133 | int16_t timerY = STATUS_BAR_LAYER_HEIGHT; 134 | GRect timerPosition = moveAndCalculateTextSize(title, timerY, false, false); 135 | 136 | //Caller name is below timer 137 | text_layer_set_text(callerName, nameAtBottom ? "" : callerNameText); 138 | int16_t nameY = timerPosition.origin.y + timerPosition.size.h; 139 | moveAndCalculateTextSize(callerName, nameY, false, false); 140 | 141 | //Caller number is near the bottom 142 | text_layer_set_text(callerNumber, nameAtBottom ? callerNameText : callerNumberText); 143 | int16_t callerNumberY = windowFrame.h - PBL_IF_ROUND_ELSE(20, 10); 144 | GRect callerNumberFrame = moveAndCalculateTextSize(callerNumber, callerNumberY, false, true); 145 | 146 | //Caller number type is above caller number 147 | text_layer_set_text(callerNumType, callerNumTypeText); 148 | int16_t callerNumberTypeY = callerNumberFrame.origin.y; 149 | moveAndCalculateTextSize(callerNumType, callerNumberTypeY, false, true); 150 | } 151 | 152 | static void setTextFieldsColor(GColor color) 153 | { 154 | text_layer_set_text_color(title, color); 155 | text_layer_set_text_color(callerName, color); 156 | text_layer_set_text_color(callerNumber, color); 157 | text_layer_set_text_color(callerNumType, color); 158 | } 159 | 160 | static void sendAction(int buttonId) 161 | { 162 | DictionaryIterator *iterator; 163 | app_message_outbox_begin(&iterator); 164 | 165 | dict_write_uint8(iterator, 0, 1); 166 | dict_write_uint8(iterator, 1, 0); 167 | dict_write_uint8(iterator, 2, buttonId); 168 | 169 | app_message_outbox_send(); 170 | } 171 | 172 | static void sendMenuPick(uint8_t buttonId) 173 | { 174 | DictionaryIterator *iterator; 175 | app_message_outbox_begin(&iterator); 176 | 177 | dict_write_uint8(iterator, 0, 5); 178 | dict_write_uint8(iterator, 1, 0); 179 | dict_write_uint8(iterator, 2, buttonId); 180 | 181 | app_message_outbox_send(); 182 | } 183 | 184 | static void button_up_press(ClickRecognizerRef recognizer, Window *window) 185 | { 186 | if (actions_menu_is_displayed()) 187 | { 188 | actions_menu_move_up(); 189 | return; 190 | } 191 | 192 | sendAction(0); 193 | } 194 | 195 | static void button_select_press(ClickRecognizerRef recognizer, Window *window) 196 | { 197 | if (actions_menu_is_displayed()) 198 | { 199 | sendMenuPick(actions_menu_get_selected_index()); 200 | actions_menu_hide(); 201 | return; 202 | } 203 | 204 | sendAction(1); 205 | } 206 | 207 | static void button_down_press(ClickRecognizerRef recognizer, Window *window) 208 | { 209 | if (actions_menu_is_displayed()) 210 | { 211 | actions_menu_move_down(); 212 | return; 213 | } 214 | 215 | sendAction(2); 216 | } 217 | 218 | static void button_up_hold(ClickRecognizerRef recognizer, Window *window) 219 | { 220 | if (actions_menu_is_displayed()) 221 | { 222 | actions_menu_move_up(); 223 | return; 224 | } 225 | 226 | sendAction(3); 227 | } 228 | 229 | static void button_select_hold(ClickRecognizerRef recognizer, Window *window) 230 | { 231 | if (actions_menu_is_displayed()) 232 | { 233 | return; 234 | } 235 | 236 | sendAction(4); 237 | } 238 | 239 | static void button_down_hold(ClickRecognizerRef recognizer, Window *window) 240 | { 241 | if (actions_menu_is_displayed()) 242 | { 243 | actions_menu_move_down(); 244 | return; 245 | } 246 | 247 | sendAction(5); 248 | } 249 | 250 | static void button_back_press(ClickRecognizerRef recognizer, void* context) 251 | { 252 | if (actions_menu_is_displayed()) 253 | { 254 | actions_menu_hide(); 255 | } 256 | else 257 | window_stack_pop(true); 258 | } 259 | 260 | 261 | static void shake(AccelAxisType axis, int32_t direction) 262 | { 263 | if (vibratingNow) //Vibration seems to generate a lot of false positives 264 | return; 265 | 266 | sendAction(6); 267 | } 268 | 269 | static void config_provider_callscreen(void* context) { 270 | window_single_click_subscribe(BUTTON_ID_UP, (ClickHandler) button_up_press); 271 | window_single_click_subscribe(BUTTON_ID_DOWN, (ClickHandler) button_down_press); 272 | window_single_click_subscribe(BUTTON_ID_SELECT, (ClickHandler) button_select_press); 273 | window_long_click_subscribe(BUTTON_ID_UP, 700, (ClickHandler) button_up_hold, NULL); 274 | window_long_click_subscribe(BUTTON_ID_SELECT, 700, (ClickHandler) button_select_hold, NULL); 275 | window_long_click_subscribe(BUTTON_ID_DOWN, 700, (ClickHandler) button_down_hold, NULL); 276 | window_single_click_subscribe(BUTTON_ID_BACK, (ClickHandler) button_back_press); 277 | 278 | } 279 | 280 | 281 | static void vibrate_cycle(void *data) 282 | { 283 | if (vibrate) 284 | { 285 | vibratingNow = true; 286 | 287 | vibes_cancel(); 288 | vibes_enqueue_custom_pattern(vibrationPattern); 289 | app_timer_register(totalVibePatternLength, vibrate_cycle_finished, NULL); 290 | } 291 | } 292 | 293 | static void vibrate_cycle_finished(void* data) 294 | { 295 | vibratingNow = false; 296 | 297 | if (vibrate) 298 | { 299 | app_timer_register(vibrationCycleDelay, vibrate_cycle, NULL); 300 | } 301 | } 302 | 303 | static void second_tick() 304 | { 305 | if (callEstablished) 306 | { 307 | elapsedTime++; 308 | updateTimer(); 309 | } 310 | } 311 | 312 | 313 | static void start_vibrating() 314 | { 315 | vibrate = true; 316 | vibrate_cycle(NULL); 317 | } 318 | 319 | static void stop_vibrating() 320 | { 321 | vibrate = false; 322 | vibes_cancel(); 323 | } 324 | 325 | static void load_icon(GBitmap** into, uint8_t iconId) 326 | { 327 | GBitmap* bitmap = *into; 328 | if (bitmap != NULL) 329 | gbitmap_destroy(bitmap); 330 | 331 | if (iconId == 0xFF) 332 | *into = NULL; 333 | else 334 | *into = gbitmap_create_with_resource(iconResources[iconId]); 335 | } 336 | 337 | static void set_icon(GBitmap** container, ButtonId buttonId, uint8_t iconId) 338 | { 339 | load_icon(container, iconId); 340 | action_bar_layer_set_icon(actionBar, buttonId, *container); 341 | } 342 | 343 | void call_window_data_received(uint8_t module, uint8_t packet, DictionaryIterator *received) { 344 | 345 | if (module == 1) 346 | { 347 | if (packet == 0) 348 | { 349 | uint8_t* flags = dict_find(received, 4)->value->data; 350 | callEstablished = flags[0] == 1; 351 | nameAtBottom = flags[1] == 1; 352 | #ifdef PBL_COLOR 353 | bool identityUpdate = flags[6] == 1; 354 | #endif 355 | uint8_t topIconId = flags[2]; 356 | uint8_t middleIconId = flags[3]; 357 | uint8_t bottomIconId = flags[4]; 358 | 359 | set_icon(&iconTop, BUTTON_ID_UP, topIconId); 360 | set_icon(&iconMiddle, BUTTON_ID_SELECT, middleIconId); 361 | set_icon(&iconBottom, BUTTON_ID_DOWN, bottomIconId); 362 | 363 | #ifndef PBL_LOW_MEMORY 364 | rtltr_strcpy(callerNumberText, dict_find(received, 3)->value->cstring); 365 | rtltr_strcpy(callerNumTypeText, dict_find(received, 2)->value->cstring); 366 | #else 367 | strcpy(callerNumberText, dict_find(received, 3)->value->cstring); 368 | strcpy(callerNumTypeText, dict_find(received, 2)->value->cstring); 369 | #endif 370 | 371 | if (callEstablished) 372 | elapsedTime = dict_find(received, 5)->value->uint16; 373 | 374 | updateTextFields(); 375 | 376 | #ifdef PBL_COLOR 377 | if (identityUpdate) 378 | { 379 | Tuple* callerImageSizeTuple = dict_find(received, 7); 380 | 381 | if (callerImageSizeTuple != NULL) 382 | { 383 | callerImageSize = callerImageSizeTuple->value->uint16; 384 | if (callerBitmap != NULL) { 385 | bitmap_layer_set_bitmap(callerBitmapLayer, NULL); 386 | gbitmap_destroy(callerBitmap); 387 | callerBitmap = NULL; 388 | setTextFieldsColor(GColorBlack); 389 | } 390 | if (bitmapReceivingBuffer != NULL) { 391 | free(bitmapReceivingBuffer); 392 | } 393 | 394 | bitmapReceivingBuffer = malloc(callerImageSize); 395 | bitmapReceivingBufferHead = 0; 396 | } 397 | } 398 | #endif 399 | vibrationPattern.num_segments = flags[7] / 2; 400 | totalVibePatternLength = 0; 401 | for (unsigned int i = 0; i < vibrationPattern.num_segments * 2; i+= 2) 402 | { 403 | vibrationPatternSegments[i / 2] = flags[8 +i] | (flags[9 +i] << 8); 404 | totalVibePatternLength += vibrationPatternSegments[i / 2]; 405 | } 406 | vibrationPattern.durations = vibrationPatternSegments; 407 | 408 | vibrationCycleDelay = 0; 409 | 410 | // Manually trigger last pause to allow shake events occurring in between vibration cycles. 411 | if (vibrationPattern.num_segments % 2 == 0) 412 | { 413 | vibrationCycleDelay = vibrationPatternSegments[vibrationPattern.num_segments - 1]; 414 | vibrationPattern.num_segments--; 415 | totalVibePatternLength -= vibrationCycleDelay; 416 | } 417 | 418 | if (!callEstablished && totalVibePatternLength > 0 && canVibrate()) 419 | start_vibrating(); 420 | else 421 | stop_vibrating(); 422 | 423 | } 424 | else if (packet == 1) 425 | { 426 | #ifndef PBL_LOW_MEMORY 427 | rtltr_strcpy(callerNameText, dict_find(received, 2)->value->cstring); 428 | #else 429 | strcpy(callerNameText, dict_find(received, 2)->value->cstring); 430 | #endif 431 | updateTextFields(); 432 | } 433 | #ifdef PBL_COLOR 434 | else if (packet == 2) 435 | { 436 | if (bitmapReceivingBuffer == NULL) 437 | return; 438 | 439 | uint16_t bufferSize = dict_find(received, 2)->value->uint16; 440 | uint8_t* buffer = dict_find(received, 3)->value->data; 441 | 442 | memcpy(&bitmapReceivingBuffer[bitmapReceivingBufferHead], buffer, bufferSize); 443 | bitmapReceivingBufferHead += bufferSize; 444 | bool finished = bitmapReceivingBufferHead == callerImageSize; 445 | 446 | if (finished) 447 | { 448 | callerBitmap = gbitmap_create_from_png_data(bitmapReceivingBuffer, callerImageSize); 449 | bitmap_layer_set_bitmap(callerBitmapLayer, callerBitmap); 450 | setTextFieldsColor(GColorWhite); 451 | } 452 | } 453 | #endif 454 | } 455 | } 456 | 457 | static void window_show(Window* me) 458 | { 459 | if (config_lightCallWindow) 460 | light_enable_interaction(); 461 | } 462 | 463 | static void window_load(Window* me) 464 | { 465 | Layer* topLayer = window_get_root_layer(window); 466 | 467 | windowFrame = layer_get_frame(topLayer).size; 468 | windowFrame.w -= ACTION_BAR_WIDTH; 469 | 470 | #ifdef PBL_COLOR 471 | uint16_t rightMargin = PBL_IF_ROUND_ELSE(ACTION_BAR_WIDTH / 2, ACTION_BAR_WIDTH); 472 | callerBitmapLayer = bitmap_layer_create(GRect(0,STATUS_BAR_LAYER_HEIGHT, SCREEN_WIDTH - rightMargin, HEIGHT_BELOW_STATUSBAR)); 473 | bitmap_layer_set_alignment(callerBitmapLayer, GAlignCenter); 474 | layer_add_child(topLayer, bitmap_layer_get_layer(callerBitmapLayer)); 475 | #endif 476 | 477 | 478 | title = text_layer_create(GRect(PBL_IF_ROUND_ELSE(ACTION_BAR_WIDTH, 0), 0, 0, 0)); 479 | text_layer_set_font(title, fonts_get_system_font(config_getFontResource(config_fontTimer))); 480 | text_layer_set_text_alignment(title, GTextAlignmentCenter); 481 | text_layer_set_background_color(title, GColorClear); 482 | layer_add_child(topLayer, text_layer_get_layer(title)); 483 | 484 | callerName = text_layer_create(GRect(0, 0, 0, 0)); 485 | text_layer_set_font(callerName, fonts_get_system_font(config_getFontResource(config_fontName)));; 486 | text_layer_set_text_alignment(callerName, GTextAlignmentCenter); 487 | text_layer_set_background_color(callerName, GColorClear); 488 | layer_add_child(topLayer, text_layer_get_layer(callerName)); 489 | text_layer_enable_screen_text_flow_and_paging(callerName, true); 490 | 491 | callerNumType = text_layer_create(GRect(PBL_IF_ROUND_ELSE(ACTION_BAR_WIDTH, 0), 0, 0, 0)); 492 | text_layer_set_font(callerNumType, fonts_get_system_font(config_getFontResource(config_fontNumberType)));; 493 | text_layer_set_text_alignment(callerNumType, GTextAlignmentCenter); 494 | text_layer_set_background_color(callerNumType, GColorClear); 495 | layer_add_child(topLayer, text_layer_get_layer(callerNumType)); 496 | 497 | callerNumber = text_layer_create(GRect(PBL_IF_ROUND_ELSE(ACTION_BAR_WIDTH, 0), 0, 0, 0)); 498 | text_layer_set_font(callerNumber, fonts_get_system_font(config_getFontResource(config_fontNumber)));; 499 | text_layer_set_text_alignment(callerNumber, GTextAlignmentCenter); 500 | text_layer_set_background_color(callerNumber, GColorClear); 501 | layer_add_child(topLayer, text_layer_get_layer(callerNumber)); 502 | 503 | actionBar = action_bar_layer_create(); 504 | action_bar_layer_set_click_config_provider(actionBar, (ClickConfigProvider) config_provider_callscreen); 505 | action_bar_layer_add_to_window(actionBar, window); 506 | layer_add_child(topLayer, action_bar_layer_get_layer(actionBar)); 507 | 508 | statusBar = status_bar_layer_create(); 509 | layer_add_child(topLayer, status_bar_layer_get_layer(statusBar)); 510 | 511 | actions_menu_init(); 512 | actions_menu_attach(topLayer); 513 | 514 | if (config_enableCallTimer) 515 | { 516 | tick_timer_service_subscribe(SECOND_UNIT, (TickHandler) second_tick); 517 | } 518 | accel_tap_service_subscribe(shake); 519 | 520 | callerNameText[0] = 0; 521 | callerNumberText[0] = 0; 522 | callerNumTypeText[0] = 0; 523 | } 524 | 525 | static void window_unload(Window* me) 526 | { 527 | gbitmap_destroy(iconTop); 528 | gbitmap_destroy(iconMiddle); 529 | gbitmap_destroy(iconBottom); 530 | 531 | text_layer_destroy(title); 532 | text_layer_destroy(callerName); 533 | text_layer_destroy(callerNumType); 534 | text_layer_destroy(callerNumber); 535 | action_bar_layer_destroy(actionBar); 536 | 537 | status_bar_layer_destroy(statusBar); 538 | 539 | 540 | #ifdef PBL_COLOR 541 | if (bitmapReceivingBuffer != NULL) 542 | { 543 | free(bitmapReceivingBuffer); 544 | bitmapReceivingBuffer = NULL; 545 | } 546 | 547 | if (callerBitmap != NULL) 548 | { 549 | gbitmap_destroy(callerBitmap); 550 | callerBitmap = NULL; 551 | } 552 | 553 | bitmap_layer_destroy(callerBitmapLayer); 554 | #endif 555 | 556 | actions_menu_deinit(); 557 | 558 | window_destroy(me); 559 | 560 | tick_timer_service_unsubscribe(); 561 | accel_tap_service_unsubscribe(); 562 | } 563 | 564 | void call_window_init(void) 565 | { 566 | elapsedTime = 0; 567 | callEstablished = false; 568 | 569 | window = window_create(); 570 | 571 | window_set_window_handlers(window, (WindowHandlers) { 572 | .load = (WindowHandler) window_load, 573 | .unload = (WindowHandler) window_unload, 574 | .appear = window_show 575 | 576 | }); 577 | 578 | window_stack_pop_all(false); 579 | if (!config_noMenu) 580 | main_menu_show_closing(); 581 | 582 | window_stack_push(window, true); 583 | setCurWindow(1); 584 | } 585 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------