Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //======================
- // MainActivity.java
- //======================
- package com.example.nattyapp;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Map;
- import com.joestelmach.natty.DateGroup;
- import com.joestelmach.natty.Parser;
- import android.os.Bundle;
- import android.app.Activity;
- import android.util.Log;
- import android.view.Menu;
- import android.widget.ArrayAdapter;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ListView lv = (ListView) findViewById(R.id.lv);
- /* data source for ListView */
- List<Date> dateList = new ArrayList<Date>();
- /* simplest possible data adapter for ListView (using only built-in item layout) */
- ListAdapter listAdapter = new ArrayAdapter<Date>(this, android.R.layout.simple_list_item_1, dateList);
- lv.setAdapter(listAdapter);
- Parser parser = new Parser();
- List<DateGroup> groups = parser.parse("the day before next thursday");
- for (DateGroup group : groups) {
- List<Date> dates = group.getDates();
- int line = group.getLine();
- int column = group.getPosition();
- String matchingValue = group.getText();
- String syntaxTree = group.getSyntaxTree().toStringTree();
- Map parseMap = group.getParseLocations();
- boolean isRecurreing = group.isRecurring();
- Date recursUntil = group.getRecursUntil();
- /* if any Dates are present in current group then add them to dateList */
- if (group.getDates() != null) {
- dateList.addAll(group.getDates());
- }
- }
- Log.i("NATTY-APP", "Test app is complete");
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }
- //==================================
- // activity_main.xml
- //==================================
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/tv"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world" />
- <ListView
- android:id="@+id/lv"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/tv"
- android:layout_marginTop="16dp" >
- </ListView>
- </RelativeLayout>
- //==================================
- // AndroidManifest.xml
- //==================================
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.nattyapp"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="17" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.example.nattyapp.MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement