Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 KB | None | 0 0
  1. package suny.com.softwareeng;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.os.Handler;
  8. import android.os.Message;
  9. import android.text.Html;
  10. import android.util.Log;
  11. import android.view.Gravity;
  12. import android.view.LayoutInflater;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.view.Window;
  16. import android.view.WindowManager;
  17. import android.widget.Button;
  18. import android.widget.CheckBox;
  19. import android.widget.EditText;
  20. import android.widget.GridLayout;
  21. import android.widget.ImageButton;
  22. import android.widget.LinearLayout;
  23. import android.widget.PopupWindow;
  24.  
  25. import com.android.volley.Request;
  26. import com.android.volley.RequestQueue;
  27. import com.android.volley.Response;
  28. import com.android.volley.VolleyError;
  29. import com.android.volley.toolbox.StringRequest;
  30. import com.android.volley.toolbox.Volley;
  31. import android.view.View;
  32. import android.view.ViewGroup.LayoutParams;
  33. import android.widget.TextView;
  34.  
  35. import java.util.ArrayList;
  36. import java.util.Date;
  37. import java.util.HashMap;
  38. import java.util.Map;
  39.  
  40. /**
  41. * Created by Lucas on 3/25/2015.
  42. */
  43. public class AddEvent extends Activity{
  44.  
  45. ArrayList<Event> event = new ArrayList<>();
  46. EditText title;
  47. EditText location;
  48. EditText time;
  49. EditText date;
  50. ImageButton ok,no;
  51. Tags tags;
  52. EditText moreInfo;
  53. int flag;
  54. Event ev;
  55. String t;
  56. Button browser;
  57. CheckBox musCheck,partCheck,movCheck,eduCheck,politCheck;
  58. private class GeocoderHandler extends Handler {
  59. @Override
  60. public void handleMessage(Message message) {
  61. String locationAddress;
  62. switch (message.what) {
  63. case 1:
  64. Bundle bundle = message.getData();
  65. locationAddress = bundle.getString("address");
  66. break;
  67. default:
  68. locationAddress = null;
  69. }
  70. Log.d("Long", locationAddress);
  71. }
  72. }
  73.  
  74.  
  75. public void callPopUp(View view){
  76. LayoutInflater layoutInflater
  77. = (LayoutInflater) getBaseContext()
  78. .getSystemService(LAYOUT_INFLATER_SERVICE);
  79. View popupView = layoutInflater.inflate(R.layout.pop_up, null);
  80. final PopupWindow popupWindow = new PopupWindow(
  81. popupView,
  82. LayoutParams.WRAP_CONTENT,
  83. LayoutParams.WRAP_CONTENT);
  84. popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
  85. ImageButton btnDismiss = (ImageButton) popupView.findViewById(R.id.dismiss);
  86. btnDismiss.setOnClickListener(new Button.OnClickListener() {
  87.  
  88. @Override
  89. public void onClick(View v) {
  90. // TODO Auto-generated method stub
  91. popupWindow.dismiss();
  92. }
  93. });
  94.  
  95. }
  96. public void add(View view){
  97. flag =1;
  98.  
  99. EditText title = (EditText) findViewById(R.id.Title);
  100. String t = title.getText().toString();
  101. EditText loc = (EditText) findViewById(R.id.Location);
  102. String l = loc.getText().toString();
  103. EditText date = (EditText) findViewById(R.id.Date);
  104. String d = date.getText().toString();
  105. EditText time = (EditText) findViewById(R.id.Time);
  106. String ti = time.getText().toString();
  107.  
  108. if (t.trim().length() != 0 && l.trim().length() !=0 && d.trim().length() !=0 && ti.trim().length() != 0) {
  109. flag=0;
  110. }else
  111. {
  112. flag = 1;
  113. Log.d("ELSE", "ELSE");
  114. callPopUp(view);
  115. }
  116.  
  117. EditText description = (EditText) findViewById(R.id.MoreInfo);
  118. String des = description.getText().toString();
  119. final String nameM = t;
  120. final String timeM = ti;
  121. final String dateM = d;
  122. final String whereM = l;
  123. final String descriptionM = des;
  124. final String authorM = Login.name;
  125. final String authorT = Login.getName();
  126. GeocodingLocation locationAddress = new GeocodingLocation();
  127. locationAddress.getAddressFromLocation(whereM,
  128. getApplicationContext(), new GeocoderHandler());
  129. Log.d("Name",authorM);
  130. final String pictureM = "@getPicture";
  131. if(flag ==0) {
  132. String url = "http://moxie.cs.oswego.edu:19991/whatzon/add";
  133. final RequestQueue queue1 = Volley.newRequestQueue(this);
  134. StringRequest sr = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
  135. @Override
  136. public void onResponse(String response) {
  137.  
  138. }
  139. }, new Response.ErrorListener() {
  140. @Override
  141. public void onErrorResponse(VolleyError error) {
  142.  
  143. }
  144. }) {
  145. @Override
  146. protected Map<String, String> getParams() {
  147. Map<String, String> params = new HashMap<String, String>();
  148. params.put("name", nameM);
  149. params.put("time", timeM);
  150. params.put("date", dateM);
  151. params.put("where", whereM);
  152. params.put("description", descriptionM);
  153. params.put("author", authorM);
  154. params.put("picture", pictureM);
  155.  
  156.  
  157. return params;
  158. }
  159. };
  160.  
  161.  
  162. queue1.add(sr);
  163. String test = Login.name;
  164. // Log.d("NAME", test);
  165.  
  166. Intent intent = new Intent(this, MenuPage.class);
  167. startActivity(intent);
  168. }
  169. }
  170. @Override
  171. protected void onCreate(Bundle savedInstanceState) {
  172. this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  173.  
  174. tags = new Tags(false,false,false,false,false);
  175. this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  176. super.onCreate(savedInstanceState);
  177. setContentView(R.layout.addevent);
  178. ok = (ImageButton) findViewById(R.id.btnYes);
  179. no = (ImageButton) findViewById(R.id.btnNo);
  180. final Context context = this;
  181. browser = (Button) findViewById(R.id.browseBtn);
  182. musCheck =(CheckBox) findViewById(R.id.musicBox);
  183. partCheck =(CheckBox) findViewById(R.id.partyBox);
  184. movCheck= (CheckBox) findViewById(R.id.moviesBox);
  185. eduCheck =(CheckBox) findViewById(R.id.educationBox);
  186. politCheck =(CheckBox) findViewById(R.id.politcsBox);
  187. title = (EditText) findViewById(R.id.Title);
  188. date = (EditText) findViewById(R.id.Date);
  189. time = (EditText) findViewById(R.id.Time);
  190. moreInfo = (EditText) findViewById(R.id.MoreInfo);
  191. location = (EditText) findViewById(R.id.Location);
  192.  
  193. String test = Login.name;
  194. // Log.d("NAME", test);
  195. /* ok.setOnClickListener(new View.OnClickListener() {
  196. public void onClick(View v) {
  197. if (title.getText().toString().trim().length() != 0)
  198. titleStr = title.getText().toString();
  199. if (location.getText().toString().trim().length() != 0)
  200. locationStr = location.getText().toString();
  201. if (moreInfo.getText().toString().trim().length() != 0)
  202. moreInfoStr = moreInfo.getText().toString();
  203. if (date.getText().toString().trim().length() != 0)
  204. dateStr = date.getText().toString();
  205.  
  206. if (time.getText().toString().trim().length() != 0)
  207. timeStr = time.getText().toString();
  208. // Log.d("TEST",dateStr);
  209. tags.setMusicTg(musCheck.isChecked());
  210. tags.setPartyTg(partCheck.isChecked());
  211. tags.setMovieTg(movCheck.isChecked());
  212. tags.setEducationTg(eduCheck.isChecked());
  213. tags.setPolitcsTg(politCheck.isChecked());
  214.  
  215.  
  216. ev = new Event(titleStr, locationStr, moreInfoStr, dateStr, timeStr, tags);
  217. event.add(ev);
  218. Intent intent = new Intent(context, MenuPage.class);
  219. startActivity(intent);
  220. // Log.d("Events",event.get(0).getTitle());
  221. Log.d("TAGS", tags.toString());
  222. Log.isLoggable("Events", event.size());
  223. for (int i = 0; i < event.size(); i++) {
  224. Log.d("Events", event.get(i).toString());
  225. }
  226. }
  227. });*/
  228. browser.setOnClickListener(new View.OnClickListener() {
  229. public void onClick(View v) {
  230.  
  231. Intent intent = new Intent();
  232. intent.setType("image/*");
  233. intent.setAction(Intent.ACTION_GET_CONTENT);
  234. startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
  235.  
  236. }
  237. });
  238. no.setOnClickListener(new View.OnClickListener() {
  239. public void onClick(View v) {
  240. if(title.getText().toString().trim().length() != 0)
  241. title.setText("");
  242. if(location.getText().toString().trim().length() != 0)
  243. location.setText("");
  244. if(moreInfo.getText().toString().trim().length() != 0)
  245. moreInfo.setText("");
  246. if(date.getText().toString().trim().length() != 0){
  247. date.setText("");
  248. if(time.getText().toString().trim().length() != 0)
  249. time.setText("");
  250. }
  251. }
  252. });
  253. ImageButton menu = (ImageButton) findViewById(R.id.menuBtn);
  254. menu.setOnClickListener(new View.OnClickListener() {
  255. public void onClick(View v) {
  256. Intent intent = new Intent(context, Events.class);
  257. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  258. startActivity(intent);
  259. }
  260. });
  261. }
  262. @Override
  263. public void onActivityResult(int requestCode,int resultCode,Intent data){
  264. if(resultCode == RESULT_OK) {
  265. if (requestCode == 1)
  266. Log.d("Image",data.getData().toString());
  267.  
  268. }
  269.  
  270. }
  271.  
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement