Вы находитесь на странице: 1из 10

CODES MOBAPP:

SHAREDPREFERENCE:

MAINACTIVITY:

package com.example.windows10home.cisneros;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText txtEmail;
EditText txtUser;
EditText txtPass;

Button button1;
Button button2;
SharedPreferences solis;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtEmail = (EditText) findViewById(R.id.editText);
txtUser = (EditText) findViewById(R.id.txtUser);
txtPass = (EditText) findViewById(R.id.editText2);

button1 = (Button) findViewById(R.id.button1);


button2 = (Button) findViewById(R.id.button2);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
solis = getSharedPreferences("USERINFORMATION" , Context.MODE_PRIVATE);
SharedPreferences.Editor editor = solis.edit();
editor.putString("EMAIL" , txtEmail.getText().toString());
editor.putString("USER" , txtUser.getText().toString());
editor.putString("PASS" , txtPass.getText().toString());
editor.apply();

if(txtEmail.getText().toString().trim().length() <= 0 && txtUser.getText().toString().trim().length() <= 0 &&


txtPass.getText().toString().trim().length() <= 0){
Toast.makeText(MainActivity.this, "Please fillup the email", Toast.LENGTH_SHORT).show();

}
else if (txtUser.getText().toString().trim().length() <= 5){
Toast.makeText(MainActivity.this, "More than 5-words Username", Toast.LENGTH_SHORT).show();

}
else if (txtPass.getText().toString().trim().length() <= 5){
Toast.makeText(MainActivity.this, "More than 5-words Password", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(MainActivity.this, "Successfull", Toast.LENGTH_SHORT).show();
}
}
});
//Login
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences next = getSharedPreferences("USERINFORMATION" , Context.MODE_PRIVATE);
String email = next.getString("EMAIL" , "");
String user = next.getString("USER", "");
String pass = next.getString("PASS","");

if (txtEmail.getText().toString().trim().equals(email) && txtUser.getText().toString().trim().equals(user) &&


txtPass.getText().toString().trim().equals(pass)){

Intent intent = new Intent( MainActivity.this , Main2Activity.class );


startActivity(intent);
}
else {
Toast.makeText(MainActivity.this, "Please FILLUP", Toast.LENGTH_SHORT).show();
}

}
});

}
}

SHAREDPREFERENCE:

MAIN2ACTIVITY:

package com.example.windows10home.cisneros;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {

EditText txt_user , txt_pass;


Button btn_log , btn_reg;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);

txt_user = (EditText) findViewById(R.id.user);


txt_pass = (EditText) findViewById(R.id.editText3);

btn_log = (Button) findViewById(R.id.bot1);


btn_reg = (Button) findViewById(R.id.bot2);

btn_log.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences results = getSharedPreferences("USERINFORMATION" , Context.MODE_PRIVATE);
String user = results.getString("USER", "");
String pass = results.getString("PASS","");

if (txt_user.getText().toString().trim().equals(user) && txt_pass.getText().toString().trim().equals(pass)) {


Intent intent = new Intent(Main2Activity.this , Main3Activity.class);
startActivity(intent);
}else{
Toast.makeText(Main2Activity.this, "Please sign up", Toast.LENGTH_SHORT).show();
}

}
});
btn_reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent ints = new Intent(Main2Activity.this , MainActivity.class);
startActivity(ints);
}
});

}
}

SHAREDPREFERENCE:

MAIN3ACTIVITY:

package com.example.windows10home.cisneros;

import android.content.Context;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class Main3Activity extends AppCompatActivity {

TextView txt_us , txt_em;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);

txt_us = (TextView) findViewById(R.id.txtview3);


txt_em = (TextView) findViewById(R.id.txtview4);

SharedPreferences results = getSharedPreferences("USERINFORMATION" , Context.MODE_PRIVATE);


String user = results.getString("USER", "");
String email = results.getString("EMAIL","");

txt_us.setText(user);
txt_em.setText(email);
}
}
NORMAL DATABASE:

MAINACTIVITY

package com.example.windows10home.cisneros;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class MainActivity extends AppCompatActivity {

public static final String FILE_NAME="example.docx";


EditText edit;
Button btnsave, btnload;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

edit=(EditText)findViewById(R.id.editText);
btnsave=(Button)findViewById(R.id.button);
btnload=(Button)findViewById(R.id.button2);

btnsave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String txt = edit.getText().toString();
FileOutputStream fos = null;
try {
fos = openFileOutput(FILE_NAME , MODE_PRIVATE);
fos.write(txt.getBytes());
Toast.makeText(MainActivity.this, "Saved to" +getFilesDir() + "/"+
FILE_NAME,Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fos !=null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
});
btnload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FileInputStream input = null;
try {
input = openFileInput (FILE_NAME);
InputStreamReader str =new InputStreamReader(input);
BufferedReader bf = new BufferedReader(str);
StringBuilder stb = new StringBuilder();
String txt;

while ((txt = bf.readLine()) !=null) {


stb.append(txt).append("\n");
}
edit.setText(stb.toString());

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (input !=null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
});
}
}

