<p dir="ltr">retry</p>
<div class="gmail_quote">On Sep 6, 2014 4:44 PM, "Mik Amchislavsky" <<a href="mailto:hailmikhail@gmail.com">hailmikhail@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Focus support</div><div> </div><div>Audio fragment focus change support.</div><div><br></div><div><div><br></div><div>index 71605f4..c81444b 100644</div><div>--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java</div><div>+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java</div><div>@@ -726,6 +726,30 @@ public class MainActivity extends ActionBarActivity {</div><div> <span style="white-space:pre-wrap"> </span>public boolean onKeyUp(int keyCode, KeyEvent event) {</div><div> <span style="white-space:pre-wrap"> </span>int id = getCurrentFocus().getId();<span style="white-space:pre-wrap"> </span></div><div> </div><div>+<span style="white-space:pre-wrap"> </span>/* Scope reduction.</div><div>+<span style="white-space:pre-wrap"> </span> * </div><div>+<span style="white-space:pre-wrap"> </span> * Simplify logic by limiting mFlingViewGroup scrolling</div><div>+<span style="white-space:pre-wrap"> </span> * in AudioBrowserFragment to the header.</div><div>+<span style="white-space:pre-wrap"> </span> * <span style="white-space:pre-wrap"> </span> </div><div>+<span style="white-space:pre-wrap"> </span> * In the future, remove this restriction and support scrolling.<span style="white-space:pre-wrap"> </span> </div><div>+<span style="white-space:pre-wrap"> </span> */</div><div>+<span style="white-space:pre-wrap"> </span>if (mCurrentFragment.equals("audio")) {</div><div>+<span style="white-space:pre-wrap"> </span>if ((id == R.id.songs_list) ||</div><div>+<span style="white-space:pre-wrap"> </span>(id == R.id.genres_list) ||</div><div>+<span style="white-space:pre-wrap"> </span>(id == R.id.artists_list) ||</div><div>+<span style="white-space:pre-wrap"> </span>(id == R.id.albums_list))<span style="white-space:pre-wrap"> </span></div><div>+<span style="white-space:pre-wrap"> </span>mFocusedPrior = id;</div><div>+<span style="white-space:pre-wrap"> </span>else if (((mFocusedPrior == R.id.songs_list) ||</div><div>+<span style="white-space:pre-wrap"> </span>(mFocusedPrior == R.id.genres_list) ||</div><div>+<span style="white-space:pre-wrap"> </span>(mFocusedPrior == R.id.artists_list) ||</div><div>+<span style="white-space:pre-wrap"> </span>(mFocusedPrior == R.id.albums_list)) &&</div><div>+<span style="white-space:pre-wrap"> </span> ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) ||</div><div>+<span style="white-space:pre-wrap"> </span>(keyCode == KeyEvent.KEYCODE_DPAD_LEFT))) {</div><div>+<span style="white-space:pre-wrap"> </span>findViewById(R.id.header).requestFocus();</div><div>+<span style="white-space:pre-wrap"> </span>return true;</div><div>+<span style="white-space:pre-wrap"> </span>}</div><div>+<span style="white-space:pre-wrap"> </span>}</div><div>+</div><div> <span style="white-space:pre-wrap"> </span>/* Menu-opening automation for Overlflow and Sliding</div><div> <span style="white-space:pre-wrap"> </span> * menus.</div><div> <span style="white-space:pre-wrap"> </span> * </div><div><br></div><div>index 187f5a0..2734e25 100644</div><div>--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java</div><div>+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java</div><div>@@ -65,6 +65,8 @@ import android.widget.ListView;</div><div> import android.widget.PopupMenu;</div><div> import android.widget.PopupMenu.OnMenuItemClickListener;</div><div> </div><div>+import android.view.KeyEvent;</div><div>+</div><div> public class AudioBrowserFragment extends Fragment {</div><div> public final static String TAG = "VLC/AudioBrowserFragment";</div><div> </div><div>@@ -87,7 +89,9 @@ public class AudioBrowserFragment extends Fragment {</div><div> public final static int MODE_ALBUM = 1;</div><div> public final static int MODE_SONG = 2;</div><div> public final static int MODE_GENRE = 3;</div><div>+<span style="white-space:pre-wrap"> </span></div><div>+<span style="white-space:pre-wrap"> </span>private ListView[] mLists;</div><div>+<span style="white-space:pre-wrap"> </span></div><div> /* All subclasses of Fragment must include a public empty constructor. */</div><div> public AudioBrowserFragment() { }</div><div> </div><div>@@ -128,7 +132,8 @@ public class AudioBrowserFragment extends Fragment {</div><div> return true;</div><div> }</div><div> });</div><div><br></div><div>+<span style="white-space:pre-wrap"> </span>mHeader.setOnKeyListener(keyListener);</div><div>+<span style="white-space:pre-wrap"> </span></div><div> mEmptyView = v.findViewById(R.id.no_media);</div><div> </div><div> ListView songsList = (ListView)v.findViewById(R.id.songs_list);</div><div>@@ -146,6 +151,22 @@ public class AudioBrowserFragment extends Fragment {</div><div> albumList.setOnItemClickListener(albumListListener);</div><div> genreList.setOnItemClickListener(genreListListener);</div><div> </div><div>+<span style="white-space:pre-wrap"> </span>/* Focus support.</div><div>+<span style="white-space:pre-wrap"> </span> * </div><div>+<span style="white-space:pre-wrap"> </span> * For convenience, create an array of ListViews to be</div><div>+<span style="white-space:pre-wrap"> </span> * used within event handlers.</div><div>+<span style="white-space:pre-wrap"> </span> * <span style="white-space:pre-wrap"> </span> </div><div>+<span style="white-space:pre-wrap"> </span> * Set common properties associated with focus support.</div><div>+<span style="white-space:pre-wrap"> </span> */</div><div>+<span style="white-space:pre-wrap"> </span>mLists = new ListView[] {artistList, albumList, songsList, genreList};<span style="white-space:pre-wrap"> </span></div><div>+<span style="white-space:pre-wrap"> </span>{</div><div>+<span style="white-space:pre-wrap"> </span>int i;</div><div>+<span style="white-space:pre-wrap"> </span>for (i=0;i<MODE_TOTAL;i++) {</div><div>+<span style="white-space:pre-wrap"> </span>mLists[i].setOnKeyListener(keyListener);</div><div>+<span style="white-space:pre-wrap"> </span>mLists[i].setFocusable(false); </div><div>+<span style="white-space:pre-wrap"> </span>}</div><div>+<span style="white-space:pre-wrap"> </span>}</div><div>+</div><div> registerForContextMenu(songsList);</div><div> registerForContextMenu(artistList);</div><div> registerForContextMenu(albumList);</div><div>@@ -168,8 +189,51 @@ public class AudioBrowserFragment extends Fragment {</div><div> mHeader.scroll(mFlingViewPosition / 3.f);</div><div> updateLists();</div><div> mMediaLibrary.addUpdateHandler(mHandler);</div><div>+ mLists[mFlingViewPosition].setFocusable(true);</div><div> }</div><div> </div><div>+<span style="white-space:pre-wrap"> </span>// Focus support. Start.</div><div>+<span style="white-space:pre-wrap"> </span>View.OnKeyListener keyListener = new View.OnKeyListener() {</div><div>+<span style="white-space:pre-wrap"> </span>@Override</div><div>+<span style="white-space:pre-wrap"> </span>public boolean onKey(View v, int keyCode, KeyEvent event) {<span style="white-space:pre-wrap"> </span></div><div>+<span style="white-space:pre-wrap"> </span>int newPosition = mFlingViewPosition;</div><div>+</div><div>+<span style="white-space:pre-wrap"> </span>if (event.getAction() != KeyEvent.ACTION_UP)</div><div>+<span style="white-space:pre-wrap"> </span>return false;</div><div>+</div><div>+<span style="white-space:pre-wrap"> </span>/* Scope reduction.</div><div>+<span style="white-space:pre-wrap"> </span> * Simplify logic by limiting scrolling to the header.</div><div>+<span style="white-space:pre-wrap"> </span> */</div><div>+<span style="white-space:pre-wrap"> </span>if (!mHeader.isFocused())</div><div>+<span style="white-space:pre-wrap"> </span>return false;</div><div>+</div><div>+<span style="white-space:pre-wrap"> </span>switch (event.getKeyCode()) {</div><div>+<span style="white-space:pre-wrap"> </span>case KeyEvent.KEYCODE_DPAD_RIGHT:</div><div>+<span style="white-space:pre-wrap"> </span>if (newPosition < (MODE_TOTAL - 1))</div><div>+<span style="white-space:pre-wrap"> </span>newPosition++;</div><div>+<span style="white-space:pre-wrap"> </span>break;</div><div>+<span style="white-space:pre-wrap"> </span>case KeyEvent.KEYCODE_DPAD_LEFT:</div><div>+<span style="white-space:pre-wrap"> </span>if (newPosition > 0)</div><div>+<span style="white-space:pre-wrap"> </span>newPosition--;</div><div>+<span style="white-space:pre-wrap"> </span>break;</div><div>+<span style="white-space:pre-wrap"> </span>default:</div><div>+<span style="white-space:pre-wrap"> </span>return false;</div><div>+<span style="white-space:pre-wrap"> </span>}</div><div>+</div><div>+<span style="white-space:pre-wrap"> </span>if (newPosition != mFlingViewPosition) {</div><div>+<span style="white-space:pre-wrap"> </span>mLists[newPosition].setFocusable(true);</div><div>+<span style="white-space:pre-wrap"> </span>mLists[mFlingViewPosition].setFocusable(false);</div><div>+<span style="white-space:pre-wrap"> </span>mFlingViewPosition = newPosition;</div><div>+<span style="white-space:pre-wrap"> </span>mFlingViewGroup.setPosition(mFlingViewPosition);</div><div>+<span style="white-space:pre-wrap"> </span>mFlingViewGroup.scrollTo(mFlingViewPosition);</div><div>+<span style="white-space:pre-wrap"> </span>} </div><div>+</div><div>+ // always return false so that MainActivity may clean up</div><div>+<span style="white-space:pre-wrap"> </span>return false;</div><div>+<span style="white-space:pre-wrap"> </span>}</div><div>+<span style="white-space:pre-wrap"> </span>};</div><div>+<span style="white-space:pre-wrap"> </span>// Focus support. End.</div><div>+</div><div> OnItemClickListener songListener = new OnItemClickListener() {</div><div> @Override</div><div> public void onItemClick(AdapterView<?> av, View v, int p, long id) {</div><div>@@ -334,6 +398,11 @@ public class AudioBrowserFragment extends Fragment {</div><div> </div><div> @Override</div><div> public void onSwitched(int position) {</div><div>+<span style="white-space:pre-wrap"> </span>/* Focus support. Before changing to a new list, update</div><div>+<span style="white-space:pre-wrap"> </span> * focus of prior list and the new list.</div><div>+<span style="white-space:pre-wrap"> </span> */</div><div>+<span style="white-space:pre-wrap"> </span>mLists[mFlingViewPosition].setFocusable(false);</div><div>+<span style="white-space:pre-wrap"> </span>mLists[position].setFocusable(true);</div><div> mHeader.highlightTab(mFlingViewPosition, position);</div><div> mFlingViewPosition = position;</div><div> }</div><div><br></div><div>index e576f51..90fd043 100644</div><div>--- a/vlc-android/res/drawable/background_item.xml</div><div>+++ b/vlc-android/res/drawable/background_item.xml</div><div>@@ -1,5 +1,10 @@</div><div> <?xml version="1.0" encoding="utf-8"?></div><div> <selector xmlns:android="<a href="http://schemas.android.com/apk/res/android" target="_blank">http://schemas.android.com/apk/res/android</a>"></div><div>+<span style="white-space:pre-wrap"> </span><item android:state_focused="true" android:state_selected="false"></div><div>+<span style="white-space:pre-wrap"> </span><shape android:shape="rectangle"></div><div>+<span style="white-space:pre-wrap"> </span><solid android:color="@color/darkgrey" /></div><div>+<span style="white-space:pre-wrap"> </span></shape></div><div>+<span style="white-space:pre-wrap"> </span></item></div><div> <item android:state_focused="true" android:state_selected="false"></div><div> <shape android:shape="rectangle"></div><div> <solid android:color="@color/darkgrey" /></div><div><br></div><div>index 68e70af..cf9d950 100644</div><div>--- a/vlc-android/res/layout/audio_browser.xml</div><div>+++ b/vlc-android/res/layout/audio_browser.xml</div><div>@@ -12,8 +12,8 @@</div><div> <span style="white-space:pre-wrap"> </span> android:scrollbars="none"</div><div> <span style="white-space:pre-wrap"> </span> android:fadingEdge="none"</div><div> <span style="white-space:pre-wrap"> </span> android:layout_width="fill_parent"</div><div>-<span style="white-space:pre-wrap"> </span> android:background="?attr/background_header"></div><div>+<span style="white-space:pre-wrap"> </span>android:background="@drawable/background_header_item"> </div><div> <span style="white-space:pre-wrap"> </span> <LinearLayout</div><div> <span style="white-space:pre-wrap"> </span> android:id="@+id/header_layout"</div><div> <span style="white-space:pre-wrap"> </span> android:layout_width="wrap_content"</div></div><div><br></div></div>
</blockquote></div>