@ -11,11 +11,15 @@ import java.util.Map.Entry;
import org.weloveastrid.rmilk.MilkPreferences ;
import org.weloveastrid.rmilk.MilkPreferences ;
import org.weloveastrid.rmilk.MilkUtilities ;
import org.weloveastrid.rmilk.MilkUtilities ;
import android.content.DialogInterface ;
import android.content.DialogInterface.OnClickListener ;
import android.content.Intent ;
import android.content.Intent ;
import android.content.pm.PackageManager ;
import android.content.pm.PackageManager ;
import android.content.pm.ResolveInfo ;
import android.content.pm.ResolveInfo ;
import android.content.res.Resources ;
import android.content.res.Resources ;
import android.net.Uri ;
import android.os.Bundle ;
import android.os.Bundle ;
import android.preference.CheckBoxPreference ;
import android.preference.Preference ;
import android.preference.Preference ;
import android.preference.Preference.OnPreferenceClickListener ;
import android.preference.Preference.OnPreferenceClickListener ;
import android.preference.PreferenceCategory ;
import android.preference.PreferenceCategory ;
@ -27,6 +31,7 @@ import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager ;
import com.todoroo.andlib.service.ContextManager ;
import com.todoroo.andlib.service.DependencyInjectionService ;
import com.todoroo.andlib.service.DependencyInjectionService ;
import com.todoroo.andlib.sql.Criterion ;
import com.todoroo.andlib.sql.Criterion ;
import com.todoroo.andlib.utility.AndroidUtilities ;
import com.todoroo.andlib.utility.DialogUtilities ;
import com.todoroo.andlib.utility.DialogUtilities ;
import com.todoroo.andlib.utility.Preferences ;
import com.todoroo.andlib.utility.Preferences ;
import com.todoroo.andlib.widget.TodorooPreferences ;
import com.todoroo.andlib.widget.TodorooPreferences ;
@ -38,6 +43,7 @@ import com.todoroo.astrid.service.StartupService;
import com.todoroo.astrid.service.TaskService ;
import com.todoroo.astrid.service.TaskService ;
import com.todoroo.astrid.utility.Constants ;
import com.todoroo.astrid.utility.Constants ;
import com.todoroo.astrid.utility.Flags ;
import com.todoroo.astrid.utility.Flags ;
import com.todoroo.astrid.voice.VoiceInputAssistant ;
import com.todoroo.astrid.voice.VoiceOutputAssistant ;
import com.todoroo.astrid.voice.VoiceOutputAssistant ;
/ * *
/ * *
@ -58,6 +64,8 @@ public class EditPreferences extends TodorooPreferences {
@Autowired
@Autowired
private Database database ;
private Database database ;
private VoiceInputAssistant voiceInputAssistant ;
public EditPreferences ( ) {
public EditPreferences ( ) {
DependencyInjectionService . getInstance ( ) . inject ( this ) ;
DependencyInjectionService . getInstance ( ) . inject ( this ) ;
}
}
@ -74,6 +82,7 @@ public class EditPreferences extends TodorooPreferences {
ContextManager . setContext ( this ) ;
ContextManager . setContext ( this ) ;
PreferenceScreen screen = getPreferenceScreen ( ) ;
PreferenceScreen screen = getPreferenceScreen ( ) ;
voiceInputAssistant = new VoiceInputAssistant ( this ) ;
// load plug-ins
// load plug-ins
Intent queryIntent = new Intent ( AstridApiConstants . ACTION_SETTINGS ) ;
Intent queryIntent = new Intent ( AstridApiConstants . ACTION_SETTINGS ) ;
@ -190,7 +199,7 @@ public class EditPreferences extends TodorooPreferences {
}
}
@Override
@Override
public void updatePreferences ( Preference preference , Object value ) {
public void updatePreferences ( final Preference preference , Object value ) {
Resources r = getResources ( ) ;
Resources r = getResources ( ) ;
if ( r . getString ( R . string . p_showNotes ) . equals ( preference . getKey ( ) ) ) {
if ( r . getString ( R . string . p_showNotes ) . equals ( preference . getKey ( ) ) ) {
if ( value ! = null & & ! ( Boolean ) value )
if ( value ! = null & & ! ( Boolean ) value )
@ -201,6 +210,47 @@ public class EditPreferences extends TodorooPreferences {
taskService . clearDetails ( Criterion . all ) ;
taskService . clearDetails ( Criterion . all ) ;
Flags . set ( Flags . REFRESH ) ;
Flags . set ( Flags . REFRESH ) ;
}
}
} else if ( r . getString ( R . string . p_voiceInputEnabled ) . equals ( preference . getKey ( ) ) ) {
if ( value ! = null & & ( Boolean ) value )
if ( ! voiceInputAssistant . isVoiceInputAvailable ( ) ) {
// voicesearch available since 2.1
if ( AndroidUtilities . getSdkVersion ( ) > 6 ) {
DialogUtilities . okCancelDialog ( this ,
r . getString ( R . string . EPr_voiceInputInstall_dlg ) ,
new OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog ,
int which ) {
// User wants to install voicesearch, take him to the market
Intent marketIntent = new Intent ( Intent . ACTION_VIEW ,
Uri . parse ( "market://search?q=pname:" + //$NON-NLS-1$
"com.google.android.voicesearch.x" ) ) ;
startActivity ( marketIntent ) ;
}
} ,
new OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog ,
int which ) {
( ( CheckBoxPreference ) preference ) . setChecked ( false ) ;
dialog . dismiss ( ) ;
}
} ) ;
} else {
DialogUtilities . okDialog ( this ,
r . getString ( R . string . EPr_voiceInputUnavailable_dlg ) ,
new OnClickListener ( ) {
@Override
public void onClick ( DialogInterface dialog ,
int which ) {
( ( CheckBoxPreference ) preference ) . setChecked ( false ) ;
dialog . dismiss ( ) ;
}
} ) ;
}
}
} else if ( r . getString ( R . string . p_voiceRemindersEnabled ) . equals ( preference . getKey ( ) ) ) {
} else if ( r . getString ( R . string . p_voiceRemindersEnabled ) . equals ( preference . getKey ( ) ) ) {
if ( value ! = null & & ( Boolean ) value )
if ( value ! = null & & ( Boolean ) value )
VoiceOutputAssistant . getInstance ( ) . checkIsTTSInstalled ( ) ;
VoiceOutputAssistant . getInstance ( ) . checkIsTTSInstalled ( ) ;