Android Open Source - DisposableIncome-OldJava Calendar Access






From Project

Back to project page DisposableIncome-OldJava.

License

The source code is released under:

MIT License

If you think the Android project DisposableIncome-OldJava 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 uk.co.wilka.disposableincome;
/*from ww  w . jav a  2s .c  om*/
import android.app.Activity;
import android.app.LoaderManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import java.util.Calendar;
import java.util.List;

public class CalendarAccess implements
        LoaderManager.LoaderCallbacks<Cursor>,
        SimpleCursorAdapter.ViewBinder {

    private static final String[] PROJECTION=
            new String[] {
                    CalendarContract.Events._ID,
                    CalendarContract.Events.TITLE,
                    CalendarContract.Events.DTSTART,
                    CalendarContract.Events.DTEND };
    private static final String[] ROW_COLUMNS=
            new String[] {
                    CalendarContract.Events.DTSTART,
                    CalendarContract.Events.TITLE
                    };
    private static final int[] ROW_IDS= new int[] { R.id.date, R.id.title,  };
    private final Activity activity;
    private SimpleCursorAdapter adapter=null;

    public CalendarAccess(Activity activity, ListView list) {

        this.activity = activity;
        adapter = new SimpleCursorAdapter(activity, R.layout.event_row, null, ROW_COLUMNS, ROW_IDS, 0);
        adapter.setViewBinder(this);
        list.setAdapter(adapter);

        activity.getLoaderManager().initLoader(0, null, this);
    }

    public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
        long millisecondsInADay = 86400000;
        long now = Calendar.getInstance().getTime().getTime() - millisecondsInADay;

        String selection = CalendarContract.Events.DTSTART + ">'" + now +"'";
        return(new CursorLoader(activity, CalendarContract.Events.CONTENT_URI, PROJECTION, selection, null, CalendarContract.Events.DTSTART));
    }

    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        adapter.swapCursor(cursor);
    }

    public void onLoaderReset(Loader<Cursor> loader) {
        adapter.swapCursor(null);
    }

    public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
        long time=0;
        String formattedTime = null;

        switch (columnIndex) {
            case 2:
            case 3:
                time=cursor.getLong(columnIndex);
                formattedTime = DateUtils.formatDateTime(activity, time, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_YEAR);
                ((TextView)view).setText(formattedTime);
                break;

            default:
                return(false);
        }

        return(true);
    }
}




Java Source Code List

uk.co.wilka.disposableincome.CalendarAccess.java
uk.co.wilka.disposableincome.CalendarProvider.java
uk.co.wilka.disposableincome.CashWithdraw.java
uk.co.wilka.disposableincome.CashWithdrawalDetailsActivity.java
uk.co.wilka.disposableincome.Cash.java
uk.co.wilka.disposableincome.DatabaseHelper.java
uk.co.wilka.disposableincome.IAccessData.java
uk.co.wilka.disposableincome.IProvideCalendar.java
uk.co.wilka.disposableincome.MainActivity.java
uk.co.wilka.disposableincome.PlusOneMonthCalendarProvider.java
uk.co.wilka.disposableincome.WithdrawDateComparer.java
uk.co.wilka.disposableincome.WithdrawType.java
uk.co.wilka.disposableincome.WithdrawalForMonthCalculator.java
uk.co.wilka.disposableincome.test.CashTest.java
uk.co.wilka.disposableincome.test.CashWithdrawTest.java
uk.co.wilka.disposableincome.test.FakeCalendarProvider.java
uk.co.wilka.disposableincome.test.PlusOneMonthCalendarProviderTests.java
uk.co.wilka.disposableincome.test.WithdrawDateComparerTests.java
uk.co.wilka.disposableincome.test.WithdrawalForMonthCalculatorTests.java