Android Open Source - TravelReminder Reminder Edit Fragment






From Project

Back to project page TravelReminder.

License

The source code is released under:

GNU General Public License

If you think the Android project TravelReminder 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.ganterd.travelreminder.fragments;
/*from   w ww.  j  a va2  s  .com*/
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.ToggleButton;

import com.ganterd.travelreminder.R;
import com.ganterd.travelreminder.Reminder;
import com.ganterd.travelreminder.RemindersHelper;

public class ReminderEditFragment extends Fragment {
  public static final String ARG_EXISTING_REMINDER = "ARG_EXISTING_REMINDER";
  
  private OnClickListener recurringDayOnClickListener = new OnClickListener() {
    @Override
    public void onClick(View b) {
      onRecurringDayToggle(b);
    }
  };
  
  Reminder existingReminder = null;
  
  public static ReminderEditFragment newInstance(Reminder existingReminder){
    ReminderEditFragment f = new ReminderEditFragment();
    
    if(existingReminder != null){
      Bundle args = new Bundle();
      args.putSerializable(ReminderEditFragment.ARG_EXISTING_REMINDER, existingReminder);
      f.setArguments(args);
    }
    
    return f;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    RelativeLayout rl = (RelativeLayout)inflater.inflate(R.layout.reminder_details, container, false);
    
    Bundle args = getArguments();
    if(args != null){
      this.existingReminder = (Reminder)args.getSerializable(ARG_EXISTING_REMINDER);
      ((EditText) rl.findViewById(R.id.textReminderName)).setText(this.existingReminder.getReminderName());
    }
    
    return rl;
  }
  
  @Override
  public void onResume(){
    super.onResume();
    
    setupRecurringDayButtons();
  }
  
  private void setupRecurringDayButtons(){
    ToggleButton b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleMonday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_MONDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_MONDAY);
    
    b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleTuesday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_TUESDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_TUESDAY);
    
    b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleWednesday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_WEDNESDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_WEDNESDAY);
    
    b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleThursday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_THURSDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_THURSDAY);
    
    b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleFriday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_FRIDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_FRIDAY);
    
    b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleSaturday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_SATURDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_SATURDAY);
    
    b = (ToggleButton)getView().findViewById(R.id.editTravelReminderToggleSunday);
    b.setChecked(this.existingReminder.getRecurring(Reminder.RECCURING_SUNDAY));
    b.setOnClickListener(this.recurringDayOnClickListener);
    b.setTag(Reminder.RECCURING_SUNDAY);
  }
  
  public void onRecurringDayToggle(View view){
    ToggleButton b = (ToggleButton)view;
    
    int day = (Integer)b.getTag();
    
    this.existingReminder.setRecurring(day, b.isChecked());
    RemindersHelper.saveReminder(this.existingReminder);
  }
}




Java Source Code List

android.UnusedStub.java
com.ganterd.travelreminder.CreateTravelReminderActivity.java
com.ganterd.travelreminder.Directions.java
com.ganterd.travelreminder.MainActivity.java
com.ganterd.travelreminder.Reminder.java
com.ganterd.travelreminder.RemindersHelper.java
com.ganterd.travelreminder.adapters.MainActivityReminderListAdapter.java
com.ganterd.travelreminder.fragments.ReminderEditArrivalTimePickerFragment.java
com.ganterd.travelreminder.fragments.ReminderEditFragment.java
com.ganterd.travelreminder.fragments.ReminderEditLocationInfo.java
com.ganterd.travelreminder.fragments.ReminderEditTravelInfo.java
com.ganterd.travelreminder.interfaces.IReminder.java