From: Petru Date: Thu, 15 Aug 2013 09:14:28 +0000 (+0300) Subject: Changes tabbed layout for adding events into single tab with scrollview X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=7908d49ec7c6e26c0564b6ceb3b541b016f1ab78;p=unical.git Changes tabbed layout for adding events into single tab with scrollview --- diff --git a/res/layout/add_event.xml b/res/layout/add_event.xml new file mode 100644 index 0000000..8ac6f0c --- /dev/null +++ b/res/layout/add_event.xml @@ -0,0 +1,194 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/add_event_basic_tab.xml b/res/layout/add_event_basic_tab.xml deleted file mode 100644 index 0b258cb..0000000 --- a/res/layout/add_event_basic_tab.xml +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/layout/add_event_details_tab.xml b/res/layout/add_event_details_tab.xml deleted file mode 100644 index 10d8b77..0000000 --- a/res/layout/add_event_details_tab.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - diff --git a/res/layout/add_event_other_tab.xml b/res/layout/add_event_other_tab.xml deleted file mode 100644 index 435138e..0000000 --- a/res/layout/add_event_other_tab.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 512b689..5d1c1c1 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -1,5 +1,7 @@ package ro.ieval.unical; +import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Date; import java.util.GregorianCalendar; import android.app.ActionBar; @@ -16,11 +18,60 @@ import android.view.MenuItem; import android.view.View; import android.widget.*; -//TODO if i want to add a new event after i edit one the fields are being filled with the last event data - public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{ + + private class OnCheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener{ + private final LinearLayout layout; + public OnCheckedChangeListener(final LinearLayout layout){ + this.layout=layout; + } + + private class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{ + private final View repeatCount; + private final View repeatUntil; + + public OnItemSelectedListener(final View repeatCount, final View repeatUntil) { + this.repeatCount=repeatCount; + this.repeatUntil=repeatUntil; + } + + @Override + public void onItemSelected(final AdapterView whatever, final View ignored, final int pos, final long id) { + switch(pos){ + case 0: + repeatCount.setVisibility(View.GONE); + repeatUntil.setVisibility(View.GONE); + break; + case 1: + repeatCount.setVisibility(View.GONE); + repeatUntil.setVisibility(View.VISIBLE); + break; + case 2: + repeatCount.setVisibility(View.VISIBLE); + repeatUntil.setVisibility(View.GONE); + break; + default: + } + } + + @Override public void onNothingSelected(final AdapterView arg0) { /* do nothing */ } + } + + @Override + public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { + if(isChecked) { + Utils.setEnabledRecursively(layout, true); + final Spinner repeatType = (Spinner) findViewById(R.id.repeat_type); + repeatType.setOnItemSelectedListener(new OnItemSelectedListener(findViewById(R.id.repeat_count),findViewById(R.id.repeat_until))); + }else { + Utils.setEnabledRecursively(layout, false); + } + } + } + private TextView dateTimeTextView; public static final String EXTRA_EVENT = "event"; + private Event event; public static void editEvent(final Context c, final Event e) { final Intent i = new Intent(c,AddEventActivity.class); @@ -33,38 +84,38 @@ public final class AddEventActivity extends Activity implements OnDateSetListene protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(R.string.add_event_title); - final Event event = getIntent().hasExtra(EXTRA_EVENT) ? (Event) getIntent().getParcelableExtra(EXTRA_EVENT) : new Event(); + event = getIntent().hasExtra(EXTRA_EVENT) ? (Event) getIntent().getParcelableExtra(EXTRA_EVENT) : new Event(); final ActionBar actionBar = getActionBar(); - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - final ActionBar.Tab t1 = actionBar.newTab().setText(this.getString(R.string.addevtab1)); - final ActionBar.Tab t2 = actionBar.newTab().setText(this.getString(R.string.addevtab2)); - final ActionBar.Tab t3 = actionBar.newTab().setText(this.getString(R.string.addevtab3)); - - final Fragment f1 = new TrivialFragment(); - final Bundle b1=new Bundle(); - b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab); - b1.putParcelable(TrivialFragment.ARGUMENT_EVENT, event); - f1.setArguments(b1); - - final Fragment f2 = new TrivialFragment(); - final Bundle b2=new Bundle(); - b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab); - b2.putParcelable(TrivialFragment.ARGUMENT_EVENT, event); - f2.setArguments(b2); - - final Fragment f3 = new TrivialFragment(); - final Bundle b3=new Bundle(); - b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab); - b3.putParcelable(TrivialFragment.ARGUMENT_EVENT, event); - f3.setArguments(b3); - - t1.setTabListener(new AddEventTabListener(f1, event, 0)); - t2.setTabListener(new AddEventTabListener(f2, event, 1)); - t3.setTabListener(new AddEventTabListener(f3, event, 2)); - - actionBar.addTab(t1); - actionBar.addTab(t2); - actionBar.addTab(t3); + setContentView(R.layout.add_event); + + if(getIntent().hasExtra(EXTRA_EVENT)) { + final LinearLayout layout = (LinearLayout) findViewById(R.id.repeat_layout); + final Switch repeatSwitch = (Switch) findViewById(R.id.repeat_switch); + Utils.setEnabledRecursively(layout, false); + + repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout)); + + EditText title = (EditText) findViewById(R.id.eventtitle); + title.setText(event.title); + + TextView tstart = (TextView) findViewById(R.id.time_start); + TextView tend = (TextView) findViewById(R.id.time_end); + SimpleDateFormat sf=new SimpleDateFormat("HH:mm"); + Date d=new Date(event.dtstart); + tstart.setText(sf.format(d).toString()); + d.setTime(event.dtend); + tend.setText(sf.format(d).toString()); + + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); + TextView dstart = (TextView)findViewById(R.id.date_start); + TextView dend = (TextView)findViewById(R.id.date_end); + d.setTime(event.dtstart); + dstart.setText(sd.format(d).toString()); + d.setTime(event.dtend); + dend.setText(sd.format(d).toString()); + EditText description = (EditText) findViewById(R.id.description); + description.setText(event.description); + } } @Override @@ -81,7 +132,8 @@ public final class AddEventActivity extends Activity implements OnDateSetListene finish(); return true; case R.id.save: - //TODO Save event + System.out.println("MuieLaComisie\n"+event.title); + Toast toast = Toast.makeText(getApplicationContext(),"Event saved!",Toast.LENGTH_LONG); toast.show(); finish(); diff --git a/src/ro/ieval/unical/AddEventTabListener.java b/src/ro/ieval/unical/AddEventTabListener.java deleted file mode 100644 index 9238d4c..0000000 --- a/src/ro/ieval/unical/AddEventTabListener.java +++ /dev/null @@ -1,63 +0,0 @@ -package ro.ieval.unical; - -import android.app.ActionBar; -import android.app.ActionBar.Tab; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.util.Log; -import android.widget.EditText; -import android.widget.TextView; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class AddEventTabListener implements ActionBar.TabListener { - private Fragment fragment; - private Event ev; - private boolean isAdded = false; - private int tabId; - - public AddEventTabListener(final Fragment fragment,Event e,int tabId) { - this.fragment = fragment; - this.ev = e; - this.tabId=tabId; - } - - @Override - public void onTabSelected(final Tab tab, final FragmentTransaction ft) { - ft.replace(android.R.id.content, fragment, null); - } - - @Override - public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { - switch (tabId) { - case 0: - ev.title=((TextView)fragment.getView().findViewById(R.id.eventtitle)).getText().toString(); - String start=((TextView)fragment.getView().findViewById(R.id.date_start)).getText()+ " " + - ((TextView)fragment.getView().findViewById(R.id.time_start)).getText(); - String end=((TextView)fragment.getView().findViewById(R.id.date_end)).getText()+ " " + - ((TextView)fragment.getView().findViewById(R.id.time_end)).getText(); - try { - Date s=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(start); - Date e=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(end); - ev.dtstart=s.getTime(); - ev.dtend=s.getTime(); - } catch (ParseException e) { - e.printStackTrace(); - } - - break; - case 1: - ev.description=fragment.getView().findViewById(R.id.description).toString(); - break; - case 2: - break; - } - } - - @Override - public void onTabReselected(final Tab tab, final FragmentTransaction ft) { - // do nothing - } -} diff --git a/src/ro/ieval/unical/TrivialFragment.java b/src/ro/ieval/unical/TrivialFragment.java deleted file mode 100644 index 5aace20..0000000 --- a/src/ro/ieval/unical/TrivialFragment.java +++ /dev/null @@ -1,112 +0,0 @@ -package ro.ieval.unical; - -import android.app.ActionBar; -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.*; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public final class TrivialFragment extends Fragment { - private static class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{ - private final View repeatCount; - private final View repeatUntil; - - public OnItemSelectedListener(final View repeatCount, final View repeatUntil) { - this.repeatCount=repeatCount; - this.repeatUntil=repeatUntil; - } - - @Override - public void onItemSelected(final AdapterView whatever, final View ignored, final int pos, final long id) { - switch(pos){ - case 0: - repeatCount.setVisibility(View.GONE); - repeatUntil.setVisibility(View.GONE); - break; - case 1: - repeatCount.setVisibility(View.GONE); - repeatUntil.setVisibility(View.VISIBLE); - break; - case 2: - repeatCount.setVisibility(View.VISIBLE); - repeatUntil.setVisibility(View.GONE); - break; - default: - } - } - - @Override public void onNothingSelected(final AdapterView arg0) { /* do nothing */ } - } - - private static class OnCheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener{ - private final LinearLayout layout; - private final View root; - public OnCheckedChangeListener(final LinearLayout layout, final View root){ - this.layout=layout; - this.root=root; - } - - @Override - public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { - if(isChecked) { - Utils.setEnabledRecursively(layout, true); - final Spinner repeatType = (Spinner) root.findViewById(R.id.repeat_type); - repeatType.setOnItemSelectedListener(new OnItemSelectedListener(root.findViewById(R.id.repeat_count),root.findViewById(R.id.repeat_until))); - }else { - Utils.setEnabledRecursively(layout, false); - } - } - } - - public static final String ARGUMENT_EVENT = "Event"; - public static final String ARGUMENT_LAYOUT = "layout"; - private Event ev; - - @Override - public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false); - - ev=getArguments().getParcelable(ARGUMENT_EVENT); - switch (getArguments().getInt(ARGUMENT_LAYOUT)) { - case R.layout.add_event_basic_tab: - final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout); - final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch); - Utils.setEnabledRecursively(layout, false); - - repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view)); - - EditText title = (EditText) view.findViewById(R.id.eventtitle); - title.setText(ev.title); - - TextView tstart = (TextView) view.findViewById(R.id.time_start); - TextView tend = (TextView) view.findViewById(R.id.time_end); - SimpleDateFormat sf=new SimpleDateFormat("HH:mm"); - Date d=new Date(ev.dtstart); - tstart.setText(sf.format(d).toString()); - d.setTime(ev.dtend); - tend.setText(sf.format(d).toString()); - - SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - TextView dstart = (TextView)view.findViewById(R.id.date_start); - TextView dend = (TextView)view.findViewById(R.id.date_end); - d.setTime(ev.dtstart); - dstart.setText(sd.format(d).toString()); - d.setTime(ev.dtend); - dend.setText(sd.format(d).toString()); - break; - case R.layout.add_event_details_tab: - EditText description = (EditText) view.findViewById(R.id.description); - description.setText(ev.description); - break; - case R.layout.add_event_other_tab: - break; - } - return view; - } -}