当前位置: 首页>>代码示例>>Java>>正文


Java Calendars类代码示例

本文整理汇总了Java中android.provider.CalendarContract.Calendars的典型用法代码示例。如果您正苦于以下问题:Java Calendars类的具体用法?Java Calendars怎么用?Java Calendars使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Calendars类属于android.provider.CalendarContract包,在下文中一共展示了Calendars类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toInsertContentValues

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
/**
 * Commodity method for the building of the ContentValues object starting from the EventInfo representation.
 * The method will return a ContentValues that will be utilised for the insert of an event
 *
 * @param context application's context
 * @return ContentValues representation of the CalendarInfo object
 */
private ContentValues toInsertContentValues(Context context) {
    final ContentValues contentValues = toContentValues();
    if (contentValues.containsKey(Events._ID) || contentValues.containsKey(Events.CALENDAR_DISPLAY_NAME)) {
        Log.w(EventInfo.class.getSimpleName(), "TThe EventInfo to insert shouldn't have id and calendarDisplayName defined, they are automatically removed");
        contentValues.remove(Events._ID);
        id = null;
        contentValues.remove(Events.CALENDAR_DISPLAY_NAME);
        calendarDisplayName = null;
    }
    if (isRecurrentEvent()) {
        contentValues.remove(Events.DTEND);
        if (endDate != null) {
            contentValues.put(Events.DURATION, "P" + ((endDate.getTime() - startDate.getTime()) / 1000) + "S");
        }
    }
    if (!contentValues.containsKey(Events.EVENT_TIMEZONE)) {
        String timezone = CalendarInfo.getCompleteInformation(context, calendarId).getAsString(Calendars.CALENDAR_TIME_ZONE);
        if (timezone == null) {
            timezone = TimeZone.getDefault().getDisplayName();
        }
        contentValues.put(Events.EVENT_TIMEZONE, timezone);
    }
    return contentValues;
}
 
开发者ID:macisamuele,项目名称:CalendarProvider-Lib,代码行数:32,代码来源:EventInfo.java

