Chapter 2

In this chapter we talk about :-

mmmm …. but what exactly is a “requirement” mean ??

In this chapter we will learn how to satisfy our customers by making sure what
you deliver is actually what they asked for.

is a singular need detailing what a particular product or service should be or do.

1) Listen to customer:-
when it comes to requirements the best thing you can do is let the customer talk,and pay attention
to what the system needs to do,you can figure out how the system will do those things later.

2) Creating a requirement list:-
based on the custmer needs we create a requirement list.

Use Case:-
is the steps that a system takes to make somthing happen,and it is a technique for
capturing the potential requirements of a new system.

  • each use case provides one or more scenarios that convey how the system should
    interact with the end user or another system to achive a specific goal.

There are three basic parts to a good use case:-
1) Clear value:
every use case must have a clear value to the system(which means it should help the customers to achive their goal)

2) Start and stop:
every use case must have a definit starting and stopping point.

3) External initiator:
every use case is started off by external initiator ,outside of the system. it could be a person or anything outside the system.

1- Working applications make customer happy. 🙂

2- Here are some key tools for making sure your customers are smiling when you show them the systems
you have built :-

3- Be careful! Good use cases make for good requirements, but a bad – or incomplete – use case can result in Bad requirements.

4- Your system must work in the real world … so plan and test for when things go wrong.

5- There are some important key words :-

Finally the source code for Dog Door System that he talk about it in this chapter you can find it Here . I implement it in C#.

Chapter 1

In this chapter we talk about :-

Great Software

mmmm … but what does “great software” mean ??

what great software mean ?

  • Great software always does what customer wants it to. So even if customer think of new ways to use the software, it doesn’t break or give the unexpected results.
  • Great software is code that is object-oriented. So there is not a bunch of duplicate code and each object pretty much controls its own behaviour. its also easy to extend because your design is really solid and flexible.
  • Great software is when you use tried-and-true design patterns and principles. you have kept your objects loosely coupled, and your code open for extension but closed for modification. That also helps make the code more reusable, so yup don’t have to rework everything to use parts of your application over and over again. 🙂

There are some important concepts we should know :-

  1. Flexibility :  1) Enable software to change and grow without constant rework.  2) Keep Application from being fragile.
  2. Encapsulation :  1) Keep the parts of your code that stay the same seperate from the parts that change.
  3. Functionality :  1) Make the cutomer happy and puts a smile into customer’s face. 🙂
  4. Design Pattern :  1) Enable reusability and make sure that you are not trying to solve a problem that someone else has already figured out.

Notes in chapter :-

  1. Don’t create problems to solve problems.
  2. Use textural description of the problem you are trying to solve to make sure that your design lines up with the intended functionality of your application.
  3. Objects should do what their names indicate.
  4. Each object should represent a single concept.
  5. Encapsulation allows you to group your application into logical parts.
  6. Any time you see duplicate code, look for a place to encapsulate.
  7. Delegation :  is when an object needs to perform a certain task and instead of doing that task directly , it asks another object to handle the task.

Finally the source code for Guitar System that he talk about it in this chapter you can find it Here . I implement it in C#.

Linking Activities Using Intents

An Android application can contain zero or more activities. When your application has more than one activity, you may need to navigate from one activity to another. In Android, you navigate between activities through what is known as an intent.

Today i will talk about how to navigate from your current activity to another one. We will create new android project.

Then we will add new Activity by right click on package name under src folder then choose New –> Other –> AndroidActivity, And give it a name (I will name it “Activity2”) and press finish button.

After that we should add this activity to our AndroidManifest.xml … We will add those lines

And as we said before @string used to add our program strings in one file called strings.xml .. So we will simply go to strings.xml file and add this line

Activity2 is the title of our new Activity .. or you can name it as you like 🙂

Then we go to our res –> layout –> right click –> New –> Other –> Android XML File … ( I will name it activity_activity2.xml ) … then add this code to it.

Return back again to strings.xml to add txtactivity by adding this line

We go to our first activity xml ( main.xml file ) and create a button by adding this code …

