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


Java Mirror.timeline方法代码示例

本文整理汇总了Java中com.google.api.services.mirror.Mirror.timeline方法的典型用法代码示例。如果您正苦于以下问题:Java Mirror.timeline方法的具体用法?Java Mirror.timeline怎么用?Java Mirror.timeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.services.mirror.Mirror的用法示例。


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

示例1: insertMultiHtmlTimelineItem

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
public static void insertMultiHtmlTimelineItem( ServletContext ctx,
                                                 HttpServletRequest req )
    throws IOException, ServletException
{
  Mirror mirror = MirrorUtils.getMirror( req );
  Timeline timeline = mirror.timeline();

  // START:insertMultiHtmlTimelineItem
  // Generate a unique Lunch Roulette bundle id
  String bundleId = "lunchRoulette" + UUID.randomUUID();

  // First Cuisine Option
  TimelineItem timelineItem1 = new TimelineItem()
    .setHtml( renderRandomCuisine( ctx ) )
    .setBundleId( bundleId )
    .setIsBundleCover( true );
  timeline.insert( timelineItem1 ).execute();

  // Alternate Cuisine Option
  TimelineItem timelineItem2 = new TimelineItem()
    .setHtml( renderRandomCuisine( ctx ) )
    .setBundleId( bundleId );
  timeline.insert( timelineItem2 ).execute();
  // END:insertMultiHtmlTimelineItem
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:26,代码来源:LunchRoulette.java

示例2: insertAndSaveSimpleHtmlTimelineItem

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
public static void insertAndSaveSimpleHtmlTimelineItem( ServletContext ctx,
                                                        String userId )
    throws IOException, ServletException
{
  Mirror mirror = MirrorUtils.getMirror( userId );
  Timeline timeline = mirror.timeline();

  // START:insertSimpleHtmlTimelineItem
  // get a cuisine, populate an object, and render the template
  String cuisine = getRandomCuisine();
  Map<String, String> data = Collections.singletonMap( "food", cuisine );
  String html = render( ctx, "glass/cuisine.ftl", data );

  TimelineItem timelineItem = new TimelineItem()
    .setTitle( "Lunch Roulette" )
    .setHtml( html )
    .setSpeakableText( "You should eat "+cuisine+" for lunch" );

  TimelineItem tiResp = timeline.insert( timelineItem ).execute();
  // END:insertSimpleHtmlTimelineItem

  setLunchRouletteId( userId, tiResp.getId() );
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:24,代码来源:LunchRoulette.java

示例3: insertAndSaveSimpleTextTimelineItem

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
public static void insertAndSaveSimpleTextTimelineItem( HttpServletRequest req )
    throws IOException
{
  String userId = SessionUtils.getUserId( req );
  Credential credential = AuthUtils.getCredential( userId );
  Mirror mirror = MirrorUtils.getMirror( credential );

  Timeline timeline = mirror.timeline();

  // START:insertAndSaveSimpleTimelineItem
  TimelineItem timelineItem = new TimelineItem()
    .setTitle( "Lunch Roulette" )
    .setText( getRandomCuisine() );

  TimelineItem tiResp = timeline.insert( timelineItem ).execute();
  
  setLunchRouletteId( userId, tiResp.getId() );
  // END:insertAndSaveSimpleTimelineItem
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:20,代码来源:LunchRoulette.java

示例4: previewOnGlass

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
private void previewOnGlass() {
	try {
		Credential cred = GoogleLogin.getInstance().getCredential();
		cred.getAccessToken();
		Mirror m = new Mirror.Builder(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), cred)
		.setApplicationName("Glassmaker Plugin")
		.build();

		String editorText = getDocumentProvider().getDocument(textEditor.getEditorInput()).get();
		deletePreviewFiles();
		TimelineItem timelineItem =  CardUtil.createTimeline(editorText);			
		Mirror.Timeline timeline = m.timeline();
		timeline.insert(timelineItem).execute();
		
	} catch (Exception e) {
		GlassmakerUIPlugin.logError(e.getMessage(), e);
	}
}
 
开发者ID:eteration,项目名称:glassmaker,代码行数:19,代码来源:CardEditor.java

示例5: insertSimpleTextTimelineItem

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
public static void insertSimpleTextTimelineItem( HttpServletRequest req )
    throws IOException
{
  Mirror mirror = MirrorUtils.getMirror( req );
  Timeline timeline = mirror.timeline();
  
  TimelineItem timelineItem = new TimelineItem()
    .setText( getRandomCuisine() );
  
  timeline.insert( timelineItem ).executeAndDownloadTo( System.out );
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:12,代码来源:LunchRoulette.java

示例6: getLastSavedTimelineItem

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
public static TimelineItem getLastSavedTimelineItem( String userId )
    throws IOException
{
  Credential credential = AuthUtils.getCredential( userId );
  Mirror mirror = MirrorUtils.getMirror( credential );
  Timeline timeline = mirror.timeline();

  // START:getLastSavedTimelineItem
  String id = getLunchRouletteId( userId );

  TimelineItem timelineItem = timeline.get( id ).execute();
  // END:getLastSavedTimelineItem

  return timelineItem;
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:16,代码来源:LunchRoulette.java

示例7: doGet

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	// get Access to Mirror Api
	Mirror mirror = getMirror(req);
	
	// get TimeLine
	Timeline timeline = mirror.timeline();
		
	try {
	    JSONObject json = new JSONObject(retrieveIPool());
	    JSONArray arr = json.getJSONArray("documents");
	    JSONArray media = new JSONArray();
	    
	    String title = null;
	    String content = null;
	    String URL = null;
	    
	    for (int i = 0; i < arr.length(); i++) {
	        title = arr.getJSONObject(i).getString("title");
	        // maybe for future use but for tts needs to be stripped from html tags
	        //content = arr.getJSONObject(i).getString("content");
	        media = arr.getJSONObject(i).getJSONArray("contentReferences");   
	    }
	    		    
	    if (media.length()!=0){
		    for (int i = 0; i < media.length(); i++) {
		    	URL = media.getJSONObject(i).getString("externalUrl");   
		    }
	    }
    
	    String html = "<article class=\"photo\">\n  <img src=\""+URL+"\" width=\"100%\" height=\"100%\">\n  <div class=\"overlay-gradient-tall-dark\"/>\n  <section>\n    <p class=\"text-auto-size\">"+title+"</p>\n  </section>\n</article>";
	    
	 // create a timeline item
		TimelineItem timelineItem = new TimelineItem()
			//.setSpeakableText(content)
			.setSpeakableText(title)
			.setHtml(html)
			.setDisplayTime(new DateTime(new Date()))
			.setNotification(new NotificationConfig().setLevel("Default"));
		
		// add menu items with built-in actions
		List<MenuItem> menuItemList = new ArrayList<MenuItem>();
		menuItemList.add(new MenuItem().setAction("DELETE"));
		menuItemList.add(new MenuItem().setAction("READ_ALOUD"));
		menuItemList.add(new MenuItem().setAction("TOGGLE_PINNED"));
		timelineItem.setMenuItems(menuItemList);
		
		// insert the crad into the timeline
		timeline.insert(timelineItem).execute();
		
		//print out results on the web browser
		resp.setContentType("text/html; charset=utf-8");
		//resp.setCharacterEncoding("UTF-8");
		resp.getWriter().println(
				"<html><head><meta http-equiv=\"refresh\" content=\"3;url=/index.html\"></head> "
						+ "<body>"+html+"</body></html>");
	} catch (JSONException e) {
	    
	    StringWriter errors = new StringWriter();
	    e.printStackTrace(new PrintWriter(errors));
	    String error =  errors.toString();
	    
	    //resp.setContentType("text/html; charset=utf-8");
	    resp.setCharacterEncoding("UTF-8");
		resp.getWriter().println(
				"<html><head><meta http-equiv=\"refresh\" content=\"3;url=/index.html\"></head> "
						+ "<body>JSON Exception " +error+" </body></html>");
	}
}
 
开发者ID:ipool,项目名称:GlassPool,代码行数:70,代码来源:IpoolAPIClient.java

示例8: doPost

import com.google.api.services.mirror.Mirror; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest req, HttpServletResponse res)
    throws IOException, ServletException
{
  // Generate Notification from request body
  JsonFactory jsonFactory = new JacksonFactory();
  Notification notification =
    jsonFactory.fromInputStream( req.getInputStream(), Notification.class );

  // Get this user action's type
  String userActionType = null;
  if( !notification.getUserActions().isEmpty() )
    userActionType = notification.getUserActions().get(0).getType();

  String userId = notification.getUserToken();
  String itemId = notification.getItemId();

  // If this is a shared timeline item, log who and which timeline item
  if( "SHARE".equals( userActionType ) )
  {
    // START:share1
    System.out.format( "User %s shared %s", userId, itemId );

    Mirror mirror = MirrorUtils.getMirror( userId );
    Timeline timeline = mirror.timeline();
    Attachments attachments = timeline.attachments();

    // get the newly created timeline item that triggered this notification
    TimelineItem timelineItem = timeline.get( itemId ).execute();

    // get the first attachment's id and content type
    Attachment attachment = timelineItem.getAttachments().get(0);
    String contentType = attachment.getContentType();
    String attachmentId = attachment.getId();

    // download the attachment image data
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    attachments.get(itemId, attachmentId).executeMediaAndDownloadTo( data ); 
    // END:share1
    // START:share2
    byte[] image = data.toByteArray();
    Blob blob = new Blob( image );
    // Save the image in the datastore
    DatastoreService store = DatastoreServiceFactory.getDatastoreService();

    // Get the current location of Glass
    Location location = mirror.locations().get("latest").execute();
    String keyValue = String.format("%.3f,%.3f",
        location.getLatitude(), location.getLongitude());
    // Store the image, type, and hash
    Key key = KeyFactory.createKey("image", keyValue);
    Entity entity = new Entity( key );
    entity.setProperty("image", blob);
    entity.setProperty("type", contentType);
    entity.setProperty("hash", LunchRoulette.toSHA1( image ));
    store.put(entity);
    // END:share2
  }
}
 
开发者ID:coderoshi,项目名称:glass,代码行数:59,代码来源:TimelineInsertServlet.java


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