FIRST ACTIVITY IN MOBAPP WITH DATE PICKER:


I DON’T KNOW THE NAME OF ACTIVITY:

MAINACTIVITY:

package com.example.windows10home.reintegradoj;

import android.app.DatePickerDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

String firstName,middleName, lastName, fullName, gender, birthday;


int year, month, dayOfMonth;
RadioGroup radioGenderGroup;
RadioButton radioGenderButton;
Button datePick;
DatePickerDialog datePickerDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button submitButton = (Button)findViewById(R.id.submit);


radioGenderGroup = (RadioGroup)findViewById(R.id.radioGenderGroup);

datePick = findViewById(R.id.datePicker);

datePick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Calendar calendar = Calendar.getInstance();


int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);

datePickerDialog = new DatePickerDialog(MainActivity.this,


new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
birthday = day + "/" + (month + 1) + "/" + year;
Toast.makeText(MainActivity.this, birthday, Toast.LENGTH_SHORT).show();
}
}, year, month, dayOfMonth);
datePickerDialog.show();
}
});

//When the submit button is clicked


submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

//Kinuha yung data from editText


EditText first = (EditText)findViewById(R.id.firstName);
EditText middle = (EditText)findViewById(R.id.middleName);
EditText last = (EditText)findViewById(R.id.lastName);

//converted the data into strings


firstName = first.getText().toString();
middleName = middle.getText().toString();
lastName = last.getText().toString();

//dito pinagsamasama to get the full name


fullName = firstName + " " + middleName + " " + lastName;

int selectedId = radioGenderGroup.getCheckedRadioButtonId();

radioGenderButton = (RadioButton) findViewById(selectedId);

gender = (String)radioGenderButton.getText();

Intent intent = new Intent(MainActivity.this, Main2Activity.class);

//passing the data from this to another activity by intent


intent.putExtra("FullName", fullName);
intent.putExtra("Gender", gender);
intent.putExtra("Birthday", birthday);

startActivity(intent);

}
});

}
}

MAIN2ACTIVITY:

package com.example.windows10home.reintegradoj;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class Main2Activity extends AppCompatActivity {

TextView fullNameContainer, genderContainer, birthdayContainer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);

fullNameContainer = (TextView)findViewById(R.id.fullName);
genderContainer = (TextView)findViewById(R.id.gender);
birthdayContainer = (TextView)findViewById(R.id.birthday);

fullNameContainer.setText("Full Name: " + getIntent().getStringExtra("FullName"));


genderContainer.setText("Gender: " + getIntent().getStringExtra("Gender"));
birthdayContainer.setText("Date Of Birth: " + getIntent().getStringExtra("Birthday"));

}
}

FLASHLIGHT:

MAINACTIVITY:

package com.example.windows10home.reintegrado;

import android.Manifest;
import android.content.pm.PackageManager;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {

ToggleButton tgb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tgb = (ToggleButton)findViewById(R.id.flashbtn);

boolean feature_camera_flash =
getPackageManager().hasSystemFeature(getPackageManager().FEATURE_CAMERA_FLASH);
boolean Camera_light = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) ==
PackageManager.PERMISSION_GRANTED;

ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA},60);


final CameraManager cm = (CameraManager) getSystemService(CAMERA_SERVICE);

tgb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String cameraID = cm.getCameraIdList()[0];

if (tgb.isChecked()) {
cm.setTorchMode(cameraID, true);
}
else {
cm.setTorchMode(cameraID, false);
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
});
}
}

FLASHLIGHT:

ANDROID MANIFEST:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.windows10home.reintegrado">

//ADD THIS IN ANDROID MANIFEST THIS PERMISSION:


<uses-permission android:name="android.permission.FLASHLIGHT"></uses-permission>
//

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>

</manifest>

INTENT PASS ACTIVITY TO OTHER ACTIVITY:

MAINACTIVITY:

package com.example.windows10home.mangareader;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Main57Activity extends AppCompatActivity {

Button btnBot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main57);

btnBot = (Button)findViewById(R.id.btn_button);

btnBot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Main57Activity.this, MainActivity.class);
startActivity(intent);
}
});

}
}

TOAST:

MAINACTIVITY:

package com.example.windows10home.mangareader;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class Main57Activity extends AppCompatActivity {

Button btnBot;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main57);
btnBot = (Button)findViewById(R.id.btn_button);

Toast.makeText(Main57Activity.this, "TOAST", Toast.LENGTH_SHORT).show();


}
}