/*
 * The MIT License
 * 
 * Copyright (C) 2014 Kiyofumi Kondoh
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package jp.ne.sakura.kkkon.android.exceptionhandler.testapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import jp.ne.sakura.kkkon.android.exceptionhandler.ExceptionHandler;

/**
 *
 * @author Kiyofumi Kondoh
 */
public class ExceptionHandlerTestApp extends Activity
{
    public static final String TAG = "appKK";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        final Context context = this.getApplicationContext();

        {
            ExceptionHandler.initialize( context );
            if ( ExceptionHandler.needReport() )
            {
                Intent reportIntent = new Intent( context, ExceptionHandlerReportApp.class );
                this.startActivity( reportIntent );
            }
            Log.d( TAG, "pre registHandler" );
            ExceptionHandler.registHandler();
        }

        super.onCreate(savedInstanceState);

        /* Create a TextView and set its content.
         * the text is retrieved by calling a native
         * function.
         */
        LinearLayout layout = new LinearLayout( this );
        layout.setOrientation( LinearLayout.VERTICAL );

        TextView  tv = new TextView(this);
        tv.setText( "ExceptionHandler" );
        layout.addView( tv );

        Button btn1 = new Button( this );
        btn1.setText( "invoke Exception" );
        btn1.setOnClickListener( new View.OnClickListener() {

            @Override
            public void onClick(View view)
            {
                final int count = 2;
                int[] array = new int[count];
                int value = array[count]; // invoke IndexOutOfBOundsException
            }
        } );
        layout.addView( btn1 );

        Button btn2 = new Button( this );
        btn2.setText( "switch Activity" );
        btn2.setOnClickListener( new View.OnClickListener() {

            @Override
            public void onClick(View view)
            {
                Intent reportIntent = new Intent( context, ExceptionHandlerReportApp.class );
                startActivity( reportIntent );
            }
        } );
        layout.addView( btn2 );

        setContentView( layout );
    }
}

@@ -1230,16 +1230,66 @@
 tivity;%0A
+import android.content.ActivityNotFoundException;%0A
 import a
@@ -1312,16 +1312,16 @@
 ontext;%0A
-
 import a
@@ -2130,32 +2130,74 @@
 ortApp.class );%0A
+                try%0A                %7B%0A    
                 
@@ -2224,32 +2224,283 @@
 reportIntent );%0A
+                %7D%0A                catch ( ActivityNotFoundException e )%0A                %7B%0A                    Log.d( TAG, %22need add Activity%5Cn%22 + %22%3Cactivity android:name=%5C%22%22 + ExceptionHandlerReportApp.class.getName()  + %22%5C%22/%3E%5Cn%22 );%0A                %7D%0A
             %7D%0A  
@@ -3773,32 +3773,74 @@
 ortApp.class );%0A
+                try%0A                %7B%0A    
                 
@@ -3862,32 +3862,286 @@
 reportIntent );%0A
+                %7D%0A                catch ( ActivityNotFoundException e )%0A                %7B%0A                    Log.d( TAG, %22need add Activity%5Cn%22 + %22%3Cactivity android:name=%5C%22%22 + ExceptionHandlerReportApp.class.getName()  + %22%5C%22/%3E%5Cn%22, e );%0A                %7D%0A
             %7D%0A  

add catch ActivityNotFoundException