Advertisement
Guest User

Untitled

a guest
May 28th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.17 KB | None | 0 0
  1. package com.example.champ.remindme;
  2. import android.app.AlertDialog;
  3. import android.content.Context;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import android.os.Bundle;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10.  
  11. public class SignUp extends AppCompatActivity {
  12. EditText editUsername,editPassword,editEmail,editMobileNumber;
  13. Button btnSignUpButton;
  14. SQLiteDatabase db;
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_sign_up);
  19. editUsername = (EditText)findViewById(R.id.editUsername);
  20. editPassword = (EditText)findViewById(R.id.editPassword);
  21. editEmail = (EditText)findViewById(R.id.editEmail);
  22. editMobileNumber = (EditText)findViewById(R.id.editMobileNumber);
  23. btnSignUpButton = (Button)findViewById(R.id.btnSiginUpButton);
  24. db=openOrCreateDatabase("RemindMe", Context.MODE_PRIVATE, null);
  25. db.execSQL("create table IF NOT EXISTS User (Username TEXT PRIMARY KEY ,Password TEXT, Email TEXT, Contact_No INTEGER)");
  26. }
  27. public void AddUser(View v){
  28. if(editUsername.length()==0||
  29. editPassword.length()==0||
  30. editEmail.length()==0||
  31. editMobileNumber.length()==0)
  32. {
  33. showMessage("Error", "Please enter all values");
  34. return;
  35. }
  36. db.execSQL("INSERT INTO User VALUES('"+editUsername.getText().toString()+"'," +
  37. "'"+editPassword.getText().toString()+ "'," +
  38. "'"+editEmail.getText().toString()+"',"+
  39. "'"+Integer.parseInt(editMobileNumber.getText().toString())+"');");
  40.  
  41. showMessage("Success", "Record added");
  42. }
  43.  
  44. public void showMessage(String title,String message)
  45. {
  46. AlertDialog.Builder builder=new AlertDialog.Builder(this);
  47. builder.setCancelable(true);
  48. builder.setTitle(title);
  49. builder.setMessage(message);
  50. builder.show();
  51. }
  52. }
  53.  
  54. package com.example.champ.remindme;
  55. import android.Manifest;
  56. import android.app.AlertDialog.Builder;
  57. import android.content.Context;
  58. import android.content.pm.PackageManager;
  59. import android.database.sqlite.SQLiteDatabase;
  60. import android.location.Address;
  61. import android.location.Geocoder;
  62. import android.os.Bundle;
  63. import android.support.v4.app.ActivityCompat;
  64. import android.support.v4.app.FragmentActivity;
  65. import android.view.View;
  66. import android.widget.EditText;
  67. import com.google.android.gms.maps.CameraUpdateFactory;
  68. import com.google.android.gms.maps.GoogleMap;
  69. import com.google.android.gms.maps.OnMapReadyCallback;
  70. import com.google.android.gms.maps.SupportMapFragment;
  71. import com.google.android.gms.maps.model.LatLng;
  72. import com.google.android.gms.maps.model.MarkerOptions;
  73. import java.io.IOException;
  74. import java.text.DateFormat;
  75. import java.text.SimpleDateFormat;
  76. import java.util.Calendar;
  77. import java.util.List;
  78.  
  79. public class AddEventPlace extends FragmentActivity implements OnMapReadyCallback {
  80.  
  81. private GoogleMap mMap;
  82. Double Latitude=0.0;
  83. Double Longitude=0.0;
  84. EditText edtAddress;
  85. String username,item;
  86. SQLiteDatabase db;
  87. @Override
  88. protected void onCreate(Bundle savedInstanceState) {
  89. super.onCreate(savedInstanceState);
  90. setContentView(R.layout.activity_add_event_place);
  91. // Obtain the SupportMapFragment and get notified when the map is ready to be used.
  92. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
  93. .findFragmentById(R.id.map);
  94. mapFragment.getMapAsync(this);
  95. edtAddress=(EditText)findViewById(R.id.Address);
  96. db=openOrCreateDatabase("RemindMe", Context.MODE_PRIVATE, null);
  97. db.execSQL("create table IF NOT EXISTS Reminder (" +
  98. "ID INTEGER PRIMARY KEY AUTOINCREMENT," +
  99. "item TEXT not NULL," +
  100. "Time TIMESTAMP DEFAULT CURRENT_TIMESTAMP not NULL," +
  101. "Date DATETIME DEFAULT CURRENT_TIMESTAMP not NULL," +
  102. "x_coordinates REAL," +
  103. "y_coordinates REAL," +
  104. "Username TEXT," +
  105. "FOREIGN KEY(Username) REFERENCES User(Username));");
  106. }
  107.  
  108.  
  109. @Override
  110. public void onMapReady(GoogleMap googleMap) {
  111. mMap = googleMap;
  112. // Add a marker in Sydney and move the camera
  113. LatLng sydney = new LatLng(-34, 151);
  114. mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
  115. mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
  116. if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
  117. // TODO: Consider calling
  118. // ActivityCompat#requestPermissions
  119. // here to request the missing permissions, and then overriding
  120. // public void onRequestPermissionsResult(int requestCode, String[] permissions,
  121. // int[] grantResults)
  122. // to handle the case where the user grants the permission. See the documentation
  123. // for ActivityCompat#requestPermissions for more details.
  124. return;
  125. }
  126. mMap.setMyLocationEnabled(true);
  127. }
  128.  
  129.  
  130. public void onSearch(View view)
  131. {
  132. EditText location_tf = (EditText)findViewById(R.id.Address);
  133. String location = location_tf.getText().toString();
  134. List<Address> addressList = null;
  135. if(location != null || !location.equals(""))
  136. {
  137. Geocoder geocoder = new Geocoder(this);
  138. try {
  139. addressList = geocoder.getFromLocationName(location , 1);
  140.  
  141.  
  142. } catch (IOException e) {
  143. e.printStackTrace();
  144. }
  145.  
  146. Address address = addressList.get(0);
  147. LatLng latLng = new LatLng(address.getLatitude() , address.getLongitude());
  148. Latitude=address.getLatitude();
  149. Longitude=address.getLongitude();
  150. //Latitude=0.0;
  151. //Longitude=0.0;
  152. mMap.addMarker(new MarkerOptions().position(latLng).title("Marker"));
  153. mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
  154.  
  155. }
  156. }
  157.  
  158. public void Done(View view){
  159. username = getIntent().getStringExtra("Username");
  160. item = getIntent().getStringExtra("item");
  161.  
  162. DateFormat timeFormat = new SimpleDateFormat("h:mm a");
  163. String time = timeFormat.format(Calendar.getInstance().getTime());
  164. DateFormat dateFormat = new SimpleDateFormat("EEE, MMM d, yy");
  165. String date = dateFormat.format(Calendar.getInstance().getTime());
  166. if(item.trim().length()==0||
  167. date.trim().length()==0||
  168. Longitude ==0.0||
  169. Latitude==0.0||
  170. username.trim().length()==0)
  171. {
  172. showMessage("Error", "Please enter all values");
  173. return;
  174. }
  175. db.execSQL("INSERT INTO Reminder (item, Time, Date, x_coordinates, y_coordinates, Username) VALUES(" +
  176. "'"+item+"'," +
  177. "'"+time+"'," +
  178. "'"+date+"',"+
  179. "'"+Longitude+"',"+
  180. "'"+Latitude+"',"+
  181. "'"+username+"'"+
  182. ");");
  183.  
  184. showMessage("Success", "Record added");
  185. }
  186.  
  187. public void showMessage(String title,String message)
  188. {
  189. Builder builder=new Builder(this);
  190. builder.setCancelable(true);
  191. builder.setTitle(title);
  192. builder.setMessage(message);
  193. builder.show();
  194. }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement