UNIT4
UNIT4
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
“android:textStyle=”bold|italic”.
android:textColor="#B00020"
• Shadow for the text can also be given in Android. The attributes required for the shadowed
text view are:
android:shadowDx=”integer_value” -> which decides the distance of text from its shadow with
respect to x axis, if the integer_value is positive the shadow is on positive of the x axis and vice versa.
android:shadowDy=”integer_value” -> which decides the distance of text from its shadow with
respect to y axis, if the integer_value is positive the shadow is on negative of the y axis and vice
versa.
android:shadowRadius=”integer_value” -> which decides the amount of the shadow to be given for
the text view.
android:shadowDx="-15"
android:shadowDy="4"
android:shadowRadius="10"
android:letterSpacing=”floatingTypeValue” -> This attribute is used to give the space between each
of the letters.
android:textAllCaps=”trueOrfalse” -> This attribute decides, all the letters should be in uppercase or
not.
android:letterSpacing="0.15"
android:textAllCaps="true"
android:drawableEnd="@drawable/ic_lappy"
Edit Text
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.EditText
EditText is a Widget of user interface (UI) used to retrieve and modify text data from a user in
an Android app
Attributes Description
android:gravity gravity is used to align the text like left, right, center, top
android:textStyle It is used to set the text style like bold, italic, bold italic, etc.
android:drawablePadding It is used to set the drawable to be drawn from the set padding
of View
AutoCompleteTextView
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.EditText
↳ android.widget.AutoCompleteTextView
The drop down can be dismissed at any time by pressing the back key or, if no
item is selected in the drop down, by pressing the enter/dpad center key.
The list of suggestions is obtained from a data adapter and appears only after a given
number of characters defined by the threshold. <AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="100px"
android:placeholder="Enter your country name"
android:id="@+id/txtcountries"/>
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter=new
ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,cou
ntries);
AutoCompleteTextView
textView=(AutoCompleteTextView)findViewById(R.id.txtcountries);
textView.setThreshold(3);
textView.setAdapter(adapter);
}
<TextView
android:autoLink="web" />
java.lang.Object
↳ android.view.View
↳ android.widget.TextView
↳ android.widget.Button
public class MyActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_layout_id);
android:adjustViewBounds
1 Set this to true if you want the ImageView to adjust its
bounds to preserve the aspect ratio of its drawable.
android:baseline
2
This is the offset of the baseline within this view.
android:baselineAlignBottom
3 If true, the image view will be baseline aligned with based on
its bottom edge.
android:cropToPadding
4
If true, the image will be cropped to fit within its padding.
android:src
5
This sets a drawable as the content of this ImageView.
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.widget.AdapterView<android.widget.ListAdapter>
↳ android.widget.AbsListView
↳ android.widget.ListView
A list view is an adapter view that does not know the details, such as type and
contents, of the views it contains. Instead list view requests views on demand
from a ListAdapter as needed, such as to display new views as the user scrolls up
or down.
Attribute Description
ListView l;
String tutorials[]
= { "Algorithms", "Data Structures",
"Languages", "Interview Corner",
"GATE", "ISRO CS",
"UGC NET CS", "CS Subjects",
"Web Technologies" };
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
l = findViewById(R.id.list);
ArrayAdapter<String> arr;
arr
= new ArrayAdapter<String>(
this,
R.layout.support_simple_spinner_dropdown_item,
tutorials);
l.setAdapter(arr);
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.widget.AdapterView<android.widget.ListAdapter>
↳ android.widget.AbsListView
↳ android.widget.GridView
A view that shows items in two-dimensional scrolling grid. The items in the grid
come from the ListAdapter associated with this view.
java.lang.Object
↳ android.view.View
↳ android.view.ViewGroup
↳ android.widget.FrameLayout
↳ android.widget.ScrollView
A view group that allows the view hierarchy placed within it to be scrolled. Scroll view
may have only one direct child placed within it. To add multiple views within the scroll
view, make the direct child you add a view group, for example LinearLayout, and place
additional views within that LinearLayout.
Scroll view supports vertical scrolling only. For horizontal scrolling,
use HorizontalScrollView instead.
Never add a RecyclerView or ListView to a scroll view. Doing so results in poor user
interface performance and a poor user experience.
java.lang.Object
↳ android.view.View
↳ android.widget.ProgressBar
A user interface element that indicates the progress of an operation. Progress bar
supports two modes to represent progress: determinate, and indeterminate.
Use indeterminate mode for the progress bar when you do not know how long an
operation will take. Indeterminate mode is the default for progress bar and shows a
cyclic animation without a specific amount of progress indicated.
Use determinate mode for the progress bar when you want to show that a specific
quantity of progress has occurred. For example, the percent remaining of a file being
retrieved, the amount records in a batch written to database, or the percent remaining
of an audio file that is playing.
CheckBox is used for adding multiple selections of items from the given set
of options. This is seen used in many android applications for adding a
feature for multiple selections.
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginStart="10dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="10dp"
android:gravity="center">
</RadioGroup>
Inflate the Layout: To use the custom layout with a toast message, you need to inflate the
XML layout file to create a View object in memory
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker.
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker.
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date the user picks.
}
}
For example, here's a button that, when tapped, calls a method to show the
dialog:
<Button
android:id="@+id/pickDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pick date"/>
When the user taps this button, the system calls the following method:
KotlinJava
findViewById<Button>(R.id.pickDate).setOnClickListener {
val newFragment = DatePickerFragment();
newFragment.show(supportFragmentManager, "datePicker");
}
Sure, here are the listeners used in date and time pickers:
1. `DatePickerDialog.OnDateSetListener`
1. `TimePickerDialog.OnTimeSetListener`
7. Static vs Dynamic: TableLayout is best for static content with known rows and
columns, whereas GridView is suited for dynamic content where the number of
items may vary.
8. Customization: TableLayout allows for more customization of individual cells,
while GridView relies on an adapter to manage its content.
9. Scrolling: GridView inherently supports scrolling if the content exceeds the
screen size, while TableLayout does not and requires additional handling for
scrolling.
UNIT 5
An Intent is a messaging object you can use to request an action from another app
component.
Intent Filter
• Implicit intent uses the intent filter to serve the user request.
• The intent filter specifies the types of intents that an activity,
service, or broadcast receiver can respond.
• Intent filters are declared in the Android manifest file.
• Intent filter must contain <action>
Most of the intent filter are describe by its
1. <action>,
2. <category> and
3. <data>.
Examples of common action:
• ACTION_VIEW: Use this action in intent
with startActivity() when you have some information that
activity can show to the user like showing an image in a gallery
app or an address to view in a map app
• ACTION_SEND: You should use this in intent
with startActivity() when you have some data that the user can
share through another app, such as an email app or social
sharing app.
• CATEGORY_BROWSABLE: The target activity allows itself to be
started by a web browser to display data referenced by a link.
Fundamental use case of Intents
Starting Activity
An activity represents the single screen in an app
Starting a Service
A Service is a component that performs operations in the background
without a user interface, which is also called a background process.
Delivering a Broadcast
A broadcast is a message that any app can receive. In android, the
system delivers various broadcast system events like device starts
charging, disable or enable airplane mode, etc.
Broadcast Receivers simply respond to broadcast messages
from other applications or from the system itself. These
messages are sometime called events or intents.
<receiver android:name="MyReceiver">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED">
</action>
</intent-filter>
</receiver>
android.intent.action.BATTERY_CHANGED
1 Sticky broadcast containing the charging state, level,
and other information about the battery.
android.intent.action.BATTERY_LOW
2
Indicates low battery condition on the device.
android.intent.action.BATTERY_OKAY
3
Indicates the battery is now okay after being low.
android.intent.action.BOOT_COMPLETED
4 This is broadcast once, after the system has finished
booting.
android.intent.action.BUG_REPORT
5
Show activity for reporting a bug.
android.intent.action.CALL
6
Perform a call to someone specified by the data.
android.intent.action.CALL_BUTTON
7 The user pressed the "call" button to go to the dialer or
other appropriate UI for placing a call.
android.intent.action.DATE_CHANGED
8
The date has changed.
android.intent.action.REBOOT
9
Have the device reboot.
Broadcasting Custom Intents
broadcastIntent(View view) {
public void
Intent intent = new Intent();
intent.setAction("com.tutorialspoint.CUSTOM_INTENT");
sendBroadcast(intent);
}
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name="MyReceiver">
<intent-filter>
<action
android:name="com.tutorialspoint.CUSTOM_INTENT">
</action>
</intent-filter>
</receiver>
</application>
Description
Methods
Foreground Services:
Services that notify the user about its ongoing operations are termed as
Foreground Services.
Background services do not require any user intervention. These services
do not notify the user about ongoing background tasks and users also
cannot access them. The process like schedule syncing of data or storing
of data fall under this service.
3. Bound Services:
This type of android service allows the components of the application
like activity to bound themselves with it. Bound services perform their
task as long as any application component is bound to it. More than one
component is allowed to bind themselves with a service at a time. In
order to bind an application component with a
service bindService() method is used.
The Life Cycle of Android Services
videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// Code to execute when the video finishes playing
}
});
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
db.execSQL(TABLE_CREATE);
@Override
onCreate(db);
Database - Fetching
Ensure consistencyyyyy……………
UNIT 6
In Android, you can use SmsManager API or devices Built-in SMS
application to send SMS's.
SmsManager API
Android requires that all APKs be digitally signed with a certificate before they
are installed on a device or updated. When releasing using Android App
Bundles, you need to sign your app bundle with an upload key before
uploading it to the Play Console, and Play App Signing takes care of the rest. For
apps distributing using APKs on the Play Store or on other stores, you must
manually sign your APKs for upload.
he following is a high-level overview of the steps you might need to take to sign
and publish a new app to Google Play:
Step 2: After you completed step 1 you will be redirected to this page
where you have to click on the CREATE APPLICATION button.
Once you click on it a pop up will be shown like this where you have to
choose your Default language and Title of your app. Then click on
the CREATE button.
Ant next thing you have to provide is the Feature Graphic of your app.
And finally when you click on SAVE DRAFT button you can see
that Store listing tab is now become turned to green and you are done
for Store listing.
After redirecting to the next page click on the CREATE RELEASE button.
After that on the next page, you have to upload your APK file in Android
App Bundles and APKs to add section.
..various steps
And then provide a valid Privacy policy URL. Note that google will
check this.
After usually 4 to 5 days they will review your app and let you know to
either approve or reject your app.
Android application run in android sandboxxx.
• App signing
You can define custom permissions for your apps and request custom
permissions from other apps by defining <uses-permission> elements. However,
carefully assess whether it is necessary to do so.