From: tobiasKaminsky Date: Fri, 13 Nov 2015 16:43:19 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/material_fab' into beta X-Git-Tag: beta-20151122~24 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/4e162ed4386f4388626b1b6387d54028e2466e1e?ds=inline;hp=-c Merge remote-tracking branch 'remotes/upstream/material_fab' into beta --- 4e162ed4386f4388626b1b6387d54028e2466e1e diff --combined src/com/owncloud/android/media/MediaService.java index 7bd9c0c6,5b865262..d6fbfcc2 --- a/src/com/owncloud/android/media/MediaService.java +++ b/src/com/owncloud/android/media/MediaService.java @@@ -21,32 -21,28 +21,33 @@@ package com.owncloud.android.media; import android.accounts.Account; +import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; import android.media.MediaPlayer.OnPreparedListener; +import android.net.Uri; import android.net.wifi.WifiManager; import android.net.wifi.WifiManager.WifiLock; import android.os.IBinder; import android.os.PowerManager; +import android.support.v7.app.AlertDialog; + import android.support.v7.app.NotificationCompat; import android.widget.Toast; import java.io.IOException; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; +import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; @@@ -128,7 -124,6 +129,6 @@@ public class MediaService extends Servi /** Notification to keep in the notification bar while a song is playing */ private NotificationManager mNotificationManager; - private Notification mNotification = null; /** File being played */ private OCFile mFile; @@@ -147,8 -142,9 +147,9 @@@ /** Control panel shown to the user to control the playback, to register through binding */ private MediaControlView mMediaController; - + /** Notification builder to create notifications, new reuse way since Android 6 */ + private NotificationCompat.Builder mNotificationBuilder; /** * Helper method to get an error message suitable to show to users for errors occurred in media playback, @@@ -215,25 -211,6 +216,25 @@@ return context.getString(messageId); } + public static AlertDialog.Builder streamWithExternalApp(final String uri, final Activity activity){ + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setMessage(activity.getString(R.string.stream_expose_password)) + .setPositiveButton(activity.getString(R.string.common_yes), + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(uri)); + activity.startActivity(i); + } + }) + .setNegativeButton(activity.getString(R.string.common_no), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // User cancelled the dialog + } + }); + return builder; + } + /** @@@ -250,6 -227,8 +251,8 @@@ createWifiLock(WifiManager.WIFI_MODE_FULL, MEDIA_WIFI_LOCK_TAG); mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + mNotificationBuilder = new NotificationCompat.Builder(this); + mNotificationBuilder.setColor(this.getResources().getColor(R.color.primary)); mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); mBinder = new MediaServiceBinder(this); } @@@ -310,7 -289,6 +313,6 @@@ mState = State.PLAYING; setUpAsForeground(String.format(getString(R.string.media_state_playing), mFile.getFileName())); configAndStartMediaPlayer(); - } } @@@ -454,7 -432,12 +456,7 @@@ releaseResources(false); // release everything except MediaPlayer try { - if (mFile == null) { - Toast.makeText(this, R.string.media_err_nothing_to_play, Toast.LENGTH_LONG).show(); - processStopRequest(true); - return; - - } else if (mAccount == null) { + if (mAccount == null) { Toast.makeText(this, R.string.media_err_not_in_owncloud, Toast.LENGTH_LONG).show(); processStopRequest(true); return; @@@ -463,12 -446,12 +465,12 @@@ createMediaPlayerIfNeeded(); mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); String url = mFile.getStoragePath(); - /* Streaming is not possible right now + if (url == null || url.length() <= 0) { url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath(); } mIsStreaming = url.startsWith("http:") || url.startsWith("https:"); - */ + mIsStreaming = false; mPlayer.setDataSource(url); @@@ -505,8 -488,6 +507,8 @@@ Log_OC.e(TAG, "IllegalArgumentException " + mAccount.name + mFile.getRemotePath(), e); Toast.makeText(this, String.format(getString(R.string.media_err_unexpected), mFile.getFileName()), Toast.LENGTH_LONG).show(); processStopRequest(true); + } catch (AccountUtils.AccountNotFoundException e) { + e.printStackTrace(); } } @@@ -553,22 -534,25 +555,25 @@@ /** * Updates the status notification */ - @SuppressWarnings("deprecation") private void updateNotification(String content) { + String ticker = String.format(getString(R.string.media_notif_ticker), getString(R.string.app_name)); + // TODO check if updating the Intent is really necessary Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class); showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, mFile); showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount); showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), - (int)System.currentTimeMillis(), - showDetailsIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - mNotification.when = System.currentTimeMillis(); - //mNotification.contentView.setTextViewText(R.id.status_text, content); - String ticker = String.format(getString(R.string.media_notif_ticker), getString(R.string.app_name)); - mNotification.setLatestEventInfo(getApplicationContext(), ticker, content, mNotification.contentIntent); - mNotificationManager.notify(R.string.media_notif_ticker, mNotification); + + mNotificationBuilder.setContentIntent(PendingIntent.getActivity(getApplicationContext(), + (int) System.currentTimeMillis(), + showDetailsIntent, + PendingIntent.FLAG_UPDATE_CURRENT)); + mNotificationBuilder.setWhen(System.currentTimeMillis()); + mNotificationBuilder.setTicker(ticker); + mNotificationBuilder.setContentTitle(ticker); + mNotificationBuilder.setContentText(content); + + mNotificationManager.notify(R.string.media_notif_ticker, mNotificationBuilder.build()); } @@@ -579,35 -563,29 +584,29 @@@ * * A notification must be created to keep the user aware of the existance of the service. */ - @SuppressWarnings("deprecation") private void setUpAsForeground(String content) { + String ticker = String.format(getString(R.string.media_notif_ticker), getString(R.string.app_name)); + /// creates status notification // TODO put a progress bar to follow the playback progress - mNotification = new Notification(); - mNotification.icon = android.R.drawable.ic_media_play; + mNotificationBuilder.setSmallIcon(R.drawable.ic_play_arrow); //mNotification.tickerText = text; - mNotification.when = System.currentTimeMillis(); - mNotification.flags |= Notification.FLAG_ONGOING_EVENT; - //mNotification.contentView.setTextViewText(R.id.status_text, "ownCloud Music Player"); // NULL POINTER - //mNotification.contentView.setTextViewText(R.id.status_text, getString(R.string.downloader_download_in_progress_content)); - + mNotificationBuilder.setWhen(System.currentTimeMillis()); + mNotificationBuilder.setOngoing(true); /// includes a pending intent in the notification showing the details view of the file Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class); showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, mFile); showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount); showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - mNotification.contentIntent = PendingIntent.getActivity(getApplicationContext(), - (int)System.currentTimeMillis(), - showDetailsIntent, - PendingIntent.FLAG_UPDATE_CURRENT); - - - //mNotificationManager.notify(R.string.downloader_download_in_progress_ticker, mNotification); - String ticker = String.format(getString(R.string.media_notif_ticker), getString(R.string.app_name)); - mNotification.setLatestEventInfo(getApplicationContext(), ticker, content, mNotification.contentIntent); - startForeground(R.string.media_notif_ticker, mNotification); - + mNotificationBuilder.setContentIntent(PendingIntent.getActivity(getApplicationContext(), + (int) System.currentTimeMillis(), + showDetailsIntent, + PendingIntent.FLAG_UPDATE_CURRENT)); + mNotificationBuilder.setContentTitle(ticker); + mNotificationBuilder.setContentText(content); + + startForeground(R.string.media_notif_ticker, mNotificationBuilder.build()); } /** @@@ -660,6 -638,7 +659,7 @@@ mState = State.STOPPED; releaseResources(true); giveUpAudioFocus(); + stopForeground(true); super.onDestroy(); }