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


Java Instances.END属性代码示例

本文整理汇总了Java中android.provider.CalendarContract.Instances.END属性的典型用法代码示例。如果您正苦于以下问题:Java Instances.END属性的具体用法?Java Instances.END怎么用?Java Instances.END使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.provider.CalendarContract.Instances的用法示例。


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

示例1: listNextCalenderEvents

private void listNextCalenderEvents( )
{
	ContentResolver cr = this.getContentResolver( );
	Cursor cursor = null;

	// cursor = cr.query( ContactsContract.Contacts.CONTENT_URI, new String[ ] { PhoneLookup.DISPLAY_NAME,
	// PhoneLookup.PHOTO_URI }, null, null,
	// null );

	long begin = System.currentTimeMillis( ); // starting time in milliseconds
	long end = begin + ( 1000 * 60 * 60 * 2 ); // ending time in milliseconds
	String[ ] proj =
		new String[ ] {
			Instances._ID,
			Instances.BEGIN,
			Instances.END,
			Instances.EVENT_ID };

	cursor = Instances.query( getContentResolver( ), proj, begin, end );

	if ( cursor == null )
	{
		Log.d( "CONTACTS", "keine Kontakte gefunden" );
	}
	else
	{
		cursor.moveToFirst( );
		while ( cursor.isAfterLast( ) == false )
		{
			Log.d( "CONTACTS", cursor.getString( 0 ) + " " + cursor.getString( 1 ) + " " + cursor.getString( 2 ) +
				" " + cursor.getString( 3 ) );
			printEventDetails( Long.parseLong( cursor.getString( 3 ) ) );
			cursor.moveToNext( );
		}
	}
	cursor.close( );
}
 
开发者ID:DerGary,项目名称:FHWS-MobileApplikationen,代码行数:37,代码来源:MainActivity.java

示例2: getCurrentEvent

/**
 * Get the current event in one of the calendars set in the preferences
 * @param currentTime Time at which the event should be searched
 * @param delay Delay that extends the search interval towards the end
 * @param early Delay that extends the search interval towards the beginning
 * @return The first event found, or null if there is none
 */
public CalendarEvent getCurrentEvent(long currentTime, long delay, long early, boolean onlyBusy) {
	ContentResolver cr = context.getContentResolver();
	
	// Make the calendar ID selection string
	String calIdsSelect = getEventCalendarIdsSelectString();
	
	if(calIdsSelect.equals("")) {
           return null;
       }

       int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR);
       if(permissionCheck != PackageManager.PERMISSION_GRANTED) {
           return null;
       }
	
	// Selection must be inclusive on the start time, and eclusive on the end time.
	// This way when setting an alarm at the end of the event, this moment is considered outside of the event
	String selection = "(" + calIdsSelect + ") AND "
			+ Instances.BEGIN + " <= ? AND "
			+ Instances.END + " > ? AND " + Instances.ALL_DAY + " = 0";
	
	if(onlyBusy) {
		selection += " AND " + Instances.AVAILABILITY + " = " + Instances.AVAILABILITY_BUSY;
	}
	
	String strCurrentTimeEarly = String.valueOf(currentTime + early);
	String strCurrentTimeDelay = String.valueOf(currentTime - delay);
	String[] selectionArgs =  new String[] { strCurrentTimeEarly, strCurrentTimeDelay };
	
	Cursor cur = cr.query(getInstancesQueryUri(), INSTANCE_PROJECTION, selection, selectionArgs, Instances.END); // Take the event that ends first
	
	CalendarEvent res;
	if(cur != null && cur.moveToNext()) {
		res = new CalendarEvent(cur.getString(INSTANCE_PROJECTION_TITLE_INDEX), cur.getLong(INSTANCE_PROJECTION_BEGIN_INDEX), cur.getLong(INSTANCE_PROJECTION_END_INDEX));
	}
	else {
		res = null;
	}

	if(cur != null) {
		cur.close();
	}
	return res;
}
 
开发者ID:RemiNV,项目名称:CalendarMute,代码行数:51,代码来源:CalendarProvider.java

示例3: run

