Advertisement
Guest User

http://stackoverflow.com/questions/16610375/how-can-i-use-na

a guest
Jun 2nd, 2013
640
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.98 KB | None | 0 0
  1. //======================
  2. //  MainActivity.java
  3. //======================
  4.  
  5. package com.example.nattyapp;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10. import java.util.Map;
  11.  
  12. import com.joestelmach.natty.DateGroup;
  13. import com.joestelmach.natty.Parser;
  14.  
  15. import android.os.Bundle;
  16. import android.app.Activity;
  17. import android.util.Log;
  18. import android.view.Menu;
  19. import android.widget.ArrayAdapter;
  20. import android.widget.ListAdapter;
  21. import android.widget.ListView;
  22.  
  23. public class MainActivity extends Activity {
  24.  
  25.     @Override
  26.     protected void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.activity_main);
  29.  
  30.         ListView lv = (ListView) findViewById(R.id.lv);
  31.  
  32.         /* data source for ListView */
  33.         List<Date> dateList = new ArrayList<Date>();
  34.         /* simplest possible data adapter for ListView (using only built-in item layout) */
  35.         ListAdapter listAdapter = new ArrayAdapter<Date>(this, android.R.layout.simple_list_item_1, dateList);
  36.         lv.setAdapter(listAdapter);
  37.  
  38.         Parser parser = new Parser();
  39.         List<DateGroup> groups = parser.parse("the day before next thursday");
  40.         for (DateGroup group : groups) {
  41.             List<Date> dates = group.getDates();
  42.             int line = group.getLine();
  43.             int column = group.getPosition();
  44.             String matchingValue = group.getText();
  45.             String syntaxTree = group.getSyntaxTree().toStringTree();
  46.             Map parseMap = group.getParseLocations();
  47.             boolean isRecurreing = group.isRecurring();
  48.             Date recursUntil = group.getRecursUntil();
  49.  
  50.             /* if any Dates are present in current group then add them to dateList */
  51.             if (group.getDates() != null) {
  52.                 dateList.addAll(group.getDates());
  53.             }
  54.         }
  55.         Log.i("NATTY-APP", "Test app is complete");
  56.     }
  57.  
  58.     @Override
  59.     public boolean onCreateOptionsMenu(Menu menu) {
  60.         // Inflate the menu; this adds items to the action bar if it is present.
  61.         getMenuInflater().inflate(R.menu.main, menu);
  62.         return true;
  63.     }
  64.  
  65. }
  66.  
  67.  
  68. //==================================
  69. // activity_main.xml
  70. //==================================
  71. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  72.     xmlns:tools="http://schemas.android.com/tools"
  73.     android:layout_width="match_parent"
  74.     android:layout_height="match_parent"
  75.     android:paddingBottom="@dimen/activity_vertical_margin"
  76.     android:paddingLeft="@dimen/activity_horizontal_margin"
  77.     android:paddingRight="@dimen/activity_horizontal_margin"
  78.     android:paddingTop="@dimen/activity_vertical_margin"
  79.     tools:context=".MainActivity" >
  80.  
  81.     <TextView
  82.         android:id="@+id/tv"
  83.         android:layout_width="wrap_content"
  84.         android:layout_height="wrap_content"
  85.         android:text="@string/hello_world" />
  86.  
  87.     <ListView
  88.         android:id="@+id/lv"
  89.         android:layout_width="match_parent"
  90.         android:layout_height="wrap_content"
  91.         android:layout_alignParentLeft="true"
  92.         android:layout_below="@+id/tv"
  93.         android:layout_marginTop="16dp" >
  94.     </ListView>
  95.  
  96. </RelativeLayout>
  97.  
  98.  
  99.  
  100. //==================================
  101. // AndroidManifest.xml
  102. //==================================
  103. <?xml version="1.0" encoding="utf-8"?>
  104. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  105.     package="com.example.nattyapp"
  106.     android:versionCode="1"
  107.     android:versionName="1.0" >
  108.  
  109.     <uses-sdk
  110.         android:minSdkVersion="8"
  111.         android:targetSdkVersion="17" />
  112.  
  113.     <application
  114.         android:allowBackup="true"
  115.         android:icon="@drawable/ic_launcher"
  116.         android:label="@string/app_name"
  117.         android:theme="@style/AppTheme" >
  118.         <activity
  119.             android:name="com.example.nattyapp.MainActivity"
  120.             android:label="@string/app_name" >
  121.             <intent-filter>
  122.                 <action android:name="android.intent.action.MAIN" />
  123.  
  124.                 <category android:name="android.intent.category.LAUNCHER" />
  125.             </intent-filter>
  126.         </activity>
  127.     </application>
  128.  
  129. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement