0% found this document useful (0 votes)
36 views10 pages

Activity - Main - XML:: Amal Lazreg 2LM2TP2

The document describes an Android application with activities for login, listing tasks, and context menus. The main activity handles button clicks to show the login dialog and register context menus. It also overrides methods for creating option menus and handling menu item selections.

Uploaded by

Adhem Naiji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views10 pages

Activity - Main - XML:: Amal Lazreg 2LM2TP2

The document describes an Android application with activities for login, listing tasks, and context menus. The main activity handles button clicks to show the login dialog and register context menus. It also overrides methods for creating option menus and handling menu item selections.

Uploaded by

Adhem Naiji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Amal Lazreg

2LM2TP2

Activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">

android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/todo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TODO APP"
android:layout_gravity="center"
android:textSize="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="__________"
android:layout_gravity="center"
android:textSize="30dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bienvenu encore une fois"
android:layout_gravity="center"
android:textSize="25dp"/>
<Button
android:id="@+id/appuyer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="appuyer longuement ici "
android:layout_gravity="center">
</Button>
<Button
android:id="@+id/connecter"

Page | 1
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" se connecter "
android:layout_gravity="center"
>
</Button>

</LinearLayout>

- Interface :

Page | 2
Dialog_login.xml :

Page | 3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_gravity="center"
android:textSize="35dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Email"
android:id="@+id/email"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="Password"
android:id="@+id/password"/>
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" LOGIN "
android:layout_gravity="center">
</Button>
<Button
android:id="@+id/fermer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Fermer "
android:layout_gravity="center">
</Button>

</LinearLayout>

Page | 4
- Interface :

MainActivity.java :

package com.lm.todoapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

Page | 5
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button mShowDialog = (Button) findViewById(R.id.connecter) ;
mShowDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder mBuilder = new
AlertDialog.Builder(MainActivity.this);
View mView =
getLayoutInflater().inflate(R.layout.dialog_login, null);
final EditText mEmail = (EditText)
mView.findViewById(R.id.email);
final EditText mPassword = (EditText)
mView.findViewById(R.id.password);
Button mLogin = (Button) mView.findViewById((R.id.login));
Button mFermer = (Button)
mView.findViewById((R.id.fermer));

mLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!mEmail.getText().toString().isEmpty() &&
!mPassword.getText().toString().isEmpty()) {
Toast.makeText(MainActivity.this, "Success
Login", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Error
Login", Toast.LENGTH_SHORT).show();

}
}
});
mBuilder.setView(mView);
AlertDialog dialog = mBuilder.create();
dialog.show();
mFermer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();

}
});

}
});
Button btn = (Button) findViewById(R.id.appuyer) ;
registerForContextMenu(btn);
}
@Override
public void onCreateContextMenu (ContextMenu menu,View
v,ContextMenu.ContextMenuInfo menuInfo){

Page | 6
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0,v.getId(),0,"Liste de taches") ;
menu.add(0,v.getId(),0,"Nombre totale") ;
menu.add(0,v.getId(),0,"plus ...") ;
}
@Override
public boolean onContextItemSelected(@NonNull MenuItem item) {
if (item.getTitle()=="Liste de taches") {
Intent in = new Intent(MainActivity.this,ListTache.class) ;
startActivity(in);
}else if (item.getTitle()=="Nombre totale") {
Toast.makeText(MainActivity.this,"0
RIEN",Toast.LENGTH_LONG).show();
}else if (item.getTitle()=="plus ...") {
Uri webpage = Uri.parse("www.google.com") ;
Intent intent = new Intent(Intent.ACTION_VIEW,webpage) ;

if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
Log.d("ImplicitIntents","can't handle this intent !") ;
}
}
return super.onOptionsItemSelected(item) ;
}
@Override
public boolean onCreateOptionsMenu (Menu menu) {
MenuInflater inf = getMenuInflater() ;
inf.inflate(R.menu.resfile,menu);
return true ;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.item1:
Toast.makeText(this,"You have selected item
1",Toast.LENGTH_SHORT).show();
return true ;
default:
return super.onOptionsItemSelected(item) ;

}
}
}

Page | 7
Menu :

Page | 8
Resfile.xml :

<?xml version="1.0" encoding="utf-8"?>


<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item1" android:title="Item 1"></item>
<item android:id="@+id/item2" android:titleCondensed="Item 2"
android:title="Item 2 mais avec un nom assez long quand meme">
<menu>
<item android:id="@+id/item3" android:title="Item 2.1"
android:checked="true"/>
<item android:id="@+id/item4" android:title="Item 2.2"/>
</menu>
</item>
<item android:id="@+id/item5" android:title="Item 3"
android:checked="true"/>
<group android:id="@+id/group1" android:checkableBehavior="all">
<item android:id="@+id/item7" android:title="Item 4.1"></item>
<item android:id="@+id/item8" android:title="Item 4.2"></item>
</group>
<group android:id="@+id/group2" android:enabled="false">
<item android:id="@+id/item9" android:title="Item 5.1"></item>
<item android:id="@+id/item10" android:title="Item 5.2"></item>
</group>
</menu>

Page | 9
Interface menu :

Page | 10

You might also like