package rkr.simplekeyboard.inputmethod.keyboard;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.inputmethod.InputMethodManager;

import rkr.simplekeyboard.inputmethod.R;
import rkr.simplekeyboard.inputmethod.latin.RichInputMethodManager;
import rkr.simplekeyboard.inputmethod.latin.settings.SettingsActivity;

public class SetupActivity extends SettingsActivity {

    @Override
    protected void onStart() {
        super.onStart();

        InputMethodManager immService = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        RichInputMethodManager.InputMethodInfoCache inputMethodInfoCache = new RichInputMethodManager.InputMethodInfoCache(immService, getPackageName());

        if (!inputMethodInfoCache.isInputMethodOfThisImeEnabled()) {
            final Context context = this;
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage(R.string.setup_message);
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent intent = new Intent(android.provider.Settings.ACTION_INPUT_METHOD_SETTINGS);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    finish();
                }
            });
            builder.setCancelable(false);

            builder.create().show();
        }
    }
}

@@ -534,24 +534,76 @@
 onStart();%0A%0A
+        boolean enabled = false;%0A%0A        try %7B%0A    
         Inpu
@@ -650,16 +650,17 @@
 Manager)
+ 
 getSyste
@@ -699,16 +699,20 @@
 RVICE);%0A
+    
         
@@ -861,22 +861,30 @@
 ));%0A
-%0A
+     
        
- if (!
+enabled = 
 inpu
@@ -931,16 +931,80 @@
 nabled()
+;%0A        %7D%0A        catch (Exception e) %7B%7D%0A%0A        if (!enabled
 ) %7B%0A    

Handle exception that should not be there