class KivMobDemo(MDApp): def __init__(self,**kwargs): self.theme_cls.theme_style = "Dark" super().__init__(**kwargs) self.rewards = Rewards_Handler(self) Points = NumericProperty(0) show_banner = False def build(self): self.ads = KivMob(TestIds.APP) self.ads.new_banner(TestIds.BANNER, False) self.ads.new_interstitial(TestIds.INTERSTITIAL) self.ads.request_banner() self.ads.request_interstitial() self.ads.set_rewarded_ad_listener(self.rewards) self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO) self.toggled = False return KivMobDemoUI() def toggle_banner(self): self.show_banner = not self.show_banner if self.show_banner: self.ads.show_banner() else: self.ads.hide_banner() def load_video(self): self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO)
class OneApp(MDApp): def __init__(self): super().__init__() self.config = Config() self.id_key = self.config.id_key self.title = self.config.title self.theme_cls.primary_palette = self.config.color def picture_taken(self, obj, filename): try: self.picture = filename except: pass def take_picture(self): try: self.screen.change_screen('camerascreen') self.screen.nav_layout.screen_manager.camerascreen.xcamera.restore_orientation( ) except: pass def build(self): self.config = Config() self.ads = KivMob('ca-app-pub-1818238534900904~2025018602') self.ads.new_banner('ca-app-pub-1818238534900904/4048546717', top_pos=False) self.ads.request_banner() self.ads.show_banner() self.screen = Builder.load_file(self.config.screen) return self.screen
class KivMobDemo(App): theme_cls = ThemeManager() show_banner = False def build(self): self.ads = KivMob(TestIds.APP) self.ads.new_banner(TestIds.BANNER, False) self.ads.new_interstitial(TestIds.INTERSTITIAL) self.ads.request_banner() self.ads.request_interstitial() self.ads.set_rewarded_ad_listener(RewardedListenerInterface()) self.ads.load_rewarded_ad(TestIds.REWARDED_VIDEO) self.toggled = False return KivMobDemoUI() def toggle_banner(self): self.show_banner = not self.show_banner if self.show_banner: self.ads.show_banner() else: self.ads.hide_banner()
class AliasApp(MDApp): ''' Alias application class ... Attributes ---------- store : JsonStore Instance of application store sm : ScreenManager Instance of screen manager active_game : BooleanProperty Indicator if active game exists dict_idxs : dict dict with dictionaries names and indexes of current word in them buttons_ready_to_use : BooleanProperty buttons enabled or not on the menu screen ads : KivMob instance of KivMob to manage advertisements Methods ------- create_main_game(round_duration, selected_dictionary, teams, penalty, last_word, points_to_win): create instance of MainGameScreen and swith to it to_game_config(): switch to the team config screen load_main_game(): load active game configuration from the `store` and switch to it start_main_game(): switch to the main game screen save_current_game(): save configuration of active game to the `store` and toggle `active_game` indicator delete_current_game(): remove configuration of active game from the `store` and toggle `active_game` indicator toggle_banner(): toggle ads banner show_interstitial(): show ads interstitial drop_game_and_create_new(): delete current game and start configuring new on_start(): kivy method on_pause(): kivy method on_stop(): kivy method build(): kivy method ''' store = JsonStore('app_store.json') sm = None active_game = BooleanProperty(False) dict_idxs = None buttons_ready_to_use = BooleanProperty(False) dialog = None ads = None def create_main_game(self, round_duration, selected_dictionary, teams, penalty, last_word, points_to_win): ''' Create main game of the application Parameters ---------- round_duration : int duration of one round in the game selected_dictionary : str selected dictionary for game words teams : list list of team names penalty : bool penalty for skipped word last_word : str word in the round after time is expired points_to_win : int amount of points to win the game ''' main_game = self.sm.get_screen('main_game') main_game.load_configuration( round_duration=round_duration, dictionary_name=selected_dictionary, dict_idx=self.store.get('dicts_idxs')[selected_dictionary], teams=teams, penalty=penalty, last_word=last_word, points_to_win=points_to_win, score=[0 for _ in teams], current_round=1, current_turn=0) self.show_interstitial() self.start_main_game() self.active_game = True def to_game_config(self): ''' Route to team config screen with dialog box if `active_game` is True ''' if self.active_game: self.dialog.open() else: self.sm.current = "team_config" def load_main_game(self): ''' Load main game of the application ''' active_game_cofig = self.store.get('active_game') main_game = self.sm.get_screen('main_game') main_game.load_configuration(**active_game_cofig) self.show_interstitial() self.start_main_game() def start_main_game(self): ''' Switch to main game screen ''' self.sm.current = 'main_game' def save_current_game(self): ''' Save main game of the application ''' main_game = self.sm.get_screen('main_game') self.save_dict_idx(main_game.dictionary_name, main_game.dict_idx) self.store.put( 'active_game', **{ key: getattr(main_game, key) for key in ( 'round_duration', 'dictionary_name', 'dict_idx', 'teams', 'penalty', 'last_word', 'points_to_win', 'score', 'current_round', 'current_turn', ) }) def save_dict_idx(self, current_dict, current_dict_idx): ''' Save index of the current dictionary to the app store Parameters ---------- current_dict : str name of current dictionary current_dict_idx : int index of current word in the dictionary ''' dict_idxs = self.store.get('dicts_idxs') dict_idxs[current_dict] = current_dict_idx self.store.put('dicts_idxs', **dict_idxs) def delete_current_game(self): ''' Delete main game of the application ''' try: self.store.delete('active_game') except KeyError: pass self.active_game = False def toggle_banner(self, show): ''' Toggle banner on the screen Parameters ---------- show : bool whether to show banner or hide ''' if show: self.ads.show_banner() else: self.ads.hide_banner() def drop_game_and_create_new(self): ''' Delete current game and start configuring new when dialog applied ''' self.delete_current_game() self.dialog.dismiss() self.to_game_config() def show_interstitial(self): ''' Show ads interstitial ''' if self.ads.is_interstitial_loaded(): self.ads.show_interstitial() else: self.ads.request_interstitial() def on_start(self): try: self.store.get('active_game') self.active_game = True except KeyError: pass try: self.dict_idxs = self.store.get('dicts_idxs') except KeyError: with open('./constants/words.json', encoding='utf-8') as f: dicts = json.load(f) idxs = {} for dictionary_name, words in dicts.items(): shuffle(words) dicts[dictionary_name] = words idxs[dictionary_name] = 0 with open('./constants/words.json', 'w', encoding='utf-8') as f: json.dump(dicts, f) self.store.put('dicts_idxs', **idxs) def on_pause(self): if self.active_game: self.save_current_game() return True def on_stop(self): self.on_pause() def build(self): self.theme_cls.theme_style = 'Dark' self.sm = Builder.load_file('main.kv') # ads self.ads = KivMob(os.environ.get('APP_ID')) self.ads.add_test_device('70356742') self.ads.new_banner(os.environ.get('BANNER_ID'), top_pos=False) self.ads.request_banner() self.ads.new_interstitial(os.environ.get('INTERSTITIAL_ID')) self.ads.request_interstitial() # dialog window to show when starting new game if active game exists self.dialog = Dialog( title='Створити нову гру?', text='Дані про поточну гру буде втрачено.', buttons=[ TextButton(text="Назад", on_release=lambda _: self.dialog.dismiss()), TextButton( text="Так", on_release=lambda _: self.drop_game_and_create_new()) ], ) Cache.append('images', 'round_background', FitImage(source="assets/imgs/round.png")) # enable buttons only in 2 second after build to avoid bugs def show_menu_buttons(): self.buttons_ready_to_use = True Clock.schedule_once(lambda _: show_menu_buttons(), 2) return self.sm
class MyApp(App): def __init__(self, **kwargs): super(MyApp, self).__init__(**kwargs) app_id = TestIds.APP self.ads = KivMob(app_id) banner_id = TestIds.BANNER interstitial_id = TestIds.INTERSTITIAL self.ads.new_banner(banner_id, top_pos=True) self.ads.new_interstitial(interstitial_id) self.show_ads() self.ads_created = True self.manga_text_color = (0, 0, 0, 1) self.start_up = True # Use in theme_color def build(self): self.title = "Manga Updates By Israel Quimson" self.phone = Phone() self.init_check_folder() self.use_kivy_settings = False # Disable kivy default settings self.phone.check_servers() self.theme_color() Clock.schedule_interval(self.check_internet, 30) return self.phone def show_ads(self): """Method to create ads""" self.ads.request_banner() self.ads.show_banner() def check_internet(self, *args): """Method to check internet""" url = 'https://1.1.1.1' # url to check timeout = 5 # timeout in seconds try: r = requests.head(url, timeout=timeout) # check the connection if not self.ads_created: # check if the ads is created self.show_ads() # Call this method to create ads self.ads_created = True # set the ads_created to true except: self.ads_created = False # If no internet set the ads created to false def build_config(self, config): """Method to define default values in Settings""" with open('version.txt', 'r') as file: version_num = file.read() config.setdefaults('basicsettings', { 'Servers': 'Mangahub', 'Version': version_num, 'darkmode': False }) def build_settings(self, settings): """Method to add Panel in the Settings using import file as data""" settings.add_json_panel('Settings', self.config, data=settings_json) def on_config_change(self, config, section, key, value): """Method on change config value in the Settings""" if key == 'Servers': self.phone.check_servers() if key == 'darkmode': self.theme_color() def theme_color(self): """Method to set the theme color and change the theme to dark mode""" mode = self.config.get( 'basicsettings', 'darkmode') # Get the value of config darkmode boolean if mode == '1': # Dark mode self.manga_text_color = (1, 1, 1, 1) self.nav_text_color = (1, 1, 1, 1) self.bg1_color = (68 / 255, 68 / 255, 68 / 255, 1) self.line_color = (0, 0, 0, 1) self.nav_bg_color = (51 / 255, 51 / 255, 51 / 255, 1) self.storage_line_color = (1, 1, 1, 1) else: # White mode self.manga_text_color = (0, 0, 0, 1) self.nav_text_color = (0, 0, 0, 1) self.bg1_color = (228 / 255, 241 / 255, 254 / 255, 1) self.line_color = (1, 1, 1, 1) self.nav_bg_color = (1, 1, 1, 1) self.storage_line_color = (0, 0, 0, 1) with self.phone.ids.phone_float.canvas.before: Color(self.bg1_color[0], self.bg1_color[1], self.bg1_color[2], self.bg1_color[3]) Rectangle(size=Window.size) with self.phone.ids.phone_anchor.canvas.before: Color(self.line_color[0], self.line_color[1], self.line_color[2], self.line_color[3]) Line(points=(0, Window.height * 0.08, Window.width, Window.height * 0.08)) with self.phone.ids.phone_grid.canvas.before: Color(self.nav_bg_color[0], self.nav_bg_color[1], self.nav_bg_color[2], self.nav_bg_color[3]) Rectangle(size=(Window.width, Window.height * 0.08), pos=self.phone.pos) with self.phone.ids.home_window.ids.home_float.canvas.before: Color(self.bg1_color[0], self.bg1_color[1], self.bg1_color[2], self.bg1_color[3]) Rectangle(size=Window.size) with self.phone.ids.search_window.ids.search_float.canvas.before: Color(self.bg1_color[0], self.bg1_color[1], self.bg1_color[2], self.bg1_color[3]) Rectangle(size=Window.size) with self.phone.ids.storage_window.ids.storage_float.canvas.before: Color(self.bg1_color[0], self.bg1_color[1], self.bg1_color[2], self.bg1_color[3]) Rectangle(size=Window.size) with self.phone.ids.storage_window.ids.storage_float.canvas: Color(self.storage_line_color[0], self.storage_line_color[1], self.storage_line_color[2], self.storage_line_color[3]) height = (Window.height - dp(self.ads.determine_banner_height())) * 0.92 * 0.9 Line(points=(0, height, Window.width, height)) with self.phone.ids.display_manga.ids.displaymanga_float.canvas.before: Color(self.bg1_color[0], self.bg1_color[1], self.bg1_color[2], self.bg1_color[3]) Rectangle(size=Window.size) self.phone.ids.storage_window.ids.storage_label.color = self.manga_text_color self.phone.ids.phone_home.color = self.nav_text_color self.phone.ids.phone_search.color = self.nav_text_color self.phone.ids.phone_favorite.color = self.nav_text_color self.phone.ids.phone_settings.color = self.nav_text_color if not self.start_up: # Check if startup self.phone.restore_default() else: self.start_up = False def close_settings(self, *settings): """Method fire when the close button in settings""" super(MyApp, self).close_settings(settings) self.ads.show_banner() def init_check_folder(self): """Method to check if the folder exist and create it if not""" if not os.path.exists('imagetemp'): os.mkdir('imagetemp') if not os.path.exists('imagerelease'): os.mkdir('imagerelease') if not os.path.exists(os.path.join('..', 'imagemanga', 'mangahub')): os.makedirs(os.path.join('..', 'imagemanga', 'mangahub')) # if not os.path.exists(os.path.join('..', 'imagemanga', 'mangareader')): # os.makedirs(os.path.join('..', 'imagemanga', 'mangareader')) # if not os.path.exists(os.path.join('..', 'imagemanga', 'mangapark')): # os.makedirs(os.path.join('..', 'imagemanga', 'mangapark')) def on_pause(self): return True # If True the App will not close when pause def on_stop(self): self.root.stop.set() # Set a stop signal for secondary python threads def on_resume(self): self.ads.request_interstitial()
class KivMobDemo(App): APP_ID = "ca-app-pub-COPY APP ID HERE" BANNER_ID = "ca-app-pub-COPY BANNER ID HERE" INTERSTITIAL_ID = "ca-app-pub-COPY INTERSTITIAL ID HERE" TEST_DEVICE_ID = "COPY DEVICE ID HERE" def build(self): self.ads = KivMob(APP_ID) self.ads.add_test_device(TEST_DEVICE_ID) self.ads.new_banner({"unitID": BANNER_ID}) self.ads.new_interstitial(INTERSTITIAL_ID) self.ads.request_banner() self.ads.request_interstitial() self.toggled = False return KivMobDemoUI() def on_start(self): """Called on application start. """ if platform not in ("android", "ios"): self.desktop_warning() def desktop_warning(self): layout = BoxLayout(orientation='vertical') layout.add_widget(Label(text='KivMob will not display ads on ' +\ 'nonmobile platforms. You must build an ' +\ 'Android project to demo ads. (iOS not yet ' +\ 'supported)', size_hint_y=1, text_size=(250, None), halign='left', valign='middle')) button_layout = BoxLayout() button1 = Button(text="Open Build Steps", size_hint=(0.8, 0.2)) button1.bind( on_release=lambda x: webbrowser.open("https://www.google.com")) button_layout.add_widget(button1) button2 = Button(text="Close", size_hint=(0.8, 0.2)) button2.bind(on_release=lambda x: popup.dismiss()) button_layout.add_widget(button2) layout.add_widget(button_layout) popup = Popup(title='KivMob Demo Alert', content=layout, size_hint=(0.9, 0.9)) popup.open() def interstitial_warning(self): layout = BoxLayout(orientation='vertical') layout.add_widget(Label(text="Ad has not loaded. " +\ "Wait a few seconds and then " +\ "try again.", size_hint_y=1, text_size=(250, None), halign='left', valign='middle')) button_layout = BoxLayout() close = Button(text="Close", size_hint=(0.8, 0.2)) close.bind(on_release=lambda x: popup.dismiss()) button_layout.add_widget(close) layout.add_widget(button_layout) popup = Popup(title='KivMob Demo Alert', content=layout, size_hint=(0.9, 0.9)) popup.open() def on_pause(self): """Android specific method. Save important app data on pause. """ return True def on_resume(self): """Android specific method. Resume paused app. """ self.ads.request_interstitial() def toggle_banner(self): if not self.toggled: self.ads.show_banner() else: self.ads.hide_banner() self.toggled = not self.toggled def show_interstitial(self): if self.ads.is_interstitial_loaded(): self.ads.show_interstitial() else: self.interstitial_warning()