Mobile Application Program-Lab Programs
Mobile Application Program-Lab Programs
Mobile Application Program-Lab Programs
1.activity_main.xml
2.MainActivity.java
package com.example.bii_exno_7;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Handler tss_handler=new Handler();
EditText tss_tv1,tss_tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tss_tv1=(EditText)findViewById(R.id.no1);
tss_tv2=(EditText)findViewById(R.id.no2);
}
public void thread1()
{
tss_tv1.setText(String.valueOf(Integer.parseInt(tss_tv1.getText().toString())+1));
tss_handler.postDelayed(run,500);
}
public void thread2()
{
tss_tv2.setText(String.valueOf(Integer.parseInt(tss_tv2.getText().toString())+1));
tss_handler.postDelayed(run,500);
}
public void start(View view)
{
tss_handler.postDelayed(run,500);
}
Runnable run=new Runnable() {
@Override
public void run() {
thread1();
thread2();
}
};
}
1.activity_main.xml
2.MainActivity.java
package com.example.student.maps;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
LocationManager locationManager;
LocationListener locationListener;
TextView latitude;
TextView longitude;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
latitude = (TextView) findViewById(R.id.lat);
longitude = (TextView) findViewById(R.id.lon);
locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
latitude.setText("Latitude :"+location.getLatitude());
longitude.setText("Longitude :"+location.getLongitude());
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
};
1.activity_main.xml
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Write"
tools:layout_editor_absoluteX="130dp"
tools:layout_editor_absoluteY="99dp"
android:onClick="write"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="146dp"
tools:layout_editor_absoluteY="147dp"
android:onClick="read"/>
</TableLayout>
</android.support.constraint.ConstraintLayout>
2.MainActivity.java
package com.example.bii_exno_8;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText text=(EditText) findViewById(R.id.write);
}
public void write(View view)
{
try
{
FileOutputStream fout=openFileOutput("CSE-B.txt",MODE_PRIVATE);
OutputStreamWriter writer1=new OutputStreamWriter(fout);
EditText text=(EditText) findViewById(R.id.write);
writer1.write(text.getText().toString());
writer1.close();
Toast.makeText(getBaseContext(),"File saved
sucessfully",Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
public void read(View view)
{
try {
FileInputStream filein = openFileInput("CSE-B.txt");
InputStreamReader reader=new InputStreamReader(filein);
char[] inputbuffer=new char[1000];
String txt="";
int charread;
while((charread=reader.read(inputbuffer))>0)
{
String read=String.copyValueOf(inputbuffer,0,charread);
txt+=read;
}
reader.close();
Toast.makeText(getBaseContext(),txt,Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
}