PageRenderTime 34ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/android.policy/java/jd-gui/miui/app/screenelement/elements/MusicControlScreenElement.java

https://bitbucket.org/chaos_rom/miui_frameworks
Java | 558 lines | 530 code | 24 blank | 4 comment | 123 complexity | 9edd791467d956e61a6a395dbf10ded4 MD5 | raw file
  1. package miui.app.screenelement.elements;
  2. import android.content.BroadcastReceiver;
  3. import android.content.Context;
  4. import android.content.Intent;
  5. import android.content.IntentFilter;
  6. import android.graphics.Bitmap;
  7. import android.graphics.BitmapFactory;
  8. import android.media.AudioManager;
  9. import android.net.Uri;
  10. import android.os.Handler;
  11. import android.os.SystemClock;
  12. import android.text.TextUtils;
  13. import android.util.Log;
  14. import android.view.KeyEvent;
  15. import java.util.ArrayList;
  16. import java.util.Iterator;
  17. import miui.app.screenelement.ResourceManager;
  18. import miui.app.screenelement.ScreenContext;
  19. import miui.app.screenelement.ScreenElementLoadException;
  20. import miui.app.screenelement.ScreenElementRoot;
  21. import miui.app.screenelement.util.IndexedNumberVariable;
  22. import miui.app.screenelement.util.Utils;
  23. import miui.util.AudioOutputHelper;
  24. import org.w3c.dom.Element;
  25. public class MusicControlScreenElement extends ElementGroup
  26. implements ButtonScreenElement.ButtonActionListener
  27. {
  28. private static final String BUTTON_MUSIC_NEXT = "music_next";
  29. private static final String BUTTON_MUSIC_PAUSE = "music_pause";
  30. private static final String BUTTON_MUSIC_PLAY = "music_play";
  31. private static final String BUTTON_MUSIC_PREV = "music_prev";
  32. private static final int CHECK_STREAM_MUSIC_DELAY = 1000;
  33. private static final String ELE_MUSIC_ALBUM_COVER = "music_album_cover";
  34. private static final String ELE_MUSIC_DISPLAY = "music_display";
  35. private static final int FRAMERATE_PLAYING = 30;
  36. private static final String LOG_TAG = "MusicControlScreenElement";
  37. private static final int MUSIC_NONE = 0;
  38. private static final int MUSIC_PLAY = 2;
  39. private static final int MUSIC_STOP = 1;
  40. public static final String TAG_NAME = "MusicControl";
  41. private boolean isPaused = false;
  42. private Bitmap mAlbumCoverBm;
  43. private String mAlbumName;
  44. private String mArtistName;
  45. private AudioManager mAudioManager;
  46. private boolean mAutoShow;
  47. private ButtonScreenElement mButtonNext = (ButtonScreenElement)findElement("music_next");
  48. private ButtonScreenElement mButtonPause = (ButtonScreenElement)findElement("music_pause");
  49. private ButtonScreenElement mButtonPlay = (ButtonScreenElement)findElement("music_play");
  50. private ButtonScreenElement mButtonPrev = (ButtonScreenElement)findElement("music_prev");
  51. private Runnable mCheckStreamMusicRunnable = new Runnable()
  52. {
  53. public void run()
  54. {
  55. MusicControlScreenElement.this.updateMusic();
  56. MusicControlScreenElement.this.updateSpectrumVisualizer();
  57. MusicControlScreenElement.this.mHandler.postDelayed(this, 1000L);
  58. }
  59. };
  60. private Bitmap mDefaultAlbumCoverBm;
  61. private Runnable mEnableSpectrumVisualizerRunnable = new Runnable()
  62. {
  63. public void run()
  64. {
  65. MusicControlScreenElement.this.mHandler.removeCallbacks(MusicControlScreenElement.this.mEnableSpectrumVisualizerRunnable);
  66. MusicControlScreenElement.this.updateSpectrumVisualizer();
  67. }
  68. };
  69. private final Handler mHandler = new Handler();
  70. private ImageScreenElement mImageAlbumCover = (ImageScreenElement)findElement("music_album_cover");
  71. private boolean mIsOnlineSongBlocking;
  72. private IndexedNumberVariable mMusicStateVar;
  73. private int mMusicStatus;
  74. private BroadcastReceiver mPlayerStatusListener = new BroadcastReceiver()
  75. {
  76. private void setTrackInfo(Intent paramAnonymousIntent)
  77. {
  78. if (MusicControlScreenElement.this.mTextDisplay == null);
  79. String str1;
  80. String str2;
  81. while (true)
  82. {
  83. return;
  84. str1 = paramAnonymousIntent.getStringExtra("track");
  85. str2 = paramAnonymousIntent.getStringExtra("artist");
  86. MusicControlScreenElement.access$402(MusicControlScreenElement.this, false);
  87. if ((!TextUtils.isEmpty(str1)) || (!TextUtils.isEmpty(str2)))
  88. break;
  89. MusicControlScreenElement.this.mTextDisplay.show(false);
  90. }
  91. if (TextUtils.isEmpty(str1))
  92. MusicControlScreenElement.this.mTextDisplay.setText(str2);
  93. while (true)
  94. {
  95. MusicControlScreenElement.this.mTextDisplay.show(true);
  96. break;
  97. if (TextUtils.isEmpty(str2))
  98. {
  99. MusicControlScreenElement.this.mTextDisplay.setText(str1);
  100. }
  101. else
  102. {
  103. TextScreenElement localTextScreenElement = MusicControlScreenElement.this.mTextDisplay;
  104. Object[] arrayOfObject = new Object[2];
  105. arrayOfObject[0] = str1;
  106. arrayOfObject[1] = str2;
  107. localTextScreenElement.setText(String.format("%s %s", arrayOfObject));
  108. }
  109. }
  110. }
  111. public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
  112. {
  113. String str1 = paramAnonymousIntent.getAction();
  114. if (!paramAnonymousIntent.getBooleanExtra("playing", false));
  115. while (true)
  116. {
  117. return;
  118. if ("com.miui.player.metachanged".equals(str1))
  119. {
  120. String str2 = paramAnonymousIntent.getStringExtra("other");
  121. if ("meta_changed_track".equals(str2))
  122. {
  123. setTrackInfo(paramAnonymousIntent);
  124. MusicControlScreenElement.this.requestAlbum(paramAnonymousIntent);
  125. }
  126. else if ("meta_changed_album".equals(str2))
  127. {
  128. MusicControlScreenElement.this.requestAlbum(paramAnonymousIntent, true);
  129. }
  130. else
  131. {
  132. MusicControlScreenElement.this.requestAlbum();
  133. }
  134. }
  135. else if ("lockscreen.action.SONG_METADATA_UPDATED".equals(str1))
  136. {
  137. setTrackInfo(paramAnonymousIntent);
  138. MusicControlScreenElement.this.setAlbumCover(paramAnonymousIntent);
  139. }
  140. else if ("com.miui.player.refreshprogress".equals(str1))
  141. {
  142. MusicControlScreenElement.access$402(MusicControlScreenElement.this, paramAnonymousIntent.getBooleanExtra("blocking", false));
  143. }
  144. else if ("com.miui.player.playstatechanged".equals(str1))
  145. {
  146. if ((MusicControlScreenElement.this.mTextDisplay != null) && (!MusicControlScreenElement.this.mTextDisplay.isVisible()))
  147. setTrackInfo(paramAnonymousIntent);
  148. MusicControlScreenElement.this.requestAlbum(paramAnonymousIntent);
  149. }
  150. }
  151. }
  152. };
  153. private SpectrumVisualizerScreenElement mSpectrumVisualizer = findSpectrumVisualizer(this);
  154. private TextScreenElement mTextDisplay = (TextScreenElement)findElement("music_display");
  155. public MusicControlScreenElement(Element paramElement, ScreenContext paramScreenContext, ScreenElementRoot paramScreenElementRoot)
  156. throws ScreenElementLoadException
  157. {
  158. super(paramElement, paramScreenContext, paramScreenElementRoot);
  159. if ((this.mButtonPrev == null) || (this.mButtonNext == null) || (this.mButtonPlay == null) || (this.mButtonPause == null))
  160. throw new ScreenElementLoadException("invalid music control");
  161. setupButton(this.mButtonPrev);
  162. setupButton(this.mButtonNext);
  163. setupButton(this.mButtonPlay);
  164. setupButton(this.mButtonPause);
  165. this.mButtonPause.show(false);
  166. String str;
  167. if (this.mImageAlbumCover != null)
  168. {
  169. str = paramElement.getAttribute("defAlbumCover");
  170. if (TextUtils.isEmpty(str))
  171. break label346;
  172. }
  173. label346: for (this.mDefaultAlbumCoverBm = this.mContext.mResourceManager.getBitmap(str); ; this.mDefaultAlbumCoverBm = BitmapFactory.decodeResource(this.mContext.mContext.getResources(), 100794537))
  174. {
  175. if (this.mDefaultAlbumCoverBm != null)
  176. this.mDefaultAlbumCoverBm.setDensity(this.mRoot.getResourceDensity());
  177. this.mAutoShow = Boolean.parseBoolean(paramElement.getAttribute("autoShow"));
  178. this.mAudioManager = ((AudioManager)paramScreenContext.mContext.getSystemService("audio"));
  179. if (this.mHasName)
  180. this.mMusicStateVar = new IndexedNumberVariable(this.mName, "music_state", paramScreenContext.mVariables);
  181. return;
  182. }
  183. }
  184. private SpectrumVisualizerScreenElement findSpectrumVisualizer(ElementGroup paramElementGroup)
  185. {
  186. Iterator localIterator = paramElementGroup.getElements().iterator();
  187. ScreenElement localScreenElement;
  188. Object localObject;
  189. if (localIterator.hasNext())
  190. {
  191. localScreenElement = (ScreenElement)localIterator.next();
  192. if ((localScreenElement instanceof SpectrumVisualizerScreenElement))
  193. localObject = (SpectrumVisualizerScreenElement)localScreenElement;
  194. }
  195. while (true)
  196. {
  197. return localObject;
  198. if (!(localScreenElement instanceof ElementGroup))
  199. break;
  200. SpectrumVisualizerScreenElement localSpectrumVisualizerScreenElement = findSpectrumVisualizer((ElementGroup)localScreenElement);
  201. if (localSpectrumVisualizerScreenElement == null)
  202. break;
  203. localObject = localSpectrumVisualizerScreenElement;
  204. continue;
  205. localObject = null;
  206. }
  207. }
  208. private int getKeyCode(String paramString)
  209. {
  210. int i;
  211. if ("music_prev".equals(paramString))
  212. i = 88;
  213. while (true)
  214. {
  215. return i;
  216. if ("music_next".equals(paramString))
  217. i = 87;
  218. else if (("music_play".equals(paramString)) || ("music_pause".equals(paramString)))
  219. i = 85;
  220. else
  221. i = -1;
  222. }
  223. }
  224. private void requestAlbum()
  225. {
  226. Intent localIntent = new Intent("lockscreen.action.SONG_METADATA_REQUEST");
  227. this.mContext.mContext.sendBroadcast(localIntent);
  228. }
  229. private void requestAlbum(Intent paramIntent)
  230. {
  231. requestAlbum(paramIntent, false);
  232. }
  233. private void requestAlbum(Intent paramIntent, boolean paramBoolean)
  234. {
  235. if (this.mImageAlbumCover == null);
  236. while (true)
  237. {
  238. return;
  239. String str1 = paramIntent.getStringExtra("album");
  240. String str2 = paramIntent.getStringExtra("artist");
  241. if ((paramBoolean) || (!Utils.equals(str1, this.mAlbumName)) || (!Utils.equals(str2, this.mArtistName)) || (this.mAlbumCoverBm == null))
  242. {
  243. Uri localUri = (Uri)paramIntent.getParcelableExtra("album_uri");
  244. String str3 = paramIntent.getStringExtra("album_path");
  245. this.mAlbumCoverBm = null;
  246. if ((localUri != null) || (str3 != null))
  247. requestAlbum();
  248. else
  249. this.mImageAlbumCover.setBitmap(this.mDefaultAlbumCoverBm);
  250. }
  251. }
  252. }
  253. private void sendMediaButtonBroadcast(int paramInt1, int paramInt2)
  254. {
  255. long l = SystemClock.uptimeMillis();
  256. KeyEvent localKeyEvent = new KeyEvent(l, l, paramInt1, paramInt2, 0);
  257. Intent localIntent = new Intent("android.intent.action.MEDIA_BUTTON", null);
  258. localIntent.putExtra("android.intent.extra.KEY_EVENT", KeyEvent.changeFlags(localKeyEvent, 8));
  259. localIntent.putExtra("forbid_double_click", true);
  260. this.mContext.mContext.sendOrderedBroadcast(localIntent, null);
  261. }
  262. private void setAlbumCover(Intent paramIntent)
  263. {
  264. if (this.mImageAlbumCover == null);
  265. ImageScreenElement localImageScreenElement1;
  266. while (true)
  267. {
  268. return;
  269. this.mAlbumName = paramIntent.getStringExtra("album");
  270. this.mArtistName = paramIntent.getStringExtra("artist");
  271. try
  272. {
  273. String str = paramIntent.getStringExtra("tmp_album_path");
  274. if (str != null)
  275. {
  276. this.mAlbumCoverBm = BitmapFactory.decodeFile(str);
  277. if (this.mAlbumCoverBm != null)
  278. this.mAlbumCoverBm.setDensity(this.mRoot.getResourceDensity());
  279. }
  280. ImageScreenElement localImageScreenElement3 = this.mImageAlbumCover;
  281. if (this.mAlbumCoverBm != null);
  282. for (Bitmap localBitmap3 = this.mAlbumCoverBm; ; localBitmap3 = this.mDefaultAlbumCoverBm)
  283. {
  284. localImageScreenElement3.setBitmap(localBitmap3);
  285. requestUpdate();
  286. break;
  287. }
  288. }
  289. catch (OutOfMemoryError localOutOfMemoryError)
  290. {
  291. Log.e("MusicControlScreenElement", "failed to load album cover bitmap: " + localOutOfMemoryError.toString());
  292. ImageScreenElement localImageScreenElement2 = this.mImageAlbumCover;
  293. if (this.mAlbumCoverBm != null);
  294. for (Bitmap localBitmap2 = this.mAlbumCoverBm; ; localBitmap2 = this.mDefaultAlbumCoverBm)
  295. {
  296. localImageScreenElement2.setBitmap(localBitmap2);
  297. requestUpdate();
  298. break;
  299. }
  300. }
  301. finally
  302. {
  303. localImageScreenElement1 = this.mImageAlbumCover;
  304. if (this.mAlbumCoverBm == null);
  305. }
  306. }
  307. for (Bitmap localBitmap1 = this.mAlbumCoverBm; ; localBitmap1 = this.mDefaultAlbumCoverBm)
  308. {
  309. localImageScreenElement1.setBitmap(localBitmap1);
  310. requestUpdate();
  311. throw localObject;
  312. }
  313. }
  314. private void setupButton(ButtonScreenElement paramButtonScreenElement)
  315. {
  316. if (paramButtonScreenElement != null)
  317. {
  318. paramButtonScreenElement.setListener(this);
  319. paramButtonScreenElement.setParent(this);
  320. }
  321. }
  322. private void updateMusic()
  323. {
  324. boolean bool1 = false;
  325. int i = 1;
  326. boolean bool2 = this.mAudioManager.isMusicActive();
  327. if (!bool2)
  328. {
  329. int j = i;
  330. if (this.mIsOnlineSongBlocking)
  331. j = 0;
  332. this.mButtonPlay.show(j);
  333. ButtonScreenElement localButtonScreenElement = this.mButtonPause;
  334. if (j == 0)
  335. bool1 = i;
  336. localButtonScreenElement.show(bool1);
  337. switch (this.mMusicStatus)
  338. {
  339. default:
  340. label84: if (!bool2)
  341. break;
  342. case 1:
  343. case 2:
  344. }
  345. }
  346. for (float f = 30.0F; ; f = 0.0F)
  347. {
  348. requestFramerate(f);
  349. return;
  350. int k = 0;
  351. break;
  352. if (bool2)
  353. i = 2;
  354. this.mMusicStatus = i;
  355. if (!this.mHasName)
  356. break label84;
  357. IndexedNumberVariable localIndexedNumberVariable = this.mMusicStateVar;
  358. if (bool2);
  359. for (double d = 1.0D; ; d = 0.0D)
  360. {
  361. localIndexedNumberVariable.set(d);
  362. break;
  363. }
  364. }
  365. }
  366. public void finish()
  367. {
  368. this.mHandler.removeCallbacks(this.mCheckStreamMusicRunnable);
  369. try
  370. {
  371. this.mContext.mContext.unregisterReceiver(this.mPlayerStatusListener);
  372. if (this.mSpectrumVisualizer != null)
  373. this.mSpectrumVisualizer.enableUpdate(false);
  374. return;
  375. }
  376. catch (IllegalArgumentException localIllegalArgumentException)
  377. {
  378. while (true)
  379. {
  380. Log.e("MusicControlScreenElement", localIllegalArgumentException.toString());
  381. localIllegalArgumentException.printStackTrace();
  382. }
  383. }
  384. }
  385. public void init()
  386. {
  387. super.init();
  388. IntentFilter localIntentFilter = new IntentFilter();
  389. localIntentFilter.addAction("com.miui.player.metachanged");
  390. localIntentFilter.addAction("lockscreen.action.SONG_METADATA_UPDATED");
  391. localIntentFilter.addAction("com.miui.player.refreshprogress");
  392. localIntentFilter.addAction("com.miui.player.playstatechanged");
  393. this.mContext.mContext.registerReceiver(this.mPlayerStatusListener, localIntentFilter, null, this.mHandler);
  394. boolean bool = AudioOutputHelper.hasActiveReceivers(this.mContext.mContext);
  395. if (bool)
  396. {
  397. this.mMusicStatus = 2;
  398. Intent localIntent = new Intent("lockscreen.action.SONG_METADATA_REQUEST");
  399. this.mContext.mContext.sendBroadcast(localIntent);
  400. if (this.mAutoShow)
  401. show(true);
  402. }
  403. IndexedNumberVariable localIndexedNumberVariable;
  404. if (this.mHasName)
  405. {
  406. localIndexedNumberVariable = this.mMusicStateVar;
  407. if (!bool)
  408. break label145;
  409. }
  410. label145: for (double d = 1.0D; ; d = 0.0D)
  411. {
  412. localIndexedNumberVariable.set(d);
  413. return;
  414. }
  415. }
  416. public boolean onButtonDoubleClick(String paramString)
  417. {
  418. return false;
  419. }
  420. public boolean onButtonDown(String paramString)
  421. {
  422. boolean bool = false;
  423. int i = getKeyCode(paramString);
  424. if (i == -1);
  425. while (true)
  426. {
  427. return bool;
  428. sendMediaButtonBroadcast(0, i);
  429. bool = true;
  430. }
  431. }
  432. public boolean onButtonLongClick(String paramString)
  433. {
  434. return false;
  435. }
  436. public boolean onButtonUp(final String paramString)
  437. {
  438. int i = 1;
  439. int j = getKeyCode(paramString);
  440. if (j == -1)
  441. i = 0;
  442. while (true)
  443. {
  444. return i;
  445. sendMediaButtonBroadcast(i, j);
  446. this.mHandler.post(new Runnable()
  447. {
  448. public void run()
  449. {
  450. if ("music_pause".equals(paramString))
  451. {
  452. MusicControlScreenElement.this.mButtonPause.show(false);
  453. MusicControlScreenElement.this.mButtonPlay.show(true);
  454. MusicControlScreenElement.access$1102(MusicControlScreenElement.this, 1);
  455. if (MusicControlScreenElement.this.mHasName)
  456. MusicControlScreenElement.this.mMusicStateVar.set(0.0D);
  457. MusicControlScreenElement.this.requestFramerate(0.0F);
  458. }
  459. while (true)
  460. {
  461. MusicControlScreenElement.this.mHandler.removeCallbacks(MusicControlScreenElement.this.mCheckStreamMusicRunnable);
  462. MusicControlScreenElement.this.mHandler.postDelayed(MusicControlScreenElement.this.mCheckStreamMusicRunnable, 3000L);
  463. MusicControlScreenElement.this.mHandler.removeCallbacks(MusicControlScreenElement.this.mEnableSpectrumVisualizerRunnable);
  464. MusicControlScreenElement.this.mHandler.postDelayed(MusicControlScreenElement.this.mEnableSpectrumVisualizerRunnable, 500L);
  465. return;
  466. if ("music_play".equals(paramString))
  467. {
  468. MusicControlScreenElement.this.mButtonPlay.show(false);
  469. MusicControlScreenElement.this.mButtonPause.show(true);
  470. MusicControlScreenElement.access$1102(MusicControlScreenElement.this, 2);
  471. if (MusicControlScreenElement.this.mHasName)
  472. MusicControlScreenElement.this.mMusicStateVar.set(1.0D);
  473. MusicControlScreenElement.this.requestFramerate(30.0F);
  474. MusicControlScreenElement.this.requestAlbum();
  475. }
  476. }
  477. }
  478. });
  479. }
  480. }
  481. public void pause()
  482. {
  483. super.pause();
  484. this.isPaused = true;
  485. this.mHandler.removeCallbacks(this.mCheckStreamMusicRunnable);
  486. if (this.mSpectrumVisualizer != null)
  487. this.mSpectrumVisualizer.enableUpdate(false);
  488. }
  489. public void resume()
  490. {
  491. super.resume();
  492. this.isPaused = false;
  493. if (isVisible())
  494. this.mHandler.postDelayed(this.mCheckStreamMusicRunnable, 1000L);
  495. }
  496. public void show(boolean paramBoolean)
  497. {
  498. super.show(paramBoolean);
  499. if (!paramBoolean)
  500. {
  501. this.mMusicStatus = 0;
  502. this.mHandler.removeCallbacks(this.mCheckStreamMusicRunnable);
  503. if (this.mSpectrumVisualizer != null)
  504. this.mSpectrumVisualizer.enableUpdate(false);
  505. requestFramerate(0.0F);
  506. }
  507. while (true)
  508. {
  509. return;
  510. updateMusic();
  511. this.mHandler.postDelayed(this.mCheckStreamMusicRunnable, 1000L);
  512. }
  513. }
  514. protected void updateSpectrumVisualizer()
  515. {
  516. boolean bool1 = this.mAudioManager.isMusicActive();
  517. SpectrumVisualizerScreenElement localSpectrumVisualizerScreenElement;
  518. if (this.mSpectrumVisualizer != null)
  519. {
  520. localSpectrumVisualizerScreenElement = this.mSpectrumVisualizer;
  521. if ((!bool1) || (!isVisible()) || (this.isPaused))
  522. break label46;
  523. }
  524. label46: for (boolean bool2 = true; ; bool2 = false)
  525. {
  526. localSpectrumVisualizerScreenElement.enableUpdate(bool2);
  527. return;
  528. }
  529. }
  530. }
  531. /* Location: /home/lithium/miui/chameleon/2.11.16/android.policy_dex2jar.jar
  532. * Qualified Name: miui.app.screenelement.elements.MusicControlScreenElement
  533. * JD-Core Version: 0.6.2
  534. */