Vous êtes sur la page 1sur 9

Compte rendue

TP: Fichiers de Préférence (SharedPreferences)

Classes : L3-SEM (Système Embarques et Mobiles)

Nom et Prénom : Jebari Ahmed


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"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/login"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="name or email"
android:importantForAutofill="no"

android:inputType="textPersonName" />
<EditText
android:id="@+id/password"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="password"
android:importantForAutofill="no"
android:inputType="textPassword" />
<Button
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:background="#FB8981"
android:text="login" />

</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_alignParentBottom="true"
android:text="no_account_yet_cleck_here_to_create_on" />
</RelativeLayout>
</LinearLayout>

ActivityMain.java :
<?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"
tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/login"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="name or email"
android:importantForAutofill="no"

android:inputType="textPersonName" />
<EditText
android:id="@+id/password"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="password"
android:importantForAutofill="no"
android:inputType="textPassword" />
<Button
android:id="@+id/button"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:background="#FB8981"
android:text="login" />

</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_alignParentBottom="true"
android:text="no_account_yet_cleck_here_to_create_on" />
</RelativeLayout>
</LinearLayout>

activity_inscri.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=".inscri">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"/>

<EditText
android:id="@+id/etemail"
android:layout_width="match_parent"

android:layout_height="45dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="25dp"
android:paddingLeft="10dp"
android:inputType="text"
android:background="@android:color/white"
android:hint="Email" />
<EditText
android:id="@+id/pass"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:layout_marginTop="25dp"
android:paddingLeft="10dp"
android:inputType="textPassword"
android:hint="Password" />

<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="25dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:text="Valider"
android:textColor="@android:color/white"
/>
</LinearLayout>

Inscri.java :
package com.example.ahmed;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class inscri extends AppCompatActivity {
public static final int Account=10;
private final static String TG="";
public static final String EMAIL_extra ="user_email";
public static final String PASSWORD_extra ="user_password";
private Button validate;
private EditText email,password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inscri);
validate =(Button)findViewById(R.id.login);
validate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { Intent intent = new
Intent(inscri.this,MainActivity.class);
startActivityForResult(intent,Account);
}
});
}
@Override
protected void onActivityResult(int requestCode, int
resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode,
data);
if (requestCode == Account) {
if (requestCode == RESULT_OK) {
String password =
data.getStringExtra(MainActivity.PASSWORD_extra);
String mail = data.getStringExtra(MainActivity.EMAIL_extra);
Toast.makeText(this, "password =" + password + " Email=" + mail,
Toast.LENGTH_LONG).show();
}
}
}
activity_home.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"
tools:context=".home">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginTop="90dp"
android:textColor="@color/black"
android:text="Welcome to Home"
android:textSize="30dp"
tools:layout_editor_absoluteX="65dp"
tools:layout_editor_absoluteY="43dp" />
</LinearLayout>

home.java :
package com.example.nouveau;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class HomeActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
}
Test final:

Vous aimerez peut-être aussi