@Override
public void run() {
	clearAllEvents();
	cal = new GregorianCalendar();
	Calendar newCal = new GregorianCalendar();
	//Reset at 12:30am
	int hourOfDay = cal.get(Calendar.HOUR_OF_DAY);
	int minOfDay = cal.get(Calendar.MINUTE);
	if(hourOfDay == 0 && minOfDay < 30){
		newCal.set(Calendar.HOUR_OF_DAY, 0);
		newCal.set(Calendar.MINUTE, 30);
		newCal.set(Calendar.SECOND, 0);	
	} else{
		newCal.add(Calendar.DAY_OF_WEEK, 1); //recalculates calendar if at the end
		newCal.set(Calendar.HOUR_OF_DAY, 0);
		newCal.set(Calendar.MINUTE, 30);
		newCal.set(Calendar.SECOND, 0);
	}
	String[] mSelectionArgs = new String[3];
	String mSelection = "DELETED = ? AND hasAlarm = ? AND allDay = ?";
	long start = cal.getTimeInMillis(); //current time
	long stop = newCal.getTimeInMillis(); //end of day
	mSelectionArgs[0] = "0"; 
	mSelectionArgs[1] = "1"; 
	mSelectionArgs[2] = "0"; 
	Cursor calendar = getContentResolver().query(Events.CONTENT_URI, null, mSelection, mSelectionArgs, Events.DTSTART+" ASC");
	//Go through and grab all events with reminders with our time constraint
	if(calendar != null && calendar.moveToFirst()){
		do{
			String repeating = calendar.getString(calendar.getColumnIndex("rrule"));
			long begin = calendar.getLong(calendar.getColumnIndex(Events.DTSTART));
			long end = calendar.getLong(calendar.getColumnIndex(Events.DTEND));
			if((repeating == null && begin >= start && end <= stop) || (repeating != null)){
				String id = calendar.getString(calendar.getColumnIndex(Events._ID));
				String name = calendar.getString(calendar.getColumnIndex(Events.TITLE));
				//Filter out deleted instances and grab repeating events
				String[] INSTANCE_PROJECTION = new String[] {
				    Instances.EVENT_ID,      // 0
				    Instances.BEGIN,         // 1
				    Instances.END,			 // 2
				    Instances.TITLE          // 3
				};
				String selection = Instances.EVENT_ID + " = ?";
				String[] selectionArgs = new String[] {id};
				Cursor instances = null;
				//Uri for events withing start and stop
				Uri.Builder builder = Instances.CONTENT_URI.buildUpon();
				ContentUris.appendId(builder, start);
				ContentUris.appendId(builder, stop);
				instances = getContentResolver().query(builder.build(), INSTANCE_PROJECTION, selection, selectionArgs, null);
				if(instances == null || instances.getCount() > 0 && instances.moveToNext()){
					//Make sure the instance's begin is after current time (since we didn't check it before)
					if(instances.getLong(instances.getColumnIndex((Instances.BEGIN))) >= start){
						begin = instances.getLong(instances.getColumnIndex(Instances.BEGIN));
						end = instances.getLong(instances.getColumnIndex(Instances.END));
						String[] toReturn = {""};
						toReturn[0] = ""+id;
						int maxReminder = 0;
						Cursor reminders = getContentResolver().query(Reminders.CONTENT_URI, null, "event_id = ?", toReturn, null);
						if(reminders != null && reminders.moveToLast()){
							do{
								int rem = reminders.getInt(reminders.getColumnIndex(Reminders.MINUTES)) ;
								if(rem > maxReminder)
									maxReminder = rem; 
							}while(reminders.moveToPrevious());
						}
						if(maxReminder >= 1 && maxReminder <= 60){
							CalendarEvent e = new CalendarEvent(id,name,begin,end,maxReminder);
							eventList.add(e);
						}
					}
				} if(instances != null && ! instances.isClosed() ) instances.close(); 
			}
		}while(calendar.moveToNext());
	} if(calendar != null && ! calendar.isClosed() ) calendar.close();
	//Run this again when you reach 12:30am either today or the next day
	long current = System.currentTimeMillis();
	if(eventList.size() > 0)
		startCalendarAlarm(0);
	thread_calSetup.postDelayed(this, (stop-current));
}
 
开发者ID:nischalshrestha,项目名称:mobilesensor,代码行数:81,代码来源:Plugin.java

示例4: getEntry

private void getEntry() {
	boolean first = false, calendar = false;
	String ID;
	long begin, end;
	String[] fields = { Instances.TITLE, Instances.BEGIN, Instances.END,
			Instances.EVENT_LOCATION, Instances.CALENDAR_ID };
	long now = System.currentTimeMillis();
	int i, j, calendar_no = calendars.length;
	Cursor eventCursor;

	currentRead = now - polltime;

	// query anything between now-polltime and now
	if (Build.VERSION.SDK_INT >= 14)
		eventCursor = CalendarContract.Instances.query(
				myStress.getContentResolver(), fields, currentRead, now + 24
						* 60 * 60 * 1000);
	else {
		Uri.Builder builder = Uri.parse(
				"content://com.android.calendar/instances/when")
				.buildUpon();
		ContentUris.appendId(builder, currentRead);
		ContentUris.appendId(builder, now + 24 * 60 * 60 * 1000);
		eventCursor = myStress.getContentResolver().query(
				builder.build(),
				new String[] { "title", "begin", "end", "eventLocation",
						"calendar_id" }, null, null, null);
	}
	// walk through all returns
	eventCursor.moveToFirst();
	for (i = 0; i < eventCursor.getCount(); i++) {
		begin = eventCursor.getLong(1);
		end = eventCursor.getLong(2);
		ID = eventCursor.getString(4);

		calendar = false;
		// see if the entry is from the calendars I want
		for (j = 0; j < calendar_no; j++)
			if (calendars[j].compareTo(ID) == 0) {
				calendar = true;
				break;
			}

		if (calendar == true)
			// is this something new?
			if (begin > currentRead && begin < now) {
				if (first == false) {
					reading.append(String.valueOf(begin) + ":"+ String.valueOf(end));
					first = true;
				} else
					reading.append("::" + String.valueOf(begin) + ":"
							+ String.valueOf(end));
			}

		eventCursor.moveToNext();
	}

	// free data
	eventCursor.close();

	// have we read anything? -> if not, delete reading string
	if (first == false)
		reading = null;
}
 
开发者ID:BlackHawk90,项目名称:myStress,代码行数:64,代码来源:CalendarHandler.java


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