package course.examples.ThreadingHandlerRunnableReuseTask;

import android.app.Activity;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;

public class OtherActivity extends Activity  implements LoadIconTask.IconLoader{

    private ImageView mImageView;
    private ProgressBar mProgressBar;
   //private Handler handler = new Handler();
    public LoadIconTask loadIconTask;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_other);

        mImageView = (ImageView) findViewById(R.id.otherImageView);
        mProgressBar = (ProgressBar) findViewById(R.id.otherProgressBar);

        final Button button = (Button) findViewById(R.id.otherLoadButton);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                loadIconTask = new LoadIconTask(OtherActivity.this);
                loadIconTask.setResId(R.drawable.painter);
                new Thread(loadIconTask).start();
            }
        });

        final Button otherButton = (Button) findViewById(R.id.otherOtherButton);
        otherButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(OtherActivity.this, "I'm Working in the other activity",
                        Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public ProgressBar getProgressBar() {
        return mProgressBar;
    }

    @Override
    public ImageView getImageView() {
        return mImageView;
    }
}
