Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
23 views
Android Studio
Uploaded by
Vansh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Android Studio For Later
Download
Save
Save Android Studio For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
23 views
Android Studio
Uploaded by
Vansh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Android Studio For Later
Carousel Previous
Carousel Next
Save
Save Android Studio For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 4
Search
Fullscreen
File ~C:\Usersvansh\AndroiaStudioProjectsIMicrolappisrcimainjavalcomiexample\micro\MainActivity.java ONO RANE 11 package com.example.micro; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; import android.hardware.Sensor; import android. hardware.SensorEvent; import android.hardware.SensorEventListener; import android. hardware. SensorManager; import android.os.Bundle; import android.widget.ProgressBar; import android.widget.TextView; import com.jj0e64.graphview.GraphView; import com.jj0e64.graphview. Viewport; import com.jj0e64.graphview. series .DataPoint; import com.jj0e64.graphview. series. LineGraphSeries; public class MainActivity extends AppCompatActivity { TextView txt_currentAccel, txt_prevAccel, txt_acceleration; ProgressBar prog_shakeMeter; private SensorManager mSensorManager; private Sensor mAccelerometer; private double accelerationCurrentValue; private double accelerationPreviousValue; private int pointsPlotted = 5; private int graphIntervalcounter = 0; private Viewport viewport; LineGraphSeries
series = new LineGraphSeries
(new DataPoint[] { new DataPoint(9, 0), new DataPoint(6, 0), new DataPoint(6, 0), new DataPoint(6, 0), Page tofFile ~ \Usersvansh'AndroidStudioProjectsIMicrolappisrcimainjavalcomiexample\micro\MainActivity.java 40 new DataPoint(0, 0) 41 vn; 42 43 private final SensorEventListener sensorEventListener = new SensorEventListener() { 45 @0verride 46 public void onSensorChanged(SensorEvent sensorEvent) { 47 float x = sensorEvent.values[@]; 48 float y = sensorEvent.values[1] 49 float z = sensorEvent.values[2] 50 51 accelerationCurrentValue = Math.sqrt((x ex tye ytz4*2)); 52 double changeInAccelleration = Math.abs( accelerationCurrentValue - accelerationPreviousValue di 53 accelerationPreviousValue = accelerationCurrentValue; 54 55 txt_currentAccel.setText("Current = "+ ( int) accelerationCurrentValue) ; 56 txt_prevAccel.setText("prev = "+ (int) accelerationPreviousValue) ; 57 txt_acceleration.setText ("Acceleration Change = " + (int) changeInAccelleration); 58 59 prog_shakeMeter. setProgress((int) changeInAcceLleration) ; 60 61 if (changeInAccelleration > 10) { 62 txt_acceleration. setBackgroundColor( Color.RED) ; 63 } else if (changeInAccelleration > 5) { 64 txt_acceleration. setBackgroundColor( Color.parseColor("#fcad03")) ; 65 } else if (changeInAccelleration > 2) { 66 txt_acceleration.setBackgroundColor( Color. YELLOW) ; 67 t Page 20f4File ~ Usersvansh'AndroiaStudioProjects|Microlappisrcimainjavalcomiexample\micro\MainActivity.java 68 69 pointsPlotted++; 70 71 series .appendData(new DataPoint( pointsPlotted , changeInAccelleration), true pointsPlotted) ; 72 viewport. setMinX(pointsPlotted) ; 73 viewport.setMinX(pointsPlotted - 200); 74 + 7 76 @Override 77 public void onAccuracyChanged(Sensor sensor , int accuracy) { 78 79 t 80 81 ty 82 83 84 85 @0verride 86 protected void onCreate (Bundle savedInstanceState) { 87 super.onCreate(savedInstanceState) ; 88 setContentView(R.layout.activity_main) ; 89 90 txt_acceleration = findViewById(R.id. txt_accel); 91 txt_currentAccel = findViewById(R.id. txt_currentAccel); 92 txt_prevAccel = findViewById(R.id. txt_prevAccel); 93 94 prog_shakeMeter = findViewById(R.id. prog_shakeMeter) ; 95 96 mSensorManager = (SensorManager) getSystemService (SENSOR_SERVICE) ; 97 mAccelerometer = mSensorManager. getDefaultSensor (Sensor. TYPE_ACCELEROMETER) ; 98 Page 3 ofFile - Usersvansh'AndroiaStudioProjects!Microlappisrcmainjavalcomiexample\micro\MainActivity.java 99 GraphView graph = (GraphView) findViewByld(R id. graph); 100 viewport = graph.getViewport(); 101 viewport.setScrollable(true) ; 102 viewport. setXAxisBoundsManual (true) ; 103 104 graph.addSeries(series) ; 105 106 + 107 108 protected void onResume() { 109 super .onResume(); 110 mSensorManager .registerListener( sensorEventListener, mAccelerometer, SensorManager SENSOR_DELAY_NORMAL) ; 111 t 112 113 protected void onPause() { 114 super. onPause(); 115 mSensorManager.unregisterListener( sensorEventListener) ; 116 + 117 118 } 119 Page 4014
You might also like
Programming Assignment: 1. Overview - Plotting Sensor Values in Real-Time
PDF
0% (1)
Programming Assignment: 1. Overview - Plotting Sensor Values in Real-Time
3 pages
PR 22pdf
PDF
No ratings yet
PR 22pdf
5 pages
Practical No 22 (1)
PDF
No ratings yet
Practical No 22 (1)
4 pages
EX 22
PDF
No ratings yet
EX 22
5 pages
MAD AK 22
PDF
No ratings yet
MAD AK 22
4 pages
MADPractical No.22
PDF
No ratings yet
MADPractical No.22
3 pages
PR No 22 MAD
PDF
No ratings yet
PR No 22 MAD
7 pages
Android_Programs prg 22
PDF
No ratings yet
Android_Programs prg 22
5 pages
Exp22 MAD
PDF
No ratings yet
Exp22 MAD
8 pages
MAD P22......
PDF
No ratings yet
MAD P22......
5 pages
Practicalno:-22 1. Write A Program To Changes The Background Color When Device Is Shuffled. Acitivity - Main - XML
PDF
0% (1)
Practicalno:-22 1. Write A Program To Changes The Background Color When Device Is Shuffled. Acitivity - Main - XML
4 pages
Practical 22
PDF
No ratings yet
Practical 22
6 pages
Practical 22.2
PDF
No ratings yet
Practical 22.2
4 pages
CFs Cyber Crime Presentation 2016
PDF
No ratings yet
CFs Cyber Crime Presentation 2016
5 pages
Practical 22
PDF
No ratings yet
Practical 22
3 pages
MAD C Practical No. 22.2
PDF
No ratings yet
MAD C Practical No. 22.2
3 pages
Practical No 22
PDF
No ratings yet
Practical No 22
4 pages
Code Without Timmer
PDF
No ratings yet
Code Without Timmer
4 pages
pr
PDF
No ratings yet
pr
16 pages
Import Android Codigo
PDF
No ratings yet
Import Android Codigo
4 pages
madpract22
PDF
No ratings yet
madpract22
5 pages
Soumana-Abdou-Amadou-Devoir Sensor - Avec - Thread
PDF
No ratings yet
Soumana-Abdou-Amadou-Devoir Sensor - Avec - Thread
2 pages
Practical 22
PDF
No ratings yet
Practical 22
8 pages
Practical No 22
PDF
No ratings yet
Practical No 22
7 pages
The Sensitive Side of Android
PDF
No ratings yet
The Sensitive Side of Android
53 pages
Practical 22
PDF
No ratings yet
Practical 22
5 pages
pr22(MAD)
PDF
No ratings yet
pr22(MAD)
2 pages
7 - 2 - Sensors - Part 2 (11-40)
PDF
No ratings yet
7 - 2 - Sensors - Part 2 (11-40)
5 pages
Practical No 22
PDF
No ratings yet
Practical No 22
8 pages
Practical 22.1
PDF
No ratings yet
Practical 22.1
3 pages
Sensor
PDF
No ratings yet
Sensor
5 pages
Ak MAD C Practical No.22
PDF
No ratings yet
Ak MAD C Practical No.22
2 pages
mad 21^J22
PDF
No ratings yet
mad 21^J22
7 pages
practical no 22
PDF
No ratings yet
practical no 22
2 pages
Working With Sensor
PDF
No ratings yet
Working With Sensor
46 pages
mad22(2) Mad learning material
PDF
No ratings yet
mad22(2) Mad learning material
1 page
pr22
PDF
No ratings yet
pr22
2 pages
Log
PDF
No ratings yet
Log
27 pages
Mad 22
PDF
No ratings yet
Mad 22
2 pages
MAD-PR-22
PDF
No ratings yet
MAD-PR-22
2 pages
Log
PDF
No ratings yet
Log
566 pages
mad21to30
PDF
No ratings yet
mad21to30
14 pages
Cppnetworkingtest
PDF
No ratings yet
Cppnetworkingtest
4 pages
sensor
PDF
No ratings yet
sensor
4 pages
Touchqode Sensors
PDF
No ratings yet
Touchqode Sensors
30 pages
New Text Documenterwe
PDF
No ratings yet
New Text Documenterwe
7 pages
School Physics Experiments With Arduino DUE
PDF
No ratings yet
School Physics Experiments With Arduino DUE
29 pages
Radar 3
PDF
No ratings yet
Radar 3
7 pages
Processing Code Radar
PDF
No ratings yet
Processing Code Radar
3 pages
L10 Self Assessment A123456
PDF
No ratings yet
L10 Self Assessment A123456
3 pages
MAD Pract 22.1
PDF
No ratings yet
MAD Pract 22.1
3 pages
Radar Processing Code
PDF
No ratings yet
Radar Processing Code
3 pages
Bahasa Pemrograman
PDF
No ratings yet
Bahasa Pemrograman
11 pages
Practice Questions For CT-II - MAD
PDF
No ratings yet
Practice Questions For CT-II - MAD
1 page
Unit 4
PDF
No ratings yet
Unit 4
21 pages
0
PDF
No ratings yet
0
6 pages
Ass 4
PDF
No ratings yet
Ass 4
1 page
Sample Synopsis - Decentralized Token Swapping
PDF
No ratings yet
Sample Synopsis - Decentralized Token Swapping
9 pages