Manul MAD
Manul MAD
Activity.main.xml
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.558"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.471" />
<TextView
android:id="@+id/result"
android:layout_width="153dp"
android:layout_height="60dp"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.424"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.492" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity.main.java
package com.example.grpquiz1;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=findViewById(R.id.button);
TextView txt=findViewById(R.id.result);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new
AlertDialog.Builder(MainActivity.this);
View custom=getLayoutInflater().inflate(R.layout.custom,null);
builder.setView(custom);
builder.setPositiveButton("Ok", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int
i) {
EditText year=custom.findViewById(R.id.year);
int v=Integer.parseInt(year.getText().toString());
int a=2022;
int b=0;
b=a-v;
txt.setText("your age is: "+b);
}
});
AlertDialog dialog=builder.create();
dialog.show();
}
});
}
}
Custom.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Date of birth"
android:textAppearance="@style/TextAppearance.AppCompat.Large" />
<EditText
android:id="@+id/day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Day" />
<EditText
android:id="@+id/month"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Month" />
<EditText
android:id="@+id/year"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Year" />
</LinearLayout>
Notificaton
Activity.main.xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="Notification!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Activity.main.java
package com.example.notification;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import java.util.Random;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showNotification();
}
});
}
private void showNotification(){
int notificationId=new Random().nextInt(100);
String channelId="notification_channel_1";
NotificationManager notificationManager=(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
// Intent intent=new
Intent(getApplicationContext(),NotificationActivity2.class);
Intent intent=new Intent(Intent.ACTION_VIEW,
Uri.parse("https://m.youtube.com/"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent
pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMU
TABLE);
NotificationCompat.Builder builder=new
NotificationCompat.Builder(getApplicationContext(),channelId);
builder.setSmallIcon(R.drawable.ic_notifications);
builder.setContentTitle("what is coding?");
builder.setDefaults(NotificationCompat.DEFAULT_ALL);
builder.setContentText("Coding is basically the computer language used
to develop apps, websites, and software. Without it, we'd have none of the
most popular technology we've come to ...");
builder.setStyle(new NotificationCompat.BigTextStyle().bigText("Coding
is basically the computer language used to develop apps, websites, and
software. Without it, we'd have none of the most popular technology we've come
to ..."));
builder.setContentIntent(pendingIntent);
//builder.setContentText(message)
builder.setAutoCancel(true);
builder.setPriority(NotificationCompat.PRIORITY_MAX);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
if (notificationManager!
=null&¬ificationManager.getNotificationChannel(channelId)==null){
NotificationChannel notificationChannel=new
NotificationChannel(
channelId,"Notification channel 1",
NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription("this notificarion
channel");
notificationChannel.enableVibration(true);
notificationChannel.enableLights(true);
notificationManager.createNotificationChannel(notificationChannel);
}
}
Notification notification=builder.build();
if (notificationManager!=null) {
notificationManager.notify(notificationId,notification);
}
}
}
Option Menu:
Activity.main.xml
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import java.util.Random;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showNotification();
}
});
}
private void showNotification(){
int notificationId=new Random().nextInt(100);
String channelId="notification_channel_1";
NotificationManager notificationManager=(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
// Intent intent=new
Intent(getApplicationContext(),NotificationActivity2.class);
Intent intent=new Intent(Intent.ACTION_VIEW,
Uri.parse("https://m.youtube.com/"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent
pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMU
TABLE);
NotificationCompat.Builder builder=new
NotificationCompat.Builder(getApplicationContext(),channelId);
builder.setSmallIcon(R.drawable.ic_notifications);
builder.setContentTitle("what is coding?");
builder.setDefaults(NotificationCompat.DEFAULT_ALL);
builder.setContentText("Coding is basically the computer language used
to develop apps, websites, and software. Without it, we'd have none of the
most popular technology we've come to ...");
builder.setStyle(new NotificationCompat.BigTextStyle().bigText("Coding
is basically the computer language used to develop apps, websites, and
software. Without it, we'd have none of the most popular technology we've come
to ..."));
builder.setContentIntent(pendingIntent);
//builder.setContentText(message)
builder.setAutoCancel(true);
builder.setPriority(NotificationCompat.PRIORITY_MAX);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
if (notificationManager!
=null&¬ificationManager.getNotificationChannel(channelId)==null){
NotificationChannel notificationChannel=new
NotificationChannel(
channelId,"Notification channel 1",
NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription("this notificarion
channel");
notificationChannel.enableVibration(true);
notificationChannel.enableLights(true);
notificationManager.createNotificationChannel(notificationChannel);
}
}
Notification notification=builder.build();
if (notificationManager!=null) {
notificationManager.notify(notificationId,notification);
}
}
}
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello i AM SOFIA Hera!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Mainmenu.xml
MainActivity.java
package com.example.optionmenu;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
Activity.main.xml
</ListView>
</RelativeLayout>
Activity.main.java
package com.example.contextmenut3;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
content.xml