Android Open Source - syncarnet Task Add Fragment






From Project

Back to project page syncarnet.

License

The source code is released under:

GNU General Public License

If you think the Android project syncarnet 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

/*
 * Copyright (C) 2013-14 Nicolas Miller, Florian Paindorge
 *//from  ww w  .  ja  v  a2  s.  co  m
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package fr.syncarnet;

import fr.syncarnet.tasks.*;
import fr.syncarnet.helpers.*;

import android.app.Fragment;
import android.app.ActionBar;
import android.app.DatePickerDialog;

import android.os.Bundle;

import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.view.View.OnClickListener;

import android.widget.Toast;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.EditText;
import android.widget.DatePicker;

import java.util.Calendar;

public class TaskAddFragment extends Fragment implements DatePickerDialog.OnDateSetListener {
  private Calendar cal = null;

  private Spinner priority = null;
  private EditText project = null;
  private EditText description = null;

  public interface Callbacks {
    public void addTask(Task t);
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if(savedInstanceState != null) {
      cal = (Calendar)savedInstanceState.getSerializable("cal");
    }
    ActionBar ab = getActivity().getActionBar();
    ab.setDisplayShowTitleEnabled(true);
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
  }

  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putSerializable("cal", cal);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup v, Bundle b) {
    View view = inflater.inflate(R.layout.taskadd_fragment, v, false);

    Button due = (Button)view.findViewById(R.id.due);
    due.setOnClickListener(new OnClickDueListener());

    Button add = (Button)view.findViewById(R.id.add);
    add.setOnClickListener(new OnClickAddListener()); 

    description = (EditText)view.findViewById(R.id.description);
    project = (EditText)view.findViewById(R.id.project);

    priority = (Spinner)view.findViewById(R.id.priority);
    priority.setSelection(1);

    return view;
  }

  private class OnClickAddListener implements OnClickListener {
    @Override
    public void onClick(View view) {
      String d = description.getText().toString().trim();
      if(d.equals("")) {
        Toast toast = Toast.makeText(getActivity(),
            getActivity().getString(R.string.nodescription),
            Toast.LENGTH_LONG);
        toast.show();
      } else {
        String p = project.getText().toString().trim();
        int pos = priority.getSelectedItemPosition();
        ((Callbacks)getActivity()).addTask(new Task(d, cal, p, PrioritySpinnerHelper.getPriority(pos)));
      }
    }
  }

  private class OnClickDueListener implements OnClickListener {
    @Override
    public void onClick(View v) {
      Calendar c = Calendar.getInstance();
      DatePickerDialog dpd = new DatePickerDialog(getActivity(), TaskAddFragment.this,
                c.get(Calendar.YEAR), 
                c.get(Calendar.MONTH), 
                c.get(Calendar.DAY_OF_MONTH));
      dpd.getDatePicker().setCalendarViewShown(true);
      dpd.getDatePicker().setSpinnersShown(false);
      dpd.show();
    }
  }

  public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    cal = Calendar.getInstance();
    cal.set(year, monthOfYear, dayOfMonth);
  }
}




Java Source Code List

fr.syncarnet.ProjectsAdapter.java
fr.syncarnet.SynCarnet.java
fr.syncarnet.TaskAddFragment.java
fr.syncarnet.TaskEditFragment.java
fr.syncarnet.TaskListAdapter.java
fr.syncarnet.TaskListFragment.java
fr.syncarnet.helpers.PrioritySpinnerHelper.java
fr.syncarnet.sync.DeviceListActivity.java
fr.syncarnet.sync.PeerListAdapter.java
fr.syncarnet.sync.PeerListDialog.java
fr.syncarnet.sync.PeerList.java
fr.syncarnet.sync.PeerSelection.java
fr.syncarnet.sync.SynCarnetBroadcastReceiver.java
fr.syncarnet.sync.SyncBTService.java
fr.syncarnet.sync.SyncService.java
fr.syncarnet.sync.SyncedDevice.java
fr.syncarnet.sync.SyncedDevicesFragment.java
fr.syncarnet.sync.TaskListTransferService.java
fr.syncarnet.tasks.DeletedTasks.java
fr.syncarnet.tasks.Priority.java
fr.syncarnet.tasks.TaskList.java
fr.syncarnet.tasks.Task.java