diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /mobile/android/base/java/org/mozilla/gecko/MediaCastingBar.java | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/base/java/org/mozilla/gecko/MediaCastingBar.java')
-rw-r--r-- | mobile/android/base/java/org/mozilla/gecko/MediaCastingBar.java | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/mobile/android/base/java/org/mozilla/gecko/MediaCastingBar.java b/mobile/android/base/java/org/mozilla/gecko/MediaCastingBar.java new file mode 100644 index 000000000..bd109058c --- /dev/null +++ b/mobile/android/base/java/org/mozilla/gecko/MediaCastingBar.java @@ -0,0 +1,131 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko; + +import org.mozilla.gecko.GeckoApp; +import org.mozilla.gecko.util.GeckoEventListener; +import org.mozilla.gecko.util.ThreadUtils; + +import org.json.JSONObject; + +import android.content.Context; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.ImageButton; +import android.widget.RelativeLayout; +import android.widget.TextView; + +public class MediaCastingBar extends RelativeLayout implements View.OnClickListener, GeckoEventListener { + private static final String LOGTAG = "GeckoMediaCastingBar"; + + private TextView mCastingTo; + private ImageButton mMediaPlay; + private ImageButton mMediaPause; + private ImageButton mMediaStop; + + private boolean mInflated; + + public MediaCastingBar(Context context, AttributeSet attrs) { + super(context, attrs); + + GeckoApp.getEventDispatcher().registerGeckoThreadListener(this, + "Casting:Started", + "Casting:Paused", + "Casting:Playing", + "Casting:Stopped"); + } + + public void inflateContent() { + LayoutInflater inflater = LayoutInflater.from(getContext()); + View content = inflater.inflate(R.layout.media_casting, this); + + mMediaPlay = (ImageButton) content.findViewById(R.id.media_play); + mMediaPlay.setOnClickListener(this); + mMediaPause = (ImageButton) content.findViewById(R.id.media_pause); + mMediaPause.setOnClickListener(this); + mMediaStop = (ImageButton) content.findViewById(R.id.media_stop); + mMediaStop.setOnClickListener(this); + + mCastingTo = (TextView) content.findViewById(R.id.media_sending_to); + + // Capture clicks on the rest of the view to prevent them from + // leaking into other views positioned below. + content.setOnClickListener(this); + + mInflated = true; + } + + public void show() { + if (!mInflated) + inflateContent(); + + setVisibility(VISIBLE); + } + + public void hide() { + setVisibility(GONE); + } + + public void onDestroy() { + GeckoApp.getEventDispatcher().unregisterGeckoThreadListener(this, + "Casting:Started", + "Casting:Paused", + "Casting:Playing", + "Casting:Stopped"); + } + + // View.OnClickListener implementation + @Override + public void onClick(View v) { + final int viewId = v.getId(); + + if (viewId == R.id.media_play) { + GeckoAppShell.notifyObservers("Casting:Play", ""); + mMediaPlay.setVisibility(GONE); + mMediaPause.setVisibility(VISIBLE); + } else if (viewId == R.id.media_pause) { + GeckoAppShell.notifyObservers("Casting:Pause", ""); + mMediaPause.setVisibility(GONE); + mMediaPlay.setVisibility(VISIBLE); + } else if (viewId == R.id.media_stop) { + GeckoAppShell.notifyObservers("Casting:Stop", ""); + } + } + + // GeckoEventListener implementation + @Override + public void handleMessage(final String event, final JSONObject message) { + final String device = message.optString("device"); + + ThreadUtils.postToUiThread(new Runnable() { + @Override + public void run() { + if (event.equals("Casting:Started")) { + show(); + if (!TextUtils.isEmpty(device)) { + mCastingTo.setText(device); + } else { + // Should not happen + mCastingTo.setText(""); + Log.d(LOGTAG, "Device name is empty."); + } + mMediaPlay.setVisibility(GONE); + mMediaPause.setVisibility(VISIBLE); + } else if (event.equals("Casting:Paused")) { + mMediaPause.setVisibility(GONE); + mMediaPlay.setVisibility(VISIBLE); + } else if (event.equals("Casting:Playing")) { + mMediaPlay.setVisibility(GONE); + mMediaPause.setVisibility(VISIBLE); + } else if (event.equals("Casting:Stopped")) { + hide(); + } + } + }); + } +} |