And as we do before go to strings.xml and add a text for button like this

Then go to our class to link your button in .xml with your button in .java class, and after that when button pressed we write the code that enable us to navigate to another Activity.

Run your code and enjoy 😀 .. This is the first screen

After you press the button .. The second Activity will be shown

That’s all for now, and i hope it’s easy to understand … if you have any question don’t hesitate 🙂

Activites and Intents – Part 3

This is the third lesson in our series of Activities And Intents … Now we will learn how to make a Progress Dialog … A progress dialog is useful for showing the progress of some activities, such as the status of a download operation.

The first thing we will create a button in our main.xml as we do in the previous tutorial …

As we do before we will go to our .java class and override onCreateDialog() method that will be called when we call showDialog(int id) method. Create an instance of the ProgressDialog class and set its various properties, such as icon, title, and style. And set the two buttons Hide and Cancel.

Then we go to onCreate() method and connect our button in .xml  with our button in .java code .. and then implement the function that when button pressed is fired .. and inside it we will call showDialog(int id) method and give the dialog a unique id. To display the progress status in the progress dialog, you need to use a Handler object to run a background thread

The background thread counts up to 100, with each count delayed by 100 milliseconds. When the count reaches 100, the progress dialog is dismissed.

Now Run your program .. and see your great result .. tadaaaaaa 😀

That’s all for now .. and sorry for my delay in publishing this lesson 🙂

Activites and Intents – Part 2

Okay now we will continue our last lesson .. in Today’s lesson the first thing that we gonna learn is how to display a dialog window .. ?!

First we will create a button in our UI (main.xml file) ..


This provides a unique identifier for the view, which you can use to reference the object from your app code, such as to read and manipulate the object (you’ll see this in the next lesson).The at sign (@) is required when you’re referring to any resource object from XML. It is followed by the resource type (id in this case), a slash, then the resource name (btn_Show).The plus sign (+) before the resource type is needed only when you’re defining a resource ID for the first time. When you compile the app, the SDK tools use the ID name to create a new resource ID in your project’s gen/ file that refers to the Button element. Once the resource ID is declared once this way, other references to the ID do not need the plus sign. Using the plus sign is necessary only when specifying a new resource ID and not needed for concrete resources such as strings or layouts.

wrap_content value specifies that the view should be only as big as needed to fit the contents of the view.

fill_parent then the Button element would fill the screen, because it would match the size of the parent LinearLayout

The next step .. we will go to our .java class and write the code that respond to click event on our button .. Let’s first descripe the shape of our Dialog that we will create .. our dialog will contain a small picture, a word beside it, some check boxes and two buttons.

First we will create an array to contain check boxes’ names, and another array to contain a boolean that indicate if this item is checked or not .. then we will do as we do before .. we will connect our button in .xml file with our button in .java code .. and then implement the function that when button pressed is fired .. and inside it we will call showDialog(int id) method and give the dialog a unique id .. 🙂

Because we will show a dialog on our screen .. so we need to override onCreateDialog() method that will be called when we call showDialog(int id)  method. So now we will write this code in our onCreateDialog() method

The preceding code sets the Dialog Icon, Title and two buttons: OK and Cancel, using the setPositiveButton() and setNegativeButton() methods, respectively. We also set a list of checkboxes for users to choose via the setMultiChoiceItems() method. For the setMultiChoiceItems() method, you passed in two arrays: one for the list of items to display and another to contain the value of each item to indicate if they are checked. When each item is checked, you use the Toast class to display a message. A toast is a view containing a quick little message for the user. When the view is shown to the user, appears as a floating view over the application. And now when i run the App … Jerry Icon appears (i love tom & jerry :D)

The last thing i want to say the meaning of MainActivity.this that we use it as a parameter in Toast.makeText … On Android, a Context is used for many operations but mostly to load and access resources .. and MainActivity.this returns the current context of the activity, if activity is destroyed then it will be destroyed also.

That’s all for now … wait the other parts of Activities and Intents series 🙂