示例2: addCalendars

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
public static void addCalendars(Context context, List<CalendarInfo> outCalendars) {
    final String primary = "\"primary\"";
    final String[] projection = { Calendars._ID, Calendars.CALENDAR_DISPLAY_NAME,
            "(" + Calendars.ACCOUNT_NAME + "=" + Calendars.OWNER_ACCOUNT + ") AS " + primary };
    final String selection = primary + " = 1";
    Cursor cursor = null;
    try {
        cursor = context.getContentResolver().query(Calendars.CONTENT_URI, projection,
                selection, null, null);
        if (cursor == null) {
            return;
        }
        while (cursor.moveToNext()) {
            final CalendarInfo ci = new CalendarInfo();
            ci.name = cursor.getString(1);
            ci.userId = context.getUserId();
            outCalendars.add(ci);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:25,代码来源:ZenModeEventRuleSettings.java

示例3: insertEvent

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
public static void insertEvent(Context context, long startTime,
                               long endTime, String title)
{
    ContentResolver resolver = context.getContentResolver();

    if (queryHandler == null)
        queryHandler = new QueryHandler(resolver);

    ContentValues values = new ContentValues();
    values.put(Events.DTSTART, startTime);
    values.put(Events.DTEND, endTime);
    values.put(Events.TITLE, title);

    if (BuildConfig.DEBUG)
        Log.d(TAG, "Calendar query start");

    queryHandler.startQuery(CALENDAR, values, Calendars.CONTENT_URI,
                            CALENDAR_PROJECTION, null, null, null);
}
 
开发者ID:billthefarmer,项目名称:diary,代码行数:20,代码来源:QueryHandler.java

示例4: getCalendarId

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
private long getCalendarId() {
  String[] projection = new String[]{Calendars._ID};
  //String selection = Calendars.ACCOUNT_NAME + "=Biermacht AND" + Calendars.ACCOUNT_TYPE + "=" + CalendarContract.ACCOUNT_TYPE_LOCAL;

  String selection = "(" + Calendars.ACCOUNT_NAME + " = ?) AND (" + Calendars.ACCOUNT_TYPE + " = ?)";
  String[] selectionArgs = new String[]{"Biermacht", CalendarContract.ACCOUNT_TYPE_LOCAL};

  // use the same values as above:
  //String[] selArgs = new String[]{"Biermacht", CalendarContract.ACCOUNT_TYPE_LOCAL};
  Cursor cursor = c.getContentResolver().query(Calendars.CONTENT_URI,
                                               projection,
                                               selection,
                                               selectionArgs,
                                               null);
  if (cursor.moveToFirst()) {
    return cursor.getLong(0);
  }
  return - 1;
}
 
开发者ID:caseydavenport,项目名称:biermacht,代码行数:20,代码来源:BrewTimerStepFragment.java

示例5: createCalendar

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
private void createCalendar() {
  ContentValues values = new ContentValues();
  values.put(Calendars.ACCOUNT_NAME, "Biermacht");
  values.put(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
  values.put(Calendars.NAME, "Biermacht Calendar");
  values.put(Calendars.CALENDAR_DISPLAY_NAME, "Biermacht Calendar");
  values.put(Calendars.CALENDAR_COLOR, 0xE6A627);
  values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_OWNER);
  values.put(Calendars.OWNER_ACCOUNT, "[email protected]");
  values.put(Calendars.CALENDAR_TIME_ZONE, "Europe/Berlin");

  Uri.Builder builder = CalendarContract.Calendars.CONTENT_URI.buildUpon();
  builder.appendQueryParameter(Calendars.ACCOUNT_NAME, "com.biermacht.brews");
  builder.appendQueryParameter(Calendars.ACCOUNT_TYPE, CalendarContract.ACCOUNT_TYPE_LOCAL);
  builder.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true");
  Uri uri = c.getContentResolver().insert(builder.build(), values);
}
 
开发者ID:caseydavenport,项目名称:biermacht,代码行数:18,代码来源:BrewTimerStepFragment.java

示例6: toContentValues

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
/**
 * Commodity method for the building of the ContentValues object starting from the CalendarInfo representation
 *
 * @return ContentValues representation of the CalendarInfo object
 */
public ContentValues toContentValues() {
    ContentValues contentValues = new ContentValues();
    contentValues.put(Calendars._ID, id);
    if (accountName != null) {
        contentValues.put(Calendars.ACCOUNT_NAME, accountName);
    }
    contentValues.put(Calendars.NAME, name == null ? accountName : name);
    contentValues.put(Calendars.CALENDAR_DISPLAY_NAME, displayName == null ? name : displayName);
    if (ownerAccount != null) {
        contentValues.put(Calendars.OWNER_ACCOUNT, ownerAccount);
    }
    if (color != null) {
        contentValues.put(Calendars.CALENDAR_COLOR, color);
    }
    if (visible != null) {
        contentValues.put(Calendars.VISIBLE, visible ? 1 : 0);
    }
    if (accountType != null) {
        contentValues.put(Calendars.ACCOUNT_TYPE, accountType);
    }
    return contentValues;
}
 
开发者ID:macisamuele,项目名称:CalendarProvider-Lib,代码行数:28,代码来源:CalendarInfo.java

示例7: deleteCalendar

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
/**
 * Deletes all Events from the EventsDB and the Calendar from the CalendarDB
 * identified by the _ID and ACCOUNT_TYPE
 * 
 * @param mContext
 * @param account
 * @return true if delete was successful
 */
public boolean deleteCalendar(Account account, long calendarId) {

	deleteAllEvents(account, calendarId);

	ContentResolver cr = mContext.getContentResolver();
	String selection = "((" + Calendars._ID + " = ?) AND  (" + Calendars.ACCOUNT_TYPE + " = ?))";
	String[] selectionArgs = new String[] { Long.toString(calendarId), Constants.ACCOUNT_TYPE };

	long ret = cr.delete(Calendars.CONTENT_URI, selection, selectionArgs);

	if (ret == 1) {
		return true;
	} else if (ret == 0) {
		return false;
	} else {
		Log.w(TAG, "WARNING deleteCalendar() deleted " + ret + " rows, should be only one!");
		return true;
	}

}
 
开发者ID:DHBWLoerrach,项目名称:campus-app,代码行数:29,代码来源:CalendarManager.java

示例8: getCalendars

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
/**
 * Returns a list of calendars available on the phone
 * @param context
 * @return list of CalendarInstances
 */
public static ArrayList<CalendarInstance> getCalendars(Context context) {
	ArrayList<CalendarInstance> result = new ArrayList<CalendarInstance>();
	
	Cursor cur = null;
	ContentResolver cr = context.getContentResolver();
	Uri uri = Calendars.CONTENT_URI;   
	String selection = null;
	String[] selectionArgs = null; 
	cur = cr.query(uri, new String[]{Calendars._ID, Calendars.NAME, Calendars.CALENDAR_DISPLAY_NAME, Calendars.ACCOUNT_NAME}, selection, selectionArgs, null);
	
	while (cur.moveToNext()) {
		result.add(new CalendarInstance(cur.getLong(cur.getColumnIndex(Calendars._ID)), cur.getString(cur.getColumnIndex(Calendars.CALENDAR_DISPLAY_NAME)), cur.getString(cur.getColumnIndex(Calendars.ACCOUNT_NAME))));
	}
	
	cur.close();
	
	return result;
}
 
开发者ID:JanBobolz,项目名称:agendawatchfaceAndroid,代码行数:24,代码来源:AgendaCalendarService.java

示例9: populateCalendars

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
public void populateCalendars() {
    String[] projection = new String[]{Calendars._ID, Calendars.NAME,
            Calendars.ACCOUNT_NAME, Calendars.ACCOUNT_TYPE};
    Cursor calCursor = this
            .getActivity()
            .getContentResolver()
            .query(Calendars.CONTENT_URI, projection, null, null,
                    Calendars._ID + " DESC");
    calendarNames = new ArrayList<String>();
    calendarAccounts = new ArrayList<String>();
    calendarTypes = new ArrayList<String>();
    calendarIds = new ArrayList<Long>();
    if (calCursor.moveToFirst()) {
        do {
            String name = calCursor.getString(1);
            if (name == null) {
                name = "Sin nombre";
            }
            calendarNames.add(name);
            calendarAccounts.add(calCursor.getString(2));
            calendarTypes.add(calCursor.getString(3));
            calendarIds.add(calCursor.getLong(0));

        } while (calCursor.moveToNext());
    }
}
 
开发者ID:tuxskar,项目名称:caluma,代码行数:27,代码来源:HomeActivity.java

示例10: populateCalendars

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
public void populateCalendars() {
    String[] projection = new String[]{Calendars._ID, Calendars.NAME,
            Calendars.ACCOUNT_NAME, Calendars.ACCOUNT_TYPE};
    Cursor calCursor = this.getActivity().getContentResolver()
            .query(Calendars.CONTENT_URI, projection,
                    null, null, Calendars._ID + " DESC");
    calendarNames = new ArrayList<String>();
    calendarAccounts = new ArrayList<String>();
    calendarTypes = new ArrayList<String>();
    calendarIds = new ArrayList<Long>();
    if (calCursor.moveToFirst()) {
        do {
            String name = calCursor.getString(1);
            if (name == null) {
                name = "Sin nombre";
            }
            calendarNames.add(name);
            calendarAccounts.add(calCursor.getString(2));
            calendarTypes.add(calCursor.getString(3));
            calendarIds.add(calCursor.getLong(0));

        } while (calCursor.moveToNext());
    }
}
 
开发者ID:tuxskar,项目名称:caluma,代码行数:25,代码来源:StudentHomeActivity.java

示例11: deleteCalendar

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
/**
 * Deletes all Events from the EventsDB and the Calendar from the CalendarDB
 * identified by the _ID and ACCOUNT_TYPE
 * 
 * @param mContext
 * @param account
 * @return true if delete was successful
 */
public boolean deleteCalendar(Account account, long calendarId) {

	deleteAllEvents(account, calendarId);
	Uri url = asSyncAdapter(Calendars.CONTENT_URI, account.name, account.type);

	ContentResolver cr = mContext.getContentResolver();
	String selection = "((" + Calendars._ID + " = ?) AND  (" + Calendars.ACCOUNT_TYPE + " = ?))";
	String[] selectionArgs = new String[] { Long.toString(calendarId), Constants.ACCOUNT_TYPE };

	long ret = cr.delete(Calendars.CONTENT_URI, selection, selectionArgs);

	if (ret == 1) {
		return true;
	} else if (ret == 0) {
		return false;
	} else {
		Log.w(TAG, "WARNING deleteCalendar() deleted " + ret + " rows, should be only one!");
		return true;
	}

}
 
开发者ID:dan-42,项目名称:DHBWCampusApp,代码行数:30,代码来源:CalendarManager.java

示例12: doSaveAction

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
public void doSaveAction() {
    // Cancel the previous operation
    mCalendarsUpdater.cancelOperation(mUpdateToken);
    mUpdateToken++;
    // This is to allow us to do queries and updates with the same AsyncQueryHandler without
    // accidently canceling queries.
    if(mUpdateToken < MIN_UPDATE_TOKEN) {
        mUpdateToken = MIN_UPDATE_TOKEN;
    }

    Iterator<Long> changeKeys = mCalendarChanges.keySet().iterator();
    while (changeKeys.hasNext()) {
        long id = changeKeys.next();
        boolean newSynced = mCalendarChanges.get(id);

        Uri uri = ContentUris.withAppendedId(Calendars.CONTENT_URI, id);
        ContentValues values = new ContentValues();
        values.put(Calendars.VISIBLE, newSynced ? 1 : 0);
        values.put(Calendars.SYNC_EVENTS, newSynced ? 1 : 0);
        mCalendarsUpdater.startUpdate(mUpdateToken, id, uri, values, null, null);
    }
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:23,代码来源:SelectSyncedCalendarsMultiAccountAdapter.java

示例13: instancesQuery

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
/**
 * Performs a query to return all visible instances in the given range
 * that match the given selection. This is a blocking function and
 * should not be done on the UI thread. This will cause an expansion of
 * recurring events to fill this time range if they are not already
 * expanded and will slow down for larger time ranges with many
 * recurring events.
 *
 * @param cr The ContentResolver to use for the query
 * @param projection The columns to return
 * @param begin The start of the time range to query in UTC millis since
 *            epoch
 * @param end The end of the time range to query in UTC millis since
 *            epoch
 * @param selection Filter on the query as an SQL WHERE statement
 * @param selectionArgs Args to replace any '?'s in the selection
 * @param orderBy How to order the rows as an SQL ORDER BY statement
 * @return A Cursor of instances matching the selection
 */
private static final Cursor instancesQuery(ContentResolver cr, String[] projection,
        int startDay, int endDay, String selection, String[] selectionArgs, String orderBy) {
    String WHERE_CALENDARS_SELECTED = Calendars.VISIBLE + "=?";
    String[] WHERE_CALENDARS_ARGS = {"1"};
    String DEFAULT_SORT_ORDER = "begin ASC";

    Uri.Builder builder = Instances.CONTENT_BY_DAY_URI.buildUpon();
    ContentUris.appendId(builder, startDay);
    ContentUris.appendId(builder, endDay);
    if (TextUtils.isEmpty(selection)) {
        selection = WHERE_CALENDARS_SELECTED;
        selectionArgs = WHERE_CALENDARS_ARGS;
    } else {
        selection = "(" + selection + ") AND " + WHERE_CALENDARS_SELECTED;
        if (selectionArgs != null && selectionArgs.length > 0) {
            selectionArgs = Arrays.copyOf(selectionArgs, selectionArgs.length + 1);
            selectionArgs[selectionArgs.length - 1] = WHERE_CALENDARS_ARGS[0];
        } else {
            selectionArgs = WHERE_CALENDARS_ARGS;
        }
    }
    return cr.query(builder.build(), projection, selection, selectionArgs,
            orderBy == null ? DEFAULT_SORT_ORDER : orderBy);
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:44,代码来源:Event.java

示例14: bindView

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
@Override
public void bindView(View view, Context context, Cursor cursor) {
    View colorBar = view.findViewById(R.id.color);
    int colorColumn = cursor.getColumnIndexOrThrow(Calendars.CALENDAR_COLOR);
    int nameColumn = cursor.getColumnIndexOrThrow(Calendars.CALENDAR_DISPLAY_NAME);
    int ownerColumn = cursor.getColumnIndexOrThrow(Calendars.OWNER_ACCOUNT);
    if (colorBar != null) {
        colorBar.setBackgroundColor(Utils.getDisplayColorFromColor(cursor
                .getInt(colorColumn)));
    }

    TextView name = (TextView) view.findViewById(R.id.calendar_name);
    if (name != null) {
        String displayName = cursor.getString(nameColumn);
        name.setText(displayName);

        TextView accountName = (TextView) view.findViewById(R.id.account_name);
        if (accountName != null) {
            accountName.setText(cursor.getString(ownerColumn));
            accountName.setVisibility(TextView.VISIBLE);
        }
    }
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:24,代码来源:EditEventView.java

示例15: findDefaultCalendarPosition

import android.provider.CalendarContract.Calendars; //导入依赖的package包/类
private int findDefaultCalendarPosition(Cursor calendarsCursor) {
    if (calendarsCursor.getCount() <= 0) {
        return -1;
    }

    String defaultCalendar = Utils.getSharedPreference(
            mActivity, GeneralPreferences.KEY_DEFAULT_CALENDAR, (String) null);

    if (defaultCalendar == null) {
        return 0;
    }
    int calendarsOwnerColumn = calendarsCursor.getColumnIndexOrThrow(Calendars.OWNER_ACCOUNT);
    int position = 0;
    calendarsCursor.moveToPosition(-1);
    while (calendarsCursor.moveToNext()) {
        if (defaultCalendar.equals(calendarsCursor.getString(calendarsOwnerColumn))) {
            return position;
        }
        position++;
    }
    return 0;
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:23,代码来源:EditEventView.java


注:本文中的android.provider.CalendarContract.Calendars类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。