Android Open Source - eVent Edit Event






From Project

Back to project page eVent.

License

The source code is released under:

Apache License

If you think the Android project eVent listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.maps;
//from  w w  w .j ava 2 s  . c  o m
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import com.google.gson.Gson;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.inputmethod.InputMethodManager;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;


public class EditEvent extends ActionBarActivity {

  private static final String LOG_TAG = "Edit Event Activity";

  eventMarker temp;
  ArrayOfEvents events;
  Spinner mspin;
  int index;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Removes TitleBar from Activity
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_edit_event);

    if (savedInstanceState == null) {
      getSupportFragmentManager().beginTransaction()
          .add(R.id.container, new PlaceholderFragment()).commit();
    }
    
    temp = eventMarker.getInstance(this);
  }
  
  @Override
  protected void onResume(){
    super.onResume();
    events = ArrayOfEvents.getInstance(this);
    EditText tv = (EditText) findViewById(R.id.editText1);
    tv.setText(temp.Title);
    tv.clearFocus();
    EditText etd = (EditText) findViewById(R.id.editText2);
    etd.setText(temp.Description);
    DatePicker dp = (DatePicker) findViewById(R.id.datePicker1);
    dp.setMinDate(System.currentTimeMillis() - 1000);
    for(int i = 0; i < events.eventsArray.size(); i++){
      if(events.eventsArray.get(i).Loc.equals(temp.Loc) && events.eventsArray.get(i).Title.equals(temp.Title)){
        index = i;
        break;
      }
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.event_details, menu);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
      return true;
    }
    return super.onOptionsItemSelected(item);
  }

  /**
   * A placeholder fragment containing a simple view.
   */
  public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_event_details,
          container, false);
      return rootView;
    }
  }
  
  public void saveEvent(View V){
    EditText et1 = (EditText) findViewById(R.id.editText1);
    temp.Title = et1.getText().toString();
    EditText et2 = (EditText) findViewById(R.id.editText2);
    temp.Description = et2.getText().toString();
    DatePicker dp = (DatePicker) findViewById(R.id.datePicker1);
    TimePicker tp = (TimePicker) findViewById(R.id.timePicker1);
    temp.deadline.set(dp.getYear(), dp.getMonth(), dp.getDayOfMonth(), tp.getCurrentHour(), tp.getCurrentMinute());
    events.eventsArray.set(index, temp);
    
    
    //hides keyboard
    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    
    Gson gson = new Gson();
    
    //overwrites the sharedpreferences with event changes
    SharedPreferences settings = getSharedPreferences(MainActivity.MYPREFS, 0);
    Editor editor = settings.edit();
    editor.putString(MainActivity.PREF_STRING_1, gson.toJson(events, ArrayOfEvents.class));
    editor.commit();

    onBackPressed();
  }
  
  public void cancel(View V){
    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
      imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    onBackPressed();
  }

}




Java Source Code List

com.example.maps.ArrayOfEvents.java
com.example.maps.DeadlineTrackerServiceTask.java
com.example.maps.DeadlineTrackerService.java
com.example.maps.EditEvent.java
com.example.maps.EventDetails.java
com.example.maps.ListEventsActivity.java
com.example.maps.MainActivity.java
com.example.maps.MakeEventActivity.java
com.example.maps.ViewTaskActivity.java
com.example.maps.eventMarker.java