55import android .content .Context ;
66import android .content .Intent ;
77import android .content .IntentFilter ;
8- import android .graphics .Color ;
9- import android .graphics .drawable .ColorDrawable ;
108import android .os .Bundle ;
11- import android .support .v4 .app .ListFragment ;
9+ import android .support .v4 .app .Fragment ;
1210import android .view .LayoutInflater ;
1311import android .view .View ;
1412import android .view .ViewGroup ;
13+ import android .widget .AdapterView ;
14+ import android .widget .LinearLayout ;
15+ import android .widget .ListAdapter ;
1516import android .widget .ListView ;
1617
1718import com .dappervision .wearscript .HardwareDetector ;
1819import com .dappervision .wearscript .WearScriptInfo ;
1920import com .dappervision .wearscript .WearScriptsAdapter ;
21+ import com .dappervision .wearscript .WearScriptsCardAdapter ;
2022import com .dappervision .wearscript .models .InstalledScripts ;
23+ import com .google .android .glass .widget .CardScrollAdapter ;
24+ import com .google .android .glass .widget .CardScrollView ;
2125
22- public class ScriptListFragment extends ListFragment {
26+
27+ public class ScriptListFragment extends Fragment {
28+ //private static final String TAG = "ScriptListFragment";
2329 private InstalledScripts mInstalledScripts ;
24- private ListView listView ;
30+ private AdapterView adapterView ;
2531 private Callbacks mCallbacks ;
32+ private ListAdapter mListAdapter ;
2633
2734 public static ScriptListFragment newInstance () {
2835 ScriptListFragment fragment = new ScriptListFragment ();
@@ -47,7 +54,14 @@ public void onDetach() {
4754
4855 public void updateUI () {
4956 mInstalledScripts .load ();
50- ((WearScriptsAdapter ) getListAdapter ()).notifyDataSetChanged ();
57+ }
58+
59+ public ListAdapter buildListAdapter (){
60+ if (HardwareDetector .isGlass ){
61+ return new WearScriptsCardAdapter (this , mInstalledScripts );
62+ }else {
63+ return new WearScriptsAdapter (this , mInstalledScripts );
64+ }
5165 }
5266
5367 @ Override
@@ -58,28 +72,30 @@ public void onCreate(Bundle savedInstanceState) {
5872 intentFilter .addAction (Intent .ACTION_PACKAGE_ADDED );
5973 intentFilter .addDataScheme ("package" );
6074 getActivity ().registerReceiver (mPackageBroadcastReciever , intentFilter );
61- setListAdapter ( new WearScriptsAdapter ( this , mInstalledScripts ) );
75+ mListAdapter = buildListAdapter ( );
6276 }
6377
6478 @ Override
6579 public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
66- View v = super . onCreateView ( inflater , container , savedInstanceState );
67- listView = ( ListView ) v . findViewById ( android . R . id . list );
68- //Style things for Glass
69- if ( HardwareDetector . isGlass ) {
70- listView . setHorizontalScrollBarEnabled ( false );
71- listView . setVerticalScrollBarEnabled ( false ) ;
72- listView . setSelector ( new ColorDrawable ( Color . TRANSPARENT ));
73- listView . setDivider ( new ColorDrawable ( Color . TRANSPARENT ));
74- listView . setDividerHeight ( 10 );
80+ LinearLayout layout = new LinearLayout ( getActivity () );
81+ if ( HardwareDetector . isGlass ){
82+ CardScrollView view = new CardScrollView ( getActivity ());
83+ view . setAdapter (( CardScrollAdapter ) mListAdapter );
84+ view . activate ( );
85+ adapterView = view ;
86+ } else {
87+ adapterView = new ListView ( getActivity ( ));
88+ adapterView . setAdapter ( mListAdapter );
7589 }
76- return v ;
90+ adapterView .setOnItemClickListener (mOnItemClickListener );
91+ layout .addView (adapterView );
92+ return layout ;
7793 }
7894
7995 @ Override
80- public void onListItemClick ( ListView l , View v , int position , long id ) {
81- WearScriptInfo info = (( WearScriptsAdapter ) getListAdapter ()). getItem ( position );
82- mCallbacks . onScriptSelected ( info );
96+ public void onResume ( ) {
97+ super . onResume ( );
98+ adapterView . requestFocus ( );
8399 }
84100
85101 @ Override
@@ -94,4 +110,12 @@ public void onReceive(Context context, Intent intent) {
94110 updateUI ();
95111 }
96112 };
113+
114+ AdapterView .OnItemClickListener mOnItemClickListener = new AdapterView .OnItemClickListener () {
115+ @ Override
116+ public void onItemClick (AdapterView <?> adapterView , View view , int i , long l ) {
117+ WearScriptInfo info = (WearScriptInfo ) mListAdapter .getItem (i );
118+ mCallbacks .onScriptSelected (info );
119+ }
120+ };
97121}
0 commit comments