package com.coolhandmook.nagdroid;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Spinner;
import android.widget.TimePicker;

public class NewNagActivity extends Activity {

	private ApplicationViewAdapter viewAdapter;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_nag);
        
        viewAdapter = new ApplicationViewAdapter(this, R.id.applicationName, getPackageManager().getInstalledApplications(0));
        Spinner spinner = (Spinner) findViewById(R.id.applicationNameSpinner);
        spinner.setAdapter(viewAdapter);
        
        TimePicker timePicker = (TimePicker) findViewById(R.id.timePicker);
        timePicker.setIs24HourView(true);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_new_nag, menu);
        return true;
    }
    
    public void onNagSave(View view)
    {
    	Spinner spinner = (Spinner) findViewById(R.id.applicationNameSpinner);
    	int selected = spinner.getLastVisiblePosition();
    	
    	ApplicationInfo application = viewAdapter.getItem(selected);
		Intent intent = getPackageManager().getLaunchIntentForPackage(application.packageName);
    	if (intent != null)
    	{
    		TimePicker timePicker = (TimePicker) findViewById(R.id.timePicker);
        	
    		Intent scheduleNew = new Intent(this, NagService.class);
    		scheduleNew.setAction(NagService.SCHEDULE_NEW);
    		scheduleNew.putExtra(NagService.ARG_HOUR, timePicker.getCurrentHour());
    		scheduleNew.putExtra(NagService.ARG_MINUTE, timePicker.getCurrentMinute());
    		scheduleNew.putExtra(NagService.ARG_PACKAGE, application.packageName);
    		startService(scheduleNew);
    	}
    	
    	finish();
    }

    public void onNagCancel(View view)
    {
    	finish();
    }
    
}

@@ -29,16 +29,80 @@
 droid;%0A%0A
+import java.util.Calendar;%0Aimport java.util.GregorianCalendar;%0A%0A
 import a
@@ -496,17 +496,18 @@
 ceState)
- 
+%0A%09
 %7B%0A      
@@ -852,32 +852,94 @@
 pter);%0A        %0A
+        Calendar calendar = new GregorianCalendar();%0A        %0A
         TimePick
@@ -1036,24 +1036,95 @@
 View(true);%0A
+        timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));%0A
     %7D%0A%0A    @
@@ -1181,16 +1181,20 @@
 nu menu)
+%0A   
  %7B%0A     

Fix clock on new nag to show correct hour past 12 noon