app dev
app dev
Method: display() which prints the text as it would appear on the screen.
EditText
Attributes: text (initially empty)hint is _editable (default True)
Method: enter_text(new_text) which sets the text to new_text if is_editable is True.
Method: display() which shows either the text or hint if text is empty.
Button:
Attribute: text (e.g."Save")
Method: click() which prints a message simulating an action when the button is pressed.
Laxate Retia
Instructions:
Complete each step below to create a Python simulation where the layout of UI components changes
based on orientation.
Scenario:
You are designing a simple UI for a mock "WeatherApp" screen with two orientations:
Scenario:
Imagine you're creating a "Photo Gallery" screen for an app. The screen displays a list of
images that should be shown in a single column in portrait mode and in a two-column grid in
landscape mode.
Instructions:
1. Define the ImageView Class:
Create a Python class ImageView to represent each image. Each ImageView should have
an image_name attribute and a display() method that prints a placeholder for the image.
You are developing a "NewsFeed" screen for an app. The news feed contains TextView
components for headlines that adapt their layout based on screen orientation. Each headline
should display in a single column in portrait mode and in two columns in landscape mode.
Instructions:
1. Define the TextView Class: Create a TextView class with an attribute text for the
headline and a display() method to print it.
2. Create the NewsFeedScreen Class:
o Define a NewsFeedScreen class with a list of TextView components
representing different headlines.
o Add a method toggle_orientation() that automatically switches between
portrait and landscape each time it is called.
o Create a display() method that arranges headlines in a single column for
portrait and in two columns for landscape.
3. Test the Orientation Toggle:
o Initialize the NewsFeedScreen with 5 or more headlines.
o Toggle the orientation multiple times and display the layout to see how it
changes dynamically.
Reflection Questions
1. How does adapting the layout for different orientations improve the user
experience?
2. What other components or changes might you add to make the layouts even more
responsive?
3. How could you extend the toggle_orientation() method to support additional
orientations or screen sizes?
Scenario:
You are designing a "Note-taking" app where users can type notes and view a list of saved
notes. When the orientation changes (from portrait to landscape or vice versa), the app should:
1. Preserve the note content that the user has typed but not yet saved.
2. Re-display the saved notes in an orientation-specific layout.
Reflection Questions
Activity Task:
Scenario:
You are developing a "LibraryApp" where users can view a list of books, search for a book by
title, and add new books to the library. The app’s action bar will contain:
Step-by-Step Instructions
Define a Book class to represent each book in the library and an ActionBar class to represent
the action bar.
5. Create an instance of LibraryApp and start the program using the run() method. Test
each action in the action bar to ensure it functions as expected.
Expected Flow
1. Home Option - Displays all books in the library. If no books are added, it should
indicate the library is empty.
2. Add Option- Prompts the user to enter a book title and author, adds it to the library,
and confirms the addition.
3. Search Option- Prompts the user for a title keyword and displays all matching books.
If no match is found, displays a “No books found” message.
Reflection Questions