Back to project page Muse.
The source code is released under:
Apache License
If you think the Android project Muse listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.prt2121.muse; /*from ww w .j a v a2 s . c o m*/ import com.google.android.glass.view.WindowUtils; import com.google.android.glass.widget.CardBuilder; import com.google.android.glass.widget.CardScrollAdapter; import com.google.android.glass.widget.CardScrollView; import com.prt2121.muse.MusicUtils.ServiceToken; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; import android.net.Uri; import android.os.Bundle; import android.os.IBinder; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.AdapterView; import java.io.File; import static com.prt2121.muse.MusicUtils.mService; public class MainActivity extends BaseGlassActivity implements ServiceConnection { private CardScrollView mCardScroller; private View mView; private ServiceToken mToken; @Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); mToken = MusicUtils.bindToService(this, this); mView = buildView(); mCardScroller = new CardScrollView(this); mCardScroller.setAdapter(new CardScrollAdapter() { @Override public int getCount() { return 1; } @Override public Object getItem(int position) { return mView; } @Override public View getView(int position, View convertView, ViewGroup parent) { return mView; } @Override public int getPosition(Object item) { if (mView.equals(item)) { return 0; } return AdapterView.INVALID_POSITION; } }); setContentView(mCardScroller); } @Override protected void onResume() { super.onResume(); mCardScroller.activate(); } @Override protected void onPause() { mCardScroller.deactivate(); super.onPause(); } @Override protected void onDestroy() { super.onDestroy(); if (mService != null) { MusicUtils.unbindFromService(mToken); mToken = null; } } protected boolean onTap() { openOptionsMenu(); return false; } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { if (featureId == WindowUtils.FEATURE_VOICE_COMMANDS || featureId == Window.FEATURE_OPTIONS_PANEL) { switch (item.getItemId()) { case R.id.play_menu_item: startPlayback(); break; case R.id.stop_menu_item: MusicUtils.playOrPause(); break; default: return true; } return true; } return super.onMenuItemSelected(featureId, item); } private View buildView() { CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT); card.setText(R.string.hello_world); return card.getView(); } @Override public void onServiceConnected(ComponentName name, IBinder service) { mService = IPlayerService.Stub.asInterface(service); } @Override public void onServiceDisconnected(ComponentName name) { mService = null; } private void startPlayback() { Uri uri = Uri.fromFile(new File("/sdcard/test.mp3")); Log.v(MainActivity.class.getSimpleName(), "uri: " + uri.toString()); if (uri != null && uri.toString().length() > 0) { MusicUtils.playFile(this, uri); // Make sure to process intent only once // TODO ? setIntent(new Intent()); } } }