package com.liulishuo.filedownloader.demo;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.liulishuo.filedownloader.FileDownloadMonitor;
import com.liulishuo.filedownloader.FileDownloader;
import com.liulishuo.filedownloader.demo.performance.PerformanceTestActivity;

/**
 * Created by Jacksgong on 12/17/15.
 */
public class MainActivity extends AppCompatActivity {

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

        setContentView(R.layout.activity_main);

        // 这是只是为了全局监控。如果你有需求需要全局监控（比如用于打点/统计）可以使用这个方式，如果没有类似需求就不需要
        // You do not have to add below code to your project only if you need monitor the global
        // FileDownloader Engine for statistic or others
        FileDownloadMonitor.setGlobalMonitor(GlobalMonitor.getImpl());
    }

    public void onClickMultitask(final View view) {
        startActivity(new Intent(this, MultitaskTestActivity.class));
    }

    public void onClickSingle(final View view) {
        startActivity(new Intent(this, SingleTaskTestActivity.class));
    }

    public void onClickHybridTest(final View view) {
        startActivity(new Intent(this, HybridTestActivity.class));
    }

    public void onClickTasksManager(final View view) {
        startActivity(new Intent(this, TasksManagerDemoActivity.class));
    }

    public void onClickPerformance(final View view) {
        startActivity(new Intent(this, PerformanceTestActivity.class));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return super.onCreateOptionsMenu(menu);
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_github:
                openGitHub();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    private void openGitHub() {
        Uri uri = Uri.parse(getString(R.string.app_github_url));
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // unbind and stop service manually if idle
        FileDownloader.getImpl().unBindServiceIfIdle();

        FileDownloadMonitor.releaseGlobalMonitor();
    }
}

@@ -770,16 +770,127 @@
 %E4%BC%BC%E9%9C%80%E6%B1%82%E5%B0%B1%E4%B8%8D%E9%9C%80%E8%A6%81%0A
+        // %E5%A6%82%E6%9E%9C%E4%BD%A0%E6%9C%89%E8%BF%99%E4%B8%AA%E9%9C%80%E6%B1%82%EF%BC%8C%E5%AE%9E%E7%8E%B0FileDownloadMonitor.IMonitor%E6%8E%A5%E5%8F%A3%EF%BC%8C%E4%B9%9F%E4%BD%BF%E7%94%A8FileDownloadMonitor.setGlobalMonitor%0A        // %E6%B3%A8%E5%86%8C%E8%BF%9B%E5%8E%BB%E5%8D%B3%E5%8F%AF%0A
         
@@ -1035,16 +1035,197 @@
  others%0A
+        // If you have such requirement, just implement FileDownloadMonitor.IMonitor, and register it%0A        // use FileDownloadDownloader.setGlobalMonitor the same as below code.%0A
         

add necessary tips for Global Monitor