@Override public void onCreate() { feedBackIntent = new Intent(BROADCAST_FEEDBACK); seekIntent = new Intent(BROADCAST_SEEK); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setOnCompletionListener(this); mediaPlayer.setOnErrorListener(this); mediaPlayer.setOnBufferingUpdateListener(this); mediaPlayer.setOnInfoListener(this); mediaPlayer.setOnSeekCompleteListener(this); mediaPlayer.setOnPreparedListener(this); mediaPlayer.reset(); DropboxConnect dropConnect = new DropboxConnect(getApplicationContext()); dropboxApi = dropConnect.getDropboxAPI(); nowplayingData = SongSQLite.getmInstance(getApplicationContext()); playingSongList = nowplayingData.getAllSong(SongSQLite.TABLE_NOWPLAYING, null); intCurrentSong = 0; if (playingSongList == null) playingSongList = new ArrayList<>(); // If Database is Emply intTotalSong = playingSongList.size(); updateCurrentSong(); initNotification(); Log.d(">>>> THAI <<<<", "onCreat() Service"); }
@Override public void onClick(View v) { if (dropboxConnect.isLinked()) { dropboxConnect.unLink(); dropboxConnect.clearAccessToken(); btnLinkToDropbox.setText("Link to DropBox"); } else dropboxConnect.getSession().startOAuth2Authentication(getActivity()); }
@Override public void onResume() { super.onResume(); dropboxConnect.saveAccessToken(); setLinked(dropboxConnect.isLinked()); Control.sendRefreshDropbox(); Log.d(">>>> THAI <<<<", "onResume() Fragment_Dropbox"); }
@Override public void onClick(View v) { if (dropboxConnect.isLinked()) { DropboxLoadFileList loadFileList = new DropboxLoadFileList( Fragment_Dropbox.this, dropboxConnect.getDropboxAPI(), DropboxConnect.MUSIC_DIR); loadFileList.execute(); } else { dropboxConnect.getSession().startOAuth2Authentication(getActivity()); } Log.d(">>>> THAI <<<<", "DropboxLoadFileList()"); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_dropbox, container, false); btnLinkToDropbox = (Button) rootView.findViewById(R.id.btnLinkToDropbox); btnLoadList = (Button) rootView.findViewById(R.id.btnLoadDropboxList); listDropbox = (ListView) rootView.findViewById(R.id.ListDropbox); adapter = new ArrayAdapter<SongItem>(getActivity(), android.R.layout.simple_list_item_1, songList); listDropbox.setAdapter(adapter); listDropbox.setOnItemClickListener(onDroptItempClick); btnLinkToDropbox.setOnClickListener(onClickLinktoDropbox); btnLoadList.setOnClickListener(onClickLoadListFile); setLinked(dropboxConnect.isLinked()); Log.d(">>>> THAI <<<<", "onCreateView() Fragment_Dropbox"); return rootView; }
@Override public void onReceive(Context context, Intent intent) { Log.d(">>>> THAI <<<<", "1. BroadcastReceiver controlReceiver - SERVICE"); int action = intent.getExtras().getInt(KEY_CONTROL_ACTION); switch (action) { case ACTION_CONTROL_SEEK: handler.removeCallbacks(sendUpdate2UI); int seekMediaTo = intent.getIntExtra(KEY_CONTROL_VALUE, 0); mediaPlayer.seekTo(seekMediaTo); handler.postDelayed(sendUpdate2UI, 1000); break; case ACTION_CONTROL_NEXT: NextAudio(); break; case ACTION_CONTROL_PREVIOUS: PrevousAudio(); break; case ACTION_CONTROL_START_PAUSE: TogglePlayAudio(); break; case ACTION_CONTROL_SELECT_SONG: intCurrentSong = intent.getIntExtra(KEY_CONTROL_VALUE, 0); StartAudio(); break; case ACTION_CONTROL_FAST_FORWARD: FastForward(10000); break; case ACTION_CONTROL_REWIND: Rewind(10000); break; case ACTION_CONTROL_STOP: StopAudio(); break; case ACTION_REQUEST_POSITION: sendFeedBackBroadcast( FEED_ACTION_SEND_POSITION, intCurrentSong, mediaPlayer.isPlaying()); break; case ACTION_GOT_URL: String sourceURL = intent.getStringExtra(KEY_CONTROL_VALUE); if (sourceURL != null) StartAudio(sourceURL); else Toast.makeText(getApplicationContext(), "Song URL is NULL", Toast.LENGTH_SHORT) .show(); break; case ACTION_CONTROL_SELECT_LIST: selectList(intent); intCurrentSong = intent.getIntExtra(KEY_SELECT_LIST_POSITION, 0); intTotalSong = playingSongList.size(); StartAudio(); break; case ACTION_CONTROL_ADD_ITEM: addtoNowplaying(intent); break; case ACTION_REFRESH_DROPBOX_API: DropboxConnect dropConnect = new DropboxConnect(getApplicationContext()); dropboxApi = dropConnect.getDropboxAPI(); break; default: break; } Log.d( ">>>> THAI <<<<", "2. BroadcastReceiver controlReceiver - SERVICE, Action = " + action); }