package test.xjl12.soeasy;

import android.content.*;
import android.net.*;
import android.os.*;
import android.support.design.widget.*;
import android.support.v7.app.*;
import android.util.*;
import android.view.*;
import android.widget.*;
import java.io.*;

import android.support.v7.widget.Toolbar;

public class TestActivity extends AppCompatActivity
{
    TextView test_textview1;
	Button fc_button;
	
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        //Test Fragment
        /**if (findViewById(R.id.testFrameLayout) != null)
        {
            if (savedInstanceState != null)
            {
                return;
            }
            Fragment first = new Fragment();
            first.setArguments(getIntent().getExtras());
            
            getFragmentManager().beginTransaction().add(R.id.testFrameLayout,first).commit();
        }*/
		fc_button = (Button) findViewById(R.id.test_fc_Button);
        test_textview1 = (TextView) findViewById(R.id.testTextView1);
		Toolbar toolbar = (Toolbar) findViewById(R.id.test_mdToolbar);
		final CoordinatorLayout mCl = (CoordinatorLayout) findViewById(R.id.test_mdCoordinatorLayout);
        Button test1 = (Button) findViewById(R.id.test_content_test_Button1);
		
		setSupportActionBar(toolbar);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		getSupportActionBar().setHomeButtonEnabled(true);
		
		test1.setOnClickListener(new View.OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					Others.test(TestActivity.this);
				}
			});
		toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener(){

				@Override
				public boolean onMenuItemClick(final MenuItem item)
				{
					switch (item.getItemId())
					{
						case R.id.help_development:
							Intent help_development_web = new Intent(Intent.ACTION_VIEW);
							help_development_web.setData(Uri.parse(getResources().getStringArray(R.array.web_url)[1]));
							startActivity(help_development_web);
							break;
						case R.id.source_item:
							Intent source_web = new Intent(Intent.ACTION_VIEW);
							source_web.setData(Uri.parse(getResources().getStringArray(R.array.web_url)[0]));
							startActivity(source_web);
							break;
						case R.id.shot_item:
							new Thread(new Runnable(){

									@Override
									public void run()
									{
										Intent shot_share = Others.SendShot(getApplicationContext());
										if (shot_share != null)
										{
											startActivity(shot_share);
										}
										else
										{
											Snackbar.make(mCl, R.string.Error_shot_error, Snackbar.LENGTH_LONG)
												.setActionTextColor(getResources().getColor(R.color.colorAccent_Light))
												.setAction(R.string.retry, new View.OnClickListener(){

													@Override
													public void onClick(View p1)
													{
														Intent intent = Others.getShot(TestActivity.this);
														if (intent != null)
														{
															startActivity(intent);
														}
														else
														{
															Toast.makeText(TestActivity.this,getString(R.string.Error_cannot_shot),Toast.LENGTH_LONG);
														}
													}
												}).show();
										}	
									}
								}).start();
							break;
						default:
							Snackbar.make(mCl, R.string.wrong, Snackbar.LENGTH_LONG)
								.setActionTextColor(getResources().getColor(R.color.colorAccent_Light))
								.setAction(R.string.send_error, new View.OnClickListener(){

									@Override
									public void onClick(View p1)
									{startActivity(Intent.createChooser(Others.isQQInstalled(getApplicationContext(), new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, getString(R.string.send_error_message, Others.getAppVersionName(getApplicationContext()), Others.getRunningActivityName(TestActivity.this), item.getTitle().toString())).setType("text/plain")), getString(R.string.Error_no_item_action)));}
								}).show();
							break;
					}
					return true;
				}
			});
		
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_actions,menu);
        return super.onCreateOptionsMenu(menu);
    }
	@Override
	public void onResume ()
	{
		super.onResume();
		Others.DeleteDirAllFile(getApplicationContext().getExternalCacheDir());
	}
    
    public void test1 (View view)
    {
        Intent web = new Intent();
        web.setAction("android.intent.action.VIEW");
        Uri baidu = Uri.parse("https:www.baidu.com");
        web.setData(baidu);
        startActivity(web);
    }
    public void TestFileWrite (View view) throws FileNotFoundException, IOException
    {
        Log.i("Test","TestFileWrite button on click");
        FileOutputStream outstream = this.openFileOutput("test.txt",Context.MODE_APPEND);
        outstream.write("测试成功！".getBytes());
        outstream.close();
    }
    public void TestFileRead (View view) throws IOException
    {
        Log.i("Test","TestFileRead button on click");
		try
		{
			InputStream is = this.openFileInput("test.txt");
			test_textview1.setText(Others.getString(is));
			is.close();
		}
		catch (FileNotFoundException e)
		{
			Toast.makeText(this,R.string.Error_no_file,Toast.LENGTH_LONG).show();
		}
    }
	public void DeleteTestFile (View view)
	{
		Others.DeleteDirAllFile(getApplicationContext().getFilesDir());
		test_textview1.setText(R.string.delete_complete);
	}
	public void TestFC (View view)
	{
		new Thread(new Runnable(){

				@Override
				public void run()
				{
					TextView test_fc = null;
					test_fc.setText(null);
				}
			}).start();
	}
	public void OpenRawTestImage (View view) throws IOException
	{
		File cache_file = new File(this.getExternalCacheDir(),Others.RandomString(8));
		InputStream test_is = getResources().openRawResource(R.mipmap.ic_launcher);
		FileOutputStream test_fos = new FileOutputStream(cache_file);
		byte[] buffer = new byte[1024];
		int byte_count = 0;
		while ((byte_count = test_is.read(buffer)) != -1)
		{
			test_fos.write(buffer,0,byte_count);
		}
		test_fos.flush();
		test_is.close();
		test_fos.close();
		Uri test_image = Uri.fromFile(cache_file);
		Intent open_test_image = new Intent(Intent.ACTION_VIEW);
		open_test_image.setDataAndType(test_image,"image/*");
		startActivity(open_test_image);
	}
}

@@ -1259,86 +1259,8 @@
 t);%0A
-        Button test1 = (Button) findViewById(R.id.test_content_test_Button1);%0A
 %09%09%0A%09
@@ -1406,167 +1406,8 @@
 %0A%09%09%0A
-%09%09test1.setOnClickListener(new View.OnClickListener()%7B%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void onClick(View p1)%0A%09%09%09%09%7B%0A%09%09%09%09%09Others.test(TestActivity.this);%0A%09%09%09%09%7D%0A%09%09%09%7D);%0A
 %09%09to

Add apk file