// Path: app/src/main/java/com/music/ting/ui/fragment/DownLoadFragment.java
// public class DownLoadFragment extends Fragment {
// 
//     private View view;
// 
//     private ImageView downLoadControl, cancelDownLoad;
//     private NumberProgressBar progressBar;
//     private TextView songTitle;
//     public static boolean isDownLoad = false;
//     private boolean isPause = true;
//     private FileInfo mFileInfo;
//     private ProgressReceiver mReceiver;
// 
//     @Override
//     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
//                              @Nullable Bundle savedInstanceState) {
// 
//         if (isDownLoad) {
//             view = inflater.inflate(R.layout.fragment_download, container, false);
//             registerReceiver();
// 
//             downLoadControl = (ImageView) view.findViewById(R.id.download_control);
//             cancelDownLoad = (ImageView) view.findViewById(R.id.delete_download);
//             progressBar = (NumberProgressBar) view.findViewById(R.id.progressBar);
//             songTitle = (TextView) view.findViewById(R.id.song_title);
// 
//             ViewOnClickListener viewOnClickListener = new ViewOnClickListener();
//             downLoadControl.setOnClickListener(viewOnClickListener);
//             cancelDownLoad.setOnClickListener(viewOnClickListener);
// 
//         } else {
//             view = inflater.inflate(R.layout.fragment_not_download, container, false);
//         }
// 
// 
// 
// 
// 
//         return view;
//     }
// 
//     /**
//      * 注册广播
//      */
//     public void registerReceiver(){
// 
//         mReceiver = new ProgressReceiver();
//         IntentFilter filter = new IntentFilter();
//         filter.addAction(DownloadService.ACTION_UPDATE);
//         filter.addAction(DownloadService.ACTION_DELETE);
//         filter.addAction(DownloadService.ACTION_FILEINFO);
//         filter.addAction(DownloadService.ACTION_OK);
//         getActivity().registerReceiver(mReceiver, filter);
//     }
// 
// 
//     /**
//      * 广播接收器
//      */
//     public class ProgressReceiver extends BroadcastReceiver{
// 
//         @Override
//         public void onReceive(Context context, Intent intent) {
//             String action = intent.getAction();
//             if (DownloadService.ACTION_UPDATE.equals(action)) {
//                 int finished = intent.getIntExtra("finished", 0);
//                 progressBar.setProgress(finished);
//                 mFileInfo = (FileInfo) intent.getSerializableExtra("fileInfo");
//                 songTitle.setText(mFileInfo.getfileName());
//             } else if (DownloadService.ACTION_DELETE.equals(action)) {
//                 isDownLoad = false;
//                 stopService();
//                 DownLoadFragment loadFragment = new DownLoadFragment();
//                 getFragmentManager().beginTransaction().replace(R.id.container,loadFragment).
//                         show(loadFragment).commit();
//             }else if(DownloadService.ACTION_OK.equals(action)){
//                 isDownLoad = false;
//                 stopService();
//                 DownLoadFragment loadFragment = new DownLoadFragment();
//                 getFragmentManager().beginTransaction().replace(R.id.container,loadFragment).
//                         show(loadFragment).commit();
// 
//             }
//         }
//     }
// 
//     /**
//      * 暂停服务
//      */
//     public void stopService(){
//         Intent intent = new Intent(view.getContext(),DownloadService.class);
//         view.getContext().stopService(intent);
// 
//     }
// 
//     class ViewOnClickListener implements View.OnClickListener {
// 
//         @Override
//         public void onClick(View v) {
//             Intent intent = new Intent(view.getContext(), DownloadService.class);
//             switch (v.getId()) {
//                 case R.id.download_control:
//                     if (isPause) {
//                         downLoadControl.setImageResource(R.drawable.ic_fa_arrow_down);
//                         intent.setAction(DownloadService.ACTION_STOP);
//                         intent.putExtra("fileInfo", mFileInfo);
//                         getActivity().startService(intent);
//                         isPause = false;
//                     } else {
//                         downLoadControl.setImageResource(R.drawable.ic_fa_pause);
//                         intent.setAction(DownloadService.ACTION_START);
//                         intent.putExtra("fileInfo", mFileInfo);
//                         getActivity().startService(intent);
//                         isPause = true;
//                     }
//                     break;
//                 case R.id.delete_download:
//                     stopService();
//                     intent.setAction(DownloadService.ACTION_DELETE);
//                     intent.putExtra("fileInfo", mFileInfo);
//                     getActivity().startService(intent);
//                     break;
// 
//             }
//         }
//     }
// 
// 
// }


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Toast;
import com.music.ting.R;
import com.music.ting.ui.fragment.DownLoadFragment;

package com.music.ting.ui.activity;



/**
 * Created by Jun on 2015/5/15.
 */
public class BaseActivity extends ActionBarActivity {

    private Toolbar toolbar;

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

    public void initToolbar(){
        toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    }


