0% found this document useful (0 votes)
20 views6 pages

Task 14

Ch g8gig8g7f7f7f7f8f

Uploaded by

yash35567
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)
20 views6 pages

Task 14

Ch g8gig8g7f7f7f7f8f

Uploaded by

yash35567
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/ 6

Task 14:- sTore and Transfer daTa and image

selecTion from gallery

CODING:-INFO ACTIVITY.xml

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


<ScrollView
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=".InfoActivity"
android:orientation="vertical"
android:gravity="start"
android:background="#61B0EF">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
android:layout_width="225dp"
android:layout_height="225dp"
android:id="@+id/ivProfilePhoto"
android:src="@drawable/photo"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40sp" />

<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:id="@+id/btnProfile"
android:layout_marginLeft="62sp"
android:layout_marginTop="17sp"
android:text="Change Profile Photo"
android:textColor="@color/black"
android:textStyle="bold|italic"
android:textSize="17sp"
android:fontFamily="serif"
android:textAlignment="center" />

<TextView
android:id="@+id/tvProfileText"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_margin="17sp"
android:layout_marginLeft="24sp"
android:paddingLeft="18sp"
android:background="@drawable/etbgshapem"
android:text="Name"
android:fontFamily="serif"
android:textColor="@color/black"
android:layout_gravity="center_vertical"
android:drawablePadding="10sp"
android:textSize="20sp"
android:textStyle="bold"
app:drawableLeftCompat="@drawable/baseline_font_download_24" />

<TextView
android:id="@+id/tvProfileText1"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_margin="17sp"
android:layout_marginLeft="24sp"
android:paddingLeft="18sp"
android:background="@drawable/etbgshapem"
android:text="Mobile No"
android:fontFamily="serif"
android:textColor="@color/black"
android:layout_gravity="center_vertical"
android:drawablePadding="12sp"
android:textSize="20sp"
android:textStyle="bold"
app:drawableLeftCompat="@drawable/baseline_local_phone_24"/>

<TextView
android:id="@+id/tvProfileText2"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_margin="17sp"
android:layout_marginLeft="24sp"
android:paddingLeft="18sp"
android:background="@drawable/etbgshapem"
android:text="Email Id"
android:fontFamily="serif"
android:textColor="@color/black"
android:layout_gravity="center_vertical"
android:drawablePadding="10sp"
android:textSize="20sp"
android:textStyle="bold"

app:drawableLeftCompat="@drawable/baseline_mark_email_unread_24" />

<TextView
android:id="@+id/tvProfileText3"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_margin="17sp"
android:layout_marginLeft="24sp"
android:paddingLeft="18sp"
android:background="@drawable/etbgshapem"
android:text="Username"
android:fontFamily="serif"
android:textColor="@color/black"
android:layout_gravity="center_vertical"
android:drawablePadding="10sp"
android:textSize="20sp"
android:textStyle="bold"
app:drawableLeftCompat="@drawable/baseline_font_download_24" />
<TextView
android:id="@+id/tvProfileText5"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_margin="17sp"
android:layout_marginLeft="24sp"
android:paddingLeft="18sp"
android:background="@drawable/etbgshapem"
android:text="Password"
android:fontFamily="serif"
android:textColor="@color/black"
android:layout_gravity="center_vertical"
android:drawablePadding="10sp"
android:textSize="20sp"
android:textStyle="bold"
app:drawableLeftCompat="@drawable/baseline_pin_24" />

</LinearLayout>

</ScrollView>
CODING:-INFO ACTIVITY.java

package com.example.smcreation;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import org.jetbrains.annotations.Nullable;

import java.io.IOException;

public class InfoActivity extends AppCompatActivity {

ImageView ivProfilePhoto;
Button btnProfile;
TextView tvName,tvMobileNo,tvEmailId,tvUsername,tvPassword;
SharedPreferences preferences;
SharedPreferences.Editor editor;

Uri imagePath;
Bitmap bitmap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_info);

preferences =
PreferenceManager.getDefaultSharedPreferences(InfoActivity.this);
editor = preferences.edit();

ivProfilePhoto = findViewById(R.id.ivProfilePhoto);
btnProfile = findViewById(R.id.btnProfile);
tvName=findViewById(R.id.tvProfileText);
tvMobileNo=findViewById(R.id.tvProfileText1);
tvEmailId=findViewById(R.id.tvProfileText2);
tvUsername=findViewById(R.id.tvProfileText3);
tvPassword=findViewById(R.id.tvProfileText5);

String strName = preferences.getString("Name","");


String strMobileNo = preferences.getString("Mobile No","");
String strEmailId = preferences.getString("Email Id","");
String strUsername = preferences.getString("Username","");
String strPassword = preferences.getString("Password","");

tvName.setText(strName);
tvMobileNo.setText(strMobileNo);
tvEmailId.setText(strEmailId);
tvUsername.setText(strUsername);
tvPassword.setText(strPassword);

btnProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openImageChooser();
}
});

private void openImageChooser() {


Intent i = new Intent();
i.setType("image/*");
i.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(i,"Select Your Profile
Image"),111);

}
@Override
protected void onActivityResult(int requestCode, int resultCode,
@Nullable Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if(requestCode ==111 && resultCode == RESULT_OK && data!=null)


{
imagePath = data.getData();
try {
bitmap =
MediaStore.Images.Media.getBitmap(getContentResolver(),imagePath);
ivProfilePhoto.setImageBitmap(bitmap);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
OUTOUT :-

You might also like