Activites and Intents – Part 1

Hello again .. i hope you all are fine 🙂

Today i will talk about something new .. in the last lesson we created an Activity that has a Button and a TextView .. but we didn’t define what’s activity ?!

Activity is a window that contains the user interface of your applications. An application can have zero or more activities, and the main aim of an activity is to interact with the user. From the moment an activity appears on the screen to the moment it is hidden, it goes through a number of stages, known as an activity’s life cycle.

And there’s another definition that i will talk about .. it’s called intent ..

An intent is basically the “glue” that enables different activities from different applications to work together seamlessly, ensuring that tasks can be performed as though they all belong to one single application.

Now let’s talk about how to create an Activity .. to create an Activity we will create a java class that extends an Activity base class.

Our Activity class then load its UI components(Buttons, TextView, EditText, … etc) from the xml file created in res/layout folder(which is here named activity_main.xml) .. and every Activity in our application must be declared in AndroidMainfest.xml file

The Activity base class defines a series of events that governs the life cycle of an activity. The Activity
class defines the following events:
➤ onCreate() — Called when the activity is first created
➤ onStart() — Called when the activity becomes visible to the user
➤ onResume() — Called when the activity starts interacting with the user
➤ onPause() — Called when the current activity is being paused and the previous activity is
being resumed
➤ onStop() — Called when the activity is no longer visible to the user
➤ onDestroy() — Called before the activity is destroyed by the system (either manually or by
the system to conserve memory)
➤ onRestart() — Called when the activity has been stopped and is restarting again

We will see an example for better understanding the Activity Life Cycle .. 🙂

First we will create a new android project .. by default we will found onCreate() method .. we will add to it a line that print a message on LogCat to know which method will be executed first …

Log.d(tag, “In onCreate() Event”);

and we will add this code that call the rest of events ..

And then we will start debugging … when we see the application .. we will see 3 messages in LogCat

When we press the Back button in android emulator … another 3 messages will be displayed in LogCat

And when we press Home button in android emulator .. another 3 messages will be displayed in LogCat

But when we press the Phone button on the Android Emulator so that the activity is pushed to the background .. we will see that LogCat contain 2 messages

Now press the Back button again to exit phone dialer .. the LogCat will display these messages

Notes :

  • The onPause() event is called in both scenarios — when an activity is sent to the background, as well as when it is killed when the user presses the Back button.
  • When an activity is started, the onStart() and onResume() events are always called, regardless of whether the activity is restored from the background or newly created.

Now we will talk about how to apply Styles and Themes to our Activity … Let’s see 🙂

To apply a dialog theme to an Activity .. we will just add one line in AndroidMainfest.xml inside our Activity

And this will produce the following output …

mmm but how to hide this title bar ?! .. The solution is to go to out onCreate method and under the line of super.onCreate(); .. we will put this line  requestWindowFeature(Window.FEATURE_NO_TITLE);  .. and this is the result … tadaaaa 😀

That’s enough for today .. i hope it’s useful .. enjoy learning 🙂

Hello World – Code Explanation

Okay now i am gonna explain the code in the previous example (HelloWorld) .. 🙂

First let’s explain what’s we write in main.xml file … we write a code for a Button and a TextView .. for the Button we specify its height and width .. and then specify the text that will be showed on it .. and the last thing we write this line
This line means that the name of this button in our java code will be btnShowText … Let me explain it in another way .. we have a main.xml file which is the UI and we have our .java class which will say “okay when this button is clicked i will show the text” .. how can we connect our UI with our code in .java ?!

The first step is to give the resource (aka Button, TextView, EditView, … etc) a name in our .xml file (as i show you above)

The second step is to tie this resource to a real Button in our .java class .. as this
Button myButton;

Now they are connected .. Congrats 😀 .. Let’s see the rest of our .java class

Here we say when myButton Clicked do the following .. make a Random number .. set the text of myTextView to be Hello World and set the size of the text to a random number from 0 to 74 .. and every time change the text color.

That’s all for now .. if you have any question don’t hesitate 🙂