    @Override
     public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.action_setting:
                Toast.makeText(this,"设置",Toast.LENGTH_SHORT).show();
                break;
            case R.id.action_download_setting:

// Path: app/src/main/java/com/music/ting/ui/fragment/DownLoadFragment.java
// public class DownLoadFragment extends Fragment {
// 
//     private View view;
// 
//     private ImageView downLoadControl, cancelDownLoad;
//     private NumberProgressBar progressBar;
//     private TextView songTitle;
//     public static boolean isDownLoad = false;
//     private boolean isPause = true;
//     private FileInfo mFileInfo;
//     private ProgressReceiver mReceiver;
// 
//     @Override
//     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
//                              @Nullable Bundle savedInstanceState) {
// 
//         if (isDownLoad) {
//             view = inflater.inflate(R.layout.fragment_download, container, false);
//             registerReceiver();
// 
//             downLoadControl = (ImageView) view.findViewById(R.id.download_control);
//             cancelDownLoad = (ImageView) view.findViewById(R.id.delete_download);
//             progressBar = (NumberProgressBar) view.findViewById(R.id.progressBar);
//             songTitle = (TextView) view.findViewById(R.id.song_title);
// 
//             ViewOnClickListener viewOnClickListener = new ViewOnClickListener();
//             downLoadControl.setOnClickListener(viewOnClickListener);
//             cancelDownLoad.setOnClickListener(viewOnClickListener);
// 
//         } else {
//             view = inflater.inflate(R.layout.fragment_not_download, container, false);
//         }
// 
// 
// 
// 
// 
//         return view;
//     }
// 
//     /**
//      * 注册广播
//      */
//     public void registerReceiver(){
// 
//         mReceiver = new ProgressReceiver();
//         IntentFilter filter = new IntentFilter();
//         filter.addAction(DownloadService.ACTION_UPDATE);
//         filter.addAction(DownloadService.ACTION_DELETE);
//         filter.addAction(DownloadService.ACTION_FILEINFO);
//         filter.addAction(DownloadService.ACTION_OK);
//         getActivity().registerReceiver(mReceiver, filter);
//     }
// 
// 
//     /**
//      * 广播接收器
//      */
//     public class ProgressReceiver extends BroadcastReceiver{
// 
//         @Override
//         public void onReceive(Context context, Intent intent) {
//             String action = intent.getAction();
//             if (DownloadService.ACTION_UPDATE.equals(action)) {
//                 int finished = intent.getIntExtra("finished", 0);
//                 progressBar.setProgress(finished);
//                 mFileInfo = (FileInfo) intent.getSerializableExtra("fileInfo");
//                 songTitle.setText(mFileInfo.getfileName());
//             } else if (DownloadService.ACTION_DELETE.equals(action)) {
//                 isDownLoad = false;
//                 stopService();
//                 DownLoadFragment loadFragment = new DownLoadFragment();
//                 getFragmentManager().beginTransaction().replace(R.id.container,loadFragment).
//                         show(loadFragment).commit();
//             }else if(DownloadService.ACTION_OK.equals(action)){
//                 isDownLoad = false;
//                 stopService();
//                 DownLoadFragment loadFragment = new DownLoadFragment();
//                 getFragmentManager().beginTransaction().replace(R.id.container,loadFragment).
//                         show(loadFragment).commit();
// 
//             }
//         }
//     }
// 
//     /**
//      * 暂停服务
//      */
//     public void stopService(){
//         Intent intent = new Intent(view.getContext(),DownloadService.class);
//         view.getContext().stopService(intent);
// 
//     }
// 
//     class ViewOnClickListener implements View.OnClickListener {
// 
//         @Override
//         public void onClick(View v) {
//             Intent intent = new Intent(view.getContext(), DownloadService.class);
//             switch (v.getId()) {
//                 case R.id.download_control:
//                     if (isPause) {
//                         downLoadControl.setImageResource(R.drawable.ic_fa_arrow_down);
//                         intent.setAction(DownloadService.ACTION_STOP);
//                         intent.putExtra("fileInfo", mFileInfo);
//                         getActivity().startService(intent);
//                         isPause = false;
//                     } else {
//                         downLoadControl.setImageResource(R.drawable.ic_fa_pause);
//                         intent.setAction(DownloadService.ACTION_START);
//                         intent.putExtra("fileInfo", mFileInfo);
//                         getActivity().startService(intent);
//                         isPause = true;
//                     }
//                     break;
//                 case R.id.delete_download:
//                     stopService();
//                     intent.setAction(DownloadService.ACTION_DELETE);
//                     intent.putExtra("fileInfo", mFileInfo);
//                     getActivity().startService(intent);
//                     break;
// 
//             }
//         }
//     }
// 
// 
// }


// Path: app/src/main/java/com/music/ting/ui/activity/BaseActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Toast;
import com.music.ting.R;
import com.music.ting.ui.fragment.DownLoadFragment;

package com.music.ting.ui.activity;



/**
 * Created by Jun on 2015/5/15.
 */
public class BaseActivity extends ActionBarActivity {

    private Toolbar toolbar;

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

    public void initToolbar(){
        toolbar = (Toolbar) findViewById(R.id.toolbar);

        setSupportActionBar(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    }


    @Override
     public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case R.id.action_setting:
                Toast.makeText(this,"设置",Toast.LENGTH_SHORT).show();
                break;
            case R.id.action_download_setting:

                DownLoadFragment downLoad = new DownLoadFragment();
