Android Open Source - Gcal_Importer Model4 Event List






From Project

Back to project page Gcal_Importer.

License

The source code is released under:

Apache License

If you think the Android project Gcal_Importer 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 net.crappo.android.androics;
//from   w w  w .  j  a v a2 s .c o m
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.Map.Entry;

import net.fortuna.ical4j.data.CalendarBuilder;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Component;
import net.fortuna.ical4j.model.ComponentList;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.model.PropertyList;
import net.fortuna.ical4j.model.component.VEvent;

public class Model4EventList {
    public Calendar calendar;
    public Locale locale;
    public TimeZone timezone;

    private ComponentList componentBuffer;

    public Model4EventList() { // ???????
        calendar = null;
        locale = new Locale("ja", "JP");
        timezone = TimeZone.getTimeZone("Asia/Tokyo");
    }

    public void readIcs(String pathStr) { // ICS??????????????????????????(??ical4j?????????)
        FileInputStream fin;
        try {
            fin = new FileInputStream(pathStr);
            CalendarBuilder builder = new CalendarBuilder();
            calendar = builder.build(fin);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ParserException e) {
            e.printStackTrace();
        }
    }

    public PropertyList getPropertyList() { return calendar.getProperties(); }

    public ComponentList getComponentList() { return calendar.getComponents(); }

    /*
     * ?????????????????????????????????
     * 1.VEvent???(key=Uid / value=DtStart) ?????????Map???????????Map.entry???ArrayList?????????value??????????????
     * 2.entry???ArrayList????key/value???????????????????LinkedMap????????
     * 3.????calendar???VEVENT????LinkedMap???key(uid)???EVENT????????????????????????????calendar?????????????????
     */
    public void mapSort() {
        Map<String, String> mapUidDtstart = new HashMap<String, String>();
        if(calendar.getComponents("VEVENT").size() == 0)  return; // VEVENT??????????????????????
        
        ComponentList components = calendar.getComponents();
        Component component;
        VEvent event;
        componentBuffer = new ComponentList();
        for(Object obj : components) {
            if( obj instanceof VEvent) { // VEVENT?  uid ??? dtstart ???????????????Map???put????????????
                event = (VEvent)obj;
                mapUidDtstart.put(event.getUid().getValue(), event.getProperties().getProperty(Property.DTSTART).getValue());
            } else { // VEVENT?????Component??????????????????????????
                component = (Component)obj;
                componentBuffer.add(component);
            }
        }
        // Map???put???????????????entrySet?????????ArrayList??????????Collection???????Value????????sort(???????????????)????
        List<Map.Entry<String,String>> entries = new ArrayList<Map.Entry<String,String>>(mapUidDtstart.entrySet());
        Collections.sort(entries, new Comparator<Map.Entry<String,String>>() {
            @Override
            public int compare(Entry<String,String> entry1, Entry<String,String> entry2) {
                return ((String)entry2.getValue()).compareTo((String)entry1.getValue());
            }
        });

        Calendar sortedCalendar = new Calendar(); // ???????????????????
        for(Object propObj : calendar.getProperties()) { // ?????????VCALENDAR???Property?????????????
            Property calHeader = (Property)propObj;
            sortedCalendar.getProperties().add(calHeader);
        }
        for(Object compObj : componentBuffer) { // ??????????????????????????VEVENT???????????????????
            component = (Component)compObj;
            sortedCalendar.getComponents().add(component);
        }
        for(Entry<String, String> entry: entries ) { // ??????????????????sort???????uid????????EVENT??????????????
            Component compoTmp = null;
            for(Object eventObj : calendar.getComponents("VEVENT")) {
                event = (VEvent)eventObj;
                if(entry.getKey().equals(event.getUid().getValue())) { // Entry???uid???VEvent???uid??????????????VEvent???????????
                    compoTmp = (Component)eventObj;
                    try { sortedCalendar.getComponents().add(compoTmp.copy()); }
                    catch (Exception e) { e.printStackTrace(); }
                }
            }
        }
        calendar = sortedCalendar; // VEvent?????????????????????????????calendar???????????????????
    }

}




Java Source Code List

net.crappo.android.androics.AccountAuthService.java
net.crappo.android.androics.AndroIcsAuthenticator.java
net.crappo.android.androics.BrowserForDownLoadActivity.java
net.crappo.android.androics.Model4EventList.java
net.crappo.android.androics.Model4Top.java
net.crappo.android.androics.ShowEventListActivity.java
net.crappo.android.androics.ShowEventListAsync.java
net.crappo.android.androics.SimpleFileDialog.java
net.crappo.android.androics.TopActivity.java
net.crappo.android.androics.TopIcsListAsync.java
net.crappo.android.androics.ZipInOutMethods.java